Пример #1
0
        public void playerAcceptedTheChallenge()
        {
            string[] usernames = Message.Split(':');
            if (usernames.Length == 2)
            {
                User firstUser  = null;
                User secondUser = null;
                foreach (User user in Singleton.Singleton.Instance.ListOfUsersLogged)
                {
                    if (user.Username == usernames[0])
                    {
                        firstUser = user;
                    }
                    else if (user.Username == usernames[1])
                    {
                        secondUser = user;
                    }
                }

                if (firstUser != null && secondUser != null)
                {
                    firstUser.IsChallenged  = false;
                    firstUser.InGame        = true;
                    secondUser.IsChallenged = false;
                    secondUser.InGame       = true;

                    notifyUsersWithInGameStatus(firstUser);
                    notifyUsersWithInGameStatus(secondUser);

                    Room room = new Room(firstUser, secondUser, Singleton.Singleton.Instance.RoomIDHelper);
                    Singleton.Singleton.Instance.RoomIDHelper += 1;
                    MessageRoomPacket packet = new MessageRoomPacket(GameProtocol.LoadGameScene(), room.ID, firstUser.Username + ":" + secondUser.Username);
                    //MessagePacket packet = new MessagePacket(GameProtocol.LoadGameScene(), room.ID, )
                    //   + "|" + firstUser.Username + ":" + secondUser.Username);
                    Othello.Server.SendPacket(firstUser.Socket, packet.getData());
                    Othello.Server.SendPacket(secondUser.Socket, packet.getData());
                    Singleton.Singleton.Instance.ListOfRooms.Add(room);
                }
            }
        }
Пример #2
0
        public static void Handle(byte[] packet, Socket clientSocket)
        {
            ushort packetType   = BitConverter.ToUInt16(packet, 0);
            ushort packetLength = BitConverter.ToUInt16(packet, 2);


            switch (packetType)
            {
            case 100:     //Login
                MessagePacket MessagePacket = new MessagePacket(packet);
                MessagePacket.doLogin(clientSocket);
                break;

            case 110:     // Register
                MessagePacket = new MessagePacket(packet);
                MessagePacket.registerAccount(clientSocket);
                break;

            case 200:     // GLOBAL CHAT MESSAGE
                MessagePacket = new MessagePacket(packet);
                MessagePacket.doGlobalChat();
                break;

            case 201:     // ROOM CHAT MESSAGE
                MessageRoomPacket MessageRoomPacket = new MessageRoomPacket(packet);
                MessageRoomPacket.doRoomChat(clientSocket, packet);
                break;

            case 250:     // CHALLENGE PACKET (USERNAME CHALLANGED YOU ... )
                MessagePacket = new MessagePacket(packet);
                MessagePacket.sendAfterChallengeAction();
                break;

            case 257:     // USER ACCEPTED THE CHALLENGE
                MessagePacket = new MessagePacket(packet);
                MessagePacket.playerAcceptedTheChallenge();
                break;

            case 258:     // USER REFUSED THE CHALLENGE
                MessagePacket = new MessagePacket(packet);
                MessagePacket.notifyUsersAfterChallengeRefuse();
                break;

            case 260:     // USER IGNORED THE CHALLENGE
                MessagePacket = new MessagePacket(packet);
                MessagePacket.notifyUsersAfterChallengeIgnore();
                break;


            case 403:     // Turn Move
                MessageRoomPacket = new MessageRoomPacket(packet);
                MessageRoomPacket.doChangesAfterTurn();
                break;

            case 406:    //Play Again
                MessageRoomPacket = new MessageRoomPacket(packet);
                MessageRoomPacket.playAgain();
                break;

            case 407:    //Surrender
                MessageRoomPacket = new MessageRoomPacket(packet);
                MessageRoomPacket.surrender();
                break;

            case 501:     // PLAYER READY
                MessageRoomPacket = new MessageRoomPacket(packet);
                MessageRoomPacket.playerReady();
                break;

            case 995:    // Back to lobby after gameover
                MessageRoomPacket = new MessageRoomPacket(packet);
                MessageRoomPacket.backToLobby();
                break;

            case 997:    // User quit while in game -> send surr to opponent and disc to other users
                MessageRoomPacket = new MessageRoomPacket(packet);
                MessageRoomPacket.opponentQuitWhileInGame();
                break;

            case 996:    // User quit after game -> send user left the room
                MessageRoomPacket = new MessageRoomPacket(packet);
                MessageRoomPacket.opponentQuitAfterEndGame();
                break;

            case 998:    // User logout
                BasicPacket basicPacket = new BasicPacket(packet);
                basicPacket.userLogout(clientSocket);
                break;

            case 999:    // User apllication close
                basicPacket = new BasicPacket(packet);
                basicPacket.applicationClose(clientSocket);
                break;
            }
        }