Fixing rejected chat and corresponding test case.

This commit is contained in:
lotodore
2012-01-08 16:56:51 +00:00
parent 915deefa8d
commit d1b6a4deec
2 changed files with 73 additions and 42 deletions
+10 -10
View File
@@ -281,17 +281,17 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
netChatRequest->chatText.size); netChatRequest->chatText.size);
server->SendToAllPlayers(packet, SessionData::Game); server->SendToAllPlayers(packet, SessionData::Game);
chatSent = true; chatSent = true;
}
// Send the message to the chat cleaner bot for ranking games. // Send the message to the chat cleaner bot for ranking games.
//if (server->GetGameData().gameType == GAME_TYPE_RANKING) //if (server->GetGameData().gameType == GAME_TYPE_RANKING)
//{ //{
server->GetLobbyThread().GetChatCleaner().HandleGameChatText( server->GetLobbyThread().GetChatCleaner().HandleGameChatText(
server->GetId(), server->GetId(),
session->GetPlayerData()->GetUniqueId(), session->GetPlayerData()->GetUniqueId(),
session->GetPlayerData()->GetName(), session->GetPlayerData()->GetName(),
string((char *)netChatRequest->chatText.buf, netChatRequest->chatText.size)); string((char *)netChatRequest->chatText.buf, netChatRequest->chatText.size));
//} //}
}
} }
} }
// Reject chat otherwise. // Reject chat otherwise.
+63 -32
View File
@@ -32,10 +32,16 @@ import pokerth_protocol.ChatRequestTypePrivate;
import pokerth_protocol.NetGameInfo; import pokerth_protocol.NetGameInfo;
import pokerth_protocol.NonZeroId; import pokerth_protocol.NonZeroId;
import pokerth_protocol.PokerTHMessage; import pokerth_protocol.PokerTHMessage;
import pokerth_protocol.StartEvent;
import pokerth_protocol.StartEventAckMessage;
import pokerth_protocol.StartEventMessage;
import pokerth_protocol.ChatRequestMessage.ChatRequestMessageSequenceType; import pokerth_protocol.ChatRequestMessage.ChatRequestMessageSequenceType;
import pokerth_protocol.ChatRequestMessage.ChatRequestMessageSequenceType.ChatRequestTypeChoiceType; import pokerth_protocol.ChatRequestMessage.ChatRequestMessageSequenceType.ChatRequestTypeChoiceType;
import pokerth_protocol.NetGameInfo.EndRaiseModeEnumType; import pokerth_protocol.NetGameInfo.EndRaiseModeEnumType;
import pokerth_protocol.NetGameInfo.NetGameTypeEnumType; import pokerth_protocol.NetGameInfo.NetGameTypeEnumType;
import pokerth_protocol.StartEventAckMessage.StartEventAckMessageSequenceType;
import pokerth_protocol.StartEventMessage.StartEventMessageSequenceType;
import pokerth_protocol.StartEventMessage.StartEventMessageSequenceType.StartEventTypeChoiceType;
import pokerth_protocol.InitialNonZeroAmountOfMoney; import pokerth_protocol.InitialNonZeroAmountOfMoney;
@@ -91,9 +97,9 @@ public class ChatTest extends TestBase {
public void testChat() throws Exception { public void testChat() throws Exception {
guestInit(); guestInit();
Socket s[] = new Socket[9]; Socket s[] = new Socket[8];
long playerId[] = new long[9]; long playerId[] = new long[8];
for (int i = 0; i < 9; i++) { for (int i = 0; i < 8; i++) {
s[i] = new Socket("localhost", 7234); s[i] = new Socket("localhost", 7234);
String username = "test" + (i+1); String username = "test" + (i+1);
String password = username; String password = username;
@@ -119,7 +125,7 @@ public class ChatTest extends TestBase {
assertTrue(msg.getChatMessage().getValue().getChatType().isChatTypeLobbySelected()); assertTrue(msg.getChatMessage().getValue().getChatType().isChatTypeLobbySelected());
assertEquals(playerId[0], msg.getChatMessage().getValue().getChatType().getChatTypeLobby().getPlayerId().getValue().longValue()); assertEquals(playerId[0], msg.getChatMessage().getValue().getChatType().getChatTypeLobby().getPlayerId().getValue().longValue());
for (int i = 0; i < 9; i++) { for (int i = 0; i < 8; i++) {
do { do {
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
} while (msg.isPlayerListMessageSelected()); } while (msg.isPlayerListMessageSelected());
@@ -189,12 +195,52 @@ public class ChatTest extends TestBase {
assertTrue(msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()); assertTrue(msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected());
} }
StartEvent startEvent = new StartEvent();
startEvent.setFillWithComputerPlayers(false);
StartEventTypeChoiceType eventType = new StartEventTypeChoiceType();
eventType.selectStartEvent(startEvent);
StartEventMessageSequenceType gameStartType = new StartEventMessageSequenceType();
gameStartType.setGameId(new NonZeroId(gameId));
gameStartType.setStartEventType(eventType);
StartEventMessage startMsg = new StartEventMessage();
startMsg.setValue(gameStartType);
msg = new PokerTHMessage();
msg.selectStartEventMessage(startMsg);
sendMessage(msg);
// Server should confirm start event.
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isStartEventMessageSelected());
// Acknowledge start event.
StartEventAckMessageSequenceType startType = new StartEventAckMessageSequenceType();
startType.setGameId(new NonZeroId(gameId));
StartEventAckMessage startAck = new StartEventAckMessage();
startAck.setValue(startType);
msg = new PokerTHMessage();
msg.selectStartEventAckMessage(startAck);
sendMessage(msg);
for (int i = 0; i < 8; i++) {
sendMessage(msg, s[i]);
}
// Server should game start.
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isGameStartMessageSelected());
// Guest user: not allowed. // Guest user: not allowed.
msg = createGameChatMsg(ChatText + 7, gameId); msg = createGameChatMsg(ChatText + 7, gameId);
sendMessage(msg); sendMessage(msg);
do { do {
msg = receiveMessage(); msg = receiveMessage();
failOnErrorMessage(msg); failOnErrorMessage(msg);
assertFalse(msg.isChatMessageSelected());
} while (!msg.isChatRejectMessageSelected()); } while (!msg.isChatRejectMessageSelected());
assertEquals(ChatText + 7, msg.getChatRejectMessage().getValue().getChatText()); assertEquals(ChatText + 7, msg.getChatRejectMessage().getValue().getChatText());
@@ -203,7 +249,7 @@ public class ChatTest extends TestBase {
msg = createGameChatMsg(ChatText + "c" + c, gameId); msg = createGameChatMsg(ChatText + "c" + c, gameId);
sendMessage(msg, s[c]); sendMessage(msg, s[c]);
do { do {
msg = receiveMessage(); msg = receiveMessage(s[c]);
failOnErrorMessage(msg); failOnErrorMessage(msg);
assertFalse(msg.isChatRejectMessageSelected()); assertFalse(msg.isChatRejectMessageSelected());
} while (!msg.isChatMessageSelected()); } while (!msg.isChatMessageSelected());
@@ -214,35 +260,20 @@ public class ChatTest extends TestBase {
assertEquals(gameId, msg.getChatMessage().getValue().getChatType().getChatTypeGame().getGameId().getValue().longValue()); assertEquals(gameId, msg.getChatMessage().getValue().getChatType().getChatTypeGame().getGameId().getValue().longValue());
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
do { if (i != c) {
msg = receiveMessage(s[i]); do {
failOnErrorMessage(msg); msg = receiveMessage(s[i]);
assertFalse(msg.isChatRejectMessageSelected()); failOnErrorMessage(msg);
} while (!msg.isChatMessageSelected()); assertFalse(msg.isChatRejectMessageSelected());
assertEquals(ChatText + "c" + c, msg.getChatMessage().getValue().getChatText()); } while (!msg.isChatMessageSelected());
assertTrue(msg.getChatMessage().getValue().getChatType().isChatTypeGameSelected()); assertEquals(ChatText + "c" + c, msg.getChatMessage().getValue().getChatText());
assertEquals(playerId[c], msg.getChatMessage().getValue().getChatType().getChatTypeGame().getPlayerId().getValue().longValue()); assertTrue(msg.getChatMessage().getValue().getChatType().isChatTypeGameSelected());
assertEquals(gameId, msg.getChatMessage().getValue().getChatType().getChatTypeGame().getGameId().getValue().longValue()); assertEquals(playerId[c], msg.getChatMessage().getValue().getChatType().getChatTypeGame().getPlayerId().getValue().longValue());
assertEquals(gameId, msg.getChatMessage().getValue().getChatType().getChatTypeGame().getGameId().getValue().longValue());
}
} }
} }
// Private and lobby messages are forbidden once the game is running.
sendMessage(joinGameRequestMsg(gameId, "", false), s[8]);
do {
msg = receiveMessage(s[8]);
failOnErrorMessage(msg);
// This player was not in the game and should not have received chat messages.
assertFalse(msg.isChatMessageSelected());
} while (!msg.isJoinGameReplyMessageSelected());
assertTrue(msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected());
// Server should confirm start event.
do {
msg = receiveMessage(s[0]);
failOnErrorMessage(msg);
} while (!msg.isGameStartMessageSelected());
// Private chat message should now be rejected. // Private chat message should now be rejected.
msg = createPrivateChatMsg(ChatText + 8, playerId[1]); msg = createPrivateChatMsg(ChatText + 8, playerId[1]);
sendMessage(msg, s[0]); sendMessage(msg, s[0]);
@@ -252,7 +283,7 @@ public class ChatTest extends TestBase {
assertFalse(msg.isChatMessageSelected()); assertFalse(msg.isChatMessageSelected());
} while (!msg.isChatRejectMessageSelected()); } while (!msg.isChatRejectMessageSelected());
for (int i = 0; i < 9; i++) { for (int i = 0; i < 8; i++) {
s[i].close(); s[i].close();
} }
} }