eqemu-server/zone/gm_commands/itemsearch.cpp
Kinglykrab 216b6ef426
[Saylinks] Convert all GM Command Saylinks to Silent Saylinks. (#2373)
* [Saylinks] Convert all GM Command Saylinks to Silent Saylinks.
- This cleans up all non-silent GM Command Saylinks that we had before due to the way they worked before. All saylinks like this should be silent now.
- Add source short hand capability for say links with same link as text.

* Defaults to r anyway.

* Spacing.
2022-08-13 20:40:22 -04:00

122 lines
2.5 KiB
C++
Executable File

#include "../client.h"
void command_itemsearch(Client *c, const Seperator *sep)
{
if (sep->arg[1][0] == 0) {
c->Message(Chat::White, "Usage: #itemsearch [search string]");
}
else {
const char *search_criteria = sep->argplus[1];
const EQ::ItemData *item = nullptr;
EQ::SayLinkEngine linker;
linker.SetLinkType(EQ::saylink::SayLinkItemData);
if (Seperator::IsNumber(search_criteria)) {
item = database.GetItem(atoi(search_criteria));
if (item) {
linker.SetItemData(item);
std::string item_id = std::to_string(item->ID);
std::string saylink_commands =
"[" +
Saylink::Silent(
"#si " + item_id,
"X"
) +
"] ";
if (item->Stackable && item->StackSize > 1) {
std::string stack_size = std::to_string(item->StackSize);
saylink_commands +=
"[" +
Saylink::Silent(
"#si " + item_id + " " + stack_size,
stack_size
) +
"]";
}
c->Message(
Chat::White,
fmt::format(
" Summon {} [{}] [{}]",
saylink_commands,
linker.GenerateLink(),
item->ID
).c_str()
);
}
else {
c->Message(
Chat::White,
fmt::format(
"Item {} not found",
search_criteria
).c_str()
);
}
return;
}
int count = 0;
char sName[64];
char sCriteria[255];
strn0cpy(sCriteria, search_criteria, sizeof(sCriteria));
strupr(sCriteria);
char *pdest;
uint32 it = 0;
while ((item = database.IterateItems(&it))) {
strn0cpy(sName, item->Name, sizeof(sName));
strupr(sName);
pdest = strstr(sName, sCriteria);
if (pdest != nullptr) {
linker.SetItemData(item);
std::string item_id = std::to_string(item->ID);
std::string saylink_commands =
"[" +
Saylink::Silent(
"#si " + item_id,
"X"
) +
"] ";
if (item->Stackable && item->StackSize > 1) {
std::string stack_size = std::to_string(item->StackSize);
saylink_commands +=
"[" +
Saylink::Silent(
"#si " + item_id + " " + stack_size,
stack_size
) +
"]";
}
c->Message(
Chat::White,
fmt::format(
" Summon {} [{}] [{}]",
saylink_commands,
linker.GenerateLink(),
item->ID
).c_str()
);
++count;
}
if (count == 50) {
break;
}
}
if (count == 50) {
c->Message(Chat::White, "50 items shown...too many results.");
}
else {
c->Message(Chat::White, "%i items found", count);
}
}
}