예제 #1
0
 public void UseTeleportAsync(SRTeleport teleport, uint destinationID)
 {
     if (Proxy.ClientlessMode)
     {
         if (InfoManager.isEntityNear(teleport.UniqueID))
         {
             PacketBuilder.UseTeleport(teleport.UniqueID, destinationID);
         }
         else
         {
             Window.Get.LogProcess(teleport.Name + " cannot be selected!");
         }
     }
     else
     {
         (new Thread(() => {
             if (WaitSelectEntity(teleport.UniqueID, 8, 250, "Selecting teleport " + teleport.TeleportName + "..."))
             {
                 PacketBuilder.UseTeleport(teleport.UniqueID, destinationID);
             }
             else
             {
                 Window.Get.LogProcess(teleport.Name + " cannot be selected!");
             }
         })).Start();
     }
 }
예제 #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");
                        }
                    }
                }
            }
        }