public void DataReceived(IAsyncResult ar) { Connection connection = (Connection)ar.AsyncState; foreach (Packet packet in connection.GetPacketsFromRecievedData(ar)) { Player player = getPlayer(packet, connection); connection.PlayerId = player.Id; UpdatePlayerPosition(player, packet); if (!loggingPacketBlackList.Contains(packet.GetType())) { Console.WriteLine("Received packet from socket: " + packet.ToString() + "for player " + player.Id); } ForwardPacketToOtherPlayers(packet, player.Id); } if (connection.Open != false) { connection.BeginReceive(new AsyncCallback(DataReceived)); } else { playersById.TryRemove(connection.PlayerId); Console.WriteLine("Player disconnected: " + connection.PlayerId); } }