Ejemplo n.º 1
0
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");

            string[] Inv = new string[64];

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            if (CommandArray[0] == "#deposit")
            {
                username = e.username;
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#deposit", Settings.botid);


                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);

                if (rank < TheMySqlManager.GetCommandRank("#deposit", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (CommandArray.Length < 1)
                {
                    goto WrongArguments;
                }

                if (!TradeHandler.storageOpen)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You must open storage first!"));
                    return;
                }

                if (TheInventory.GettingInventoryItems == true || TheInventory.inventoryRequested)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please wait a moment for me to finish getting my inventory..."));
                    return;
                }

                TheTradeHandler.makingDeposit = true;
                //ok, let's do a deposit
                uint   quantity = 0;
                string itemName = "";
                int    SQLID    = -1;

                int    nameToID = -1;
                string str      = "";
                try
                {
                    if (CommandArray.Length < 2)
                    {
                        goto WrongArguments;
                    }
                    if (CommandArray.Length < 3)
                    {
                        quantity = 1;
                        try
                        {
                            SQLID    = int.Parse(CommandArray[1]);
                            nameToID = SQLID;
                        }
                        catch
                        {
                            itemName = CommandArray[1] + " ";
                            nameToID = TheMySqlManager.GetItemID(CommandArray[1], Settings.botid, true);
                        }
                    }
                    if (CommandArray.Length > 2)
                    {
                        int i;
                        try
                        {
                            quantity = uint.Parse(CommandArray[1]);
                            for (i = 2; i < CommandArray.Length; i++)
                            {
                                str += CommandArray[i] + " ";
                            }
                        }
                        catch
                        {
                            quantity = 1;
                            for (i = 1; i < CommandArray.Length; i++)
                            {
                                str += CommandArray[i] + " ";
                            }
                        }
                        finally
                        {
                            str      = str.Trim();
                            nameToID = TheMySqlManager.GetItemID(str, Settings.botid, true);
                            itemName = str + " ";
                        }
                    }
                }
                catch
                {
                    goto WrongArguments;
                }
                finally
                {
                    try
                    {
                        SQLID = int.Parse(str);
                    }
                    catch
                    {
                        SQLID = nameToID;
                    }
                }

                int invCount = 0;
                MyStorageItem = new Storage.StorageItem();
                foreach (Inventory.inventory_item myInventoryItem in TheInventory.GetInventoryList())
                {
                    if (myInventoryItem.SqlID == SQLID)
                    {
                        TheTCPWrapper.Send(CommandCreator.DEPOSIT_ITEM(myInventoryItem.pos, (UInt16)quantity));
                        TheInventory.requestInventory();
                        TheTradeHandler.makingDeposit  = false;
                        TheTradeHandler.depositMade    = true;
                        MyStorageItem.knownItemsID     = myInventoryItem.SqlID;
                        MyStorageItem.imageid          = myInventoryItem.imageid;
                        MyStorageItem.category_num     = -1;
                        MyStorageItem.name             = myInventoryItem.name;
                        MyStorageItem.reservedQuantity = 0;
                        MyStorageItem.name             = myInventoryItem.name;
                        break;
                    }
                    invCount++;
                }
                if (!TheTradeHandler.depositMade)
                {
                    TheTradeHandler.makingDeposit = false;
                    string outputString = "I don't seem to have any " + itemName + " in inventory!";
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outputString));
                }
            }
            return;

WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #deposit command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#deposit amt item                         "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #deposit 1 silver ore            "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------"));
            return;
        }
Ejemplo n.º 2
0
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");
            string[] Inv=new string[64];

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            if (CommandArray[0] == "#withdraw")
            {
                username = e.username;
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#withdraw", Settings.botid);

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);

                if (rank < TheMySqlManager.GetCommandRank("#withdraw", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (CommandArray.Length < 1)
                    goto WrongArguments;

                if (TheStorage.TheStorageCategories.Count == 0)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You must open storage first!"));
                    return;
                }

                if (TradeHandler.openingStorage)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please wait a moment for storage to finish opening!"));
                    return;
                }

                if (TheInventory.GettingInventoryItems == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please wait a moment for me to finish getting my inventory..."));
                    return;
                }

                //ok, let's do a withdraw
                totalWithdrawn = 0;
                string itemName = "";
                int SQLID = -1;
                int nameToID = -1;
                string str = "";
                try
                {
                    if (CommandArray.Length < 2)
                    {
                        goto WrongArguments;
                    }
                    if (CommandArray.Length < 3)
                    {
                        quantity = 1;
                        try
                        {
                            SQLID = int.Parse(CommandArray[1]);
                            nameToID = SQLID;
                        }
                        catch
                        {
                            itemName = CommandArray[1] + " ";
                            nameToID = TheMySqlManager.GetItemID(CommandArray[1], Settings.botid, true);
                        }
                    }
                    if (CommandArray.Length > 2)
                    {
                        int i;
                        try
                        {
                            quantity = uint.Parse(CommandArray[1]);
                            for (i = 2; i < CommandArray.Length; i++)
                            {
                                str += CommandArray[i] + " ";
                            }
                        }
                        catch
                        {
                            quantity = 1;
                            for (i = 1; i < CommandArray.Length; i++)
                            {
                                str += CommandArray[i] + " ";
                            }
                        }
                        finally
                        {
                            str = str.Trim();
                            nameToID = TheMySqlManager.GetItemID(str, Settings.botid, true);
                            itemName = str + " ";
                        }
                    }
                }
                catch
                {
                    goto WrongArguments;
                }
                finally
                {
                    try
                    {
                        SQLID = int.Parse(str);
                    }
                    catch
                    {
                        SQLID = nameToID;
                    }
                }
                //Console.WriteLine(quantity + " " + SQLID);
                //try
                //{
                //    quantity = UInt32.Parse(CommandArray[1]);
                //    try
                //    {
                //        SQLID = int.Parse(CommandArray[2]);
                //    }
                //    catch
                //    {
                //        for (int i = 2; i < CommandArray.Length; i++)
                //        {
                //            itemName += CommandArray[i] + " ";
                //        }
                //        SQLID = TheMySqlManager.GetItemID(itemName, Settings.botid, true);
                //    }
                //}
                //catch
                //{
                //    quantity = 1;
                //    try
                //    {
                //        SQLID = int.Parse(CommandArray[1]);
                //    }
                //    catch
                //    {
                //        for (int i = 1; i < CommandArray.Length; i++)
                //        {
                //            itemName += CommandArray[i] + " ";
                //        }
                //        SQLID = TheMySqlManager.GetItemID(itemName,Settings.botid, true);
                //    }
                //}
                System.Collections.ArrayList StorageSnapshot = new System.Collections.ArrayList();
                StorageSnapshot = TheStorage.GetStorageList();
                int total_items = StorageSnapshot.Count;

                //Console.WriteLine(quantity + "|" + itemName + "|" + SQLID);
                //Console.WriteLine("total items: " + total_items);
                for (int i = 0; i < total_items; i++)
                {
                    MyStorageItem = (Storage.StorageItem)StorageSnapshot[i];
                    if (MyStorageItem.knownItemsID == SQLID)
                    {
                        TheTradeHandler.makingWithdraw = true;
                        //Console.WriteLine(MyStorageItem.pos + MyStorageItem.name + MyStorageItem.knownItemsID + "|" + MyStorageItem.quantity);
                        TheTCPWrapper.Send(CommandCreator.GET_STORAGE_CATEGORY((byte)MyStorageItem.category_num));
                        break;
                    }
                }
                if (!TheTradeHandler.makingWithdraw)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I don't seem to have any " + itemName + "in storage!"));
                }
            }
            return;

            WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[-------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #withdraw command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#withdraw amt item                         "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[-------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #withdraw 1 silver ore            "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[-------------------------------------------"));
            return;
        }
Ejemplo n.º 3
0
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");
            string[] Inv=new string[64];

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            if (CommandArray[0] == "#deposit")
            {
                username = e.username;
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#deposit", Settings.botid);

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);

                if (rank < TheMySqlManager.GetCommandRank("#deposit", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (CommandArray.Length < 1)
                    goto WrongArguments;

                if (!TradeHandler.storageOpen)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You must open storage first!"));
                    return;
                }

                if (TheInventory.GettingInventoryItems == true || TheInventory.inventoryRequested)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please wait a moment for me to finish getting my inventory..."));
                    return;
                }

                TheTradeHandler.makingDeposit = true;
                //ok, let's do a deposit
                uint quantity = 0;
                string itemName = "";
                int SQLID = -1;

                int nameToID = -1;
                string str = "";
                try
                {
                    if (CommandArray.Length < 2)
                    {
                        goto WrongArguments;
                    }
                    if (CommandArray.Length < 3)
                    {
                        quantity = 1;
                        try
                        {
                            SQLID = int.Parse(CommandArray[1]);
                            nameToID = SQLID;
                        }
                        catch
                        {
                            itemName = CommandArray[1] + " ";
                            nameToID = TheMySqlManager.GetItemID(CommandArray[1], Settings.botid, true);
                        }
                    }
                    if (CommandArray.Length > 2)
                    {
                        int i;
                        try
                        {
                            quantity = uint.Parse(CommandArray[1]);
                            for (i = 2; i < CommandArray.Length; i++)
                            {
                                str += CommandArray[i] + " ";
                            }
                        }
                        catch
                        {
                            quantity = 1;
                            for (i = 1; i < CommandArray.Length; i++)
                            {
                                str += CommandArray[i] + " ";
                            }
                        }
                        finally
                        {
                            str = str.Trim();
                            nameToID = TheMySqlManager.GetItemID(str, Settings.botid, true);
                            itemName = str + " ";
                        }
                    }
                }
                catch
                {
                    goto WrongArguments;
                }
                finally
                {
                    try
                    {
                        SQLID = int.Parse(str);
                    }
                    catch
                    {
                        SQLID = nameToID;
                    }
                }

                int invCount = 0;
                MyStorageItem = new Storage.StorageItem();
                foreach (Inventory.inventory_item myInventoryItem in TheInventory.GetInventoryList())
                {
                    if (myInventoryItem.SqlID == SQLID)
                    {
                        TheTCPWrapper.Send(CommandCreator.DEPOSIT_ITEM(myInventoryItem.pos, (UInt16)quantity));
                        TheInventory.requestInventory();
                        TheTradeHandler.makingDeposit = false;
                        TheTradeHandler.depositMade = true;
                        MyStorageItem.knownItemsID = myInventoryItem.SqlID;
                        MyStorageItem.imageid = myInventoryItem.imageid;
                        MyStorageItem.category_num = -1;
                        MyStorageItem.name = myInventoryItem.name;
                        MyStorageItem.reservedQuantity = 0;
                        MyStorageItem.name = myInventoryItem.name;
                        break;
                    }
                    invCount++;
                }
                if (!TheTradeHandler.depositMade)
                {
                    TheTradeHandler.makingDeposit = false;
                    string outputString = "I don't seem to have any " + itemName + " in inventory!";
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outputString));
                }
            }
            return;

            WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #deposit command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#deposit amt item                         "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #deposit 1 silver ore            "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------"));
            return;
        }
Ejemplo n.º 4
0
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");

            string[] Inv = new string[64];

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            if (CommandArray[0] == "#withdraw")
            {
                username = e.username;
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#withdraw", Settings.botid);


                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);

                if (rank < TheMySqlManager.GetCommandRank("#withdraw", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (CommandArray.Length < 1)
                {
                    goto WrongArguments;
                }

                if (TheStorage.TheStorageCategories.Count == 0)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You must open storage first!"));
                    return;
                }

                if (TradeHandler.openingStorage)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please wait a moment for storage to finish opening!"));
                    return;
                }

                if (TheInventory.GettingInventoryItems == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please wait a moment for me to finish getting my inventory..."));
                    return;
                }

                //ok, let's do a withdraw
                totalWithdrawn = 0;
                string itemName = "";
                int    SQLID    = -1;
                int    nameToID = -1;
                string str      = "";
                try
                {
                    if (CommandArray.Length < 2)
                    {
                        goto WrongArguments;
                    }
                    if (CommandArray.Length < 3)
                    {
                        quantity = 1;
                        try
                        {
                            SQLID    = int.Parse(CommandArray[1]);
                            nameToID = SQLID;
                        }
                        catch
                        {
                            itemName = CommandArray[1] + " ";
                            nameToID = TheMySqlManager.GetItemID(CommandArray[1], Settings.botid, true);
                        }
                    }
                    if (CommandArray.Length > 2)
                    {
                        int i;
                        try
                        {
                            quantity = uint.Parse(CommandArray[1]);
                            for (i = 2; i < CommandArray.Length; i++)
                            {
                                str += CommandArray[i] + " ";
                            }
                        }
                        catch
                        {
                            quantity = 1;
                            for (i = 1; i < CommandArray.Length; i++)
                            {
                                str += CommandArray[i] + " ";
                            }
                        }
                        finally
                        {
                            str      = str.Trim();
                            nameToID = TheMySqlManager.GetItemID(str, Settings.botid, true);
                            itemName = str + " ";
                        }
                    }
                }
                catch
                {
                    goto WrongArguments;
                }
                finally
                {
                    try
                    {
                        SQLID = int.Parse(str);
                    }
                    catch
                    {
                        SQLID = nameToID;
                    }
                }
                //Console.WriteLine(quantity + " " + SQLID);
                //try
                //{
                //    quantity = UInt32.Parse(CommandArray[1]);
                //    try
                //    {
                //        SQLID = int.Parse(CommandArray[2]);
                //    }
                //    catch
                //    {
                //        for (int i = 2; i < CommandArray.Length; i++)
                //        {
                //            itemName += CommandArray[i] + " ";
                //        }
                //        SQLID = TheMySqlManager.GetItemID(itemName, Settings.botid, true);
                //    }
                //}
                //catch
                //{
                //    quantity = 1;
                //    try
                //    {
                //        SQLID = int.Parse(CommandArray[1]);
                //    }
                //    catch
                //    {
                //        for (int i = 1; i < CommandArray.Length; i++)
                //        {
                //            itemName += CommandArray[i] + " ";
                //        }
                //        SQLID = TheMySqlManager.GetItemID(itemName,Settings.botid, true);
                //    }
                //}
                System.Collections.ArrayList StorageSnapshot = new System.Collections.ArrayList();
                StorageSnapshot = TheStorage.GetStorageList();
                int total_items = StorageSnapshot.Count;

                //Console.WriteLine(quantity + "|" + itemName + "|" + SQLID);
                //Console.WriteLine("total items: " + total_items);
                for (int i = 0; i < total_items; i++)
                {
                    MyStorageItem = (Storage.StorageItem)StorageSnapshot[i];
                    if (MyStorageItem.knownItemsID == SQLID)
                    {
                        TheTradeHandler.makingWithdraw = true;
                        //Console.WriteLine(MyStorageItem.pos + MyStorageItem.name + MyStorageItem.knownItemsID + "|" + MyStorageItem.quantity);
                        TheTCPWrapper.Send(CommandCreator.GET_STORAGE_CATEGORY((byte)MyStorageItem.category_num));
                        break;
                    }
                }
                if (!TheTradeHandler.makingWithdraw)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I don't seem to have any " + itemName + "in storage!"));
                }
            }
            return;

WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[-------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #withdraw command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#withdraw amt item                         "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[-------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #withdraw 1 silver ore            "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[-------------------------------------------"));
            return;
        }