private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e) { string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\""); string[] Inv = new string[64]; string searchName = ""; string inputCategory = ""; if (Message[0] != '#') { Message = "#" + Message; } string[] CommandArray = Message.Split(' '); bool issto = false; if (CommandArray[0] == "#sto") { issto = true; } if (issto) { bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#sto", 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("#sto", Settings.botid)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!")); return; } // if (TheTradeHandler.Trading == false || TheTradeHandler.username.ToLower() == "") //// if (TheTradeHandler.Trading == false || TheTradeHandler.username.ToLower() != e.username.ToLower()) // { // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Someone must be trading with me first!")); // return; // } if (!TradeHandler.storageOpen) { if (TradeHandler.openingStorage) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please wait a moment for storage to finish opening.")); } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You must open storage first!")); } return; } if (CommandArray.Length < 1) { goto WrongArguments; } else if (CommandArray.Length > 1) //inputCategory = (string)CommandArray.GetValue(1); { for (int i = 1; i < CommandArray.Length; i++) { if (inputCategory.Length > 0) { inputCategory += (" " + (string)CommandArray[i]); } else { inputCategory += (string)CommandArray[i]; } } //Console.WriteLine("inputCategory:{0}", inputCategory); } else { if (TheStorage.TheStorageCategories.Count > 0 && TradeHandler.storageOpen) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please enter one of the following categories (or an item name)!")); foreach (Storage.StorageCategory MyStorageCategory in TheStorage.TheStorageCategories) { if (MyStorageCategory.num != -1) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, MyStorageCategory.name)); } } TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "All")); } return; } string searchcategory = ""; bool categoryFound = false; searchName = inputCategory; foreach (Storage.StorageCategory MyStorageCategory in TheStorage.TheStorageCategories) { searchcategory = MyStorageCategory.name.ToLower(); if (searchcategory.Contains(inputCategory) || (inputCategory.Contains("all"))) { searchName = ""; categoryFound = true; } } if (categoryFound == false) { inputCategory = "all"; } //pm the boarder string str = ""; string str2 = ""; int lineLength = 55; str = "["; str = str.PadRight(lineLength, '-'); str2 = "["; str2 = str2.PadRight(lineLength, '='); //string header = "[ItemID: Qty: Name:"; //header = header.PadRight(lineLength, ' '); string catname = ""; bool itemsFound = false; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2)); bool Member = (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == true); //loop through the storage sending pms foreach (Storage.StorageCategory MyStorageCategory in TheStorage.TheStorageCategories) { catname = "[Item ID: Count: Category: " + MyStorageCategory.name.Substring(0, MyStorageCategory.name.Length); catname = catname.PadRight(lineLength, ' '); searchcategory = MyStorageCategory.name.ToLower(); if (searchcategory.Contains(inputCategory) || (inputCategory.Contains("all"))) { if (searchName == "") { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, catname)); // send header //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, header)); } bool categoryPrinted = false; foreach (Storage.StorageItem MyStorageItem in TheStorage.GetStorageList()) { string outputLine = ""; Int32 tempAmount = 0; string temp; string spaces = " "; temp = MyStorageItem.knownItemsID.ToString(); temp = temp.PadLeft(6, ' '); outputLine = "[" + temp + spaces; tempAmount = (Int32)(MyStorageItem.quantity - MyStorageItem.reservedQuantity); if (tempAmount < 0) { tempAmount = 0; } // temp = (MyStorageItem.quantity - MyStorageItem.reservedQuantity).ToString(); temp = tempAmount.ToString(); temp = temp.PadLeft(5, ' '); outputLine += temp + spaces + MyStorageItem.name.Substring(0, MyStorageItem.name.Length); outputLine = outputLine.PadRight(lineLength, ' '); if (searchName != "") { if (MyStorageItem.name.ToLower().Contains(searchName) && MyStorageItem.category_num == MyStorageCategory.num) { if (categoryPrinted == false) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, catname)); } TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outputLine)); itemsFound = true; categoryPrinted = true; } } else if (MyStorageItem.category_num == MyStorageCategory.num) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outputLine)); itemsFound = true; } } if (itemsFound == false && searchName == "") { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[None found")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); } else if (itemsFound == true) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); } itemsFound = false; } } return; } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #sto command:")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#sto <item> ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #sto ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #sto silver ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------")); return; }
private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e) { int UsedSlots = 0; string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\""); string[] Inv = new string[64]; int maxlen = 4; if (Message[0] != '#') { Message = "#" + Message; } string[] CommandArray = Message.Split(' '); bool isinv = false, isinvmembers = false; if (CommandArray[0] == "#inv" || CommandArray[0] == "#i" || CommandArray[0] == "#inb" || CommandArray[0] == "#sell" || CommandArray[0] == "#selling" || CommandArray[0] == "#inventory") { isinv = true; } if (CommandArray[0] == "#invmembers" || CommandArray[0] == "#im" || CommandArray[0] == "#invmemvers" || CommandArray[0] == "#invmember" || CommandArray[0] == "#invmemver") { isinvmembers = true; } if (isinv || isinvmembers) { bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#inv", Settings.botid); string str1 = "", str2 = ""; if (TheInventory.GettingInventoryItems == true) { str2 = "I am building my inventory list, please try again in a few seconds"; str1 = str1.PadRight(str2.Length, '='); str1 = "[" + str1; str2 = "[" + str2; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2)); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); return; } if (disabled == true) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled")); return; } if (Settings.IsTradeBot == false) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!")); return; } int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid); if (rank < TheMySqlManager.GetCommandRank("#inv", Settings.botid)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!")); return; } if ((CommandArray[0] == "#im" || CommandArray[0] == "#invmembers" || CommandArray[0] == "#invmemvers" || CommandArray[0] == "#invmember" || CommandArray[0] == "#invmemver") && ((rank < TheMySqlManager.GetCommandRank("#invmembers", Settings.botid)) && TheMySqlManager.CheckIfBannedGuild(e.username, Settings.botid) < 1)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!")); return; } if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly.")); return; } if (CommandArray.Length < 1) { goto WrongArguments; } char invFiller = TheMySqlManager.getInvFiller(); System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList(); System.Collections.Hashtable MySellingItemsList = TheMySqlManager.GetSellingItemList(0); // sum up all inventory items if the items are on sale System.Collections.SortedList TheInventoryList = new System.Collections.SortedList(); foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList) { //adjust the number of slots used... if (MyInventoryItem.pos < 36) { if (MyInventoryItem.is_stackable) { UsedSlots++; } else { UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity); } } //adjust the amount //only display if in selling list if (MySellingItemsList.Contains(MyInventoryItem.SqlID)) { //if already in inventory output (eg.., two slots) just sum the quantity //otherwise add to inventory output if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36) { Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID]; TempInventoryItem.quantity += MyInventoryItem.quantity; TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem; } else { if (MyInventoryItem.pos < 36) { TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem); } } } } //foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values) //{ // if(maxlen<MyInventoryItem.name.Length && (MyInventoryItem.pos < 36)) // maxlen = MyInventoryItem.name.Length; //} //maxlen++; maxlen = 20 + 25 - Settings.Loginname.Length; // pm all summed up inventory items on sale int i = 0; for (i = 0; i < 64; i++) { Inv[i] = "ZZZZZZZZZZZZZZZZ"; } int c = 0; string str = ""; str2 = ""; str = "["; str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); bool Member = (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == true); str = "[name".PadRight(maxlen, ' '); str = str + "|qty".PadRight(7, ' '); str = str + "|price".PadRight(14, ' '); str = str + "|id".PadRight(6, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); str = "["; str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); string msg, msg2; foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values) { if (MyInventoryItem.pos < 36) { msg = ("[" + MyInventoryItem.name).PadRight(maxlen, i == 0 ? ' ' : invFiller); { uint tempAmount = 0; if ((TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)) < MyInventoryItem.quantity) { tempAmount = MyInventoryItem.quantity; tempAmount = tempAmount - (TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)); } else { continue; } msg2 = tempAmount.ToString(); } msg2 = msg2.PadLeft(6, i == 0 ? ' ' : invFiller); msg = msg + "|" + msg2; TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]); if (isinv) { msg2 = MySellingItem.pricesale.ToString(); } else { msg2 = MySellingItem.pricesalemembers.ToString(); } if (!msg2.Contains(".")) { msg2 += ".00gc"; } else if (msg2[msg2.Length - 2] == '.') { msg2 += "0gc"; } else { msg2 += "gc"; } msg2 = msg2.PadLeft(13, i == 0 ? ' ' : invFiller); msg = msg + "|" + msg2; msg2 = MyInventoryItem.SqlID.ToString().PadLeft(5, i == 0 ? ' ' : invFiller); msg = msg + "|" + msg2; Inv[c] = msg; c++; i = 1 - i; } } int d; // for (d = 0; d < c; d++) // { // str = Inv[d].Substring(16) + Inv[d].Substring(0, 16); // Inv[d] = str; // } Array.Sort(Inv); i = maxlen + 13; string filter = ""; if (CommandArray.Length > 1) { bool firstTime = true; foreach (string filterPart in CommandArray) { if (firstTime) { firstTime = false; continue; } filter += (" " + filterPart); } //filter = Message.Substring(CommandArray[0].Length); } else { filter = ""; } for (d = 0; d < c; d++) { str = Inv[d]; //27 chars after the name.... if (filter == "" || Inv[d].ToLower().Contains(filter.ToLower().Trim())) { string[] outFields = Inv[d].Split('|'); string outString = Inv[d]; if (outFields[0].Length > maxlen) { outString = outFields[0].Substring(0, maxlen - 3) + "..."; outString = outString.PadRight(maxlen, ' ') + "|".PadRight(7, ' ') + "|".PadRight(14, ' ') + "|".PadRight(6, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString)); outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' '); int count = 0; foreach (string tempString in outFields) { if (count == 0) { count++; continue; } outString += "|" + tempString; } } TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString)); } else { //for (i = 1; i < CommandArray.Length; i++) { //if (Inv[d].ToLower().Contains(CommandArray[i].ToLower().Trim())) Console.WriteLine("inv(d): " + Inv[d] + " filter: " + filter); if (Inv[d].ToLower().Contains(filter.ToLower().Trim())) { string[] outFields = Inv[d].Split('|'); string outString = Inv[d]; if (outFields[0].Length > maxlen) { outString = outFields[0].Substring(0, maxlen - 3) + "..."; outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString)); outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' '); foreach (string tempString in outFields) { outString += "|" + tempString; } } TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString)); i = CommandArray.Length; } } } } int Phys = TheMySqlManager.GetBotPhysqiue(Settings.botid); int Coord = TheMySqlManager.GetBotCoordination(Settings.botid); int carry = (Phys + Coord) * 10; //int UsedSpace = TheMySqlManager.GetBotUsedSpace(Settings.botid); //int UsedSlots = TheMySqlManager.GetBotUsedSlots(Settings.botid); int UsedSpace = TheStats.MyCurrentCarryingAmt; int FreeSpace = carry - UsedSpace; str = "["; str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); str = "["; str += FreeSpace.ToString() + " EMU Avail|"; str += (36 - UsedSlots).ToString() + " Open slot(s)"; if (rank > 89) { //str += TheMySqlManager.moneylevel(Settings.botid).ToString() + " gc"; str += "|" + TheInventory.GetMoneyAmount().ToString() + " gc"; } str = str.PadRight(maxlen + 27, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); str = "["; if (Member) { if ((CommandArray[0] != "#im" && CommandArray[0] != "#invmembers" && CommandArray[0] != "#invmemvers" && CommandArray[0] != "#invmember" && CommandArray[0] != "#invmemver")) { str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); str = "[Use invmembers (im) to see member prices"; str = str.PadRight(maxlen + 27, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); } //if (isinv) //{ // str = "[to see member prices use invmembers or im"; // str = str.PadRight(maxlen + 28, ' '); // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); //} } str = "["; str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); return; } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #inv command:")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#inv ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #inv ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #inv silver ore ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------")); return; }
private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e) { string Message = e.Message.ToLower(); if (Message[0] != '#') { Message = "#" + Message; } string[] CommandArray = Message.Split(' '); if (CommandArray[0] == "#putonsale") { bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#putonsale", Settings.botid); if (disabled == true) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled")); return; } if (Settings.IsTradeBot == false) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!")); return; } if (TheMySqlManager.GetUserRank(e.username, Settings.botid) < TheMySqlManager.GetCommandRank("#putonsale", Settings.botid)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!")); return; } if (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == false) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not a trade alliance member!")); return; } if (TheTradeHandler.Trading == false || TradeHandler.username.ToLower() != e.username.ToLower()) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please trade with me first!")); return; } try { if (CommandArray.Length < 1) { goto WrongArguments; } if (TheTradeHandler.Donating == false && TheTradeHandler.Billance == 0 && TheTradeHandler.PartnerTradeItemsList.Count == 0 && TheTradeHandler.MyItemList.Count == 0) { TheTradeHandler.PutOnSale = true; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You can give the items to me now.")); } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Plese restart the trade. And put no items on the trade before sending #putonsale.")); } } catch { goto WrongArguments; } } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Here is the usage of the #putonsale command:")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "#putonsale")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "------------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Example: #putonsale")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Example: #putonsale 44")); return; }
//private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e) //{ // uint quantity = 0; // int SQLID = 0; // int nameToID = -1; // uint ItemsPlacedOnTrade = 0; // string Message = e.Message.ToLower(); // if (Message[0] != '#') // { // Message = "#" + Message; // } // string[] CommandArray = Message.Split(' '); // if (CommandArray[0] == "#buy" || CommandArray[0] == "#b" || CommandArray[0] == "#byt") // { // if (Settings.IsTradeBot == false) // { // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!")); // return; // } // bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#buy", Settings.botid); // if (disabled == true) // { // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled")); // return; // } // if (TheMySqlManager.GetUserRank(e.username, Settings.botid) < TheMySqlManager.GetCommandRank("#buy", Settings.botid)) // { // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!")); // return; // } // if (TheTradeHandler.Trading == false || TradeHandler.username.ToLower() != e.username.ToLower()) // { // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please trade with me first!")); // return; // } // try // { // if (CommandArray.Length < 2) // { // goto WrongArguments; // } // if (CommandArray.Length < 3) // { // quantity = 1; // nameToID = TheMySqlManager.GetItemID(CommandArray[1], Settings.botid, false); // if (nameToID != -1) // { // SQLID = nameToID; // } // if (nameToID == -1) // { // SQLID = int.Parse(CommandArray[1]); // } // } // if (CommandArray.Length > 2) // { // string str = ""; // int i; // if (!uint.TryParse(CommandArray[1], out quantity)) // { // quantity = 1; // for (i = 1; i < CommandArray.Length; i++) // { // str += CommandArray[i] + " "; // } // } // else // { // for (i = 2; i < CommandArray.Length; i++) // { // str += CommandArray[i] + " "; // } // } // str = str.Trim(); // nameToID = TheMySqlManager.GetItemID(str, Settings.botid,false); // if (nameToID == -1) // { // SQLID = int.Parse(CommandArray[2]); // } // if (nameToID != -1) // { // SQLID = nameToID; // } // } // } // catch // { // goto WrongArguments; // } // if (TheTradeHandler.Donating == true) // { // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I can't sell you items while donating. Please start a new trade session.")); // return; // } // System.Collections.Hashtable MySellingItemList = TheMySqlManager.GetSellingItemList(0); // if (MySellingItemList.Contains(SQLID)) // { // ItemsPlacedOnTrade = TheTradeHandler.PutItemsOnTrade(SQLID, quantity); // TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)MySellingItemList[SQLID]; // if (ItemsPlacedOnTrade > 0) // { // Check if the user is member if the trade alliance // decimal temp = 0; // if (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == true) // { // TheTradeHandler.AddTrade(SQLID, MySellingItem.pricesalemembers, ItemsPlacedOnTrade, "sold to"); // temp = (decimal)MySellingItem.pricesalemembers * ItemsPlacedOnTrade; // TheTradeHandler.ChangeBillance(-(System.Convert.ToInt32(System.Math.Ceiling(temp)))); // } // else // { // TheTradeHandler.AddTrade(SQLID, MySellingItem.pricesale, ItemsPlacedOnTrade, "sold to"); // temp = (decimal)MySellingItem.pricesale * ItemsPlacedOnTrade; // TheTradeHandler.ChangeBillance(-((System.Convert.ToInt32(System.Math.Ceiling(temp))))); // } // } // } // if (ItemsPlacedOnTrade < quantity) // { // if (ItemsPlacedOnTrade == 0) // { // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I don't have this item!")); // } // else // { // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I only have " + ItemsPlacedOnTrade.ToString() + " of this item!")); // } // } // } // return; //WrongArguments: // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|---------------------------------------")); // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|Here is the usage of the #buy command: ")); // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|#buy <quantity> <name or itemid> ")); // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|---------------------------------------")); // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|Example: #buy 12 2 ")); // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|Example: #buy 1 Pickaxe ")); // TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|---------------------------------------")); // return; //} private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e) { uint quantity = 0; int SQLID = 0; int nameToID = -1; uint ItemsPlacedOnTrade = 0; string Message = e.Message.ToLower(); if (Message[0] != '#') { Message = "#" + Message; } string[] CommandArray = Message.Split(' '); if (CommandArray[0] == "#buy" || CommandArray[0] == "#b" || CommandArray[0] == "#byt") { if (Settings.IsTradeBot == false) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!")); return; } bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#buy", Settings.botid); if (disabled == true) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled")); return; } if (TheMySqlManager.GetUserRank(e.username, Settings.botid) < TheMySqlManager.GetCommandRank("#buy", Settings.botid)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!")); return; } if (TheTradeHandler.Trading == false || TradeHandler.username.ToLower() != e.username.ToLower()) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Please trade with me first!")); return; } if (TheTradeHandler.AcceptStateMe > 0) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You cannont issue more buy commands once I've partially accepted the trade!")); return; } try { if (CommandArray.Length < 2) { goto WrongArguments; } if (CommandArray.Length < 3) { quantity = 1; nameToID = TheMySqlManager.GetItemID(CommandArray[1], Settings.botid, false); if (nameToID != -1) { SQLID = nameToID; } if (nameToID == -1) { SQLID = int.Parse(CommandArray[1]); } } if (CommandArray.Length > 2) { string str = ""; int i; if (!uint.TryParse(CommandArray[1], out quantity)) { quantity = 1; for (i = 1; i < CommandArray.Length; i++) { str += CommandArray[i] + " "; } } else { for (i = 2; i < CommandArray.Length; i++) { str += CommandArray[i] + " "; } } str = str.Trim(); nameToID = TheMySqlManager.GetItemID(str, Settings.botid, false); if (nameToID == -1) { SQLID = int.Parse(CommandArray[2]); } if (nameToID != -1) { SQLID = nameToID; } } } catch { goto WrongArguments; } if (TheTradeHandler.Donating == true) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I can't sell you items while donating. Please start a new trade session.")); return; } System.Collections.Hashtable MySellingItemList = TheMySqlManager.GetSellingItemList(0); bool itemFound = false; foreach (int itemId in MySellingItemList.Keys) { if (SQLID == itemId) { itemFound = true; } } if (itemFound) { TheTradeHandler.totalCalculated = false; ItemsPlacedOnTrade = TheTradeHandler.PutItemsOnTrade(SQLID, quantity); TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)MySellingItemList[SQLID]; if (ItemsPlacedOnTrade > 0) { // Check if the user is member if the trade alliance //decimal temp = 0; if (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == true) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I sell " + TheMySqlManager.GetKnownItemsname(MySellingItem.KnownItemsSqlID) + " for " + MySellingItem.pricesalemembers + "gc each.")); TheTradeHandler.AddTrade(SQLID, MySellingItem.pricesalemembers, ItemsPlacedOnTrade, "sold to"); //temp = (decimal)MySellingItem.pricesalemembers * ItemsPlacedOnTrade; //TheTradeHandler.ChangeBillance(-(System.Convert.ToInt32(System.Math.Ceiling(temp)))); } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I sell " + TheMySqlManager.GetKnownItemsname(MySellingItem.KnownItemsSqlID) + " for " + MySellingItem.pricesale + "gc each.")); TheTradeHandler.AddTrade(SQLID, MySellingItem.pricesale, ItemsPlacedOnTrade, "sold to"); //temp = (decimal)MySellingItem.pricesale * ItemsPlacedOnTrade; //TheTradeHandler.ChangeBillance(-((System.Convert.ToInt32(System.Math.Ceiling(temp))))); } } } //if (ItemsPlacedOnTrade < quantity) { if (ItemsPlacedOnTrade == 0) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I don't have this item!")); } else if (ItemsPlacedOnTrade < quantity) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I only have " + ItemsPlacedOnTrade.ToString() + " of this item!")); } } } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I don't sell this item or invalid syntax")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|---------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|Here is the usage of the #buy command: ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|#buy <quantity> <name or itemid> ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|---------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|Example: #buy 12 2 ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|Example: #buy 1 Pickaxe ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "|---------------------------------------")); return; }
private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e) { int UsedSlots = 0; string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\""); string[] Inv = new string[512]; if (Message[0] != '#') { Message = "#" + Message; } string[] CommandArray = Message.Split(' '); if (CommandArray[0] == "#wanted" || CommandArray[0] == "#w" || CommandArray[0] == "#want" || CommandArray[0] == "#buying") { if (Settings.IsTradeBot == false) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!")); return; } int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid); if (rank < TheMySqlManager.GetCommandRank("#wanted", Settings.botid)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!")); return; } if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly.")); return; } string str = "", str2 = ""; if (TheInventory.GettingInventoryItems == true) { str2 = "I am building my inventory list, please try again in a few seconds"; str = str.PadRight(str2.Length, '='); str = "[" + str; str2 = "[" + str2; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2)); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); return; } if (CommandArray.Length < 1) { goto WrongArguments; } string filter = ""; if (CommandArray.Length > 1) { //filter = Message.Substring(CommandArray[0].Length); bool firstTime = true; foreach (string filterPart in CommandArray) { if (firstTime) { firstTime = false; continue; } filter += (" " + filterPart); } } else { filter = ""; } int i = 0; for (i = 0; i < 512; i++) { Inv[i] = "ZZZZZZZZZZZZZZZZ"; } int c = 0; char wantedFiller = TheMySqlManager.getWantedFiller(); bool showZeroPrice = TheMySqlManager.getShowZeroPrice(); System.Collections.Hashtable MyWantedItemsList = TheMySqlManager.GetWantedItemList(0); System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList(); foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList) { if (MyInventoryItem.pos < 36) { if (MyInventoryItem.is_stackable) { UsedSlots++; } else { UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity); } } } // pm all summed up inventory items on sale int maxlen = 20 + 29 - Settings.Loginname.Length; bool Member = (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == true); TheLogger.Debug("Trade Member " + (Member ? "Yes\n" : "No\n")); //maximum characters is 64 on 8x6, server is taking up 12 chars, then length of bot name (eg., josi would result in 16 giving max of the rest of the line being 48 str = "["; str = str.PadRight(maxlen + 23, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); str = "[name"; str = str.PadRight(maxlen, ' '); str += "| price| qty"; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); //Draw separator line ---------------- str = "["; str = str.PadRight(maxlen + 23, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); i = 1; foreach (TradeHandler.WantedItem MyWantedItem in MyWantedItemsList.Values) { if (MyWantedItem.pricepurchase == 0 && showZeroPrice == false && Member == false) { continue; } //i = 1 - i; string msg = "["; int q = 99999, q2; string item = TheMySqlManager.GetKnownItemsname(MyWantedItem.KnownItemsSqlID); msg += item; msg = msg.PadRight(maxlen, (i == 0) ? ' ' : wantedFiller); msg += "|"; if (Member) { str = MyWantedItem.pricepurchasemembers.ToString(); } else { str = MyWantedItem.pricepurchase.ToString(); } if (!str.Contains(".")) { str += ".00gc"; } else if (str[str.Length - 2] == '.') { str += "0gc"; } else { str += "gc"; } str = str.PadLeft(13, (i == 0) ? ' ' : wantedFiller); msg += str; if (TheInventory.HaveItem(MyWantedItem.KnownItemsSqlID) == -1) { q2 = MyWantedItem.maxquantity; if (MyWantedItem.maxquantity == 0) { str = "No limit".PadLeft(8, (i == 0) ? ' ' : wantedFiller); } else if (q2 > 0) { str = q2.ToString().PadLeft(8, (i == 0) ? ' ' : wantedFiller); } } else { q2 = MyWantedItem.maxquantity - TheInventory.Quantity(MyWantedItem.KnownItemsSqlID); q = q2; if (MyWantedItem.maxquantity == 0) { str = "No limit".PadLeft(8, (i == 0) ? ' ' : wantedFiller); } else if (q2 > 0) { str = q2.ToString().PadLeft(8, (i == 0) ? ' ' : wantedFiller); } } str = "|" + str; msg += str; //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, msg)); if (q > 0 || MyWantedItem.maxquantity == 0) { Inv[c++] = msg; } } int d; Array.Sort(Inv); i = maxlen + 13 + 12; for (d = 0; d < c; d++) { if (filter == "" || Inv[d].ToLower().Contains(filter.ToLower().Trim())) { string[] outFields = Inv[d].Split('|'); string outString = Inv[d]; if (outFields[0].Length > maxlen) { outString = outFields[0].Substring(0, maxlen - 3) + "..."; outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString)); outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' '); int count = 0; foreach (string tempString in outFields) { if (count == 0) { count++; continue; } outString += "|" + tempString; } } TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString)); } else { //for (i = 1; i < CommandArray.Length; i++) { if (Inv[d].ToLower().Contains(filter.ToLower().Trim())) { //I don't think this is ever getting done, from here down... string[] outFields = Inv[d].Split('|'); string outString = Inv[d]; if (outFields[0].Length > maxlen) { outString = outFields[0].Substring(0, maxlen - 3) + "..."; outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString)); outString = "[...".PadRight(maxlen, ' '); foreach (string tempString in outFields) { outString += "|" + tempString; } } //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, Inv[d])); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString)); i = CommandArray.Length; } } } } str = "["; str = str.PadRight(maxlen + 23, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); int Phys = TheMySqlManager.GetBotPhysqiue(Settings.botid); int Coord = TheMySqlManager.GetBotCoordination(Settings.botid); int carry = (Phys + Coord) * 10; int UsedSpace = TheStats.MyCurrentCarryingAmt; int FreeSpace = carry - UsedSpace; str = "["; str += FreeSpace.ToString() + " EMU Avail|"; str += (36 - UsedSlots).ToString() + " Open slot(s)"; if (rank > 89) { str += "|" + TheInventory.GetMoneyAmount().ToString() + " gc"; } str = str.PadRight(maxlen + 11 + 12, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); if (Member) { str = "["; str = str.PadRight(maxlen + 11 + 12, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); str = "[You have Member rates on purchases"; str = str.PadRight(maxlen + 11 + 12, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); } str = "["; str = str.PadRight(maxlen + 11 + 12, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); //str = "[To sell something to me just trade with me"; //str = str.PadRight(maxlen + 11 + 12, ' '); //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); //str = "[and place the item(s) you want to sell on"; //str = str.PadRight(maxlen + 11 + 12, ' '); //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); //str = "[the trade"; //str = str.PadRight(maxlen + 11 + 12, ' '); //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); //str = "["; //str = str.PadRight(maxlen + 11 + 12, '='); //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #wanted command:")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#wanted [name|id] ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[-----------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #wanted essence ")); return; }