コード例 #1
0
ファイル: MessageRoomPacket.cs プロジェクト: DMIRICA/Othello
        public void playerReady()
        {
            if (CurrentRoom != null)
            {
                if (CurrentRoom.FirstUser != null && CurrentRoom.FirstUser.Username == Message)
                {
                    CurrentRoom.FirstUser.Player.ReadyToStart = true;
                    if (!CurrentRoom.SecondUser.Player.ReadyToStart)
                    {
                        BasicPacket p = new BasicPacket(GameProtocol.PlayerReady());
                        Othello.Server.SendPacket(CurrentRoom.SecondUser.Socket, p.getData());
                    }
                }
                else if (CurrentRoom.SecondUser != null && CurrentRoom.SecondUser.Username == Message)
                {
                    CurrentRoom.SecondUser.Player.ReadyToStart = true;
                    if (!CurrentRoom.FirstUser.Player.ReadyToStart)
                    {
                        BasicPacket p = new BasicPacket(GameProtocol.PlayerReady());
                        Othello.Server.SendPacket(CurrentRoom.FirstUser.Socket, p.getData());
                    }
                }

                if (CurrentRoom.areBothPlayersReady())
                {
                    CurrentRoom.startGame();
                    CurrentRoom.FirstUser.Player.ReadyToStart  = false;
                    CurrentRoom.SecondUser.Player.ReadyToStart = false;
                }
            }
        }
コード例 #2
0
ファイル: MessageRoomPacket.cs プロジェクト: DMIRICA/Othello
        public void playAgain()
        {
            if (CurrentRoom != null)
            {
                if (CurrentRoom.FirstUser.Username == Message)
                {
                    CurrentRoom.FirstUser.Player.PlayAgain = true;
                    if (!CurrentRoom.SecondUser.Player.PlayAgain)
                    {
                        BasicPacket bp = new BasicPacket(GameProtocol.PlayAgain());
                        Othello.Server.SendPacket(CurrentRoom.SecondUser.Socket, bp.getData());
                    }
                }
                else if (CurrentRoom.SecondUser.Username == Message)
                {
                    CurrentRoom.SecondUser.Player.PlayAgain = true;
                    if (!CurrentRoom.FirstUser.Player.PlayAgain)
                    {
                        BasicPacket bp = new BasicPacket(GameProtocol.PlayAgain());
                        Othello.Server.SendPacket(CurrentRoom.FirstUser.Socket, bp.getData());
                    }
                }

                if (CurrentRoom.isAblePlayAgain())
                {
                    CurrentRoom.PlayAgain();
                    CurrentRoom.resetPlayAgain();
                }
            }
        }
コード例 #3
0
ファイル: MessagePacket.cs プロジェクト: DMIRICA/Othello
        public void doLogin(Socket clientSocket)
        {
            string[] fields   = Message.Split('|');
            string   username = fields[0];
            string   password = fields[1];
            User     user     = Singleton.Singleton.Instance.DatabaseConnection.isPasswordRight(username, password);

            if (user != null)
            {
                if (Singleton.Singleton.Instance.isUserLogged(username))
                {
                    BasicPacket bp = new BasicPacket(GameProtocol.AlreadyOnlinePacketID());
                    Othello.Server.SendPacket(clientSocket, bp.getData());
                }
                else
                {
                    user.InGame = false;
                    user.Socket = clientSocket;
                    Singleton.Singleton.Instance.ListOfUsersLogged.Add(user);
                    //Send to current user logged the list with all the users logged and the status of them
                    string PacketMessage = "";
                    foreach (User u in Singleton.Singleton.Instance.ListOfUsersLogged)
                    {
                        if (u.Username == username)
                        {
                            continue;
                        }
                        PacketMessage += u.Username + ":" + u.IsChallenged + ":" + u.InGame + "|";
                        MessagePacket messagePacket = new MessagePacket(GameProtocol.AlertUsersNewUserLoggedID(), username + ":False");
                        Othello.Server.SendPacket(u.Socket, messagePacket.getData());
                    }
                    MessagePacket packet = new MessagePacket(GameProtocol.UsersLoggedListPacketID(), PacketMessage);
                    Othello.Server.SendPacket(user.Socket, packet.getData());
                }
            }
            else
            {
                BasicPacket bp = new BasicPacket(GameProtocol.FailedLoginPacketID());
                Othello.Server.SendPacket(clientSocket, bp.getData());
            }
        }