public void ProcessClientMessage(TcpClient client, NETMSG msg) { switch (msg.Type) { case NETMSG.MSG_TYPES.CLIENT_REQUEST_SYNC: SendClient(client, new NETMSG(NETMSG.MSG_TYPES.SERVER_GAME, objToBytes(this.game))); break; case NETMSG.MSG_TYPES.CLIENT_DISCONNECT: this.clients.Remove(client); Console.WriteLine("client disconnected"); game.Disconnect((uint)NETMSG.bytesToObj(msg.Payload)); FullBroadCast(new NETMSG(NETMSG.MSG_TYPES.PLAYER_DISCONNECTED, msg.Payload)); break; case NETMSG.MSG_TYPES.CLIENT_OK: //for sync purposes break; case NETMSG.MSG_TYPES.CLIENT_READY: //for sync purposes break; case NETMSG.MSG_TYPES.CLIENT_REQUEST_UID: CardUtils.Player p = game.createPlayer(); game.AddPlayer(p); SendClient(client, new NETMSG(NETMSG.MSG_TYPES.SERVER_PLAYER_UID, objToBytes(p))); FullBroadCast(new NETMSG(NETMSG.MSG_TYPES.PLAYER_CONNECTED, objToBytes(p))); break; case NETMSG.MSG_TYPES.PLAYER_PASS: game.Pass(((CardUtils.Player)NETMSG.bytesToObj(msg.Payload)).ID); BroadCastExceptForClient(client, msg); break; case NETMSG.MSG_TYPES.PLAYER_PICKS: Console.WriteLine("player picked: " + (uint)NETMSG.bytesToObj(msg.Payload)); game.PickCard((uint)NETMSG.bytesToObj(msg.Payload)); BroadCastExceptForClient(client, msg); break; case NETMSG.MSG_TYPES.PLAYER_BETS: game.Bet(((BET)NETMSG.bytesToObj(msg.Payload)).PlayerID, ((BET)NETMSG.bytesToObj(msg.Payload)).betTOAdd); BroadCastExceptForClient(client, msg); break; default: break; } }
private void processServerMessage(NETMSG msg) { switch (msg.Type) { case NETMSG.MSG_TYPES.SERVER_OK: //this is a sync message break; case NETMSG.MSG_TYPES.SERVER_GAME: this.Game = (CardUtils.Game)NETMSG.bytesToObj(msg.Payload); break; case NETMSG.MSG_TYPES.SERVER_FULL: MessageBox.Show("The server is full. Closing connection."); ExitRequested = true; break; case NETMSG.MSG_TYPES.SERVER_ERROR: MessageBox.Show("SERVER_ERROR received from Server: \n" + msg.Message + "."); break; case NETMSG.MSG_TYPES.SERVER_CLOSING: MessageBox.Show("The server will close or you were kicked. Disconnecting from server."); ExitRequested = true; break; case NETMSG.MSG_TYPES.SERVER_PLAYER_UID: this.playerID = ((CardUtils.Player)NETMSG.bytesToObj(msg.Payload)).ID; break; case NETMSG.MSG_TYPES.PLAYER_BETS: this.Game.Bet(((BET)NETMSG.bytesToObj(msg.Payload)).PlayerID, ((BET)NETMSG.bytesToObj(msg.Payload)).betTOAdd); break; case NETMSG.MSG_TYPES.PLAYER_CONNECTED: CardUtils.Player pla = (CardUtils.Player)NETMSG.bytesToObj(msg.Payload); Console.WriteLine("new player!: " + pla.ID); Game.AddPlayer(pla); break; case NETMSG.MSG_TYPES.PLAYER_DISCONNECTED: uint id = (uint)NETMSG.bytesToObj(msg.Payload); this.Game.Disconnect(id); break; case NETMSG.MSG_TYPES.PLAYER_PASS: this.Game.Pass(((CardUtils.Player)NETMSG.bytesToObj(msg.Payload)).ID); break; case NETMSG.MSG_TYPES.PLAYER_PICKS: this.Game.Pass((uint)NETMSG.bytesToObj(msg.Payload)); break; case NETMSG.MSG_TYPES.END_GAME: //say who won break; default: MessageBox.Show("Unknown NETMSG struct object received"); break; } }
private void processServerMessage(NETMSG msg) { switch (msg.Type) { case NETMSG.MSG_TYPES.SERVER_OK: //this is a sync message break; case NETMSG.MSG_TYPES.SERVER_GAME: this.Game = (CardUtils.Game)NETMSG.bytesToObj(msg.Payload); break; case NETMSG.MSG_TYPES.SERVER_FULL: MessageBox.Show("The server is full. Closing connection."); ExitRequested = true; break; case NETMSG.MSG_TYPES.SERVER_ERROR: MessageBox.Show("SERVER_ERROR received from Server: \n" + msg.Message + "."); break; case NETMSG.MSG_TYPES.SERVER_CLOSING: MessageBox.Show("The server will close or you were kicked. Disconnecting from server."); ExitRequested = true; break; case NETMSG.MSG_TYPES.SERVER_PLAYER_UID: this.playerID = ((CardUtils.Player)NETMSG.bytesToObj(msg.Payload)).ID; break; case NETMSG.MSG_TYPES.PLAYER_BETS: this.Game.Bet(((BET)NETMSG.bytesToObj(msg.Payload)).PlayerID, ((BET)NETMSG.bytesToObj(msg.Payload)).betTOAdd); //ui.RefreshView(); RefreshUI(); break; case NETMSG.MSG_TYPES.PLAYER_CONNECTED: CardUtils.Player pla = (CardUtils.Player)NETMSG.bytesToObj(msg.Payload); if (Game.Players.Where(_player => _player.ID == pla.ID).Count() > 0) { printl("... real funny, william, but player " + pla.ID + " seems to already be in the list..."); break; } printl("adding a new player: " + pla.ID); Game.AddPlayer(pla); //printl( playerID + " sees total count:" + Game.Players.Count ); if (Game.Players.Count == 1) { printl("i should now be the one playing. " + pla.ID); Game.PlayingPlayer = Game.Players[0]; } else if (Game.Players.Count > 3) { foreach (CardUtils.Player _p in Game.Players) { printl("- " + _p.ID); } } //ui.RefreshView(); RefreshUI(); break; case NETMSG.MSG_TYPES.PLAYER_DISCONNECTED: uint id = (uint)NETMSG.bytesToObj(msg.Payload); this.Game.Disconnect(id); //ui.RefreshView(); RefreshUI(); break; case NETMSG.MSG_TYPES.PLAYER_PASS: uint passedID = (uint)NETMSG.bytesToObj(msg.Payload); this.Game.Pass(passedID); printl(passedID + "told me he passed, i think " + Game.PlayingPlayer.ID + " is now playing."); if (this.Game.PlayingPlayer.ID == this.playerID) { printl("i will now be playing."); this.IsPlaying = true; } ShowWinner(); RefreshUI(); break; case NETMSG.MSG_TYPES.PLAYER_PICKS: PICK pick = ((PICK)NETMSG.bytesToObj(msg.Payload)); this.Game.PickCard(pick.PlayerID, pick.Card); ShowWinner(); RefreshUI(); break; case NETMSG.MSG_TYPES.END_GAME: //say who won //ui.RefreshView RefreshUI(); break; case NETMSG.MSG_TYPES.PLAYER_YOURTURN: //this.Game.PlayingPlayer = this.Game.FindPlayer( playerID ); printl("i will be the first player."); IsPlaying = true; //ui.RefreshView(); RefreshUI(); break; default: MessageBox.Show("Unknown NETMSG struct object received"); break; } }
public void ProcessClientMessage(TcpClient client, NETMSG msg) { switch (msg.Type) { case NETMSG.MSG_TYPES.CLIENT_REQUEST_SYNC: SendClient(client, new NETMSG(NETMSG.MSG_TYPES.SERVER_GAME, objToBytes(this.game))); break; case NETMSG.MSG_TYPES.CLIENT_DISCONNECT: this.clients.Remove(client); printl("client disconnected"); game.Disconnect((uint)NETMSG.bytesToObj(msg.Payload)); FullBroadCast(new NETMSG(NETMSG.MSG_TYPES.PLAYER_DISCONNECTED, msg.Payload)); break; case NETMSG.MSG_TYPES.CLIENT_OK: //for sync purposes break; case NETMSG.MSG_TYPES.CLIENT_READY: //for sync purposes break; case NETMSG.MSG_TYPES.CLIENT_REQUEST_UID: CardUtils.Player p = game.createPlayer(); game.AddPlayer(p); if (game.Players.Count == 1) { printl(p.ID + " is the first so he starts."); game.PlayingPlayer = game.Players[0]; clients[client].Add(new NETMSG(NETMSG.MSG_TYPES.PLAYER_YOURTURN, null)); } SendClient(client, new NETMSG(NETMSG.MSG_TYPES.SERVER_PLAYER_UID, objToBytes(p))); FullBroadCast(new NETMSG(NETMSG.MSG_TYPES.PLAYER_CONNECTED, objToBytes(p))); break; case NETMSG.MSG_TYPES.PLAYER_PASS: uint passingID = (uint)NETMSG.bytesToObj(msg.Payload); printl(passingID + " passed."); game.Pass(passingID); FullBroadCast(msg); break; case NETMSG.MSG_TYPES.PLAYER_PICKS: printl("player picked: " + (uint)NETMSG.bytesToObj(msg.Payload)); uint pid = (uint)NETMSG.bytesToObj(msg.Payload); CardUtils.Card picked = game.PickCard(pid); FullBroadCast( new NETMSG( NETMSG.MSG_TYPES.PLAYER_PICKS, objToBytes( new PICK( pid, picked ) ) ) ); break; case NETMSG.MSG_TYPES.PLAYER_BETS: game.Bet(((BET)NETMSG.bytesToObj(msg.Payload)).PlayerID, ((BET)NETMSG.bytesToObj(msg.Payload)).betTOAdd); FullBroadCast(msg); //BroadCastExceptForClient(client, msg); break; default: break; } }