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; } }