Exemple #1
0
 public void backToLobby()
 {
     if (CurrentRoom.FirstUser != null && CurrentRoom.FirstUser.Username == Message)
     {
         User   currentUser   = Singleton.Singleton.Instance.GetUserLoogedByUsername(Message);
         String PacketMessage = "";
         foreach (User u in Singleton.Singleton.Instance.ListOfUsersLogged)
         {
             if (u.Username == Message)
             {
                 continue;
             }
             if (CurrentRoom.SecondUser != null && u.Username == CurrentRoom.SecondUser.Username)
             {
                 MessagePacket mp = new MessagePacket(GameProtocol.BackToLobby(), Message);
                 Othello.Server.SendPacket(u.Socket, mp.getData());
             }
             PacketMessage += u.Username + ":" + u.IsChallenged + ":" + u.InGame + "|";
             MessagePacket messagePacket = new MessagePacket(GameProtocol.ChangeUserToOnline(), Message);
             Othello.Server.SendPacket(u.Socket, messagePacket.getData());
         }
         MessagePacket packet = new MessagePacket(GameProtocol.LoadMainSceneFromGame(), PacketMessage);
         Othello.Server.SendPacket(currentUser.Socket, packet.getData());
         currentUser.InGame    = false;
         CurrentRoom.FirstUser = null;
         if (CurrentRoom.SecondUser == null)
         {
             Singleton.Singleton.Instance.ListOfRooms.Remove(CurrentRoom);
         }
     }
     else
     {
         User   currentUser   = Singleton.Singleton.Instance.GetUserLoogedByUsername(Message);
         String PacketMessage = "";
         foreach (User u in Singleton.Singleton.Instance.ListOfUsersLogged)
         {
             if (u.Username == Message)
             {
                 continue;
             }
             if (CurrentRoom.FirstUser != null && u.Username == CurrentRoom.FirstUser.Username)
             {
                 MessagePacket mp = new MessagePacket(GameProtocol.BackToLobby(), Message);
                 Othello.Server.SendPacket(u.Socket, mp.getData());
             }
             PacketMessage += u.Username + ":" + u.IsChallenged + ":" + u.InGame + "|";
             MessagePacket messagePacket = new MessagePacket(GameProtocol.ChangeUserToOnline(), Message);
             Othello.Server.SendPacket(u.Socket, messagePacket.getData());
         }
         MessagePacket packet = new MessagePacket(GameProtocol.LoadMainSceneFromGame(), PacketMessage);
         Othello.Server.SendPacket(currentUser.Socket, packet.getData());
         currentUser.InGame     = false;
         CurrentRoom.SecondUser = null;
         if (CurrentRoom.FirstUser == null)
         {
             Singleton.Singleton.Instance.ListOfRooms.Remove(CurrentRoom);
         }
     }
 }
Exemple #2
0
        public void notifyUsersAfterChallengeRefuse()
        {
            string[]      splits = Message.Split(':');
            MessagePacket mp     = new MessagePacket(GameProtocol.ChangeUserToOnline(), splits[0]);

            foreach (User u in Singleton.Singleton.Instance.ListOfUsersLogged)
            {
                if (u.Username == splits[0])
                {
                    u.IsChallenged = false;
                }
                else if (u.Username == splits[1])
                {
                    Othello.Server.SendPacket(u.Socket, new MessagePacket(GameProtocol.UserRefusedChallengePacketID(), splits[0]).getData());
                }
                else
                {
                    Othello.Server.SendPacket(u.Socket, mp.getData());
                }
            }
        }