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