示例#1
0
 public void Read(WorldPacket data)
 {
     FactionGroup = data.ReadInt32();
     Locale       = data.ReadInt32();
     RequesterVirtualRealmAddress = data.ReadUInt32();
 }
示例#2
0
 public AuctionSellItem(WorldPacket packet) : base(packet)
 {
 }
示例#3
0
        public bool Update(uint diff, PacketFilter updater)
        {
            // Update Timeout timer.
            UpdateTimeOutTime(diff);

            // Before we process anything:
            // If necessary, kick the player from the character select screen
            if (IsConnectionIdle())
            {
                m_Socket[(int)ConnectionType.Realm].CloseSocket();
            }

            WorldPacket firstDelayedPacket = null;
            uint        processedPackets   = 0;
            long        currentTime        = Time.UnixTime;

            WorldPacket packet;

            //Check for any packets they was not recived yet.
            while (m_Socket[(int)ConnectionType.Realm] != null && !_recvQueue.IsEmpty && (_recvQueue.TryPeek(out packet, updater) && packet != firstDelayedPacket) && _recvQueue.TryDequeue(out packet))
            {
                try
                {
                    var handler = PacketManager.GetHandler((ClientOpcodes)packet.GetOpcode());
                    switch (handler.sessionStatus)
                    {
                    case SessionStatus.Loggedin:
                        if (!_player)
                        {
                            if (!m_playerRecentlyLogout)
                            {
                                if (firstDelayedPacket == null)
                                {
                                    firstDelayedPacket = packet;
                                }

                                QueuePacket(packet);
                                Log.outDebug(LogFilter.Network, "Re-enqueueing packet with opcode {0} with with status OpcodeStatus.Loggedin. Player is currently not in world yet.", (ClientOpcodes)packet.GetOpcode());
                            }
                            break;
                        }
                        else if (_player.IsInWorld && AntiDOS.EvaluateOpcode(packet, currentTime))
                        {
                            handler.Invoke(this, packet);
                        }
                        break;

                    case SessionStatus.LoggedinOrRecentlyLogout:
                        if (!_player && !m_playerRecentlyLogout && !m_playerLogout)
                        {
                            LogUnexpectedOpcode(packet, handler.sessionStatus, "the player has not logged in yet and not recently logout");
                        }
                        else if (AntiDOS.EvaluateOpcode(packet, currentTime))
                        {
                            handler.Invoke(this, packet);
                        }
                        break;

                    case SessionStatus.Transfer:
                        if (!_player)
                        {
                            LogUnexpectedOpcode(packet, handler.sessionStatus, "the player has not logged in yet");
                        }
                        else if (_player.IsInWorld)
                        {
                            LogUnexpectedOpcode(packet, handler.sessionStatus, "the player is still in world");
                        }
                        else if (AntiDOS.EvaluateOpcode(packet, currentTime))
                        {
                            handler.Invoke(this, packet);
                        }
                        break;

                    case SessionStatus.Authed:
                        // prevent cheating with skip queue wait
                        if (m_inQueue)
                        {
                            LogUnexpectedOpcode(packet, handler.sessionStatus, "the player not pass queue yet");
                            break;
                        }

                        if ((ClientOpcodes)packet.GetOpcode() == ClientOpcodes.EnumCharacters)
                        {
                            m_playerRecentlyLogout = false;
                        }

                        if (AntiDOS.EvaluateOpcode(packet, currentTime))
                        {
                            handler.Invoke(this, packet);
                        }
                        break;

                    default:
                        Log.outError(LogFilter.Network, "Received not handled opcode {0} from {1}", (ClientOpcodes)packet.GetOpcode(), GetPlayerInfo());
                        break;
                    }
                }
                catch (InternalBufferOverflowException ex)
                {
                    Log.outError(LogFilter.Network, "InternalBufferOverflowException: {0} while parsing {1} from {2}.", ex.Message, (ClientOpcodes)packet.GetOpcode(), GetPlayerInfo());
                }
                catch (EndOfStreamException)
                {
                    Log.outError(LogFilter.Network, "WorldSession:Update EndOfStreamException occured while parsing a packet (opcode: {0}) from client {1}, accountid={2}. Skipped packet.",
                                 (ClientOpcodes)packet.GetOpcode(), GetRemoteAddress(), GetAccountId());
                }

                processedPackets++;

                if (processedPackets > 100)
                {
                    break;
                }
            }

            if (m_Socket[(int)ConnectionType.Realm] != null && m_Socket[(int)ConnectionType.Realm].IsOpen() && _warden != null)
            {
                _warden.Update();
            }

            ProcessQueryCallbacks();

            if (updater.ProcessUnsafe())
            {
                long currTime = Time.UnixTime;
                // If necessary, log the player out
                if (ShouldLogOut(currTime) && m_playerLoading.IsEmpty())
                {
                    LogoutPlayer(true);
                }

                if (m_Socket[(int)ConnectionType.Realm] != null && GetPlayer() && _warden != null)
                {
                    _warden.Update();
                }

                //- Cleanup socket if need
                if ((m_Socket[(int)ConnectionType.Realm] != null && !m_Socket[(int)ConnectionType.Realm].IsOpen()) ||
                    (m_Socket[(int)ConnectionType.Instance] != null && !m_Socket[(int)ConnectionType.Instance].IsOpen()))
                {
                    expireTime -= expireTime > diff ? diff : expireTime;
                    if (expireTime < diff || forceExit || !GetPlayer())
                    {
                        if (m_Socket[(int)ConnectionType.Realm] != null)
                        {
                            m_Socket[(int)ConnectionType.Realm].CloseSocket();
                            m_Socket[(int)ConnectionType.Realm] = null;
                        }
                        if (m_Socket[(int)ConnectionType.Instance] != null)
                        {
                            m_Socket[(int)ConnectionType.Instance].CloseSocket();
                            m_Socket[(int)ConnectionType.Instance] = null;
                        }
                    }
                }

                if (m_Socket[(int)ConnectionType.Realm] == null)
                {
                    return(false);                                       //Will remove this session from the world session map
                }
            }

            return(true);
        }
示例#4
0
 public AuctionHelloRequest(WorldPacket packet) : base(packet)
 {
 }
示例#5
0
 public void Write(WorldPacket data)
 {
     data.WriteInt32(AuctionItemID);
     data.WriteUInt64(BidAmount);
     Item.Write(data);
 }
示例#6
0
 public AuctionPlaceBid(WorldPacket packet) : base(packet)
 {
 }
示例#7
0
 public AuctionReplicateItems(WorldPacket packet) : base(packet)
 {
 }
示例#8
0
 public CalendarEventRSVP(WorldPacket packet) : base(packet)
 {
 }
示例#9
0
 public CalendarGetNumPending(WorldPacket packet) : base(packet)
 {
 }
示例#10
0
 public CalendarGetCalendar(WorldPacket packet) : base(packet)
 {
 }
示例#11
0
 public CalendarEventInvite(WorldPacket packet) : base(packet)
 {
 }
示例#12
0
 public CalendarCopyEvent(WorldPacket packet) : base(packet)
 {
 }
示例#13
0
 public CalendarRemoveEvent(WorldPacket packet) : base(packet)
 {
 }
示例#14
0
    public void getPackets()
    {
        //GD.Print("Get Packets");
        //GD.Print(wrapped_client.GetAvailablePacketCount());
        if (connected && client.GetAvailableBytes() > 0)
        {
            //byte[] packet_data = wrapped_client.GetPacket();
            //UInt32 packetLength = BitConverter.ToUInt32(packet_data, 0);
            //short packetId = BitConverter.ToInt16(packet_data, 4);
            UInt32 packetLength = (UInt32)client.GetU32();
            short  packetId     = (short)client.Get16();
            var    packetData   = client.GetData((int)packetLength - 2);
            //var data = new List<byte>(packet_data).GetRange(6, packet_data.Length -6).ToArray();
            //GD.Print(BitConverter.ToString( (byte[]) packetData[1]));
            var data   = (byte[])packetData[1];
            var packet = Packets.Packets.decode(packetId, data);

            if (GetParent().GetNodeOrNull("GUI") != null)
            {
                var gui = (Control)GetParent().GetNodeOrNull("GUI");
                gui.Call("recordPacket", packetLength + 4);
            }

            GD.Print(String.Format("Received packet {0}, ID: {1} Length: {2}", packet.name, packetId, packetLength));

            if (packet is ReadyPacket)
            {
                ReadyPacket parsed_packet = (ReadyPacket)packet;
                if (parsed_packet.code == 0)
                {
                    string token       = (string)GetParent().GetNode("Discord Integration").Call("getToken");
                    var    loginPacket = new LoginPacket(token);
                    GD.Print("Sending login");
                    sendPacket(loginPacket);
                }
                else if (parsed_packet.code == 1)
                {
                    var requestWorldPacket = new RequestWorldPacket();
                    sendPacket(requestWorldPacket);
                    if (!joined)
                    {
                        var loadingRes = GD.Load <PackedScene>("res://scenes/world.tscn");
                        var node       = loadingRes.Instance();
                        node.SetName("WorldScene");
                        var loadingGuiRes = GD.Load <PackedScene>("res://scenes/gui.tscn");
                        var gui           = (Control)loadingGuiRes.Instance();
                        gui.SetName("GUI");
                        GetParent().Call("setState", 2);
                        GetParent().AddChild(node);
                        //GetParent().AddChild(gui);
                        GetParent().AddChild(gui);
                        //node.AddChild(gui);
                        GetParent().GetNode("GameLoader").Free();
                        //var playerSpriteScene = (PackedScene) node.Call("getSprite", "rowan");
                        //var playerSprite = (AnimatedSprite) playerSpriteScene.Instance();
                        //playerSprite.SetName("PlayerSprite");
                        //node.GetNode("World/Player").AddChild(playerSprite);
                        //playerSprite.Position = ((KinematicBody2D) node.GetNode("Player")).Position;
                        //playerSprite.Visible = true;
                        //GD.Print(playerSprite);
                        joined = true;
                    }
                }
            }
            else if (packet is PongPacket)
            {
                PongPacket parsed_packet = (PongPacket)packet;
                GD.Print("Got pong of " + parsed_packet.message);
            }
            else if (packet is LoginResultPacket)
            {
                LoginResultPacket parsed_packet = (LoginResultPacket)packet;
                GD.Print("Login Result: " + parsed_packet.responseCode.ToString() + " Name: " + parsed_packet.userId);
                var joinGamePacket = new JoinGamePacket();
                sendPacket(joinGamePacket);
            }
            else if (packet is WorldPacket)
            {
                WorldPacket parsed_packet = (WorldPacket)packet;
                //GD.Print(parsed_packet.debug);
                GetParent().GetNode("WorldScene").Call("loadWorld", new object[] { parsed_packet.worldData, parsed_packet.bumpData, parsed_packet.height, parsed_packet.width });
            }
            else if (packet is PlayerPositionPacket)
            {
                PlayerPositionPacket parsed_packet = (PlayerPositionPacket)packet;
                GetParent().GetNode("WorldScene/World/Player").Call("move", new object[] { parsed_packet.x, parsed_packet.y });
            }
            else if (packet is ChatPacket)
            {
                ChatPacket parsed_packet = (ChatPacket)packet;
                GetNode("../GUI/Chat").Call("AddMessage", parsed_packet.author + ": " + parsed_packet.msg);
            }
            else if (packet is EntityPacket)
            {
                EntityPacket parsed_packet = (EntityPacket)packet;
                GD.Print("Got entity '", parsed_packet.sprite, "' at ", parsed_packet.x, ",", parsed_packet.y, " ID: ", parsed_packet.uuid);
                GetNode("../WorldScene").Call("addEntity", parsed_packet.x, parsed_packet.y, parsed_packet.type, parsed_packet.facing, parsed_packet.interactable, parsed_packet.sprite, parsed_packet.uuid, parsed_packet.type != 2);
            }
            else if (packet is EntityMovePacket)
            {
                EntityMovePacket parsed_packet = (EntityMovePacket)packet;
                GD.Print("Got entity moving to ", parsed_packet.x, ",", parsed_packet.y, " ID: ", parsed_packet.uuid);
                GetNode("../WorldScene").Call("moveEntity", parsed_packet.uuid, parsed_packet.x, parsed_packet.y, parsed_packet.facing);
            }
            else if (packet is InvalidateCachePacket)
            {
                InvalidateCachePacket parsed_packet = (InvalidateCachePacket)packet;
                GD.Print(parsed_packet.uuid, " Invalidated.");
                GetNode("../WorldScene").Call("hideEntity", parsed_packet.uuid);
            }
            else if (packet is DialoguePacket)
            {
                DialoguePacket parsed_packet = (DialoguePacket)packet;
                GD.Print("Got dialogue \"", parsed_packet.text, "\"");
                Window window = (Window)GetNode("../GUI/Window");
                window.OpenDialoguePanel();
                DialoguePanel dialoguePanel = window.OpenDialoguePanel(); //(DialoguePanel) GetNode("../GUI/Window/DialoguePanel");
                dialoguePanel.SetDialogue(parsed_packet.text, parsed_packet.author, parsed_packet.sprite, parsed_packet.substitutions, parsed_packet.optionViews);
            }
            else if (packet is CloseDialoguePacket)
            {
                CloseDialoguePacket parsed_packet = (CloseDialoguePacket)packet;
                DialoguePanel       dialoguePanel = (DialoguePanel)GetNode("../GUI/Window/DialoguePanel");
                dialoguePanel.CloseDialogue(parsed_packet.guid);
                //dialoguePanel.SetDialogue(parsed_packet.text, parsed_packet.author, parsed_packet.sprite, parsed_packet.substitutions, parsed_packet.optionViews);
            }
            else if (packet is PlayerDataPacket)
            {
                PlayerDataPacket parsed_packet = (PlayerDataPacket)packet;
                var player = (Player)GetNode("../WorldScene/World/Player");
                player.SetUuid(parsed_packet.guid);
                if (player.GetNodeOrNull("PlayerSprite") != null)
                {
                    player.GetNodeOrNull("PlayerSprite").Free();
                }
                var playerSpriteScene = (PackedScene)GetNode("../WorldScene").Call("getSprite", parsed_packet.sprite);
                var playerSprite      = (AnimatedSprite)playerSpriteScene.Instance();
                playerSprite.SetName("PlayerSprite");
                player.AddChild(playerSprite);
            }
            else if (packet is InventoryPacket)
            {
                InventoryPacket parsed_packet = (InventoryPacket)packet;
                var             player        = (Player)GetNode("../WorldScene/World/Player");
                if (player.guid == parsed_packet.inventory.guid)
                {
                    player.inventory = parsed_packet.inventory;
                    foreach (Item item in player.inventory.items)
                    {
                        GD.Print("Item: ", item.GetName(), " \"", item.GetDescription(), "\"");
                    }
                }
            }
            else if (packet is AddItemPacket)
            {
                AddItemPacket parsed_packet = (AddItemPacket)packet;
                var           player        = (Player)GetNode("../WorldScene/World/Player");
                if (player.guid == parsed_packet.guid)
                {
                    //TODO: Make use of indices.
                    player.inventory.AddItem(parsed_packet.item, true);
                }
            }
            else if (packet is ModifyItemPacket)
            {
                ModifyItemPacket parsed_packet = (ModifyItemPacket)packet;
                var player = (Player)GetNode("../WorldScene/World/Player");
                if (player.guid == parsed_packet.guid)
                {
                    //TODO: Make use of indices.
                    player.inventory.UpdateItem(parsed_packet.item, parsed_packet.index);
                }
            }
        }
        else
        {
            var testPacket = new Packets.PingPacket("Hello There!");
            //sendPacket(testPacket);
        }
    }
示例#15
0
 public CalendarComplain(WorldPacket packet) : base(packet)
 {
 }
示例#16
0
 public CalendarCommunityFilter(WorldPacket packet) : base(packet)
 {
 }
示例#17
0
 public CalendarUpdateEvent(WorldPacket packet) : base(packet)
 {
 }
示例#18
0
 public CalendarEventSignUp(WorldPacket packet) : base(packet)
 {
 }
示例#19
0
 public AuctionRemoveItem(WorldPacket packet) : base(packet)
 {
 }
示例#20
0
 public CalendarRemoveInvite(WorldPacket packet) : base(packet)
 {
 }
示例#21
0
 public AuctionListPendingSales(WorldPacket packet) : base(packet)
 {
 }
示例#22
0
 public CalendarEventStatus(WorldPacket packet) : base(packet)
 {
 }
示例#23
0
 public AuctionListItems(WorldPacket packet) : base(packet)
 {
 }
示例#24
0
 public SetSavedInstanceExtend(WorldPacket packet) : base(packet)
 {
 }
示例#25
0
 public void Write(WorldPacket data)
 {
     data.WriteInt32(AuctionItemID);
     data.WritePackedGuid(Bidder);
     Item.Write(data);
 }
示例#26
0
 public CalendarEventModeratorStatus(WorldPacket packet) : base(packet)
 {
 }
示例#27
0
        //todo fix me
        public bool EvaluateOpcode(WorldPacket packet, long time)
        {
            uint maxPacketCounterAllowed = 0;// GetMaxPacketCounterAllowed(p.GetOpcode());

            // Return true if there no limit for the opcode
            if (maxPacketCounterAllowed == 0)
            {
                return(true);
            }

            if (!_PacketThrottlingMap.ContainsKey(packet.GetOpcode()))
            {
                _PacketThrottlingMap[packet.GetOpcode()] = new PacketCounter();
            }

            PacketCounter packetCounter = _PacketThrottlingMap[packet.GetOpcode()];

            if (packetCounter.lastReceiveTime != time)
            {
                packetCounter.lastReceiveTime = time;
                packetCounter.amountCounter   = 0;
            }

            // Check if player is flooding some packets
            if (++packetCounter.amountCounter <= maxPacketCounterAllowed)
            {
                return(true);
            }

            Log.outWarn(LogFilter.Network, "AntiDOS: Account {0}, IP: {1}, Ping: {2}, Character: {3}, flooding packet (opc: {4} (0x{4}), count: {5})",
                        Session.GetAccountId(), Session.GetRemoteAddress(), Session.GetLatency(), Session.GetPlayerName(), packet.GetOpcode(), packetCounter.amountCounter);

            switch (_policy)
            {
            case Policy.Log:
                return(true);

            case Policy.Kick:
                Log.outInfo(LogFilter.Network, "AntiDOS: Player kicked!");
                return(false);

            case Policy.Ban:
                BanMode bm       = (BanMode)WorldConfig.GetIntValue(WorldCfg.PacketSpoofBanmode);
                uint    duration = WorldConfig.GetUIntValue(WorldCfg.PacketSpoofBanduration);  // in seconds
                string  nameOrIp = "";
                switch (bm)
                {
                case BanMode.Character:         // not supported, ban account
                case BanMode.Account:
                    Global.AccountMgr.GetName(Session.GetAccountId(), out nameOrIp);
                    break;

                case BanMode.IP:
                    nameOrIp = Session.GetRemoteAddress();
                    break;
                }
                Global.WorldMgr.BanAccount(bm, nameOrIp, duration, "DOS (Packet Flooding/Spoofing", "Server: AutoDOS");
                Log.outInfo(LogFilter.Network, "AntiDOS: Player automatically banned for {0} seconds.", duration);
                return(false);
            }
            return(true);
        }
示例#28
0
 public CalendarAddEvent(WorldPacket packet) : base(packet)
 {
 }
示例#29
0
 public void QueuePacket(WorldPacket packet)
 {
     _recvQueue.Enqueue(packet);
 }
示例#30
0
 public WhoRequestPkt(WorldPacket packet) : base(packet)
 {
 }