private void Client_OnPacketReceive(object sender, ReceivePacketArgs e) { var client = (Client)sender; if (e.Packet is AuthenticationPacket) { var account = ((AuthenticationPacket)e.Packet).Account; if (AllowedAccounts.Contains(account)) { IPacket packet = new InformationPacket(); packet.Execute(client); } else { RemoveClient(client); } } else if (e.Packet is InformationPacket) { var info = ((InformationPacket)e.Packet); client.NetworkId = info.NetworkId; AddClient(client); OnClientConnect?.Invoke(this, new ClientStateChangeArgs(client.NetworkId, client, info)); } else { OnClientPacketReceive?.Invoke(this, e); } }
public void Dispose() { if (!IsDisposed) { ServerEndPoint = null; InternalSocket.Disconnect(false); InternalSocket.Shutdown(SocketShutdown.Both); InternalSocket.Dispose(); foreach (var client in ConnectedClients) { RemoveClient(client.Value); } AllowedAccounts.RemoveRange(0, AllowedAccounts.Count); AllowedAccounts = null; ConnectedClients = null; IsDisposed = true; } }
public Server(string ip, int port, Account account) { ServerEndPoint = new IPEndPoint(IPAddress.Parse(ip), port); AllowedAccounts.Add(account); }