示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
文件: Zone.cs 项目: Setz0r/Onyx
 public Zone(ZONEID zoneId)
 {
     ZoneId = zoneId;
 }