Пример #1
0
        /// <summary>
        /// Analyze client packets.
        /// </summary>
        /// <param name="packet">Client packet</param>
        /// <returns>True if the packet won't be sent to the server</returns>
        private bool Local_PacketHandler(Packet packet)
        {
            // Opcode filter
            switch (packet.Opcode)
            {
            case Opcode.CLIENT_AUTH_REQUEST:
                if (Bot.Get.LoggedFromBot)
                {
                    return(true);
                }
                break;

            case Opcode.CLIENT_CHARACTER_SELECTION_JOIN_REQUEST:
                InfoManager.SetCharacter(packet.ReadAscii());
                return(true);

            case Opcode.CLIENT_CHARACTER_CONFIRM_SPAWN:
                if (!ClientlessMode)
                {
                    InfoManager.OnTeleported();
                }
                break;

            case Opcode.CLIENT_CHARACTER_MOVEMENT:

                break;

            case Opcode.CLIENT_CHARACTER_MOVEMENT_ANGLE:

                break;

            case Opcode.CLIENT_CHAT_REQUEST:
            {
                // Keep on track all private messages sent
                SRTypes.Chat t         = (SRTypes.Chat)packet.ReadByte();
                byte         chatIndex = packet.ReadByte();
                if (t == SRTypes.Chat.All)
                {
                    string message = packet.ReadAscii();
                    return(Bot.Get.OnChatSending(message));
                }
                else if (t == SRTypes.Chat.Private)
                {
                    Window w = Window.Get;
                    w.LogChatMessage(w.Chat_rtbxPrivate, packet.ReadAscii() + "(To)", packet.ReadAscii());
                }
            }
            break;
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Called when a message is received.
        /// </summary>
        public void OnChatReceived(SRTypes.Chat type, string playerName, string message)
        {
            Window w = Window.Get;

            // Check Bot commands
            if (type == SRTypes.Chat.All)
            {
                if (playerName == InfoManager.CharName)
                {
                    switch (message)
                    {
                    case "PING":
                        if (m_Ping != null)
                        {
                            m_Ping.Stop();
                            message = "[xBot] Your current ping : " + m_Ping.ElapsedMilliseconds + "(ms)";
                            PacketBuilder.Client.SendNotice(message);
                            m_Ping = null;
                            if (Proxy.ClientlessMode)
                            {
                                w.LogChatMessage(w.Chat_rtbxAll, "xBot", message);
                            }
                        }
                        return;
                    }
                }
            }
            // Check Leader Commands
            if (w.Party_cbxActivateLeaderCommands.Checked && playerName != "")
            {
                bool isLeader = false;
                w.Party_lstvLeaderList.InvokeIfRequired(() => {
                    isLeader = w.Party_lstvLeaderList.Items.ContainsKey(playerName.ToUpper());
                });

                if (isLeader)
                {
                    if (message.StartsWith("INJECT "))
                    {
                        string[] data = message.Substring(7).ToUpper().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (data.Length >= 1)
                        {
                            ushort opcode;
                            if (ushort.TryParse(data[0], NumberStyles.HexNumber, null, out opcode))
                            {
                                bool encrypted = false;
                                int  dataIndex = 1;
                                if (data.Length > 1 && (data[dataIndex] == "FALSE" || data[dataIndex] == "TRUE"))
                                {
                                    encrypted = bool.Parse(data[dataIndex++]);
                                }
                                List <byte> bytes = new List <byte>();
                                for (int j = dataIndex; j < data.Length; j++)
                                {
                                    byte temp;
                                    if (byte.TryParse(data[j], NumberStyles.HexNumber, null, out temp))
                                    {
                                        bytes.Add(temp);
                                    }
                                }
                                Proxy.Agent.InjectToServer(new Packet(opcode, encrypted, false, bytes.ToArray()));
                                PacketBuilder.SendChatPrivate(playerName, "Packet has been injected");
                            }
                        }
                    }
                    else if (message.StartsWith("TRACE"))
                    {
                        if (message == "TRACE")
                        {
                            StartTrace(playerName);
                            return;
                        }
                        else
                        {
                            string[] data = message.Substring(5).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            if (data.Length == 1)
                            {
                                StartTrace(data[0]);
                            }
                        }
                    }
                    else if (message.StartsWith("TELEPORT "))
                    {
                        message = message.Substring(9);
                        // Check params correctly
                        string[] data;
                        if (message.Contains(","))
                        {
                            data = message.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        }
                        else
                        {
                            data = message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        }
                        // IF there is at least 2 params
                        if (data.Length > 1)
                        {
                            // Check if the teleport link is from teleport model IDs
                            uint sourceTeleportID, destinationTeleportID;
                            if (uint.TryParse(data[0], out sourceTeleportID) && uint.TryParse(data[1], out destinationTeleportID))
                            {
                                uint destinationID = DataManager.GetTeleportLinkDestinationID(sourceTeleportID, destinationTeleportID);
                                if (destinationID != 0)
                                {
                                    SRTeleport teleport = InfoManager.TeleportAndBuildings.Find(t => t.ID == sourceTeleportID);
                                    if (teleport != null)
                                    {
                                        UseTeleportAsync(teleport, destinationID);
                                    }
                                    else
                                    {
                                        PacketBuilder.SendChatPrivate(playerName, "Teleport link is not near");
                                    }
                                }
                                else
                                {
                                    PacketBuilder.SendChatPrivate(playerName, "Teleport link not found. Please, verify the teleports ID correctly");
                                }
                                return;
                            }
                            // Check if the teleport link name exists
                            NameValueCollection teleportLinkData = DataManager.GetTeleportLink(data[0], data[1]);
                            if (teleportLinkData != null)
                            {
                                sourceTeleportID = uint.Parse(teleportLinkData["id"]);
                                // Check if the teleport source is near
                                SRTeleport teleport = InfoManager.TeleportAndBuildings.Find(t => t.ID == sourceTeleportID);
                                if (teleport != null)
                                {
                                    // Try to select teleport
                                    UseTeleportAsync(teleport, uint.Parse(teleportLinkData["destinationid"]));
                                }
                                else
                                {
                                    PacketBuilder.SendChatPrivate(playerName, "Teleport link is not near");
                                }
                            }
                            else
                            {
                                PacketBuilder.SendChatPrivate(playerName, "Teleport link not found. Please, verify the teleports location correctly");
                            }
                        }
                    }
                    else if (message.StartsWith("RECALL "))
                    {
                        message = message.Substring(7);
                        if (message != "")
                        {
                            NameValueCollection teleportLinkData = DataManager.GetTeleportLink(message);
                            if (teleportLinkData != null)
                            {
                                uint modelID = uint.Parse(teleportLinkData["id"]);
                                if (modelID != 0)
                                {
                                    // Check if the teleport is near
                                    SRTeleport teleport = InfoManager.TeleportAndBuildings.Find(t => t.ID == modelID);
                                    if (teleport != null)
                                    {
                                        PacketBuilder.DesignateRecall(teleport.UniqueID);
                                    }
                                    else
                                    {
                                        PacketBuilder.SendChatPrivate(playerName, "Teleport is not near");
                                    }
                                }
                            }
                            else
                            {
                                PacketBuilder.SendChatPrivate(playerName, "Wrong teleport name");
                            }
                        }
                    }
                    else if (message == "NOTRACE")
                    {
                        StopTrace();
                    }
                    else if (message == "RETURN")
                    {
                        if (!UseReturnScroll())
                        {
                            PacketBuilder.SendChatPrivate(playerName, "Return scroll not found");
                        }
                    }
                }
            }
        }