Trying to bring life to the server.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <gamedata.h>
|
||||
#include <game.h>
|
||||
#include <playerinterface.h>
|
||||
#include <handinterface.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -258,10 +259,12 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> answer(new NetPacketHandStart);
|
||||
|
||||
// Initialize hand.
|
||||
Game &curGame = server.GetGame();
|
||||
curGame.initHand();
|
||||
PlayerInterface **playerArray = curGame.getPlayerArray();
|
||||
|
||||
// Send cards to all players.
|
||||
for (int i = 0; i < curGame.getActualQuantityPlayers(); i++)
|
||||
{
|
||||
if (playerArray[i]->getNetSessionData().get())
|
||||
@@ -278,13 +281,51 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
||||
}
|
||||
}
|
||||
|
||||
server.SetState(ServerRecvStateFinal::Instance());
|
||||
// Start hand.
|
||||
curGame.startHand();
|
||||
|
||||
server.SetState(ServerRecvStateStartRound::Instance());
|
||||
|
||||
return MSG_NET_GAME_SERVER_HAND;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateStartRound &
|
||||
ServerRecvStateStartRound::Instance()
|
||||
{
|
||||
static ServerRecvStateStartRound state;
|
||||
return state;
|
||||
}
|
||||
|
||||
ServerRecvStateStartRound::ServerRecvStateStartRound()
|
||||
{
|
||||
}
|
||||
|
||||
ServerRecvStateStartRound::~ServerRecvStateStartRound()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateStartRound::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// TODO: send error msg
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateStartRound::Process(ServerRecvThread &server)
|
||||
{
|
||||
Game &curGame = server.GetGame();
|
||||
|
||||
curGame.getCurrentHand()->switchRounds();
|
||||
|
||||
server.SetState(ServerRecvStateFinal::Instance());
|
||||
|
||||
return MSG_NET_GAME_SERVER_ROUND;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateFinal &
|
||||
ServerRecvStateFinal::Instance()
|
||||
{
|
||||
|
||||
@@ -109,6 +109,27 @@ protected:
|
||||
ServerRecvStateStartHand();
|
||||
};
|
||||
|
||||
// State: Start new round.
|
||||
class ServerRecvStateStartRound : public ServerRecvState
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
static ServerRecvStateStartRound &Instance();
|
||||
|
||||
virtual ~ServerRecvStateStartRound();
|
||||
|
||||
//
|
||||
virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> data);
|
||||
|
||||
//
|
||||
virtual int Process(ServerRecvThread &server);
|
||||
|
||||
protected:
|
||||
|
||||
// Protected constructor - this is a singleton.
|
||||
ServerRecvStateStartRound();
|
||||
};
|
||||
|
||||
// State: Final.
|
||||
class ServerRecvStateFinal : public ServerRecvState
|
||||
{
|
||||
|
||||
@@ -159,6 +159,7 @@ private:
|
||||
friend class ServerRecvStateInit;
|
||||
friend class ServerRecvStateStartGame;
|
||||
friend class ServerRecvStateStartHand;
|
||||
friend class ServerRecvStateStartRound;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
#define MSG_NET_GAME_SERVER_START 6
|
||||
#define MSG_NET_GAME_CLIENT_HAND 7
|
||||
#define MSG_NET_GAME_SERVER_HAND 8
|
||||
#define MSG_NET_GAME_SERVER_ROUND 10
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user