예제 #1
0
        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;
            }
        }
예제 #2
0
        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;
            }
        }