Exemplo n.º 1
0
		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);
			}
		}
Exemplo n.º 2
0
		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));
				}
			}
		}
Exemplo n.º 3
0
 public ClientEventArgs(ClientInfo info)
 {
     this.Client = info;
 }
Exemplo n.º 4
0
		private bool TryKickPlayer(ClientInfo client)
		{
			TcpClient connection;
			if (this.Clients.TryRemove(client, out connection))
			{
				connection.Close();
				return true;
			}
			return false;
		}
Exemplo n.º 5
0
		public void KickPlayer(int id, string reason)
		{
			ClientInfo client = new ClientInfo(id);
			if (this.TryKickPlayer(client))
			{
				this.log.WriteClientDisconnected(client.Id, reason);
			}
		}
Exemplo n.º 6
0
		private void KickPlayer(ClientInfo client)
		{
			if (this.TryKickPlayer(client))
			{
				log.WriteClientDisconnected(client.Id);
			}
		}