public void SendTo(int clientId, string message) { ClientInfo info = new ClientInfo(clientId); TcpClient client; if (this.Clients.TryGetValue(info, out client)) { ServiceManager.Networker.SendOverStream(client.GetStream(), Notification.CreatePlainMessage(clientId, message)); this.log.WriteDataSent(clientId, message); } }
private async Task AcceptClientAsync() { while (!this.isDisposed) { var client = await listener.AcceptTcpClientAsync(); var info = new ClientInfo(this.counter);; if (this.Clients.TryAdd(info, client)) { Interlocked.Increment(ref this.counter); this.OnClientConnected(new ClientEventArgs(info)); this.log.WriteClientConnected(info.Id); this.SendTo(info.Id, Notification.CreateHandshake(info.Id)); } } }
public ClientEventArgs(ClientInfo info) { this.Client = info; }
private bool TryKickPlayer(ClientInfo client) { TcpClient connection; if (this.Clients.TryRemove(client, out connection)) { connection.Close(); return true; } return false; }
public void KickPlayer(int id, string reason) { ClientInfo client = new ClientInfo(id); if (this.TryKickPlayer(client)) { this.log.WriteClientDisconnected(client.Id, reason); } }
private void KickPlayer(ClientInfo client) { if (this.TryKickPlayer(client)) { log.WriteClientDisconnected(client.Id); } }