public void StartManagerSettings() { Guid clientGuid = _data.ClientsConnectedInServer.GetGuid(_client); try { AllGroupsManagedByClient(clientGuid); string dataReceived = _requests.GetStringMessage(_client); GroupChat oldGroupChat = null; if (dataReceived == "0") { _logger.LogInformation($"client dont want to enter manager settings to any group"); } else { oldGroupChat = SendGroup(dataReceived); SendAllConecctedClients(clientGuid); GroupChat newGroupChat = WaitToGetGroupFromClient(); AddGroup(newGroupChat, oldGroupChat, clientGuid); _logger.LogInformation($"client {clientGuid} change settings group {newGroupChat.Name}"); } } catch (Exception) { ChatUtils.RemoveClientWhenOut(_client, clientGuid, _data); } }
private void LeaveGroup() { var clientGuid = _data.ClientsConnectedInServer.GetGuid(_client); try { SendAllClientGroups(clientGuid); string dataReceived = _requests.GetStringMessage(_client); if (dataReceived == "0") { _logger.LogInformation($"client {clientGuid} dont want to leave any group"); } else { RemoveParticipantFromGroup(dataReceived, clientGuid); RemoveManagerFromGroup(dataReceived, clientGuid); _logger.LogInformation($"client {clientGuid} leave group {dataReceived}"); } } catch (Exception) { ChatUtils.RemoveClientWhenOut(_client, clientGuid, _data); } }
private void StartGroupChat() { bool end = false; GroupChat group = null; var clientGuid = _data.ClientsConnectedInServer.GetGuid(_client); try { SendAllClientGroups(clientGuid); string dataReceived = _requests.GetStringMessage(_client); if (dataReceived == "0") { _logger.LogInformation("client dont want to enter chat in any group"); } else { group = _data.AllGroupsChat.GetGroupsChat().Where(g => g.Name == dataReceived).First(); _logger.LogInformation($"client {clientGuid} enter to group chat {group.Name}"); _data.AllGroupsChat.AddClientConnected(group, _client); SendMessagesHistory(group); while (!end) { dataReceived = _requests.GetStringMessage(_client); if (dataReceived == "0") { MessageRequest messageRequest = new MessageRequest(MessageKey.Exit, "0"); _requests.SendModelMessage(_client, messageRequest); ClientOutOfGroup(group); _data.AllGroupsChat.RemoveClientUnConnected(group, _client); end = true; } else { string message = $"{clientGuid} send: {dataReceived}"; SendMessageToEachClient(group, message); } } } } catch (Exception) { end = true; _data.AllGroupsChat.RemoveClientUnConnected(group, _client); ChatUtils.RemoveClientWhenOut(_client, clientGuid, _data); } _logger.LogInformation("client out chat"); }
private void StartGlobalChat() { bool end = false; var clientGuid = _data.ClientsInGlobalChat.GetClient(_client); SendMessagesHistory(); SendAllAboutEnter(clientGuid); while (!end) { try { string dataReceivedType = _requests.GetStringMessage(_client); if (dataReceivedType == "0") { _data.ClientsInGlobalChat.Remove(clientGuid); SendAllAboutExist(clientGuid); end = true; } else { if (dataReceivedType == MessageType.STRING.ToString()) { string dataReceived = _requests.GetStringMessage(_client); SendAllStringMessage(clientGuid, dataReceived); } else if (dataReceivedType == MessageType.PIC.ToString()) { _requests.GetPictureMessage(_client); SendAllPicMessage(clientGuid); } else { _data.ClientsInGlobalChat.Remove(clientGuid); SendAllAboutExist(clientGuid); end = true; } } } catch (Exception) { end = true; ChatUtils.RemoveClientWhenOut(_client, clientGuid, _data); _data.ClientsInGlobalChat.Remove(clientGuid); } } }
public void CreateGroup() { Guid clientGuid = _data.ClientsConnectedInServer.GetGuid(_client); try { SendAllConecctedClients(clientGuid); GroupChat groupChat = WaitToGetGroupFromClient(); AddGroup(groupChat, clientGuid); } catch (Exception) { ChatUtils.RemoveClientWhenOut(_client, clientGuid, _data); } }
private void StartPrivateChat() { Guid clientGuid = _data.ClientsConnectedInServer.GetGuid(_client); Guid guidToSend; try { SendAllClientsConnected(clientGuid); string dataReceived = _requests.GetStringMessage(_client); TcpClient clientSend; Guid.TryParse(dataReceived, out guidToSend); if (_data.ClientsConnectedInServer.Clients.TryGetValue(guidToSend, out clientSend)) { bool end = false; AddPrivateChat(clientGuid, guidToSend); SendMessagesHistory(clientGuid, guidToSend); while (!end) { dataReceived = _requests.GetStringMessage(_client); if (dataReceived == "0") { ExistChat(clientGuid, guidToSend); end = true; } else { SendMessage(dataReceived, clientGuid, guidToSend, clientSend); } } } else { string message = $"fail"; ChatUtils.SandStringMessage(_client, _requests, message); } } catch (Exception) { ChatUtils.RemoveClientWhenOut(_client, clientGuid, _data); } }