Esempio n. 1
0
        internal static void Init()
        {
            // Register handlers
            Core.RegisterServerMessageCallback(0x1A, new MessageCallback(OnItemDetails));
            Core.RegisterServerMessageCallback(0x1D, new MessageCallback(OnObjectRemove));
            Core.RegisterServerMessageCallback(0x24, new MessageCallback(OnOpenContainer));
            Core.RegisterServerMessageCallback(0x25, new MessageCallback(OnAddToContainer));
            Core.RegisterServerMessageCallback(0x3C, new MessageCallback(OnContainerContents));
            Core.RegisterServerMessageCallback(0x2E, new MessageCallback(OnCharacterAddItem));
            Core.RegisterServerMessageCallback(0x11, new MessageCallback(OnCharacterStatus));
            Core.RegisterServerMessageCallback(0x2D, new MessageCallback(OnUpdateStats));
            Core.RegisterServerMessageCallback(0xA1, new MessageCallback(OnUpdateHits));
            Core.RegisterServerMessageCallback(0xA2, new MessageCallback(OnUpdateMana));
            Core.RegisterServerMessageCallback(0xA3, new MessageCallback(OnUpdateStamina));
            Core.RegisterServerMessageCallback(0x1B, new MessageCallback(OnLoginConfirm), CallbackPriority.High);
            Core.RegisterServerMessageCallback(0x20, new MessageCallback(OnPlayerSync));
            Core.RegisterServerMessageCallback(0x77, new MessageCallback(OnCharacterUpdate));
            Core.RegisterServerMessageCallback(0x78, new MessageCallback(OnCharacterInformation));
            Core.RegisterServerMessageCallback(0x98, new MessageCallback(OnThingName));
            Core.RegisterServerMessageCallback(0x1C, new MessageCallback(OnAsciiSpeech));
            Core.RegisterServerMessageCallback(0xAE, new MessageCallback(OnUniSpeech));
            Core.RegisterServerMessageCallback(0x4F, new MessageCallback(OnSunLight));
            Core.RegisterServerMessageCallback(0x72, new MessageCallback(OnWarMode));

            Core.Disconnected += new EventHandler(Core_Disconnected);

            WalkHandling.Init();
        }
Esempio n. 2
0
        static CallbackResult OnLoginConfirm(byte[] data, CallbackResult prevResult)
        {
            lock (World.SyncRoot) {
                if (data[0] != 0x1B)
                {
                    throw new Exception("Invalid packet passed to OnLoginConfirm.");
                }

                bool expected = (World.PlayerSerial == World.InvalidSerial);
                uint serial   = ByteConverter.BigEndian.ToUInt32(data, 1);

                if (!expected && World.PlayerSerial != serial)
                {
                    Trace.WriteLine("Invalid serial in LoginConfirm! Packet ignored.", "World");
                    return(CallbackResult.Normal);
                }

                World.PlayerSerial = serial;

                RealCharacter chr = World.FindRealCharacter(World.PlayerSerial);
                if (chr == null)
                {
                    chr = new RealCharacter(World.PlayerSerial);
                    World.Add(chr);
                }

                chr.Graphic = ByteConverter.BigEndian.ToUInt16(data, 9);

                chr.X = ByteConverter.BigEndian.ToUInt16(data, 11);
                chr.Y = ByteConverter.BigEndian.ToUInt16(data, 13);
                chr.Z = ByteConverter.BigEndian.ToSByte(data, 16);

                chr.Direction = ByteConverter.BigEndian.ToByte(data, 17);

                WalkHandling.ClearStack();

                if (expected)
                {
                    Trace.WriteLine(String.Format("Player logged in. ({0}).", chr), "World");
                }
                else
                {
                    Trace.WriteLine("Unexpected LoginConfirm packet.", "World");
                }

                return(CallbackResult.Normal);
            }
        }
Esempio n. 3
0
        static CallbackResult OnPlayerSync(byte[] data, CallbackResult prevResult)
        {
            lock (World.SyncRoot) {
                if (data[0] != 0x20)
                {
                    throw new Exception("Invalid packet passed to OnPlayerSync.");
                }

                uint serial = ByteConverter.BigEndian.ToUInt32(data, 1);

                if (World.RealPlayer == null)
                {
                    Trace.WriteLine(String.Format("LoginConfirm packet not received yet."), "World");
                    return(CallbackResult.Normal);
                }

                if (World.PlayerSerial != serial)
                {
                    throw new InvalidOperationException("Invalid serial in 0x20 packet.");
                }

                World.RealPlayer.Graphic = ByteConverter.BigEndian.ToUInt16(data, 5);
                World.RealPlayer.Status  = data[7];
                World.RealPlayer.Color   = ByteConverter.BigEndian.ToUInt16(data, 8);
                World.RealPlayer.Flags   = ByteConverter.BigEndian.ToByte(data, 10);

                World.RealPlayer.X = ByteConverter.BigEndian.ToUInt16(data, 11);
                World.RealPlayer.Y = ByteConverter.BigEndian.ToUInt16(data, 13);
                World.RealPlayer.Z = ByteConverter.BigEndian.ToSByte(data, 18);

                World.RealPlayer.Direction = ByteConverter.BigEndian.ToByte(data, 17);

                WalkHandling.ClearStack();

                Trace.WriteLine(String.Format("Player updated ({0}).", World.RealPlayer), "World");

                ObjectChanged(serial, ObjectChangeType.CharUpdated);
                return(CallbackResult.Normal);
            }
        }