public bool RecieveDataCallback(UDPServer server, EndPoint endpoint, byte[] buffer, int offset, int size) { if (size > 0) { Console.WriteLine(Utility.ByteArrayToString(buffer.Take(size).ToArray())); Player player = null; ZONEID playerZone = GetZoneIDByEndpoint(endpoint); if (playerZone == ZONEID.NONE) { if (!clients.TryUpdate(endpoint, playerZone, ZONEID.NONE)) { if (clients.TryAdd(endpoint, ZONEID.NONE)) // temp { player = new Player(); player.Client = new UDPClient(server, endpoint); } } // possible new connection // TODO: check database for endpoint/zone } else { player = GetPlayerByEndpoint(endpoint); if (player == null) { player = zones[playerZone].InsertPlayer(server, endpoint); if (player != null) { } //else //{ // // player already logged in. //} } } if (player != null) { string keybytes = "000000000000000000000000000000005CE05DAD"; byte[] key = Utility.StringToByteArray(keybytes); player.Client.SetBlowfishKey(key); player.Client.RecvData(buffer.Skip(offset).Take(size).ToArray()); ushort bytesProcessed = PacketHandler.ProcessPacket(player, player.Client.dataBuffer, size, this); if (bytesProcessed > 0) { player.Client.ResetBuffer(); } } return(true); } return(false); }
public Player GetPlayerByEndpoint(EndPoint ep) { if (clients.ContainsKey(ep)) { ZONEID zoneId = clients[ep]; if (zones.ContainsKey(zoneId)) { var player = zones[zoneId].Players.FirstOrDefault(x => x.Value.Client.endpoint == ep); if (!player.Equals(default(KeyValuePair <uint, Player>))) { return(player.Value); } } } return(null); }
public Zone(ZONEID zoneId) { ZoneId = zoneId; }