Exemplo n.º 1
0
        protected void Send(AppPacket packet)
        {
            if (packet.Size > 512 - 7)
            {
                // Fragment
                WriteLine("Fragment :(");
            }
            else
            {
                if (Debug)
                {
                    //ForegroundColor = ConsoleColor.Green;
                    WriteLine($"Sending app packet (opcode {packet.Opcode:X04}, {this}):");
                    if (packet.Data == null)
                    {
                        WriteLine("!Null data!");
                    }
                    else
                    {
                        Hexdump(packet.Data);
                    }
                    //ResetColor();
                }

                var data = new byte[packet.Size];
                data[1] = (byte)(packet.Opcode >> 8);
                data[0] = (byte)packet.Opcode;
                if (packet.Data != null)
                {
                    Array.Copy(packet.Data, 0, data, 2, packet.Data.Length);
                }
                Send(new Packet(SessionOp.Single, data));
            }
        }
Exemplo n.º 2
0
        protected override void HandleSessionResponse(Packet packet)
        {
            Send(packet);

            var data = new byte[464];
            var str  = $"{AccountID}\0{SessionKey}";

            Array.Copy(Encoding.ASCII.GetBytes(str), data, str.Length);
            Send(AppPacket.Create(WorldOp.SendLoginInfo, data));
        }
Exemplo n.º 3
0
        public void UpdatePosition(Tuple <float, float, float, float> Position)
        {
            var update = new ClientPlayerPositionUpdate {
                ID       = PlayerSpawnId,
                Sequence = UpdateSequence++,
                X        = Position.Item1,
                Y        = Position.Item2,
                Sub1     = new ClientUpdatePositionSub1(),
                Z        = Position.Item3,
                Sub2     = new ClientUpdatePositionSub2(0, (ushort)(Position.Item4 * 8f * 255f))
            };

            Send(AppPacket.Create(ZoneOp.ClientUpdate, update));
        }
Exemplo n.º 4
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            WriteLine($"Foo? {(WorldOp) packet.Opcode}");
            switch ((WorldOp)packet.Opcode)
            {
            case WorldOp.GuildsList:
                break;

            case WorldOp.LogServer:
            case WorldOp.ApproveWorld:
            case WorldOp.EnterWorld:
            case WorldOp.ExpansionInfo:
                break;

            case WorldOp.SendCharInfo:
                var chars = new CharacterSelect(packet.Data);
                CharacterList?.Invoke(this, chars.Characters);
                break;

            case WorldOp.MessageOfTheDay:
                MOTD?.Invoke(this, Encoding.ASCII.GetString(packet.Data));
                break;

            case WorldOp.ZoneServerInfo:
                var info = packet.Get <ZoneServerInfo>();
                ZoneServer?.Invoke(this, info);
                break;

            case WorldOp.SetChatServer:
            case WorldOp.SetChatServer2:
                ChatServerList?.Invoke(this, packet.Data);
                break;

            case WorldOp.PostEnterWorld:
                // The emu doesn't do anything with ApproveWorld and WorldClientReady so we may be able to just skip them both.
                Send(AppPacket.Create(WorldOp.ApproveWorld));
                Send(AppPacket.Create(WorldOp.WorldClientReady));
                break;

            case WorldOp.ApproveName:
                CharacterCreateNameApproval?.Invoke(this, packet.Data[0] == 1);
                break;

            default:
                WriteLine($"Unhandled packet in WorldStream: {(WorldOp) packet.Opcode} (0x{packet.Opcode:X04})");
                Hexdump(packet.Data);
                break;
            }
        }
Exemplo n.º 5
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            switch ((LoginOp)packet.Opcode)
            {
            case LoginOp.ChatMessage:
                Send(AppPacket.Create(LoginOp.Login, new Login(), CryptoBlob));
                break;

            case LoginOp.LoginAccepted:
                if (packet.Data.Length < 90)
                {
                    LoginSuccess?.Invoke(this, false);
                }
                else
                {
                    var dec = Decrypt(packet.Data, 10);
                    var rep = new LoginReply(dec);
                    AccountID  = rep.AcctID;
                    SessionKey = rep.Key;
                    LoginSuccess?.Invoke(this, true);
                }

                break;

            case LoginOp.ServerListResponse:
                var header = packet.Get <ServerListHeader>();
                ServerList?.Invoke(this, header.Servers);
                break;

            case LoginOp.PlayEverquestResponse:
                var resp = packet.Get <PlayResponse>();

                if (!resp.Allowed)
                {
                    CurPlay = null;
                }

                PlaySuccess?.Invoke(this, CurPlay);
                break;

            default:
                WriteLine($"Unhandled packet in LoginStream: {(LoginOp) packet.Opcode} (0x{packet.Opcode:X04})");
                Hexdump(packet.Data);
                break;
            }
        }
Exemplo n.º 6
0
        void HandleAppPacketProxy(AppPacket packet)
        {
            if (Debug)
            {
                //ForegroundColor = ConsoleColor.Magenta;
                WriteLine($"Received app packet (opcode {packet.Opcode:X04}, {this}):");
                if (packet.Data == null)
                {
                    WriteLine("!Null data!");
                }
                else
                {
                    Hexdump(packet.Data);
                }
                //ResetColor();
            }

            HandleAppPacket(packet);
        }
Exemplo n.º 7
0
 protected override void HandleSessionResponse(Packet packet) =>
 Send(AppPacket.Create(LoginOp.SessionReady, new SessionReady()));
Exemplo n.º 8
0
 public void Play(ServerListElement server)
 {
     CurPlay = server;
     Send(AppPacket.Create(LoginOp.PlayEverquestRequest, new PlayRequest(5, server.RuntimeID)));
 }
Exemplo n.º 9
0
 public void RequestServerList() =>
 Send(AppPacket.Create(LoginOp.ServerListRequest, new byte[] { 0, 0, 0, 0 }));
Exemplo n.º 10
0
 protected abstract void HandleAppPacket(AppPacket packet);
Exemplo n.º 11
0
        bool ProcessPacket(Packet packet, bool self = false)
        {
            switch ((SessionOp)packet.Opcode)
            {
            case SessionOp.Bare:
                var bapp = new AppPacket(packet.Data);
                HandleAppPacketProxy(bapp);
                break;

            case SessionOp.Single:
                futurePackets[packet.Sequence] = null;
                var app = new AppPacket(packet.Data);
                HandleAppPacketProxy(app);
                InSequence = (ushort)((packet.Sequence + 1) % 65536);
                if (Debug)
                {
                    WriteLine($"Single packet updated sequence from {packet.Sequence} to {InSequence}");
                }
                break;

            case SessionOp.Fragment:
                var tlen = packet.Data.NetU32(0);
                var rlen = -4;
                for (var i = packet.Sequence; futurePackets[i] != null && rlen < tlen; ++i)
                {
                    rlen += futurePackets[i].Data.Length;
                }
                if (rlen < tlen)
                {
                    // Don't have all the pieces yet
                    futurePackets[packet.Sequence] = packet;
                    return(false);
                }

                var tdata = new byte[rlen];
                rlen = 0;
                var last = 0;
                for (var i = packet.Sequence; rlen < tlen; ++i)
                {
                    var off   = i == packet.Sequence ? 4 : 0;
                    var fdata = futurePackets[i % 65536].Data;
                    Array.Copy(fdata, off, tdata, rlen, fdata.Length - off);
                    rlen            += fdata.Length - off;
                    futurePackets[i] = null;
                    last             = i;
                }

                InSequence = (ushort)((last + 1) % 65536);
                if (Debug)
                {
                    WriteLine(
                        $"Fragmented packet updated our sequence from {packet.Sequence} to {InSequence} ({last - packet.Sequence} packets)");
                }
                HandleAppPacketProxy(new AppPacket(tdata));
                break;
            }

            while (!self && futurePackets[InSequence] != null)
            {
                if (!ProcessPacket(futurePackets[InSequence], self: true))
                {
                    break;
                }
            }
            return(true);
        }
Exemplo n.º 12
0
 public void SendEnterWorld(EnterWorld enterWorld)
 {
     Send(AppPacket.Create(WorldOp.EnterWorld, enterWorld));
 }
Exemplo n.º 13
0
 public void SendCharacterCreate(CharCreate charCreate)
 {
     Send(AppPacket.Create(WorldOp.CharacterCreate, charCreate));
 }
Exemplo n.º 14
0
 public void SendNameApproval(NameApproval nameApproval)
 {
     Send(AppPacket.Create(WorldOp.ApproveName, nameApproval));
 }
Exemplo n.º 15
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            //WriteLine($"Zone app packet: {(ZoneOp) packet.Opcode}");
            switch ((ZoneOp)packet.Opcode)
            {
            case ZoneOp.PlayerProfile:
                var player = packet.Get <PlayerProfile>();
                //WriteLine(player);
                break;

            case ZoneOp.TimeOfDay:
                var timeofday = packet.Get <TimeOfDay>();
                //WriteLine(timeofday);
                break;

            case ZoneOp.TaskActivity:
                // XXX: Handle short activities!
                //var activity = packet.Get<TaskActivity>();
                //WriteLine(activity);
                break;

            case ZoneOp.TaskDescription:
                var desc = packet.Get <TaskDescription>();
                //WriteLine(desc);
                break;

            case ZoneOp.CompletedTasks:
                var comp = packet.Get <CompletedTasks>();
                //WriteLine(comp);
                break;

            case ZoneOp.XTargetResponse:
                var xt = packet.Get <XTarget>();
                //WriteLine(xt);
                break;

            case ZoneOp.Weather:
                var weather = packet.Get <Weather>();
                //WriteLine(weather);

                if (Entering)
                {
                    Send(AppPacket.Create(ZoneOp.ReqNewZone));
                }
                break;

            case ZoneOp.TributeTimer:
                var timer = packet.Get <TributeTimer>();
                //WriteLine(timer);
                break;

            case ZoneOp.TributeUpdate:
                var update = packet.Get <TributeInfo>();
                //WriteLine(update);
                break;

            case ZoneOp.ZoneEntry:
                var mob = packet.Get <Spawn>();
                if (mob.Name == CharName)
                {
                    PlayerSpawnId = (ushort)mob.SpawnID;
                }
                Spawned?.Invoke(this, mob);
                break;

            case ZoneOp.NewZone:
                Send(AppPacket.Create(ZoneOp.ReqClientSpawn));
                break;

            case ZoneOp.SendExpZonein:
                if (Entering)
                {
                    Send(AppPacket.Create(ZoneOp.ClientReady));
                    Entering = false;
                }

                break;

            case ZoneOp.CharInventory:
                break;

            case ZoneOp.SendFindableNPCs:
                var npc = packet.Get <FindableNPC>();
                //WriteLine(npc);
                break;

            case ZoneOp.ClientUpdate:
                var pu = packet.Get <PlayerPositionUpdate>();
                PositionUpdated?.Invoke(this, pu);
                break;

            case ZoneOp.HPUpdate:
                break;

            case ZoneOp.SpawnDoor:
                for (var i = 0; i < packet.Data.Length; i += 92)
                {
                    var door = new Door(packet.Data, i);
                    WriteLine(door);
                }
                break;

            default:
                WriteLine($"Unhandled packet in ZoneStream: {(ZoneOp) packet.Opcode} (0x{packet.Opcode:X04})");
                Hexdump(packet.Data);
                break;
            }
        }
Exemplo n.º 16
0
        protected override void HandleSessionResponse(Packet packet)
        {
            Send(packet);

            Send(AppPacket.Create(ZoneOp.ZoneEntry, new ClientZoneEntry(CharName)));
        }