Ejemplo n.º 1
0
        private async Task CreateRoom(ClientObject client, string roomName)
        {
            try
            {
                int roomId = await Database.AddRoom(roomName);

                if (roomId == -1)
                {
                    NotifyClient($"This room already exists!", client);
                    return;
                }
                if (!await Database.GiveInvite(client.UserLogin, roomName))
                {
                    onServerInform($"Ошибка выдачи приглашения пользователю {client.UserLogin} в комнату {roomName}.");
                    return;
                }
                ChatRoom newRoom = new ChatRoom(roomName);
                rooms.Add(roomId, newRoom);
                newRoom.AddClientToRoom(client);
                NotifyClient($"{ChatSyntax.CreateRoomCmd} {roomName}", client);
            }
            catch
            {
                NotifyClient($"Couldn't create room with this name.", client);
            }
        }
Ejemplo n.º 2
0
 private async Task InviteToRoom(ClientObject client, string[] userAndRoomName)
 {
     try
     {
         if (userAndRoomName.Length < 2)
         {
             return;
         }
         //if (!await Database.CheckInvite(client, userAndRoomName[1]))
         ChatRoom whereToInvite = GetUsersChatRoomByName(client, userAndRoomName[0]);
         if (whereToInvite == null)
         {
             NotifyClient($"You don't have access to this room.", client);
             return;
         }
         for (int i = 1; i < userAndRoomName.Length; i++)
         {
             if (await Database.GiveInvite(userAndRoomName[i], whereToInvite.Name))
             {
                 NotifyClient($"You've invited {userAndRoomName[i]} to the room {whereToInvite.Name}!", client);
                 var invitedClient = GetClientByLogin(userAndRoomName[i]);
                 if (invitedClient != null)
                 {
                     NotifyClient($"You've been invited to the room {whereToInvite.Name}!", invitedClient);
                     whereToInvite.AddClientToRoom(invitedClient);
                     SendChatHistoryToClient(invitedClient, new List <ChatRoom> {
                         whereToInvite
                     });
                     NotifyClient(ChatSyntax.CreateRoomCmd + " " + whereToInvite.Name, invitedClient);
                 }
             }
         }
     }
     catch
     {
         NotifyClient($"Can't send invasion to this room.", client);
     }
 }