mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 09:06:46 +00:00
[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:
+41
-38
@@ -5,67 +5,70 @@ extern WorldServer worldserver;
|
||||
|
||||
void command_ban(Client *c, const Seperator *sep)
|
||||
{
|
||||
if (sep->arg[1][0] == 0 || sep->arg[2][0] == 0) {
|
||||
c->Message(Chat::White, "Usage: #ban <charname> <message>");
|
||||
int arguments = sep->argnum;
|
||||
if (arguments < 2) {
|
||||
c->Message(Chat::White, "Usage: #ban [Character Name] [Reason]");
|
||||
return;
|
||||
}
|
||||
|
||||
auto account_id = database.GetAccountIDByChar(sep->arg[1]);
|
||||
|
||||
std::string message;
|
||||
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>");
|
||||
std::string character_name = sep->arg[1];
|
||||
if (character_name.empty()) {
|
||||
c->Message(Chat::White, "Usage: #ban [Character Name] [Reason]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (account_id == 0) {
|
||||
c->Message(Chat::Red, "Character does not exist.");
|
||||
std::string reason = sep->argplus[2];
|
||||
if (reason.empty()) {
|
||||
c->Message(Chat::White, "Usage: #ban [Character Name] [Reason]");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string query = StringFormat(
|
||||
"UPDATE account SET status = -2, ban_reason = '%s' "
|
||||
"WHERE id = %i", EscapeString(message).c_str(), account_id
|
||||
auto account_id = database.GetAccountIDByChar(character_name.c_str());
|
||||
if (!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(
|
||||
Chat::Red,
|
||||
"Account number %i with the character %s has been banned with message: \"%s\"",
|
||||
account_id,
|
||||
sep->arg[1],
|
||||
message.c_str());
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Account ID {} with the character {} has been banned for the following reason: \"{}\"",
|
||||
account_id,
|
||||
character_name,
|
||||
reason
|
||||
).c_str()
|
||||
);
|
||||
|
||||
ServerPacket flagUpdatePack(ServerOP_FlagUpdate, 6);
|
||||
*((uint32 *) &flagUpdatePack.pBuffer[0]) = account_id;
|
||||
*((int16 *) &flagUpdatePack.pBuffer[4]) = -2;
|
||||
ServerPacket flagUpdatePack(ServerOP_FlagUpdate, sizeof(ServerFlagUpdate_Struct));
|
||||
ServerFlagUpdate_Struct *sfus = (ServerFlagUpdate_Struct *) flagUpdatePack.pBuffer;
|
||||
sfus->account_id = account_id;
|
||||
sfus->admin = -2;
|
||||
worldserver.SendPacket(&flagUpdatePack);
|
||||
|
||||
Client *client = nullptr;
|
||||
client = entity_list.GetClientByName(sep->arg[1]);
|
||||
client = entity_list.GetClientByName(character_name.c_str());
|
||||
if (client) {
|
||||
client->WorldKick();
|
||||
return;
|
||||
}
|
||||
|
||||
ServerPacket kickPlayerPack(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
|
||||
ServerPacket kickPlayerPack(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
|
||||
ServerKickPlayer_Struct *skp = (ServerKickPlayer_Struct *) kickPlayerPack.pBuffer;
|
||||
strcpy(skp->adminname, c->GetName());
|
||||
strcpy(skp->name, sep->arg[1]);
|
||||
strcpy(skp->name, character_name.c_str());
|
||||
skp->adminrank = c->Admin();
|
||||
worldserver.SendPacket(&kickPlayerPack);
|
||||
}
|
||||
|
||||
+62
-28
@@ -5,47 +5,81 @@ extern WorldServer worldserver;
|
||||
|
||||
void command_flag(Client *c, const Seperator *sep)
|
||||
{
|
||||
if (sep->arg[2][0] == 0) {
|
||||
if (!c->GetTarget() || (c->GetTarget() && c->GetTarget() == c)) {
|
||||
c->UpdateAdmin();
|
||||
c->Message(Chat::White, "Refreshed your admin flag from DB.");
|
||||
}
|
||||
else if (c->GetTarget() && c->GetTarget() != c && c->GetTarget()->IsClient()) {
|
||||
c->GetTarget()->CastToClient()->UpdateAdmin();
|
||||
c->Message(Chat::White, "%s's admin flag has been refreshed.", c->GetTarget()->GetName());
|
||||
c->GetTarget()->Message(Chat::White, "%s refreshed your admin flag.", c->GetName());
|
||||
int arguments = sep->argnum;
|
||||
if (!arguments) {
|
||||
auto target = c->GetTarget() && c->GetTarget()->IsClient() ? c->GetTarget()->CastToClient() : c;
|
||||
if (target != c) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Status level has been refreshed for {}.",
|
||||
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) {
|
||||
//this check makes banning players by less than this level
|
||||
//impossible, but i'll leave it in anyways
|
||||
auto status = std::stoi(sep->arg[1]);
|
||||
if (status < -2 || status > 255) {
|
||||
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->UpdateAdmin();
|
||||
}
|
||||
else {
|
||||
if (atoi(sep->arg[1]) > c->Admin()) {
|
||||
c->Message(Chat::White, "You cannot set people's status to higher than your own");
|
||||
}
|
||||
else if (atoi(sep->arg[1]) < 0 && c->Admin() < commandBanPlayers) {
|
||||
c->Message(Chat::White, "You have too low of status to suspend/ban");
|
||||
}
|
||||
else if (!database.SetAccountStatus(sep->argplus[2], atoi(sep->arg[1]))) {
|
||||
c->Message(Chat::White, "Unable to set GM Flag.");
|
||||
} else {
|
||||
if (status > c->Admin()) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"You cannot set someone's status level to {} because your status level is only {}.",
|
||||
status,
|
||||
c->Admin()
|
||||
).c_str()
|
||||
);
|
||||
} 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 {
|
||||
c->Message(Chat::White, "Set GM Flag on account.");
|
||||
|
||||
std::string user;
|
||||
std::string loginserver;
|
||||
ParseAccountString(sep->argplus[2], user, loginserver);
|
||||
ParseAccountString(account_name, user, loginserver);
|
||||
|
||||
ServerPacket pack(ServerOP_FlagUpdate, 6);
|
||||
*((uint32 *) pack.pBuffer) = database.GetAccountIDByName(user.c_str(), loginserver.c_str());
|
||||
*((int16 *) &pack.pBuffer[4]) = atoi(sep->arg[1]);
|
||||
account_id = database.GetAccountIDByName(account_name, loginserver);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+25
-13
@@ -2,20 +2,32 @@
|
||||
|
||||
void command_ipban(Client *c, const Seperator *sep)
|
||||
{
|
||||
if (sep->arg[1] == 0) {
|
||||
c->Message(Chat::White, "Usage: #ipban [xxx.xxx.xxx.xxx]");
|
||||
int arguments = sep->argnum;
|
||||
if (!arguments) {
|
||||
c->Message(Chat::White, "Usage: #ipban [IP]");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (database.AddBannedIP(sep->arg[1], c->GetName())) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
"%s has been successfully added to the banned_ips table by %s",
|
||||
sep->arg[1],
|
||||
c->GetName());
|
||||
}
|
||||
else {
|
||||
c->Message(Chat::White, "IPBan Failed (IP address is possibly already in the table?)");
|
||||
}
|
||||
|
||||
std::string ip = sep->arg[1];
|
||||
if (ip.empty()) {
|
||||
c->Message(Chat::White, "Usage: #ipban [IP]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (database.AddBannedIP(ip, c->GetName())) {
|
||||
c->Message(
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+29
-24
@@ -5,32 +5,37 @@ extern WorldServer worldserver;
|
||||
|
||||
void command_kick(Client *c, const Seperator *sep)
|
||||
{
|
||||
if (sep->arg[1][0] == 0) {
|
||||
c->Message(Chat::White, "Usage: #kick [charname]");
|
||||
int arguments = sep->argnum;
|
||||
if (!arguments) {
|
||||
c->Message(Chat::White, "Usage: #kick [Character Name]");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Client *client = entity_list.GetClientByName(sep->arg[1]);
|
||||
if (client != 0) {
|
||||
if (client->Admin() <= c->Admin()) {
|
||||
client->Message(Chat::White, "You have been kicked by %s", c->GetName());
|
||||
auto outapp = new EQApplicationPacket(OP_GMKick, 0);
|
||||
client->QueuePacket(outapp);
|
||||
client->Kick("Ordered kicked by command");
|
||||
c->Message(Chat::White, "Kick: local: kicking %s", sep->arg[1]);
|
||||
}
|
||||
}
|
||||
else if (!worldserver.Connected()) {
|
||||
c->Message(Chat::White, "Error: World server 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, sep->arg[1]);
|
||||
skp->adminrank = c->Admin();
|
||||
worldserver.SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
|
||||
std::string character_name = sep->arg[1];
|
||||
auto client = entity_list.GetClientByName(character_name.c_str());
|
||||
if (client) {
|
||||
if (client->Admin() <= c->Admin()) {
|
||||
auto outapp = new EQApplicationPacket(OP_GMKick, 0);
|
||||
client->QueuePacket(outapp);
|
||||
client->Kick("Ordered kicked by command");
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"{} has been kicked from the server.",
|
||||
character_name
|
||||
).c_str()
|
||||
);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,20 +5,19 @@ extern WorldServer worldserver;
|
||||
|
||||
void command_setlsinfo(Client *c, const Seperator *sep)
|
||||
{
|
||||
if (sep->argnum != 2) {
|
||||
c->Message(Chat::White, "Format: #setlsinfo email password");
|
||||
}
|
||||
else {
|
||||
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.");
|
||||
int arguments = sep->argnum;
|
||||
if (arguments < 2) {
|
||||
c->Message(Chat::White, "Usage: #setlsinfo [Email] [Password]");
|
||||
return;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,28 +2,50 @@
|
||||
|
||||
void command_setpass(Client *c, const Seperator *sep)
|
||||
{
|
||||
if (sep->argnum != 2) {
|
||||
c->Message(Chat::White, "Format: #setpass accountname password");
|
||||
int arguments = sep->argnum;
|
||||
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;
|
||||
uint32 tmpid = database.GetAccountIDByName(user.c_str(), loginserver.c_str(), &tmpstatus);
|
||||
if (!tmpid) {
|
||||
c->Message(Chat::White, "Error: Account not found");
|
||||
}
|
||||
else if (tmpstatus > c->Admin()) {
|
||||
c->Message(Chat::White, "Cannot change password: Account's status is higher than yours");
|
||||
}
|
||||
else if (database.SetLocalPassword(tmpid, sep->arg[2])) {
|
||||
c->Message(Chat::White, "Password changed.");
|
||||
}
|
||||
else {
|
||||
c->Message(Chat::White, "Error changing password.");
|
||||
}
|
||||
std::string account_name;
|
||||
std::string loginserver;
|
||||
ParseAccountString(sep->arg[1], account_name, loginserver);
|
||||
int16 status = 0;
|
||||
auto account_id = database.GetAccountIDByName(account_name, loginserver, &status);
|
||||
if (!account_id) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Account {} not found.",
|
||||
account_name
|
||||
).c_str()
|
||||
);
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user