Don't use runningPlayerLists in server, as all in players are not in these lists. Fixed game state in lobby for players joining after a game started.

This commit is contained in:
lotodore
2007-09-29 22:50:57 +00:00
parent 27b82a4260
commit 879cac4bbc
5 changed files with 27 additions and 15 deletions
+14 -10
View File
@@ -30,6 +30,8 @@
#include <playerinterface.h>
#include <handinterface.h>
#include <boost/bind.hpp>
#include <sstream>
using namespace std;
@@ -551,18 +553,19 @@ ServerGameStateStartRound::Process(ServerGameThread &server)
{
assert(newRound > curRound);
// Retrieve non-fold players. If only one player is left, no cards are shown.
PlayerList runningPlayers = curGame.getRunningPlayerList();
list<boost::shared_ptr<PlayerInterface> > nonFoldPlayers = *curGame.getActivePlayerList();
nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD);
if (curGame.getCurrentHand()->getAllInCondition()
&& !curGame.getCurrentHand()->getCardsShown()
&& runningPlayers->size() > 1)
&& nonFoldPlayers.size() > 1)
{
// Send cards of all active players to all players (all in).
boost::shared_ptr<NetPacket> allIn(new NetPacketAllInShowCards);
NetPacketAllInShowCards::Data allInData;
PlayerListConstIterator i = runningPlayers->begin();
PlayerListConstIterator end = runningPlayers->end();
PlayerListConstIterator i = nonFoldPlayers.begin();
PlayerListConstIterator end = nonFoldPlayers.end();
while (i != end)
{
@@ -621,13 +624,14 @@ ServerGameStateStartRound::Process(ServerGameThread &server)
curGame.getCurrentHand()->getCurrentBeRo()->postRiverRun();
// Retrieve non-fold players. If only one player is left, no cards are shown.
PlayerList runningPlayers = curGame.getRunningPlayerList();
// if (runningPlayers.empty()) TODO throw exception
list<boost::shared_ptr<PlayerInterface> > nonFoldPlayers = *curGame.getActivePlayerList();
nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD);
// if (nonFoldPlayers.empty()) TODO throw exception
if (runningPlayers->size() == 1)
if (nonFoldPlayers.size() == 1)
{
// End of Hand, but keep cards hidden.
boost::shared_ptr<PlayerInterface> player = runningPlayers->front();
boost::shared_ptr<PlayerInterface> player = nonFoldPlayers.front();
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandHideCards);
NetPacketEndOfHandHideCards::Data endHandData;
endHandData.playerId = player->getMyUniqueID();
@@ -643,8 +647,8 @@ ServerGameStateStartRound::Process(ServerGameThread &server)
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandShowCards);
NetPacketEndOfHandShowCards::Data endHandData;
PlayerListConstIterator i = runningPlayers->begin();
PlayerListConstIterator end = runningPlayers->end();
PlayerListConstIterator i = nonFoldPlayers.begin();
PlayerListConstIterator end = nonFoldPlayers.end();
while (i != end)
{
+8 -2
View File
@@ -158,8 +158,6 @@ ServerGameThread::Main()
void
ServerGameThread::InternalStartGame()
{
GetLobbyThread().NotifyStartingGame(GetId());
// Set order of players.
AssignPlayerNumbers();
@@ -196,6 +194,8 @@ ServerGameThread::InternalStartGame()
SetStartData(startData);
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), GetNextGameNum()));
GetLobbyThread().NotifyStartingGame(GetId());
}
void
@@ -264,6 +264,12 @@ ServerGameThread::IsPlayerConnected(const std::string &name) const
return GetSessionManager().IsPlayerConnected(name);
}
bool
ServerGameThread::IsRunning() const
{
return m_game.get() != NULL;
}
void
ServerGameThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
{
+1 -1
View File
@@ -671,7 +671,7 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
boost::shared_ptr<NetPacket> packet(new NetPacketGameListNew);
NetPacketGameListNew::Data packetData;
packetData.gameId = game.GetId();
packetData.gameInfo.mode = GAME_MODE_CREATED;
packetData.gameInfo.mode = game.IsRunning() ? GAME_MODE_STARTED : GAME_MODE_CREATED;
packetData.gameInfo.name = game.GetName();
packetData.gameInfo.data = game.GetGameData();
packetData.gameInfo.players = game.GetPlayerIdList();
+3 -1
View File
@@ -66,6 +66,8 @@ public:
PlayerIdList GetPlayerIdList() const;
bool IsPlayerConnected(const std::string &name) const;
bool IsRunning() const;
protected:
typedef std::deque<SessionWrapper> SessionQueue;
@@ -129,7 +131,7 @@ private:
GameData m_gameData;
StartData m_startData;
std::auto_ptr<Game> m_game;
boost::shared_ptr<Game> m_game;
const u_int32_t m_id;
const std::string m_name;
const std::string m_password;
+1 -1
View File
@@ -32,7 +32,7 @@
#define NET_CLIENT_TERMINATE_TIMEOUT_MSEC 1000
#define NET_SERVER_TERMINATE_TIMEOUT_MSEC 2000
#define NET_IRC_TERMINATE_TIMEOUT_MSEC 2000
#define NET_IRC_TERMINATE_TIMEOUT_MSEC 5000
#define NET_DEFAULT_GAME "default"