コード例 #1
0
ファイル: PacketHandler.cs プロジェクト: Setz0r/Onyx
        public static bool ProcessDataChunk(Player player, byte[] chunkData, ZoneCluster cluster)
        {
            if (chunkData.Length > 0)
            {
                byte id   = chunkData[0];
                int  size = chunkData[1] * 2;

                Func <Player, byte[], bool> method;

                if (!IncomingPacketChunks.TryGetValue(id, out method))
                {
                    return(false);
                }

                bool result = false;

                if (size >= chunkData.Length)
                {
                    result = method(player, chunkData);
                }

                return(result);
            }

            return(false);
        }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: Setz0r/Onyx
        public void LoadZoneClusters()
        {
            // TODO: replace with yaml loading
            ZoneCluster clusterA  = new ZoneCluster();
            Zone        testZoneA = new Zone(ZONEID.BASTOK_MARKETS);

            clusterA.zones.TryAdd(ZONEID.BASTOK_MARKETS, testZoneA);
            Zone testZoneB = new Zone(ZONEID.BASTOK_MINES);

            clusterA.zones.TryAdd(ZONEID.BASTOK_MINES, testZoneB);
            Zone testZoneC = new Zone(ZONEID.PORT_BASTOK);

            clusterA.zones.TryAdd(ZONEID.PORT_BASTOK, testZoneC);
            Zone testZoneD = new Zone(ZONEID.METALWORKS);

            clusterA.zones.TryAdd(ZONEID.METALWORKS, testZoneD);
            clusters.Add(clusterA);
            ZoneCluster clusterB  = new ZoneCluster();
            Zone        testZoneE = new Zone(ZONEID.NORTH_GUSTABERG);

            clusterB.zones.TryAdd(ZONEID.NORTH_GUSTABERG, testZoneE);
            Zone testZoneF = new Zone(ZONEID.ZERUHN_MINES);

            clusterB.zones.TryAdd(ZONEID.ZERUHN_MINES, testZoneF);
            Zone testZoneG = new Zone(ZONEID.PALBOROUGH_MINES);

            clusterB.zones.TryAdd(ZONEID.PALBOROUGH_MINES, testZoneG);
            Zone testZoneH = new Zone(ZONEID.SOUTH_GUSTABERG);

            clusterB.zones.TryAdd(ZONEID.SOUTH_GUSTABERG, testZoneH);
            clusters.Add(clusterB);
        }
コード例 #3
0
ファイル: PacketHandler.cs プロジェクト: Setz0r/Onyx
        public static ushort ProcessPacket(Player player, byte[] packetData, int packetSize, ZoneCluster cluster)
        {
            bool    canProcess = true;
            ByteRef packetRef  = new ByteRef(packetData.Take(packetSize).ToArray());

            byte[] decryptedData;
            ushort cursor = 0;

            // TODO: make this more efficient and trim off the header before anything else...

            int checksum = Utility.Checksum(packetRef.GetBytes(PACKET_HEADER_SIZE, packetSize - PACKET_HEADER_SIZE), packetSize - (PACKET_HEADER_SIZE + 16), packetRef.GetBytes(packetSize - 16, 16));

            decryptedData = packetRef.Get();
            if (checksum != 0)
            {
                Crypto.DecryptPacket(player.Client.blowfish, ref decryptedData);
                packetRef = new ByteRef(decryptedData);
                checksum  = Utility.Checksum(packetRef.GetBytes(PACKET_HEADER_SIZE, packetSize - PACKET_HEADER_SIZE), packetSize - (PACKET_HEADER_SIZE + 16), packetRef.GetBytes(packetSize - 16, 16));
                if (checksum != 0)
                {
                    canProcess = false;
                    Logger.Error("Unable to decrypt a packet");
                    packetRef.DebugDump();
                }
            }
            packetRef = new ByteRef(packetRef.Get().Skip(PACKET_HEADER_SIZE).ToArray());
            while (canProcess && packetRef.Length - cursor > 4)
            {
                byte   id   = packetRef.GetByte(cursor);
                ushort size = (byte)(packetRef.GetByte(cursor + 1) * 2);
                if (size > packetRef.Length)
                {
                    return(0);
                }
                if (!ProcessDataChunk(player, packetRef.GetBytes(cursor, size), cluster))
                {
                    Logger.Warning("Unable to process chunk ID {0} for Player ID: {1}, Possible validation issue", new object[] { id, player.PlayerId });
                }
                cursor += size;
            }

            return(cursor);
        }