[Commands] Cleanup #ban, #ipban, #flag, #kick, #setlsinfo, and #setpass Commands. (#2104)

* [Commands] Cleanup #ban, #ipban, #flag, and #kick Commands.
- Cleanup messages and logic.
- Add ServerFlagUpdate_Struct for flag updates.

* Add #setlsinfo and #setpass to cleanup.

* Update setlsinfo.cpp

* Update database.cpp

* Update database.cpp

* Update command.cpp
This commit is contained in:
Kinglykrab 2022-05-07 23:28:45 -04:00 committed by GitHub
parent 07b46ed445
commit d9c41526e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 312 additions and 227 deletions

View File

@ -92,112 +92,123 @@ Database::~Database()
*/ */
uint32 Database::CheckLogin(const char* name, const char* password, const char *loginserver, int16* oStatus) { uint32 Database::CheckLogin(const char* name, const char* password, const char *loginserver, int16* oStatus) {
if(strlen(name) >= 50 || strlen(password) >= 50) if (strlen(name) >= 50 || strlen(password) >= 50)
return(0); return(0);
char tmpUN[100]; char temporary_username[100];
char tmpPW[100]; char temporary_password[100];
DoEscapeString(tmpUN, name, strlen(name)); DoEscapeString(temporary_username, name, strlen(name));
DoEscapeString(tmpPW, password, strlen(password)); DoEscapeString(temporary_password, password, strlen(password));
std::string query = StringFormat("SELECT id, status FROM account WHERE `name`='%s' AND ls_id='%s' AND password is not null " std::string query = fmt::format(
"and length(password) > 0 and (password='%s' or password=MD5('%s'))", "SELECT id, status FROM account WHERE `name` = '{}' AND ls_id = '{}' AND password is NOT NULL "
tmpUN, EscapeString(loginserver).c_str(), tmpPW, tmpPW); "AND length(password) > 0 AND (password = '{}' OR password = MD5('{}'))",
temporary_username,
EscapeString(loginserver),
temporary_password,
temporary_password
);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()) if (!results.Success() || !results.RowCount()) {
{
return 0; return 0;
} }
if(results.RowCount() == 0)
return 0;
auto row = results.begin(); auto row = results.begin();
uint32 id = atoi(row[0]); auto id = std::stoul(row[0]);
if (oStatus) if (oStatus) {
*oStatus = atoi(row[1]); *oStatus = std::stoi(row[1]);
}
return id; return id;
} }
//Get Banned IP Address List - Only return false if the incoming connection's IP address is not present in the banned_ips table. //Get Banned IP Address List - Only return false if the incoming connection's IP address is not present in the banned_ips table.
bool Database::CheckBannedIPs(const char* loginIP) bool Database::CheckBannedIPs(std::string login_ip)
{ {
std::string query = StringFormat("SELECT ip_address FROM banned_ips WHERE ip_address='%s'", loginIP); auto query = fmt::format(
"SELECT ip_address FROM banned_ips WHERE ip_address = '{}'",
login_ip
);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()) if (!results.Success() || results.RowCount() != 0) {
{
return true; return true;
} }
if (results.RowCount() != 0)
return true;
return false; return false;
} }
bool Database::AddBannedIP(char* bannedIP, const char* notes) { bool Database::AddBannedIP(std::string banned_ip, std::string notes) {
std::string query = StringFormat("INSERT into banned_ips SET ip_address='%s', notes='%s'", bannedIP, notes); auto query = fmt::format(
"INSERT into banned_ips SET ip_address = '{}', notes = '{}'",
EscapeString(banned_ip),
EscapeString(notes)
);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
return false; return false;
} }
return true; return true;
} }
bool Database::CheckGMIPs(const char* ip_address, uint32 account_id) { bool Database::CheckGMIPs(std::string login_ip, uint32 account_id) {
std::string query = StringFormat("SELECT * FROM `gm_ips` WHERE `ip_address` = '%s' AND `account_id` = %i", ip_address, account_id); auto query = fmt::format(
"SELECT * FROM `gm_ips` WHERE `ip_address` = '{}' AND `account_id` = {}",
login_ip,
account_id
);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()) if (!results.Success()) {
return false; return false;
}
if (results.RowCount() == 1) if (results.RowCount() == 1) {
return true; return true;
}
return false; return false;
} }
bool Database::AddGMIP(char* ip_address, char* name) { void Database::LoginIP(uint32 account_id, std::string login_ip) {
std::string query = StringFormat("INSERT into `gm_ips` SET `ip_address` = '%s', `name` = '%s'", ip_address, name); auto query = fmt::format(
auto results = QueryDatabase(query); "INSERT INTO account_ip SET accid = {}, ip = '{}' ON DUPLICATE KEY UPDATE count=count+1, lastused=now()",
return results.Success(); account_id,
} login_ip
);
void Database::LoginIP(uint32 AccountID, const char* LoginIP) {
std::string query = StringFormat("INSERT INTO account_ip SET accid=%i, ip='%s' ON DUPLICATE KEY UPDATE count=count+1, lastused=now()", AccountID, LoginIP);
QueryDatabase(query); QueryDatabase(query);
} }
int16 Database::CheckStatus(uint32 account_id) int16 Database::CheckStatus(uint32 account_id)
{ {
std::string query = StringFormat( auto query = fmt::format(
"SELECT `status`, TIMESTAMPDIFF(SECOND, NOW(), `suspendeduntil`) FROM `account` WHERE `id` = %i", "SELECT `status`, TIMESTAMPDIFF(SECOND, NOW(), `suspendeduntil`) FROM `account` WHERE `id` = {}",
account_id); account_id
);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success())
return 0;
if (results.RowCount() != 1) if (!results.Success() || results.RowCount() != 1) {
return 0; return 0;
}
auto row = results.begin(); auto row = results.begin();
int16 status = atoi(row[0]); int16 status = std::stoi(row[0]);
int32 date_diff = 0; int32 date_diff = 0;
if (row[1] != nullptr) if (row[1]) {
date_diff = atoi(row[1]); date_diff = std::stoi(row[1]);
}
if (date_diff > 0) if (date_diff > 0) {
return -1; return -1;
}
return status; return status;
} }
@ -307,9 +318,7 @@ bool Database::SetAccountStatus(const std::string& account_name, int16 status)
LogInfo("Account [{}] is attempting to be set to status [{}]", account_name, status); LogInfo("Account [{}] is attempting to be set to status [{}]", account_name, status);
std::string query = fmt::format( std::string query = fmt::format(
SQL( "UPDATE account SET status = {} WHERE name = '{}'",
UPDATE account SET status = {} WHERE name = '{}'
),
status, status,
account_name account_name
); );
@ -807,36 +816,34 @@ uint32 Database::GetAccountIDByChar(uint32 char_id) {
return atoi(row[0]); return atoi(row[0]);
} }
uint32 Database::GetAccountIDByName(const char* accname, const char *loginserver, int16* status, uint32* lsid) { uint32 Database::GetAccountIDByName(std::string account_name, std::string loginserver, int16* status, uint32* lsid) {
if (!isAlphaNumeric(accname)) if (!isAlphaNumeric(account_name.c_str())) {
return 0; return 0;
}
std::string query = StringFormat("SELECT `id`, `status`, `lsaccount_id` FROM `account` WHERE `name` = '%s' AND `ls_id`='%s' LIMIT 1", auto query = fmt::format(
EscapeString(accname).c_str(), EscapeString(loginserver).c_str()); "SELECT `id`, `status`, `lsaccount_id` FROM `account` WHERE `name` = '{}' AND `ls_id` = '{}' LIMIT 1",
EscapeString(account_name),
EscapeString(loginserver)
);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()) { if (!results.Success() || !results.RowCount()) {
return 0; return 0;
} }
if (results.RowCount() != 1)
return 0;
auto row = results.begin(); auto row = results.begin();
auto account_id = std::stoul(row[0]);
uint32 id = atoi(row[0]); if (status) {
*status = static_cast<int16>(std::stoi(row[1]));
if (status)
*status = atoi(row[1]);
if (lsid) {
if (row[2])
*lsid = atoi(row[2]);
else
*lsid = 0;
} }
return id; if (lsid) {
*lsid = row[2] ? std::stoul(row[2]) : 0;
}
return account_id;
} }
void Database::GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID) { void Database::GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID) {

View File

@ -121,16 +121,15 @@ public:
/* General Information Queries */ /* General Information Queries */
bool AddBannedIP(char* bannedIP, const char* notes); //Add IP address to the banned_ips table. bool AddBannedIP(std::string banned_ip, std::string notes); //Add IP address to the banned_ips table.
bool AddGMIP(char* ip_address, char* name); bool CheckBannedIPs(std::string login_ip); //Check incoming connection against banned IP table.
bool CheckBannedIPs(const char* loginIP); //Check incoming connection against banned IP table. bool CheckGMIPs(std::string login_ip, uint32 account_id);
bool CheckGMIPs(const char* loginIP, uint32 account_id);
bool CheckNameFilter(const char* name, bool surname = false); bool CheckNameFilter(const char* name, bool surname = false);
bool CheckUsedName(const char* name); bool CheckUsedName(const char* name);
uint32 GetAccountIDByChar(const char* charname, uint32* oCharID = 0); uint32 GetAccountIDByChar(const char* charname, uint32* oCharID = 0);
uint32 GetAccountIDByChar(uint32 char_id); uint32 GetAccountIDByChar(uint32 char_id);
uint32 GetAccountIDByName(const char* accname, const char *loginserver, int16* status = 0, uint32* lsid = 0); uint32 GetAccountIDByName(std::string account_name, std::string loginserver, int16* status = 0, uint32* lsid = 0);
uint32 GetCharacterID(const char *name); uint32 GetCharacterID(const char *name);
uint32 GetCharacterInfo(const char* iName, uint32* oAccID = 0, uint32* oZoneID = 0, uint32* oInstanceID = 0, float* oX = 0, float* oY = 0, float* oZ = 0); uint32 GetCharacterInfo(const char* iName, uint32* oAccID = 0, uint32* oZoneID = 0, uint32* oInstanceID = 0, float* oX = 0, float* oY = 0, float* oZ = 0);
uint32 GetGuildIDByCharID(uint32 char_id); uint32 GetGuildIDByCharID(uint32 char_id);
@ -142,7 +141,7 @@ public:
std::string GetCharNameByID(uint32 char_id); std::string GetCharNameByID(uint32 char_id);
std::string GetNPCNameByID(uint32 npc_id); std::string GetNPCNameByID(uint32 npc_id);
std::string GetCleanNPCNameByID(uint32 npc_id); std::string GetCleanNPCNameByID(uint32 npc_id);
void LoginIP(uint32 AccountID, const char* LoginIP); void LoginIP(uint32 account_id, std::string login_ip);
/* Instancing */ /* Instancing */

View File

@ -1776,6 +1776,11 @@ struct ServerDzCreateSerialized_Struct {
char cereal_data[0]; char cereal_data[0];
}; };
struct ServerFlagUpdate_Struct {
uint32 account_id;
int16 admin;
};
#pragma pack() #pragma pack()
#endif #endif

View File

@ -490,7 +490,7 @@ bool Client::HandleSendLoginInfoPacket(const EQApplicationPacket *app)
if (!is_player_zoning) { if (!is_player_zoning) {
SendExpansionInfo(); SendExpansionInfo();
SendCharInfo(); SendCharInfo();
database.LoginIP(cle->AccountID(), long2ip(GetIP()).c_str()); database.LoginIP(cle->AccountID(), long2ip(GetIP()));
} }
cle->SetIP(GetIP()); cle->SetIP(GetIP());
@ -997,7 +997,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
// Voidd: Anti-GM Account hack, Checks source ip against valid GM Account IP Addresses // Voidd: Anti-GM Account hack, Checks source ip against valid GM Account IP Addresses
if (RuleB(World, GMAccountIPList) && GetAdmin() >= (RuleI(World, MinGMAntiHackStatus))) { if (RuleB(World, GMAccountIPList) && GetAdmin() >= (RuleI(World, MinGMAntiHackStatus))) {
if(!database.CheckGMIPs(long2ip(GetIP()).c_str(), GetAccountID())) { if(!database.CheckGMIPs(long2ip(GetIP()), GetAccountID())) {
LogInfo("GM Account not permited from source address [{}] and accountid [{}]", long2ip(GetIP()).c_str(), GetAccountID()); LogInfo("GM Account not permited from source address [{}] and accountid [{}]", long2ip(GetIP()).c_str(), GetAccountID());
eqs->Close(); eqs->Close();
} }

View File

@ -752,15 +752,14 @@ void ConsoleSetPass(
connection->SendLine("Format: setpass accountname password"); connection->SendLine("Format: setpass accountname password");
} }
else { else {
std::string prefix = "eqemu"; std::string prefix = "eqemu";
std::string raw_user = ""; std::string raw_user = "";
ParseAccountString(args[0], raw_user, prefix); ParseAccountString(args[0], raw_user, prefix);
int16 tmpstatus = 0; auto account_id = database.GetAccountIDByName(raw_user, prefix);
uint32 tmpid = database.GetAccountIDByName(raw_user.c_str(), prefix.c_str(), &tmpstatus);
if (!tmpid) { if (!account_id) {
connection->SendLine("Error: Account not found"); connection->SendLine("Error: Account not found");
} }
} }

View File

@ -124,7 +124,7 @@ int command_init(void)
command_add("apply_shared_memory", "[shared_memory_name] - Tells every zone and world to apply a specific shared memory segment by name.", AccountStatus::GMImpossible, command_apply_shared_memory) || command_add("apply_shared_memory", "[shared_memory_name] - Tells every zone and world to apply a specific shared memory segment by name.", AccountStatus::GMImpossible, command_apply_shared_memory) ||
command_add("attack", "[Entity Name] - Make your NPC target attack an entity by name", AccountStatus::GMLeadAdmin, command_attack) || command_add("attack", "[Entity Name] - Make your NPC target attack an entity by name", AccountStatus::GMLeadAdmin, command_attack) ||
command_add("augmentitem", "Force augments an item. Must have the augment item window open.", AccountStatus::GMImpossible, command_augmentitem) || command_add("augmentitem", "Force augments an item. Must have the augment item window open.", AccountStatus::GMImpossible, command_augmentitem) ||
command_add("ban", "[name] [reason]- Ban by character name", AccountStatus::GMLeadAdmin, command_ban) || command_add("ban", "[Character Name] [Reason]- Ban by character name", AccountStatus::GMLeadAdmin, command_ban) ||
command_add("bind", "- Sets your targets bind spot to their current location", AccountStatus::GMMgmt, command_bind) || command_add("bind", "- Sets your targets bind spot to their current location", AccountStatus::GMMgmt, command_bind) ||
#ifdef BOTS #ifdef BOTS
@ -178,7 +178,7 @@ int command_init(void)
command_add("findtask", "[search criteria] - Search for a task", AccountStatus::Guide, command_findtask) || command_add("findtask", "[search criteria] - Search for a task", AccountStatus::Guide, command_findtask) ||
command_add("findzone", "[search criteria] - Search database zones", AccountStatus::GMAdmin, command_findzone) || command_add("findzone", "[search criteria] - Search database zones", AccountStatus::GMAdmin, command_findzone) ||
command_add("fixmob", "[race|gender|texture|helm|face|hair|haircolor|beard|beardcolor|heritage|tattoo|detail] [next|prev] - Manipulate appearance of your target", AccountStatus::QuestTroupe, command_fixmob) || command_add("fixmob", "[race|gender|texture|helm|face|hair|haircolor|beard|beardcolor|heritage|tattoo|detail] [next|prev] - Manipulate appearance of your target", AccountStatus::QuestTroupe, command_fixmob) ||
command_add("flag", "[status] [acctname] - Refresh your admin status, or set an account's admin status if arguments provided", AccountStatus::Player, command_flag) || command_add("flag", "[Status] [Account Name] - Refresh your admin status, or set an account's Admin status if arguments provided", AccountStatus::Player, command_flag) ||
command_add("flagedit", "- Edit zone flags on your target. Use #flagedit help for more info.", AccountStatus::GMAdmin, command_flagedit) || command_add("flagedit", "- Edit zone flags on your target. Use #flagedit help for more info.", AccountStatus::GMAdmin, command_flagedit) ||
command_add("flags", "- displays the Zone Flags of you or your target", AccountStatus::Player, command_flags) || command_add("flags", "- displays the Zone Flags of you or your target", AccountStatus::Player, command_flags) ||
command_add("flymode", "[0/1/2/3/4/5] - Set your or your player target's flymode to ground/flying/levitate/water/floating/levitate_running", AccountStatus::Guide, command_flymode) || command_add("flymode", "[0/1/2/3/4/5] - Set your or your player target's flymode to ground/flying/levitate/water/floating/levitate_running", AccountStatus::Guide, command_flymode) ||
@ -216,11 +216,11 @@ int command_init(void)
command_add("interrupt", "[message id] [color] - Interrupt your casting. Arguments are optional.", AccountStatus::Guide, command_interrupt) || command_add("interrupt", "[message id] [color] - Interrupt your casting. Arguments are optional.", AccountStatus::Guide, command_interrupt) ||
command_add("invsnapshot", "- Manipulates inventory snapshots for your current target", AccountStatus::QuestTroupe, command_invsnapshot) || command_add("invsnapshot", "- Manipulates inventory snapshots for your current target", AccountStatus::QuestTroupe, command_invsnapshot) ||
command_add("invul", "[On|Off]] - Turn player target's or your invulnerable flag on or off", AccountStatus::QuestTroupe, command_invul) || command_add("invul", "[On|Off]] - Turn player target's or your invulnerable flag on or off", AccountStatus::QuestTroupe, command_invul) ||
command_add("ipban", "[IP address] - Ban IP by character name", AccountStatus::GMMgmt, command_ipban) || command_add("ipban", "[IP] - Ban IP", AccountStatus::GMMgmt, command_ipban) ||
command_add("iplookup", "[charname] - Look up IP address of charname", AccountStatus::GMMgmt, command_iplookup) || command_add("iplookup", "[charname] - Look up IP address of charname", AccountStatus::GMMgmt, command_iplookup) ||
command_add("iteminfo", "- Get information about the item on your cursor", AccountStatus::Steward, command_iteminfo) || command_add("iteminfo", "- Get information about the item on your cursor", AccountStatus::Steward, command_iteminfo) ||
command_add("itemsearch", "[search criteria] - Search for an item", AccountStatus::Steward, command_itemsearch) || command_add("itemsearch", "[search criteria] - Search for an item", AccountStatus::Steward, command_itemsearch) ||
command_add("kick", "[charname] - Disconnect charname", AccountStatus::GMLeadAdmin, command_kick) || command_add("kick", "[Character Name] - Disconnect a player by name", AccountStatus::GMLeadAdmin, command_kick) ||
command_add("kill", "- Kill your target", AccountStatus::GMAdmin, command_kill) || command_add("kill", "- Kill your target", AccountStatus::GMAdmin, command_kill) ||
command_add("killallnpcs", " [npc_name] Kills all npcs by search name, leave blank for all attackable NPC's", AccountStatus::GMMgmt, command_killallnpcs) || command_add("killallnpcs", " [npc_name] Kills all npcs by search name, leave blank for all attackable NPC's", AccountStatus::GMMgmt, command_killallnpcs) ||
command_add("lastname", "[Last Name] - Set you or your player target's lastname", AccountStatus::Guide, command_lastname) || command_add("lastname", "[Last Name] - Set you or your player target's lastname", AccountStatus::Guide, command_lastname) ||
@ -324,9 +324,9 @@ int command_init(void)
command_add("setgraveyard", "[zone name] - Creates a graveyard for the specified zone based on your target's LOC.", AccountStatus::GMMgmt, command_setgraveyard) || command_add("setgraveyard", "[zone name] - Creates a graveyard for the specified zone based on your target's LOC.", AccountStatus::GMMgmt, command_setgraveyard) ||
command_add("sethp", "[Health] - Set your or your target's Health", AccountStatus::GMAdmin, command_sethp) || command_add("sethp", "[Health] - Set your or your target's Health", AccountStatus::GMAdmin, command_sethp) ||
command_add("setlanguage", "[language ID] [value] - Set your target's language skillnum to value", AccountStatus::Guide, command_setlanguage) || command_add("setlanguage", "[language ID] [value] - Set your target's language skillnum to value", AccountStatus::Guide, command_setlanguage) ||
command_add("setlsinfo", "[email] [password] - Set login server email address and password (if supported by login server)", AccountStatus::Steward, command_setlsinfo) || command_add("setlsinfo", "[Email] [Password] - Set loginserver email address and password (if supported by loginserver)", AccountStatus::Steward, command_setlsinfo) ||
command_add("setmana", "[Mana] - Set your or your target's Mana", AccountStatus::GMAdmin, command_setmana) || command_add("setmana", "[Mana] - Set your or your target's Mana", AccountStatus::GMAdmin, command_setmana) ||
command_add("setpass", "[accountname] [password] - Set local password for accountname", AccountStatus::GMLeadAdmin, command_setpass) || command_add("setpass", "[Account Name] [Password] - Set local password by account name", AccountStatus::GMLeadAdmin, command_setpass) ||
command_add("setpvppoints", "[Amount] - Set your or your player target's PVP points", AccountStatus::GMAdmin, command_setpvppoints) || command_add("setpvppoints", "[Amount] - Set your or your player target's PVP points", AccountStatus::GMAdmin, command_setpvppoints) ||
command_add("setskill", "[skillnum] [value] - Set your target's skill skillnum to value", AccountStatus::Guide, command_setskill) || command_add("setskill", "[skillnum] [value] - Set your target's skill skillnum to value", AccountStatus::Guide, command_setskill) ||
command_add("setskillall", "[Skill Level] - Set all of your or your target's skills to the specified skill level", AccountStatus::Guide, command_setskillall) || command_add("setskillall", "[Skill Level] - Set all of your or your target's skills to the specified skill level", AccountStatus::Guide, command_setskillall) ||

View File

@ -5,67 +5,70 @@ extern WorldServer worldserver;
void command_ban(Client *c, const Seperator *sep) void command_ban(Client *c, const Seperator *sep)
{ {
if (sep->arg[1][0] == 0 || sep->arg[2][0] == 0) { int arguments = sep->argnum;
c->Message(Chat::White, "Usage: #ban <charname> <message>"); if (arguments < 2) {
c->Message(Chat::White, "Usage: #ban [Character Name] [Reason]");
return; return;
} }
auto account_id = database.GetAccountIDByChar(sep->arg[1]); std::string character_name = sep->arg[1];
if (character_name.empty()) {
std::string message; c->Message(Chat::White, "Usage: #ban [Character Name] [Reason]");
int i = 2;
while (1) {
if (sep->arg[i][0] == 0) {
break;
}
if (message.length() > 0) {
message.push_back(' ');
}
message += sep->arg[i];
++i;
}
if (message.length() == 0) {
c->Message(Chat::White, "Usage: #ban <charname> <message>");
return; return;
} }
if (account_id == 0) { std::string reason = sep->argplus[2];
c->Message(Chat::Red, "Character does not exist."); if (reason.empty()) {
c->Message(Chat::White, "Usage: #ban [Character Name] [Reason]");
return; return;
} }
std::string query = StringFormat( auto account_id = database.GetAccountIDByChar(character_name.c_str());
"UPDATE account SET status = -2, ban_reason = '%s' " if (!account_id) {
"WHERE id = %i", EscapeString(message).c_str(), account_id c->Message(
Chat::White,
fmt::format(
"Character {} does not exist."
).c_str(),
character_name
);
return;
}
auto query = fmt::format(
"UPDATE account SET status = -2, ban_reason = '{}' WHERE id = {}",
EscapeString(reason),
account_id
); );
auto results = database.QueryDatabase(query); auto results = database.QueryDatabase(query);
c->Message( c->Message(
Chat::Red, Chat::White,
"Account number %i with the character %s has been banned with message: \"%s\"", fmt::format(
account_id, "Account ID {} with the character {} has been banned for the following reason: \"{}\"",
sep->arg[1], account_id,
message.c_str()); character_name,
reason
).c_str()
);
ServerPacket flagUpdatePack(ServerOP_FlagUpdate, 6); ServerPacket flagUpdatePack(ServerOP_FlagUpdate, sizeof(ServerFlagUpdate_Struct));
*((uint32 *) &flagUpdatePack.pBuffer[0]) = account_id; ServerFlagUpdate_Struct *sfus = (ServerFlagUpdate_Struct *) flagUpdatePack.pBuffer;
*((int16 *) &flagUpdatePack.pBuffer[4]) = -2; sfus->account_id = account_id;
sfus->admin = -2;
worldserver.SendPacket(&flagUpdatePack); worldserver.SendPacket(&flagUpdatePack);
Client *client = nullptr; Client *client = nullptr;
client = entity_list.GetClientByName(sep->arg[1]); client = entity_list.GetClientByName(character_name.c_str());
if (client) { if (client) {
client->WorldKick(); client->WorldKick();
return; return;
} }
ServerPacket kickPlayerPack(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct)); ServerPacket kickPlayerPack(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
ServerKickPlayer_Struct *skp = (ServerKickPlayer_Struct *) kickPlayerPack.pBuffer; ServerKickPlayer_Struct *skp = (ServerKickPlayer_Struct *) kickPlayerPack.pBuffer;
strcpy(skp->adminname, c->GetName()); strcpy(skp->adminname, c->GetName());
strcpy(skp->name, sep->arg[1]); strcpy(skp->name, character_name.c_str());
skp->adminrank = c->Admin(); skp->adminrank = c->Admin();
worldserver.SendPacket(&kickPlayerPack); worldserver.SendPacket(&kickPlayerPack);
} }

View File

@ -5,47 +5,81 @@ extern WorldServer worldserver;
void command_flag(Client *c, const Seperator *sep) void command_flag(Client *c, const Seperator *sep)
{ {
if (sep->arg[2][0] == 0) { int arguments = sep->argnum;
if (!c->GetTarget() || (c->GetTarget() && c->GetTarget() == c)) { if (!arguments) {
c->UpdateAdmin(); auto target = c->GetTarget() && c->GetTarget()->IsClient() ? c->GetTarget()->CastToClient() : c;
c->Message(Chat::White, "Refreshed your admin flag from DB."); if (target != c) {
} c->Message(
else if (c->GetTarget() && c->GetTarget() != c && c->GetTarget()->IsClient()) { Chat::White,
c->GetTarget()->CastToClient()->UpdateAdmin(); fmt::format(
c->Message(Chat::White, "%s's admin flag has been refreshed.", c->GetTarget()->GetName()); "Status level has been refreshed for {}.",
c->GetTarget()->Message(Chat::White, "%s refreshed your admin flag.", c->GetName()); target->GetCleanName()
).c_str()
);
target->Message(
Chat::White,
fmt::format(
"Your status level has been refreshed by {}.",
c->GetCleanName()
).c_str()
);
} else {
c->Message(Chat::White, "Your status level has been refreshed.");
} }
target->UpdateAdmin();
return;
} }
else if (!sep->IsNumber(1) || atoi(sep->arg[1]) < -2 || atoi(sep->arg[1]) > 255 || strlen(sep->arg[2]) == 0) {
c->Message(Chat::White, "Usage: #flag [status] [acctname]");
if (
!sep->IsNumber(1) ||
strlen(sep->arg[2]) == 0
) {
c->Message(Chat::White, "Usage: #flag [Status] [Account Name]");
return;
} }
else if (c->Admin() < commandChangeFlags) { auto status = std::stoi(sep->arg[1]);
//this check makes banning players by less than this level if (status < -2 || status > 255) {
//impossible, but i'll leave it in anyways c->Message(Chat::White, "The lowest a status level can go is -2 and the highest a status level can go is 255.");
return;
}
std::string account_name = sep->argplus[2];
auto account_id = database.GetAccountIDByChar(account_name.c_str());
if (c->Admin() < commandChangeFlags) { //this check makes banning players by less than this level impossible, but i'll leave it in anyways
c->Message(Chat::White, "You may only refresh your own flag, doing so now."); c->Message(Chat::White, "You may only refresh your own flag, doing so now.");
c->UpdateAdmin(); c->UpdateAdmin();
} } else {
else { if (status > c->Admin()) {
if (atoi(sep->arg[1]) > c->Admin()) { c->Message(
c->Message(Chat::White, "You cannot set people's status to higher than your own"); Chat::White,
} fmt::format(
else if (atoi(sep->arg[1]) < 0 && c->Admin() < commandBanPlayers) { "You cannot set someone's status level to {} because your status level is only {}.",
c->Message(Chat::White, "You have too low of status to suspend/ban"); status,
} c->Admin()
else if (!database.SetAccountStatus(sep->argplus[2], atoi(sep->arg[1]))) { ).c_str()
c->Message(Chat::White, "Unable to set GM Flag."); );
} else if (status < 0 && c->Admin() < commandBanPlayers) {
c->Message(Chat::White, "Your status level is not high enough to ban or suspend.");
} else if (!database.SetAccountStatus(account_name, status)) {
c->Message(Chat::White, "Failed to set status level.");
} }
else { else {
c->Message(Chat::White, "Set GM Flag on account."); c->Message(Chat::White, "Set GM Flag on account.");
std::string user; std::string user;
std::string loginserver; std::string loginserver;
ParseAccountString(sep->argplus[2], user, loginserver); ParseAccountString(account_name, user, loginserver);
ServerPacket pack(ServerOP_FlagUpdate, 6); account_id = database.GetAccountIDByName(account_name, loginserver);
*((uint32 *) pack.pBuffer) = database.GetAccountIDByName(user.c_str(), loginserver.c_str());
*((int16 *) &pack.pBuffer[4]) = atoi(sep->arg[1]); ServerPacket pack(ServerOP_FlagUpdate, sizeof(ServerFlagUpdate_Struct));
ServerFlagUpdate_Struct *sfus = (ServerFlagUpdate_Struct *) pack.pBuffer;
sfus->account_id = account_id;
sfus->admin = status;
worldserver.SendPacket(&pack); worldserver.SendPacket(&pack);
} }
} }

View File

@ -2,20 +2,32 @@
void command_ipban(Client *c, const Seperator *sep) void command_ipban(Client *c, const Seperator *sep)
{ {
if (sep->arg[1] == 0) { int arguments = sep->argnum;
c->Message(Chat::White, "Usage: #ipban [xxx.xxx.xxx.xxx]"); if (!arguments) {
c->Message(Chat::White, "Usage: #ipban [IP]");
return;
} }
else {
if (database.AddBannedIP(sep->arg[1], c->GetName())) { std::string ip = sep->arg[1];
c->Message( if (ip.empty()) {
Chat::White, c->Message(Chat::White, "Usage: #ipban [IP]");
"%s has been successfully added to the banned_ips table by %s", return;
sep->arg[1], }
c->GetName());
} if (database.AddBannedIP(ip, c->GetName())) {
else { c->Message(
c->Message(Chat::White, "IPBan Failed (IP address is possibly already in the table?)"); Chat::White,
} fmt::format(
"IP '{}' has been successfully banned.",
ip
).c_str()
);
} else {
c->Message(
Chat::White,
"IP '{}' has failed to be banned, the IP address may already be in the table.",
ip
);
} }
} }

View File

@ -5,32 +5,37 @@ extern WorldServer worldserver;
void command_kick(Client *c, const Seperator *sep) void command_kick(Client *c, const Seperator *sep)
{ {
if (sep->arg[1][0] == 0) { int arguments = sep->argnum;
c->Message(Chat::White, "Usage: #kick [charname]"); if (!arguments) {
c->Message(Chat::White, "Usage: #kick [Character Name]");
return;
} }
else {
Client *client = entity_list.GetClientByName(sep->arg[1]); std::string character_name = sep->arg[1];
if (client != 0) { auto client = entity_list.GetClientByName(character_name.c_str());
if (client->Admin() <= c->Admin()) { if (client) {
client->Message(Chat::White, "You have been kicked by %s", c->GetName()); if (client->Admin() <= c->Admin()) {
auto outapp = new EQApplicationPacket(OP_GMKick, 0); auto outapp = new EQApplicationPacket(OP_GMKick, 0);
client->QueuePacket(outapp); client->QueuePacket(outapp);
client->Kick("Ordered kicked by command"); client->Kick("Ordered kicked by command");
c->Message(Chat::White, "Kick: local: kicking %s", sep->arg[1]); c->Message(
} Chat::White,
} fmt::format(
else if (!worldserver.Connected()) { "{} has been kicked from the server.",
c->Message(Chat::White, "Error: World server disconnected"); character_name
} ).c_str()
else { );
auto pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
ServerKickPlayer_Struct *skp = (ServerKickPlayer_Struct *) pack->pBuffer;
strcpy(skp->adminname, c->GetName());
strcpy(skp->name, sep->arg[1]);
skp->adminrank = c->Admin();
worldserver.SendPacket(pack);
safe_delete(pack);
} }
} else if (!worldserver.Connected()) {
c->Message(Chat::White, "The world server is currently disconnected.");
} else {
auto pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
ServerKickPlayer_Struct *skp = (ServerKickPlayer_Struct *) pack->pBuffer;
strcpy(skp->adminname, c->GetName());
strcpy(skp->name, character_name.c_str());
skp->adminrank = c->Admin();
worldserver.SendPacket(pack);
safe_delete(pack);
} }
} }

View File

@ -5,20 +5,19 @@ extern WorldServer worldserver;
void command_setlsinfo(Client *c, const Seperator *sep) void command_setlsinfo(Client *c, const Seperator *sep)
{ {
if (sep->argnum != 2) { int arguments = sep->argnum;
c->Message(Chat::White, "Format: #setlsinfo email password"); if (arguments < 2) {
} c->Message(Chat::White, "Usage: #setlsinfo [Email] [Password]");
else { return;
auto pack = new ServerPacket(
ServerOP_LSAccountUpdate,
sizeof(ServerLSAccountUpdate_Struct));
ServerLSAccountUpdate_Struct *s = (ServerLSAccountUpdate_Struct *) pack->pBuffer;
s->useraccountid = c->LSAccountID();
strn0cpy(s->useraccount, c->AccountName(), 30);
strn0cpy(s->user_email, sep->arg[1], 100);
strn0cpy(s->userpassword, sep->arg[2], 50);
worldserver.SendPacket(pack);
c->Message(Chat::White, "Login Server update packet sent.");
} }
auto pack = new ServerPacket(ServerOP_LSAccountUpdate, sizeof(ServerLSAccountUpdate_Struct));
auto s = (ServerLSAccountUpdate_Struct *) pack->pBuffer;
s->useraccountid = c->LSAccountID();
strn0cpy(s->useraccount, c->AccountName(), 30);
strn0cpy(s->user_email, sep->arg[1], 100);
strn0cpy(s->userpassword, sep->arg[2], 50);
worldserver.SendPacket(pack);
c->Message(Chat::White, "Your email and local loginserver password have been set.");
} }

View File

@ -2,28 +2,50 @@
void command_setpass(Client *c, const Seperator *sep) void command_setpass(Client *c, const Seperator *sep)
{ {
if (sep->argnum != 2) { int arguments = sep->argnum;
c->Message(Chat::White, "Format: #setpass accountname password"); if (arguments < 2) {
c->Message(Chat::White, "Usage: #setpass [Account Name] [Password]");
return;
} }
else {
std::string user;
std::string loginserver;
ParseAccountString(sep->arg[1], user, loginserver);
int16 tmpstatus = 0; std::string account_name;
uint32 tmpid = database.GetAccountIDByName(user.c_str(), loginserver.c_str(), &tmpstatus); std::string loginserver;
if (!tmpid) { ParseAccountString(sep->arg[1], account_name, loginserver);
c->Message(Chat::White, "Error: Account not found"); int16 status = 0;
} auto account_id = database.GetAccountIDByName(account_name, loginserver, &status);
else if (tmpstatus > c->Admin()) { if (!account_id) {
c->Message(Chat::White, "Cannot change password: Account's status is higher than yours"); c->Message(
} Chat::White,
else if (database.SetLocalPassword(tmpid, sep->arg[2])) { fmt::format(
c->Message(Chat::White, "Password changed."); "Account {} not found.",
} account_name
else { ).c_str()
c->Message(Chat::White, "Error changing password."); );
} return;
} }
if (status > c->Admin()) {
c->Message(
Chat::White,
fmt::format(
"You cannot change the password for Account {} as its status is higher than yours.",
account_name
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Password {} changed for Account {}.",
(
database.SetLocalPassword(account_id, sep->arg[2]) ?
"successfully" :
"failed"
),
account_name
).c_str()
);
} }

View File

@ -2555,7 +2555,7 @@ void QuestManager::whisper(const char *message) {
std::string mob_name = owner->GetCleanName(); std::string mob_name = owner->GetCleanName();
std::string new_message = fmt::format("{} whispers, '{}'", mob_name, message); std::string new_message = fmt::format("{} whispers, '{}'", mob_name, message);
initiator->Message(315, new_message.c_str()); initiator->Message(Chat::EchoChat1, new_message.c_str());
} }
int QuestManager::getlevel(uint8 type) int QuestManager::getlevel(uint8 type)