The console server can now be fully used for a single game. The first player to join the game is admin, he can start the game and kick players.

However, if the admin player leaves, a new game can only be started if all players have left before (this is a bug, admin status should be passed to another player).
This commit is contained in:
lotodore
2007-08-02 20:52:13 +00:00
parent f11998c28c
commit 0da29b3874
25 changed files with 481 additions and 262 deletions
+35 -13
View File
@@ -1,4 +1,6 @@
Changelog: Changelog:
08-02-2007: Added new requests for game start and kick player.
Type ids changed.
07-24-2007: Join Game ACK / Player Joined do not specify player number. 07-24-2007: Join Game ACK / Player Joined do not specify player number.
Player order is transferred on game start. Player order is transferred on game start.
This is not compatible to the previous protocol. This is not compatible to the previous protocol.
@@ -113,12 +115,32 @@ Server Notification: Player Left
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Client Request: Kick Player
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 5 | Message Length = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Player ID | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Client Request: Start Event
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 6 | Message Length = 4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Server Notification: Game Start Server Notification: Game Start
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 5 | Message Length | | Message Type = 7 | Message Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Start Dealer Player Id | Number of Players | | Start Dealer Player Id | Number of Players |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -147,7 +169,7 @@ Server Notification: Hand Start
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 6 | Message Length = 8 | | Message Type = 8 | Message Length = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Your 1st Card | Your 2nd Card | | Your 1st Card | Your 2nd Card |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -161,7 +183,7 @@ Server Request/Notification: Player's Turn
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 7 | Message Length = 8 | | Message Type = 9 | Message Length = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Game State | Player ID | | Game State | Player ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -178,7 +200,7 @@ Client Reply/Request: Player's Action
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 8 | Message Length = 12 | | Message Type = 10 | Message Length = 12 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Game State | Player Action | | Game State | Player Action |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -203,7 +225,7 @@ Server Notification: Player's Action Done
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 9 | Message Length = 20 | | Message Type = 11 | Message Length = 20 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Game State | Player Id | | Game State | Player Id |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -224,7 +246,7 @@ Server Reply: Player's Action Rejected
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 10 | Message Length = 16 | | Message Type = 12 | Message Length = 16 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Game State | Player Action | | Game State | Player Action |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -252,7 +274,7 @@ Server Notification: Deal Flop Cards
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 11 | Message Length = 12 | | Message Type = 13 | Message Length = 12 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flop 1st Card | Flop 2nd Card | | Flop 1st Card | Flop 2nd Card |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -265,7 +287,7 @@ Server Notification: Deal Turn Card
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 12 | Message Length = 8 | | Message Type = 14 | Message Length = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Turn Card | Reserved | | Turn Card | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -276,7 +298,7 @@ Server Notification: Deal River Card
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 13 | Message Length = 8 | | Message Type = 15 | Message Length = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| River Card | Reserved | | River Card | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -287,7 +309,7 @@ Server Notification: All In Show Cards
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 14 | Message Length | | Message Type = 16 | Message Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Number Of PlayerCards Records | Reserved | | Number Of PlayerCards Records | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -309,7 +331,7 @@ Server Notification: End Of Hand Show Cards
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 15 | Message Length | | Message Type = 17 | Message Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Number Of PlayerResult Records | Reserved | |Number Of PlayerResult Records | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -341,7 +363,7 @@ Server Notification: End Of Hand Hide Cards
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 16 | Message Length = 16 | | Message Type = 18 | Message Length = 16 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Player Id | Reserved | | Player Id | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -356,7 +378,7 @@ Server Notification: End Of Game
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 17 | Message Length = 8 | | Message Type = 19 | Message Length = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Winner Player Id | Reserved | | Winner Player Id | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+2 -2
View File
@@ -105,7 +105,8 @@ void ServerGuiWrapper::logPlayerWinGame(std::string playerName, int gameID) {}
void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); } void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); }
void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); } void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); }
void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); } void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); }
void ServerGuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerName); } void ServerGuiWrapper::SignalNetClientSelfJoined(const string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientSelfJoined(playerName, rights); }
void ServerGuiWrapper::SignalNetClientPlayerJoined(const string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerName, rights); }
void ServerGuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerLeft(playerName); } void ServerGuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerLeft(playerName); }
void ServerGuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); } void ServerGuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); }
void ServerGuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientChatMsg(playerName, msg); } void ServerGuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientChatMsg(playerName, msg); }
@@ -115,5 +116,4 @@ void ServerGuiWrapper::SignalNetServerSuccess(int actionID) { if (myServercb) my
void ServerGuiWrapper::SignalNetServerError(int errorID, int osErrorID) { if (myServercb) myServercb->SignalNetServerError(errorID, osErrorID); } void ServerGuiWrapper::SignalNetServerError(int errorID, int osErrorID) { if (myServercb) myServercb->SignalNetServerError(errorID, osErrorID); }
void ServerGuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerJoined(playerName); } void ServerGuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerJoined(playerName); }
void ServerGuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerLeft(playerName); } void ServerGuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerLeft(playerName); }
void ServerGuiWrapper::SignalNetServerStartDialog() { if (myServercb) myServercb->SignalNetServerStartDialog(); }
+2 -2
View File
@@ -89,7 +89,8 @@ public:
void SignalNetClientConnect(int actionID); void SignalNetClientConnect(int actionID);
void SignalNetClientGameInfo(int actionID); void SignalNetClientGameInfo(int actionID);
void SignalNetClientError(int errorID, int osErrorID); void SignalNetClientError(int errorID, int osErrorID);
void SignalNetClientPlayerJoined(const std::string &playerName); void SignalNetClientSelfJoined(const std::string &playerName, PlayerRights rights);
void SignalNetClientPlayerJoined(const std::string &playerName, PlayerRights rights);
void SignalNetClientPlayerLeft(const std::string &playerName); void SignalNetClientPlayerLeft(const std::string &playerName);
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg); void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientWaitDialog(); void SignalNetClientWaitDialog();
@@ -100,7 +101,6 @@ public:
void SignalNetServerError(int errorID, int osErrorID); void SignalNetServerError(int errorID, int osErrorID);
void SignalNetServerPlayerJoined(const std::string &playerName); void SignalNetServerPlayerJoined(const std::string &playerName);
void SignalNetServerPlayerLeft(const std::string &playerName); void SignalNetServerPlayerLeft(const std::string &playerName);
void SignalNetServerStartDialog();
private: private:
+5 -5
View File
@@ -107,7 +107,8 @@ void GuiWrapper::logPlayerWinGame(std::string playerName, int gameID) { myLog->s
void GuiWrapper::SignalNetClientConnect(int actionID) { myW->signalNetClientConnect(actionID); } void GuiWrapper::SignalNetClientConnect(int actionID) { myW->signalNetClientConnect(actionID); }
void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->signalNetClientGameInfo(actionID); } void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->signalNetClientGameInfo(actionID); }
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); } void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); }
void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str())); } void GuiWrapper::SignalNetClientSelfJoined(const string &playerName, PlayerRights rights) { myW->signalNetClientSelfJoined(QString::fromUtf8(playerName.c_str()), rights); }
void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName, PlayerRights rights) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str()), rights); }
void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName) void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName)
{ {
QString tmpName(QString::fromUtf8(playerName.c_str())); QString tmpName(QString::fromUtf8(playerName.c_str()));
@@ -116,11 +117,10 @@ void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName)
} }
void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myW->signalNetClientGameStart(game); } void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myW->signalNetClientGameStart(game); }
void GuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { myChat->signalChatMessage(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); } void GuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { myChat->signalChatMessage(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); }
void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowClientWaitDialog(); } void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowNetworkStartDialog(); }
void GuiWrapper::SignalNetServerSuccess(int actionID) { } void GuiWrapper::SignalNetServerSuccess(int actionID) { }
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { myW->signalNetServerError(errorID, osErrorID); } void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { myW->signalNetServerError(errorID, osErrorID); }
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->signalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); } void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { }
void GuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { myW->signalNetServerPlayerLeft(QString::fromUtf8(playerName.c_str())); } void GuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { }
void GuiWrapper::SignalNetServerStartDialog() { myW->signalShowServerStartDialog(); }
+2 -5
View File
@@ -42,9 +42,6 @@ public:
Session &getSession(); Session &getSession();
void setSession(boost::shared_ptr<Session> session); void setSession(boost::shared_ptr<Session> session);
void showServerStartDialog();
void showClientWaitDialog();
void refreshSet() const; void refreshSet() const;
void refreshCash() const; void refreshCash() const;
void refreshAction(int =-1, int =-1) const; void refreshAction(int =-1, int =-1) const;
@@ -99,7 +96,8 @@ public:
void SignalNetClientConnect(int actionID); void SignalNetClientConnect(int actionID);
void SignalNetClientGameInfo(int actionID); void SignalNetClientGameInfo(int actionID);
void SignalNetClientError(int errorID, int osErrorID); void SignalNetClientError(int errorID, int osErrorID);
void SignalNetClientPlayerJoined(const std::string &playerName); void SignalNetClientSelfJoined(const std::string &playerName, PlayerRights rights);
void SignalNetClientPlayerJoined(const std::string &playerName, PlayerRights rights);
void SignalNetClientPlayerLeft(const std::string &playerName); void SignalNetClientPlayerLeft(const std::string &playerName);
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg); void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientWaitDialog(); void SignalNetClientWaitDialog();
@@ -110,7 +108,6 @@ public:
void SignalNetServerError(int errorID, int osErrorID); void SignalNetServerError(int errorID, int osErrorID);
void SignalNetServerPlayerJoined(const std::string &playerName); void SignalNetServerPlayerJoined(const std::string &playerName);
void SignalNetServerPlayerLeft(const std::string &playerName); void SignalNetServerPlayerLeft(const std::string &playerName);
void SignalNetServerStartDialog();
private: private:
+14 -33
View File
@@ -587,8 +587,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
//Nachrichten Thread-Save //Nachrichten Thread-Save
connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int))); connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int)));
connect(this, SIGNAL(signalShowServerStartDialog()), this, SLOT(showServerStartDialog())); connect(this, SIGNAL(signalShowNetworkStartDialog()), this, SLOT(showNetworkStartDialog()));
connect(this, SIGNAL(signalShowClientWaitDialog()), this, SLOT(showClientWaitDialog()));
connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet())); connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet()));
connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash())); connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash()));
@@ -631,18 +630,16 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
connect(this, SIGNAL(signalNextRoundCleanGui()), this, SLOT(nextRoundCleanGui())); connect(this, SIGNAL(signalNextRoundCleanGui()), this, SLOT(nextRoundCleanGui()));
connect(this, SIGNAL(signalNetClientConnect(int)), myConnectToServerDialog, SLOT(refresh(int))); connect(this, SIGNAL(signalNetClientConnect(int)), myConnectToServerDialog, SLOT(refresh(int)));
connect(this, SIGNAL(signalNetClientGameInfo(int)), myWaitingForServerGameDialog, SLOT(refresh(int))); connect(this, SIGNAL(signalNetClientGameInfo(int)), myStartNetworkGameDialog, SLOT(refresh(int)));
connect(this, SIGNAL(signalNetClientPlayerJoined(QString)), myWaitingForServerGameDialog, SLOT(addConnectedPlayer(QString))); connect(this, SIGNAL(signalNetClientSelfJoined(QString, int)), myStartNetworkGameDialog, SLOT(joinedNetworkGame(QString, int)));
connect(this, SIGNAL(signalNetClientPlayerLeft(QString)), myWaitingForServerGameDialog, SLOT(removePlayer(QString))); connect(this, SIGNAL(signalNetClientPlayerJoined(QString, int)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString, int)));
connect(this, SIGNAL(signalNetClientPlayerLeft(QString)), myStartNetworkGameDialog, SLOT(removePlayer(QString)));
// Errors are handled globally, not within one dialog. // Errors are handled globally, not within one dialog.
connect(this, SIGNAL(signalNetClientError(int, int)), this, SLOT(networkError(int, int))); connect(this, SIGNAL(signalNetClientError(int, int)), this, SLOT(networkError(int, int)));
connect(this, SIGNAL(signalNetServerError(int, int)), this, SLOT(networkError(int, int))); connect(this, SIGNAL(signalNetServerError(int, int)), this, SLOT(networkError(int, int)));
connect(this, SIGNAL(signalNetClientGameStart(boost::shared_ptr<Game>)), this, SLOT(networkStart(boost::shared_ptr<Game>))); connect(this, SIGNAL(signalNetClientGameStart(boost::shared_ptr<Game>)), this, SLOT(networkStart(boost::shared_ptr<Game>)));
connect(this, SIGNAL(signalNetServerPlayerJoined(QString)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString)));
connect(this, SIGNAL(signalNetServerPlayerLeft(QString)), myStartNetworkGameDialog, SLOT(removePlayer(QString)));
//Sound //Sound
mySDLPlayer = new SDLPlayer(myConfig); mySDLPlayer = new SDLPlayer(myConfig);
@@ -743,7 +740,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
gameData.guiSpeed = 4; gameData.guiSpeed = 4;
gameData.playerActionTimeoutSec = myCreateNetworkGameDialog->spinBox_netTimeOutPlayerAction->value(); gameData.playerActionTimeoutSec = myCreateNetworkGameDialog->spinBox_netTimeOutPlayerAction->value();
myStartNetworkGameDialog->setSession(&myServerGuiInterface->getSession()); myStartNetworkGameDialog->setSession(&getSession());
myStartNetworkGameDialog->treeWidget->clear(); myStartNetworkGameDialog->treeWidget->clear();
myServerGuiInterface->getSession().startNetworkServer(gameData); myServerGuiInterface->getSession().startNetworkServer(gameData);
@@ -751,7 +748,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
myStartNetworkGameDialog->setMaxPlayerNumber(gameData.maxNumberOfPlayers); myStartNetworkGameDialog->setMaxPlayerNumber(gameData.maxNumberOfPlayers);
showServerStartDialog(); showNetworkStartDialog();
} }
} }
@@ -766,7 +763,8 @@ void mainWindowImpl::callJoinNetworkGameDialog() {
if (myServerGuiInterface.get()) if (myServerGuiInterface.get())
myServerGuiInterface->getSession().terminateNetworkServer(); myServerGuiInterface->getSession().terminateNetworkServer();
myWaitingForServerGameDialog->treeWidget->clear(); myStartNetworkGameDialog->setSession(&getSession());
myStartNetworkGameDialog->treeWidget->clear();
// Maybe use QUrl::toPunycode. // Maybe use QUrl::toPunycode.
mySession->startNetworkClient( mySession->startNetworkClient(
myJoinNetworkGameDialog->lineEdit_ipAddress->text().toUtf8().constData(), myJoinNetworkGameDialog->lineEdit_ipAddress->text().toUtf8().constData(),
@@ -783,7 +781,7 @@ void mainWindowImpl::callJoinNetworkGameDialog() {
actionJoin_network_Game->trigger(); // re-trigger actionJoin_network_Game->trigger(); // re-trigger
} }
else { else {
showClientWaitDialog(); showNetworkStartDialog();
} }
} }
} }
@@ -891,7 +889,7 @@ void mainWindowImpl::initGui(int speed)
} }
} }
void mainWindowImpl::showServerStartDialog() void mainWindowImpl::showNetworkStartDialog()
{ {
myStartNetworkGameDialog->exec(); myStartNetworkGameDialog->exec();
@@ -899,28 +897,11 @@ void mainWindowImpl::showServerStartDialog()
//some gui modifications //some gui modifications
networkGameModification(); networkGameModification();
myServerGuiInterface->getSession().initiateNetworkServerGame();
} }
else { else {
mySession->terminateNetworkClient(); mySession->terminateNetworkClient();
myServerGuiInterface->getSession().terminateNetworkServer(); if (myServerGuiInterface)
} myServerGuiInterface->getSession().terminateNetworkServer();
}
void mainWindowImpl::showClientWaitDialog()
{
if (!myServerGuiInterface.get() || !myServerGuiInterface->getSession().isNetworkServerRunning())
{
myWaitingForServerGameDialog->exec();
if (myWaitingForServerGameDialog->result() == QDialog::Accepted) {
//some gui modifications
networkGameModification();
}
else {
mySession->terminateNetworkClient();
}
} }
} }
@@ -2547,7 +2528,7 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
} }
// close dialogs // close dialogs
myConnectToServerDialog->reject(); myConnectToServerDialog->reject();
myWaitingForServerGameDialog->reject(); myStartNetworkGameDialog->reject();
} }
void mainWindowImpl::networkStart(boost::shared_ptr<Game> game) void mainWindowImpl::networkStart(boost::shared_ptr<Game> game)
+4 -7
View File
@@ -76,8 +76,7 @@ public:
signals: signals:
void signalInitGui(int speed); void signalInitGui(int speed);
void signalShowServerStartDialog(); void signalShowNetworkStartDialog();
void signalShowClientWaitDialog();
void signalRefreshSet(); void signalRefreshSet();
void signalRefreshCash(); void signalRefreshCash();
@@ -123,18 +122,16 @@ signals:
void signalNetClientGameInfo(int actionID); void signalNetClientGameInfo(int actionID);
void signalNetClientError(int errorID, int osErrorID); void signalNetClientError(int errorID, int osErrorID);
void signalNetServerError(int errorID, int osErrorID); void signalNetServerError(int errorID, int osErrorID);
void signalNetClientPlayerJoined(QString playerName); void signalNetClientSelfJoined(QString playerName, int rights);
void signalNetClientPlayerJoined(QString playerName, int rights);
void signalNetClientPlayerLeft(QString playerName); void signalNetClientPlayerLeft(QString playerName);
void signalNetClientGameStart(boost::shared_ptr<Game> game); void signalNetClientGameStart(boost::shared_ptr<Game> game);
void signalNetServerPlayerJoined(QString playerName);
void signalNetServerPlayerLeft(QString playerName);
public slots: public slots:
void initGui(int speed); void initGui(int speed);
void showServerStartDialog(); void showNetworkStartDialog();
void showClientWaitDialog();
//refresh-Funktionen //refresh-Funktionen
void refreshSet(); void refreshSet();
@@ -20,9 +20,10 @@
#include "startnetworkgamedialogimpl.h" #include "startnetworkgamedialogimpl.h"
#include "session.h" #include "session.h"
#include "configfile.h" #include "configfile.h"
#include <net/socket_msg.h>
startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFile *config) startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFile *config)
: QDialog(parent), myConfig(config) : QDialog(parent), myConfig(config), isAdmin(false)
{ {
setupUi(this); setupUi(this);
@@ -36,15 +37,29 @@ startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFi
} }
void startNetworkGameDialogImpl::startGame() { void startNetworkGameDialogImpl::startGame() {
assert(mySession);
mySession->sendStartEvent();
} }
void startNetworkGameDialogImpl::cancel() { void startNetworkGameDialogImpl::cancel() {
} }
void startNetworkGameDialogImpl::refresh(int actionID) {
void startNetworkGameDialogImpl::addConnectedPlayer(QString playerName) { if (actionID == MSG_NET_GAME_CLIENT_START)
{
QTimer::singleShot(500, this, SLOT(accept()));
}
}
void startNetworkGameDialogImpl::joinedNetworkGame(QString playerName, int rights) {
isAdmin = rights == PLAYER_RIGHTS_ADMIN;
addConnectedPlayer(playerName, rights);
}
void startNetworkGameDialogImpl::addConnectedPlayer(QString playerName, int rights) {
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,0); QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,0);
item->setData(0, 0, playerName); item->setData(0, 0, playerName);
@@ -64,7 +79,7 @@ void startNetworkGameDialogImpl::removePlayer(QString playerName) {
void startNetworkGameDialogImpl::playerSelected(QTreeWidgetItem*, int) { void startNetworkGameDialogImpl::playerSelected(QTreeWidgetItem*, int) {
pushButton_Kick->setEnabled(TRUE); pushButton_Kick->setEnabled(isAdmin);
} }
void startNetworkGameDialogImpl::kickPlayer() { void startNetworkGameDialogImpl::kickPlayer() {
@@ -89,7 +104,7 @@ void startNetworkGameDialogImpl::kickPlayer() {
void startNetworkGameDialogImpl::checkPlayerQuantity() { void startNetworkGameDialogImpl::checkPlayerQuantity() {
if (treeWidget->topLevelItemCount() >= 2) if (treeWidget->topLevelItemCount() >= 2 && isAdmin)
pushButton_startGame->setEnabled(TRUE); pushButton_startGame->setEnabled(TRUE);
else else
pushButton_startGame->setEnabled(FALSE); pushButton_startGame->setEnabled(FALSE);
@@ -37,7 +37,9 @@ public slots:
void startGame(); void startGame();
void cancel(); void cancel();
void addConnectedPlayer(QString playerName); void refresh(int actionID);
void joinedNetworkGame(QString playerName, int rights);
void addConnectedPlayer(QString playerName, int rights);
void removePlayer(QString playerName); void removePlayer(QString playerName);
void playerSelected(QTreeWidgetItem*, int); void playerSelected(QTreeWidgetItem*, int);
void kickPlayer(); void kickPlayer();
@@ -54,6 +56,7 @@ public slots:
private: private:
int maxPlayerNumber; int maxPlayerNumber;
bool isAdmin;
ConfigFile *myConfig; ConfigFile *myConfig;
Session *mySession; Session *mySession;
}; };
+3 -1
View File
@@ -23,6 +23,7 @@
#include <string> #include <string>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <playerdata.h>
class Game; class Game;
@@ -36,7 +37,8 @@ public:
virtual void SignalNetClientError(int errorID, int osErrorID) = 0; virtual void SignalNetClientError(int errorID, int osErrorID) = 0;
virtual void SignalNetClientGameStart(boost::shared_ptr<Game> game) = 0; virtual void SignalNetClientGameStart(boost::shared_ptr<Game> game) = 0;
virtual void SignalNetClientPlayerJoined(const std::string &playerName) = 0; virtual void SignalNetClientSelfJoined(const std::string &playerName, PlayerRights rights) = 0;
virtual void SignalNetClientPlayerJoined(const std::string &playerName, PlayerRights rights) = 0;
virtual void SignalNetClientPlayerLeft(const std::string &playerName) = 0; virtual void SignalNetClientPlayerLeft(const std::string &playerName) = 0;
virtual void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg) = 0; virtual void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg) = 0;
+3
View File
@@ -52,6 +52,8 @@ public:
const std::string &pwd, const std::string &pwd,
const std::string &playerName); const std::string &playerName);
void SendKickPlayer(const std::string &playerName);
void SendStartEvent();
void SendPlayerAction(); void SendPlayerAction();
void SendChatMessage(const std::string &msg); void SendChatMessage(const std::string &msg);
@@ -89,6 +91,7 @@ protected:
void MapPlayerDataList(); void MapPlayerDataList();
const PlayerDataList &GetPlayerDataList() const; const PlayerDataList &GetPlayerDataList() const;
boost::shared_ptr<PlayerData> GetPlayerDataByUniqueId(unsigned id); boost::shared_ptr<PlayerData> GetPlayerDataByUniqueId(unsigned id);
boost::shared_ptr<PlayerData> GetPlayerDataByName(const std::string &name);
void RemoveDisconnectedPlayers(); void RemoveDisconnectedPlayers();
+2 -2
View File
@@ -447,7 +447,7 @@ ClientStateWaitSession::InternalProcess(ClientThread &client, boost::shared_ptr<
// TODO: Type Human is fixed here. // TODO: Type Human is fixed here.
// Player number is 0 on join. Will be set when the game starts. // Player number is 0 on join. Will be set when the game starts.
boost::shared_ptr<PlayerData> playerData( boost::shared_ptr<PlayerData> playerData(
new PlayerData(joinGameAckData.yourPlayerUniqueId, 0, PLAYER_TYPE_HUMAN)); new PlayerData(joinGameAckData.yourPlayerUniqueId, 0, joinGameAckData.ptype, joinGameAckData.prights));
playerData->SetName(context.GetPlayerName()); playerData->SetName(context.GetPlayerName());
client.AddPlayerData(playerData); client.AddPlayerData(playerData);
@@ -516,7 +516,7 @@ ClientStateWaitGame::InternalProcess(ClientThread &client, boost::shared_ptr<Net
packet->ToNetPacketPlayerJoined()->GetData(netPlayerData); packet->ToNetPacketPlayerJoined()->GetData(netPlayerData);
boost::shared_ptr<PlayerData> playerData( boost::shared_ptr<PlayerData> playerData(
new PlayerData(netPlayerData.playerId, 0, netPlayerData.ptype)); new PlayerData(netPlayerData.playerId, 0, netPlayerData.ptype, netPlayerData.prights));
playerData->SetName(netPlayerData.playerName); playerData->SetName(netPlayerData.playerName);
client.AddPlayerData(playerData); client.AddPlayerData(playerData);
} }
+51 -1
View File
@@ -85,6 +85,30 @@ ClientThread::Init(
context.SetPlayerName(playerName); context.SetPlayerName(playerName);
} }
void
ClientThread::SendKickPlayer(const string &playerName)
{
boost::shared_ptr<PlayerData> tmpPlayer = GetPlayerDataByName(playerName);
if (tmpPlayer.get())
{
boost::shared_ptr<NetPacket> request(new NetPacketKickPlayer);
NetPacketKickPlayer::Data requestData;
requestData.playerId = tmpPlayer->GetUniqueId();
static_cast<NetPacketKickPlayer *>(request.get())->SetData(requestData);
GetSender().Send(GetContext().GetSocket(), request);
}
}
void
ClientThread::SendStartEvent()
{
// Warning: This function is called in the context of the GUI thread.
// Create a network packet for the server start event.
boost::shared_ptr<NetPacket> startEvent(new NetPacketStartEvent);
// The sender is thread-safe, so just dump the packet.
GetSender().Send(GetContext().GetSocket(), startEvent);
}
void void
ClientThread::SendPlayerAction() ClientThread::SendPlayerAction()
{ {
@@ -274,7 +298,10 @@ ClientThread::AddPlayerData(boost::shared_ptr<PlayerData> playerData)
if (playerData.get() && !playerData->GetName().empty()) if (playerData.get() && !playerData->GetName().empty())
{ {
m_playerDataList.push_back(playerData); m_playerDataList.push_back(playerData);
GetCallback().SignalNetClientPlayerJoined(playerData->GetName()); if (playerData->GetUniqueId() == GetGuiPlayerId())
GetCallback().SignalNetClientSelfJoined(playerData->GetName(), playerData->GetRights());
else
GetCallback().SignalNetClientPlayerJoined(playerData->GetName(), playerData->GetRights());
} }
} }
@@ -360,6 +387,29 @@ ClientThread::GetPlayerDataByUniqueId(unsigned id)
return tmpPlayer; return tmpPlayer;
} }
boost::shared_ptr<PlayerData>
ClientThread::GetPlayerDataByName(const std::string &name)
{
boost::shared_ptr<PlayerData> tmpPlayer;
if (!name.empty())
{
PlayerDataList::const_iterator i = m_playerDataList.begin();
PlayerDataList::const_iterator end = m_playerDataList.end();
while (i != end)
{
if ((*i)->GetName() == name)
{
tmpPlayer = *i;
break;
}
++i;
}
}
return tmpPlayer;
}
void void
ClientThread::RemoveDisconnectedPlayers() ClientThread::RemoveDisconnectedPlayers()
{ {
+140 -13
View File
@@ -31,19 +31,21 @@ using namespace std;
#define NET_TYPE_JOIN_GAME_ACK 0x0002 #define NET_TYPE_JOIN_GAME_ACK 0x0002
#define NET_TYPE_PLAYER_JOINED 0x0003 #define NET_TYPE_PLAYER_JOINED 0x0003
#define NET_TYPE_PLAYER_LEFT 0x0004 #define NET_TYPE_PLAYER_LEFT 0x0004
#define NET_TYPE_GAME_START 0x0005 #define NET_TYPE_KICK_PLAYER 0x0005
#define NET_TYPE_HAND_START 0x0006 #define NET_TYPE_START_EVENT 0x0006
#define NET_TYPE_PLAYERS_TURN 0x0007 #define NET_TYPE_GAME_START 0x0007
#define NET_TYPE_PLAYERS_ACTION 0x0008 #define NET_TYPE_HAND_START 0x0008
#define NET_TYPE_PLAYERS_ACTION_DONE 0x0009 #define NET_TYPE_PLAYERS_TURN 0x0009
#define NET_TYPE_PLAYERS_ACTION_REJECTED 0x000A #define NET_TYPE_PLAYERS_ACTION 0x000A
#define NET_TYPE_DEAL_FLOP_CARDS 0x000B #define NET_TYPE_PLAYERS_ACTION_DONE 0x000B
#define NET_TYPE_DEAL_TURN_CARD 0x000C #define NET_TYPE_PLAYERS_ACTION_REJECTED 0x000C
#define NET_TYPE_DEAL_RIVER_CARD 0x000D #define NET_TYPE_DEAL_FLOP_CARDS 0x000D
#define NET_TYPE_ALL_IN_SHOW_CARDS 0x000E #define NET_TYPE_DEAL_TURN_CARD 0x000E
#define NET_TYPE_END_OF_HAND_SHOW_CARDS 0x000F #define NET_TYPE_DEAL_RIVER_CARD 0x000F
#define NET_TYPE_END_OF_HAND_HIDE_CARDS 0x0010 #define NET_TYPE_ALL_IN_SHOW_CARDS 0x0010
#define NET_TYPE_END_OF_GAME 0x0011 #define NET_TYPE_END_OF_HAND_SHOW_CARDS 0x0011
#define NET_TYPE_END_OF_HAND_HIDE_CARDS 0x0012
#define NET_TYPE_END_OF_GAME 0x0013
#define NET_TYPE_SEND_CHAT_TEXT 0x0200 #define NET_TYPE_SEND_CHAT_TEXT 0x0200
#define NET_TYPE_CHAT_TEXT 0x0201 #define NET_TYPE_CHAT_TEXT 0x0201
@@ -126,6 +128,18 @@ struct GCC_PACKED NetPacketPlayerLeftData
u_int16_t reserved; u_int16_t reserved;
}; };
struct GCC_PACKED NetPacketKickPlayerData
{
NetPacketHeader head;
u_int16_t playerId;
u_int16_t reserved;
};
struct GCC_PACKED NetPacketStartEventData
{
NetPacketHeader head;
};
struct GCC_PACKED NetPacketGameStartData struct GCC_PACKED NetPacketGameStartData
{ {
NetPacketHeader head; NetPacketHeader head;
@@ -324,6 +338,12 @@ NetPacket::Create(char *data, unsigned &dataSize)
case NET_TYPE_PLAYER_LEFT: case NET_TYPE_PLAYER_LEFT:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketPlayerLeft); tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketPlayerLeft);
break; break;
case NET_TYPE_KICK_PLAYER:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketKickPlayer);
break;
case NET_TYPE_START_EVENT:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketStartEvent);
break;
case NET_TYPE_GAME_START: case NET_TYPE_GAME_START:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketGameStart); tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketGameStart);
break; break;
@@ -480,6 +500,18 @@ NetPacket::ToNetPacketPlayerLeft() const
return NULL; return NULL;
} }
const NetPacketKickPlayer *
NetPacket::ToNetPacketKickPlayer() const
{
return NULL;
}
const NetPacketStartEvent *
NetPacket::ToNetPacketStartEvent() const
{
return NULL;
}
const NetPacketGameStart * const NetPacketGameStart *
NetPacket::ToNetPacketGameStart() const NetPacket::ToNetPacketGameStart() const
{ {
@@ -983,6 +1015,101 @@ NetPacketPlayerLeft::InternalCheck(const NetPacketHeader* data) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
NetPacketKickPlayer::NetPacketKickPlayer()
: NetPacket(NET_TYPE_KICK_PLAYER, sizeof(NetPacketKickPlayerData), sizeof(NetPacketKickPlayerData))
{
}
NetPacketKickPlayer::~NetPacketKickPlayer()
{
}
boost::shared_ptr<NetPacket>
NetPacketKickPlayer::Clone() const
{
boost::shared_ptr<NetPacket> newPacket(new NetPacketKickPlayer);
try
{
newPacket->SetRawData(GetRawData());
} catch (const NetException &)
{
// Need to return the new packet anyway.
}
return newPacket;
}
void
NetPacketKickPlayer::SetData(const NetPacketKickPlayer::Data &inData)
{
NetPacketKickPlayerData *tmpData = (NetPacketKickPlayerData *)GetRawData();
// Set the data.
tmpData->playerId = htons(inData.playerId);
// Check the packet - just in case.
Check(GetRawData());
}
void
NetPacketKickPlayer::GetData(NetPacketKickPlayer::Data &outData) const
{
// We assume that the data is valid. Validity has already been checked.
NetPacketKickPlayerData *tmpData = (NetPacketKickPlayerData *)GetRawData();
outData.playerId = ntohs(tmpData->playerId);
}
const NetPacketKickPlayer *
NetPacketKickPlayer::ToNetPacketKickPlayer() const
{
return this;
}
void
NetPacketKickPlayer::InternalCheck(const NetPacketHeader* data) const
{
// Nothing to do.
}
//-----------------------------------------------------------------------------
NetPacketStartEvent::NetPacketStartEvent()
: NetPacket(NET_TYPE_START_EVENT, sizeof(NetPacketStartEventData), sizeof(NetPacketStartEventData))
{
}
NetPacketStartEvent::~NetPacketStartEvent()
{
}
boost::shared_ptr<NetPacket>
NetPacketStartEvent::Clone() const
{
boost::shared_ptr<NetPacket> newPacket(new NetPacketStartEvent);
try
{
newPacket->SetRawData(GetRawData());
} catch (const NetException &)
{
// Need to return the new packet anyway.
}
return newPacket;
}
const NetPacketStartEvent *
NetPacketStartEvent::ToNetPacketStartEvent() const
{
return this;
}
void
NetPacketStartEvent::InternalCheck(const NetPacketHeader* data) const
{
// Nothing to do.
}
//-----------------------------------------------------------------------------
NetPacketGameStart::NetPacketGameStart() NetPacketGameStart::NetPacketGameStart()
: NetPacket(NET_TYPE_GAME_START, sizeof(NetPacketGameStartData), MAX_PACKET_SIZE) : NetPacket(NET_TYPE_GAME_START, sizeof(NetPacketGameStartData), MAX_PACKET_SIZE)
{ {
+118 -102
View File
@@ -232,109 +232,129 @@ ServerRecvStateInit::InternalProcess(ServerRecvThread &server, SessionWrapper se
{ {
int retVal = MSG_SOCK_INIT_DONE; int retVal = MSG_SOCK_INIT_DONE;
// Session should be in initial state. if (packet->ToNetPacketJoinGame())
if (session.sessionData->GetState() != SessionData::Init)
{ {
server.SessionError(session, ERR_SOCK_INVALID_STATE); // Session should be in initial state.
return retVal; if (session.sessionData->GetState() != SessionData::Init)
} {
server.SessionError(session, ERR_SOCK_INVALID_STATE);
return retVal;
}
// Only accept join game packets. const NetPacketJoinGame *tmpPacket = packet->ToNetPacketJoinGame();
const NetPacketJoinGame *tmpPacket = packet->ToNetPacketJoinGame();
if (!tmpPacket) NetPacketJoinGame::Data joinGameData;
tmpPacket->GetData(joinGameData);
// Check the protocol version.
if (joinGameData.versionMajor != NET_VERSION_MAJOR)
{
server.SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED);
return retVal;
}
size_t curNumPlayers = server.GetCurNumberOfPlayers();
// Check the number of players.
if (curNumPlayers >= (size_t)server.GetGameData().maxNumberOfPlayers)
{
server.SessionError(session, ERR_NET_SERVER_FULL);
return retVal;
}
// Check the server password.
if (!server.CheckPassword(joinGameData.password))
{
server.SessionError(session, ERR_NET_INVALID_PASSWORD);
return retVal;
}
// Check whether the player name is correct.
// Paranoia check, this is also done in netpacket.
if (joinGameData.playerName.empty() || joinGameData.playerName.size() > MAX_NAME_SIZE)
{
server.SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
return retVal;
}
// Check whether this player is already connected.
if (server.IsPlayerConnected(joinGameData.playerName))
{
server.SessionError(session, ERR_NET_PLAYER_NAME_IN_USE);
return retVal;
}
// Create player data object.
// TODO HACK first player is admin
PlayerRights rights = PLAYER_RIGHTS_NORMAL;
if (server.GetCurNumberOfPlayers() == 0)
rights = PLAYER_RIGHTS_ADMIN;
boost::shared_ptr<PlayerData> tmpPlayerData(
new PlayerData(m_curUniquePlayerId++, 0, PLAYER_TYPE_HUMAN, rights));
tmpPlayerData->SetName(joinGameData.playerName);
tmpPlayerData->SetNetSessionData(session.sessionData);
// Send ACK to client.
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
NetPacketJoinGameAck::Data joinGameAckData;
joinGameAckData.sessionId = session.sessionData->GetId(); // TODO: currently unused.
joinGameAckData.yourPlayerUniqueId = tmpPlayerData->GetUniqueId();
joinGameAckData.gameData = server.GetGameData();
joinGameAckData.ptype = tmpPlayerData->GetType();
joinGameAckData.prights = tmpPlayerData->GetRights();
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
server.GetSender().Send(session.sessionData->GetSocket(), answer);
// Send notifications for connected players to client.
PlayerDataList tmpPlayerList = server.GetPlayerDataList();
PlayerDataList::iterator player_i = tmpPlayerList.begin();
PlayerDataList::iterator player_end = tmpPlayerList.end();
while (player_i != player_end)
{
boost::shared_ptr<NetPacket> otherPlayerJoined(new NetPacketPlayerJoined);
NetPacketPlayerJoined::Data otherPlayerJoinedData;
otherPlayerJoinedData.playerId = (*player_i)->GetUniqueId();
otherPlayerJoinedData.playerName = (*player_i)->GetName();
otherPlayerJoinedData.ptype = (*player_i)->GetType();
static_cast<NetPacketPlayerJoined *>(otherPlayerJoined.get())->SetData(otherPlayerJoinedData);
server.GetSender().Send(session.sessionData->GetSocket(), otherPlayerJoined);
++player_i;
}
// Send "Player Joined" to other fully connected clients.
boost::shared_ptr<NetPacket> thisPlayerJoined(new NetPacketPlayerJoined);
NetPacketPlayerJoined::Data thisPlayerJoinedData;
thisPlayerJoinedData.playerId = tmpPlayerData->GetUniqueId();
thisPlayerJoinedData.playerName = tmpPlayerData->GetName();
thisPlayerJoinedData.ptype = tmpPlayerData->GetType();
thisPlayerJoinedData.prights = tmpPlayerData->GetRights();
static_cast<NetPacketPlayerJoined *>(thisPlayerJoined.get())->SetData(thisPlayerJoinedData);
server.SendToAllPlayers(thisPlayerJoined);
// Set player data for session.
server.SetSessionPlayerData(session.sessionData, tmpPlayerData);
// Session is now established.
session.sessionData->SetState(SessionData::Established);
}
else if (packet->ToNetPacketStartEvent())
{
server.InternalStartGame();
server.SetState(SERVER_START_GAME_STATE::Instance());
}
else if (packet->ToNetPacketKickPlayer())
{
NetPacketKickPlayer::Data kickPlayerData;
packet->ToNetPacketKickPlayer()->GetData(kickPlayerData);
server.InternalKickPlayer(kickPlayerData.playerId);
}
else
{ {
server.SessionError(session, ERR_SOCK_INVALID_PACKET); server.SessionError(session, ERR_SOCK_INVALID_PACKET);
return retVal;
} }
NetPacketJoinGame::Data joinGameData;
tmpPacket->GetData(joinGameData);
// Check the protocol version.
if (joinGameData.versionMajor != NET_VERSION_MAJOR)
{
server.SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED);
return retVal;
}
size_t curNumPlayers = server.GetCurNumberOfPlayers();
// Check the number of players.
if (curNumPlayers >= (size_t)server.GetGameData().maxNumberOfPlayers)
{
server.SessionError(session, ERR_NET_SERVER_FULL);
return retVal;
}
// Check the server password.
if (!server.CheckPassword(joinGameData.password))
{
server.SessionError(session, ERR_NET_INVALID_PASSWORD);
return retVal;
}
// Check whether the player name is correct.
// Paranoia check, this is also done in netpacket.
if (joinGameData.playerName.empty() || joinGameData.playerName.size() > MAX_NAME_SIZE)
{
server.SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
return retVal;
}
// Check whether this player is already connected.
if (server.IsPlayerConnected(joinGameData.playerName))
{
server.SessionError(session, ERR_NET_PLAYER_NAME_IN_USE);
return retVal;
}
// Create player data object.
boost::shared_ptr<PlayerData> tmpPlayerData(
new PlayerData(m_curUniquePlayerId++, 0, PLAYER_TYPE_HUMAN));
tmpPlayerData->SetName(joinGameData.playerName);
tmpPlayerData->SetNetSessionData(session.sessionData);
// Send ACK to client.
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
NetPacketJoinGameAck::Data joinGameAckData;
joinGameAckData.sessionId = session.sessionData->GetId(); // TODO: currently unused.
joinGameAckData.yourPlayerUniqueId = tmpPlayerData->GetUniqueId();
joinGameAckData.gameData = server.GetGameData();
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
server.GetSender().Send(session.sessionData->GetSocket(), answer);
// Send notifications for connected players to client.
PlayerDataList tmpPlayerList = server.GetPlayerDataList();
PlayerDataList::iterator player_i = tmpPlayerList.begin();
PlayerDataList::iterator player_end = tmpPlayerList.end();
while (player_i != player_end)
{
boost::shared_ptr<NetPacket> otherPlayerJoined(new NetPacketPlayerJoined);
NetPacketPlayerJoined::Data otherPlayerJoinedData;
otherPlayerJoinedData.playerId = (*player_i)->GetUniqueId();
otherPlayerJoinedData.playerName = (*player_i)->GetName();
otherPlayerJoinedData.ptype = (*player_i)->GetType();
static_cast<NetPacketPlayerJoined *>(otherPlayerJoined.get())->SetData(otherPlayerJoinedData);
server.GetSender().Send(session.sessionData->GetSocket(), otherPlayerJoined);
++player_i;
}
// Send "Player Joined" to other fully connected clients.
boost::shared_ptr<NetPacket> thisPlayerJoined(new NetPacketPlayerJoined);
NetPacketPlayerJoined::Data thisPlayerJoinedData;
thisPlayerJoinedData.playerId = tmpPlayerData->GetUniqueId();
thisPlayerJoinedData.playerName = tmpPlayerData->GetName();
thisPlayerJoinedData.ptype = tmpPlayerData->GetType();
static_cast<NetPacketPlayerJoined *>(thisPlayerJoined.get())->SetData(thisPlayerJoinedData);
server.SendToAllPlayers(thisPlayerJoined);
// Set player data for session.
server.SetSessionPlayerData(session.sessionData, tmpPlayerData);
// Session is now established.
session.sessionData->SetState(SessionData::Established);
return retVal; return retVal;
} }
@@ -1039,11 +1059,7 @@ ServerRecvStateNextGameDelay::Process(ServerRecvThread &server)
server.SendToAllPlayers(endGame); server.SendToAllPlayers(endGame);
// Switch back to the GUI, wait for the start of a new game. // Wait for the start of a new game.
// Luckily, the names are still in the GUI dialog.
// We just need to show the proper dialog, and people can
// join or leave as usual.
server.GetCallback().SignalNetServerStartDialog();
server.SetState(ServerRecvStateInit::Instance()); server.SetState(ServerRecvStateInit::Instance());
} }
+12 -21
View File
@@ -140,15 +140,10 @@ ServerRecvThread::NotificationLoop()
Notification notification = m_notificationQueue.front(); Notification notification = m_notificationQueue.front();
m_notificationQueue.pop_front(); m_notificationQueue.pop_front();
switch(notification.message) // switch(notification.message)
{ // {
case NOTIFY_GAME_START: // break;
InternalStartGame(); // }
break;
case NOTIFY_KICK_PLAYER:
InternalKickPlayer(notification.param);
break;
}
} }
} }
@@ -249,8 +244,6 @@ ServerRecvThread::CleanupSessionMap()
void void
ServerRecvThread::InternalStartGame() ServerRecvThread::InternalStartGame()
{ {
SetState(SERVER_START_GAME_STATE::Instance());
// Kick all players which are not fully connected. // Kick all players which are not fully connected.
RemoveNotEstablishedSessions(); RemoveNotEstablishedSessions();
// Set order of players. // Set order of players.
@@ -295,14 +288,10 @@ ServerRecvThread::InternalStartGame()
} }
void void
ServerRecvThread::InternalKickPlayer(const string playerName) ServerRecvThread::InternalKickPlayer(unsigned uniqueId)
{ {
if (!playerName.empty()) SessionWrapper tmpSession = GetSessionByUniquePlayerId(uniqueId);
{ SessionError(tmpSession, ERR_NET_PLAYER_KICKED);
SessionWrapper tmpSession = GetSessionByPlayerName(playerName);
SessionError(tmpSession, ERR_NET_PLAYER_KICKED);
}
} }
SessionWrapper SessionWrapper
@@ -394,9 +383,11 @@ ServerRecvThread::AddSession(boost::shared_ptr<SessionData> sessionData)
void void
ServerRecvThread::SessionError(SessionWrapper session, int errorCode) ServerRecvThread::SessionError(SessionWrapper session, int errorCode)
{ {
assert(session.sessionData.get()); if (session.sessionData.get())
SendError(session.sessionData->GetSocket(), errorCode); {
CloseSessionDelayed(session); SendError(session.sessionData->GetSocket(), errorCode);
CloseSessionDelayed(session);
}
} }
void void
-20
View File
@@ -57,26 +57,6 @@ ServerThread::Init(unsigned serverPort, bool ipv6, bool sctp, const std::string
GetRecvThread().Init(pwd, gameData); GetRecvThread().Init(pwd, gameData);
} }
void
ServerThread::StartGame()
{
if (!IsRunning())
return; // TODO: throw exception
// Thread-safe notification.
GetRecvThread().AddNotification(NOTIFY_GAME_START, "");
}
void
ServerThread::KickPlayer(const string &playerName)
{
if (!IsRunning())
return; // TODO: throw exception
// Thread-safe notification.
GetRecvThread().AddNotification(NOTIFY_KICK_PLAYER, playerName);
}
ServerCallback & ServerCallback &
ServerThread::GetCallback() ServerThread::GetCallback()
{ {
+43
View File
@@ -44,6 +44,8 @@ class NetPacketJoinGame;
class NetPacketJoinGameAck; class NetPacketJoinGameAck;
class NetPacketPlayerJoined; class NetPacketPlayerJoined;
class NetPacketPlayerLeft; class NetPacketPlayerLeft;
class NetPacketKickPlayer;
class NetPacketStartEvent;
class NetPacketGameStart; class NetPacketGameStart;
class NetPacketHandStart; class NetPacketHandStart;
class NetPacketPlayersTurn; class NetPacketPlayersTurn;
@@ -82,6 +84,8 @@ public:
virtual const NetPacketJoinGameAck *ToNetPacketJoinGameAck() const; virtual const NetPacketJoinGameAck *ToNetPacketJoinGameAck() const;
virtual const NetPacketPlayerJoined *ToNetPacketPlayerJoined() const; virtual const NetPacketPlayerJoined *ToNetPacketPlayerJoined() const;
virtual const NetPacketPlayerLeft *ToNetPacketPlayerLeft() const; virtual const NetPacketPlayerLeft *ToNetPacketPlayerLeft() const;
virtual const NetPacketKickPlayer *ToNetPacketKickPlayer() const;
virtual const NetPacketStartEvent *ToNetPacketStartEvent() const;
virtual const NetPacketGameStart *ToNetPacketGameStart() const; virtual const NetPacketGameStart *ToNetPacketGameStart() const;
virtual const NetPacketHandStart *ToNetPacketHandStart() const; virtual const NetPacketHandStart *ToNetPacketHandStart() const;
virtual const NetPacketPlayersTurn *ToNetPacketPlayersTurn() const; virtual const NetPacketPlayersTurn *ToNetPacketPlayersTurn() const;
@@ -215,6 +219,45 @@ protected:
virtual void InternalCheck(const NetPacketHeader* data) const; virtual void InternalCheck(const NetPacketHeader* data) const;
}; };
class NetPacketKickPlayer : public NetPacket
{
public:
struct Data
{
u_int16_t playerId;
};
NetPacketKickPlayer();
virtual ~NetPacketKickPlayer();
virtual boost::shared_ptr<NetPacket> Clone() const;
void SetData(const Data &inData);
void GetData(Data &outData) const;
virtual const NetPacketKickPlayer *ToNetPacketKickPlayer() const;
protected:
virtual void InternalCheck(const NetPacketHeader* data) const;
};
class NetPacketStartEvent : public NetPacket
{
public:
NetPacketStartEvent();
virtual ~NetPacketStartEvent();
virtual boost::shared_ptr<NetPacket> Clone() const;
virtual const NetPacketStartEvent *ToNetPacketStartEvent() const;
protected:
virtual void InternalCheck(const NetPacketHeader* data) const;
};
class NetPacketGameStart : public NetPacket class NetPacketGameStart : public NetPacket
{ {
public: public:
-2
View File
@@ -33,8 +33,6 @@ public:
virtual void SignalNetServerPlayerJoined(const std::string &playerName) = 0; virtual void SignalNetServerPlayerJoined(const std::string &playerName) = 0;
virtual void SignalNetServerPlayerLeft(const std::string &playerName) = 0; virtual void SignalNetServerPlayerLeft(const std::string &playerName) = 0;
virtual void SignalNetServerStartDialog() = 0;
}; };
#endif #endif
+1 -4
View File
@@ -36,9 +36,6 @@
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200 #define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
// Notifications
#define NOTIFY_GAME_START 1
#define NOTIFY_KICK_PLAYER 2
class ServerRecvState; class ServerRecvState;
class SenderThread; class SenderThread;
@@ -103,7 +100,7 @@ protected:
void CleanupSessionMap(); void CleanupSessionMap();
void InternalStartGame(); void InternalStartGame();
void InternalKickPlayer(const std::string playerName); void InternalKickPlayer(unsigned uniqueId);
SessionWrapper GetSession(SOCKET sock) const; SessionWrapper GetSession(SOCKET sock) const;
SessionWrapper GetSessionByPlayerName(const std::string playerName) const; SessionWrapper GetSessionByPlayerName(const std::string playerName) const;
-2
View File
@@ -43,8 +43,6 @@ public:
// Set the parameters. // Set the parameters.
void Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd, void Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd,
const GameData &gameData); const GameData &gameData);
void StartGame();
void KickPlayer(const std::string &playerName);
ServerCallback &GetCallback(); ServerCallback &GetCallback();
GuiInterface &GetGui(); GuiInterface &GetGui();
+2 -2
View File
@@ -19,8 +19,8 @@
#include <playerdata.h> #include <playerdata.h>
PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type) PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights)
: m_uniqueId(uniqueId), m_number(number), m_type(type) : m_uniqueId(uniqueId), m_number(number), m_type(type), m_rights(rights)
{ {
} }
+4 -1
View File
@@ -43,7 +43,7 @@ enum PlayerRights
class PlayerData class PlayerData
{ {
public: public:
PlayerData(unsigned uniqueId, int number, PlayerType type); PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights);
~PlayerData(); ~PlayerData();
const std::string &GetName() const const std::string &GetName() const
@@ -60,6 +60,8 @@ public:
{m_netSessionData = session;} {m_netSessionData = session;}
PlayerType GetType() const PlayerType GetType() const
{return m_type;} {return m_type;}
PlayerRights GetRights() const
{return m_rights;}
unsigned GetUniqueId() const unsigned GetUniqueId() const
{return m_uniqueId;} {return m_uniqueId;}
int GetNumber() const int GetNumber() const
@@ -76,6 +78,7 @@ private:
std::string m_name; std::string m_name;
std::string m_avatarFile; std::string m_avatarFile;
PlayerType m_type; PlayerType m_type;
PlayerRights m_rights;
boost::shared_ptr<SessionData> m_netSessionData; boost::shared_ptr<SessionData> m_netSessionData;
}; };
+13 -17
View File
@@ -69,7 +69,9 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat
//PlayerData erzeugen //PlayerData erzeugen
// UniqueId = PlayerNumber for local games. // UniqueId = PlayerNumber for local games.
boost::shared_ptr<PlayerData> playerData(new PlayerData(i, i, i == 0 ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER)); boost::shared_ptr<PlayerData> playerData(new PlayerData(i, i,
i == 0 ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER,
i == 0 ? PLAYER_RIGHTS_ADMIN : PLAYER_RIGHTS_NORMAL));
playerData->SetName(myConfig->readConfigString(myName.str())); playerData->SetName(myConfig->readConfigString(myName.str()));
playerData->SetAvatarFile(myConfig->readConfigString(myAvatar.str())); playerData->SetAvatarFile(myConfig->readConfigString(myAvatar.str()));
@@ -172,16 +174,6 @@ void Session::startNetworkServer(const GameData &gameData)
myNetServer->Run(); myNetServer->Run();
} }
void Session::initiateNetworkServerGame()
{
if (!myNetServer)
{
assert(false);
return;
}
myNetServer->StartGame();
}
void Session::terminateNetworkServer() void Session::terminateNetworkServer()
{ {
if (!myNetServer) if (!myNetServer)
@@ -207,6 +199,13 @@ void Session::waitForNetworkServer(unsigned timeoutMsec)
} }
} }
void Session::sendStartEvent()
{
if (!myNetClient)
return; // only act if client is running.
myNetClient->SendStartEvent();
}
void Session::sendClientPlayerAction() void Session::sendClientPlayerAction()
{ {
if (!myNetClient) if (!myNetClient)
@@ -223,12 +222,9 @@ void Session::sendChatMessage(const std::string &message)
void Session::kickPlayer(const std::string &playerName) void Session::kickPlayer(const std::string &playerName)
{ {
if (!myNetServer) if (!myNetClient)
{ return; // only act if client is running.
assert(false); myNetClient->SendKickPlayer(playerName);
return;
}
myNetServer->KickPlayer(playerName);
} }
bool Session::isNetworkClientRunning() const bool Session::isNetworkClientRunning() const
+1 -1
View File
@@ -50,7 +50,7 @@ public:
void terminateNetworkClient(); void terminateNetworkClient();
void startNetworkServer(const GameData &gameData); void startNetworkServer(const GameData &gameData);
void initiateNetworkServerGame(); void sendStartEvent();
void terminateNetworkServer(); void terminateNetworkServer();
void waitForNetworkServer(unsigned timeoutMsec); void waitForNetworkServer(unsigned timeoutMsec);