Beispiel #1
0
        public string JoinRoom(int roomId)
        {
            if (UserName == null)
            {
                return("errorNoUserName");
            }

            Room room = Room.GetRoomFromId(roomId);

            if (room == null)
            {
                return("errorRoomNotFound");
            }
            Room currentRoom = GetRoom();

            if (!room.Users.Contains(this))
            {
                if (currentRoom != null)
                {
                    currentRoom.Users.Remove(this);
                    //Si l'utilisateur était déjà dans une room, il la quitte
                }

                room.Users.Add(this);
                SocketSender.SendToAllUsers("userjoinroom|" + Id + "," + roomId);
                return(null);
            }
            else
            {
                return("errorAlreadyInRoom");
            }
        }
Beispiel #2
0
        public static string CreateRoom(User user)
        {
            if (user.UserName == null)
            {
                return("errorNoUserName");
            }
            Room room = new Room();

            SocketSender.SendToAllUsers("newroom|" + room.Id + "," + room.Name);
            return(user.JoinRoom(room.Id));
        }
Beispiel #3
0
 public string SetName(string name)
 {
     if (MainManager.Users.Where(users => users.UserName == name).FirstOrDefault() == null)
     {
         if (string.IsNullOrEmpty(name))
         {
             return("errorNotValidUserName");
         }
         UserName = name;
         SocketSender.SendToAllUsers("newname|" + Id + "," + name);
         return(null);
     }
     return("errorNameAlreadyUsed");
 }
Beispiel #4
0
        public string SendLink(string link)
        {
            if (UserName == null)
            {
                return("errorNoUserName");
            }

            if (GetRoom() == null)
            {
                return("errorNotInRoom");
            }

            SocketSender.SendToUserRoomExceptUser(this, link);
            return(null);
        }
Beispiel #5
0
        public static string RenameRoom(User user, string newName, int roomId)
        {
            if (user.UserName == null)
            {
                return("errorNoUserName");
            }
            Room room = Room.GetRoomFromId(roomId);

            if (room == null)
            {
                return("errorRoomNotFound");
            }
            room.Name = newName;
            SocketSender.SendToAllUsers("newroomname|" + room.Id + "," + room.Name);
            return(null);
        }
Beispiel #6
0
        public string LeaveRoom()
        {
            if (UserName == null)
            {
                return("errorNoUserName");
            }

            Room room = GetRoom();

            if (room == null)
            {
                return("errorNotInRoom");
            }
            room.Users.Remove(this);
            SocketSender.SendToAllUsers("leaveroom|" + Id);
            return(null);
        }
Beispiel #7
0
        public static string RemoveRoom(User user, int roomId)
        {
            if (user.UserName == null)
            {
                return("errorNoUserName");
            }
            Room room = GetRoomFromId(roomId);

            if (room == null)
            {
                return("errorRoomNotFound");
            }
            if (room.Users.Count != 0)
            {
                return("errorRoomNotEmpty");
            }
            MainManager.Rooms.Remove(room);
            SocketSender.SendToAllUsers("removeroom|" + room.Id);
            return(null);
        }