mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 18:51:29 +00:00
[Bug Fix] Fix issue with #suspend (#4314)
* [Bug Fix] Fix issue with #suspend * Add suspension clearing * Update character_data_repository.h * Final push.
This commit is contained in:
parent
e26d17182e
commit
e33e076b2a
@ -206,9 +206,19 @@ void Database::LoginIP(uint32 account_id, const std::string& login_ip)
|
|||||||
QueryDatabase(query);
|
QueryDatabase(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 Database::CheckStatus(uint32 account_id)
|
int16 Database::GetAccountStatus(uint32 account_id)
|
||||||
{
|
{
|
||||||
return AccountRepository::GetAccountStatus(*this, account_id);
|
auto e = AccountRepository::FindOne(*this, account_id);
|
||||||
|
|
||||||
|
if (e.suspendeduntil > 0 && e.suspendeduntil < std::time(nullptr)) {
|
||||||
|
e.status = 0;
|
||||||
|
e.suspendeduntil = 0;
|
||||||
|
e.suspend_reason = "";
|
||||||
|
|
||||||
|
AccountRepository::UpdateOne(*this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Database::CreateAccount(
|
uint32 Database::CreateAccount(
|
||||||
|
|||||||
@ -170,7 +170,7 @@ public:
|
|||||||
bool SetAccountStatus(const std::string& account_name, int16 status);
|
bool SetAccountStatus(const std::string& account_name, int16 status);
|
||||||
bool SetLocalPassword(uint32 account_id, const std::string& password);
|
bool SetLocalPassword(uint32 account_id, const std::string& password);
|
||||||
bool UpdateLiveChar(const std::string& name, uint32 account_id);
|
bool UpdateLiveChar(const std::string& name, uint32 account_id);
|
||||||
int16 CheckStatus(uint32 account_id);
|
int16 GetAccountStatus(uint32 account_id);
|
||||||
void SetAccountCRCField(uint32 account_id, const std::string& field_name, uint64 checksum);
|
void SetAccountCRCField(uint32 account_id, const std::string& field_name, uint64 checksum);
|
||||||
uint32 CheckLogin(const std::string& name, const std::string& password, const std::string& loginserver, int16* status = 0);
|
uint32 CheckLogin(const std::string& name, const std::string& password, const std::string& loginserver, int16* status = 0);
|
||||||
uint32 CreateAccount(
|
uint32 CreateAccount(
|
||||||
|
|||||||
@ -64,6 +64,22 @@ public:
|
|||||||
|
|
||||||
return Strings::ToUnsignedInt(row[0]);
|
return Strings::ToUnsignedInt(row[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CharacterData FindByName(
|
||||||
|
Database& db,
|
||||||
|
const std::string& character_name
|
||||||
|
)
|
||||||
|
{
|
||||||
|
auto l = CharacterDataRepository::GetWhere(
|
||||||
|
db,
|
||||||
|
fmt::format(
|
||||||
|
"`name` = '{}' LIMIT 1",
|
||||||
|
Strings::Escape(character_name)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return l.empty() ? CharacterDataRepository::NewEntity() : l.front();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //EQEMU_CHARACTER_DATA_REPOSITORY_H
|
#endif //EQEMU_CHARACTER_DATA_REPOSITORY_H
|
||||||
|
|||||||
@ -60,7 +60,7 @@ struct EQ::Net::ConsoleLoginStatus CheckLogin(const std::string &username, const
|
|||||||
const std::string& account_name = database.GetAccountName(ret.account_id);
|
const std::string& account_name = database.GetAccountName(ret.account_id);
|
||||||
|
|
||||||
ret.account_name = account_name;
|
ret.account_name = account_name;
|
||||||
ret.status = database.CheckStatus(ret.account_id);
|
ret.status = database.GetAccountStatus(ret.account_id);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,7 @@ void LoginServer::ProcessUsertoWorldReqLeg(uint16_t opcode, EQ::Net::Packet &p)
|
|||||||
|
|
||||||
UsertoWorldRequestLegacy_Struct *utwr = (UsertoWorldRequestLegacy_Struct *) p.Data();
|
UsertoWorldRequestLegacy_Struct *utwr = (UsertoWorldRequestLegacy_Struct *) p.Data();
|
||||||
uint32 id = database.GetAccountIDFromLSID("eqemu", utwr->lsaccountid);
|
uint32 id = database.GetAccountIDFromLSID("eqemu", utwr->lsaccountid);
|
||||||
int16 status = database.CheckStatus(id);
|
int16 status = database.GetAccountStatus(id);
|
||||||
|
|
||||||
LogDebug(
|
LogDebug(
|
||||||
"id [{}] status [{}] account_id [{}] world_id [{}] from_id [{}] to_id [{}] ip [{}]",
|
"id [{}] status [{}] account_id [{}] world_id [{}] from_id [{}] to_id [{}] ip [{}]",
|
||||||
@ -146,7 +146,7 @@ void LoginServer::ProcessUsertoWorldReq(uint16_t opcode, EQ::Net::Packet &p)
|
|||||||
|
|
||||||
UsertoWorldRequest_Struct *utwr = (UsertoWorldRequest_Struct *) p.Data();
|
UsertoWorldRequest_Struct *utwr = (UsertoWorldRequest_Struct *) p.Data();
|
||||||
uint32 id = database.GetAccountIDFromLSID(utwr->login, utwr->lsaccountid);
|
uint32 id = database.GetAccountIDFromLSID(utwr->login, utwr->lsaccountid);
|
||||||
int16 status = database.CheckStatus(id);
|
int16 status = database.GetAccountStatus(id);
|
||||||
|
|
||||||
LogDebug(
|
LogDebug(
|
||||||
"id [{}] status [{}] account_id [{}] world_id [{}] from_id [{}] to_id [{}] ip [{}]",
|
"id [{}] status [{}] account_id [{}] world_id [{}] from_id [{}] to_id [{}] ip [{}]",
|
||||||
|
|||||||
@ -59,7 +59,7 @@ EQ::Net::WebsocketLoginStatus CheckLogin(
|
|||||||
|
|
||||||
ret.account_name = database.GetAccountName(static_cast<uint32>(ret.account_id));
|
ret.account_name = database.GetAccountName(static_cast<uint32>(ret.account_id));
|
||||||
ret.logged_in = true;
|
ret.logged_in = true;
|
||||||
ret.status = database.CheckStatus(ret.account_id);
|
ret.status = database.GetAccountStatus(ret.account_id);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1849,7 +1849,7 @@ void Client::FriendsWho(char *FriendsString) {
|
|||||||
void Client::UpdateAdmin(bool from_database) {
|
void Client::UpdateAdmin(bool from_database) {
|
||||||
int16 tmp = admin;
|
int16 tmp = admin;
|
||||||
if (from_database) {
|
if (from_database) {
|
||||||
admin = database.CheckStatus(account_id);
|
admin = database.GetAccountStatus(account_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp == admin && from_database) {
|
if (tmp == admin && from_database) {
|
||||||
|
|||||||
@ -6,46 +6,56 @@ extern WorldServer worldserver;
|
|||||||
|
|
||||||
void command_suspend(Client *c, const Seperator *sep)
|
void command_suspend(Client *c, const Seperator *sep)
|
||||||
{
|
{
|
||||||
auto arguments = sep->argnum;
|
const uint16 arguments = sep->argnum;
|
||||||
if (arguments < 2 || !sep->IsNumber(2)) {
|
if (arguments < 2 || !sep->IsNumber(2)) {
|
||||||
c->Message(Chat::White, "Usage: #suspend [Character Name] [Days] [Reason]");
|
c->Message(Chat::White, "Usage: #suspend [Character Name] [Days] [Reason]");
|
||||||
c->Message(Chat::White, "Note: Specify 0 days to lift a suspension");
|
c->Message(Chat::White, "Note: Specify 0 days to lift a suspension, reason is not required when removing a suspension");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string character_name = Strings::ToLower(sep->arg[1]);
|
const std::string& character_name = sep->arg[1];
|
||||||
auto days = Strings::ToUnsignedInt(sep->arg[2]);
|
|
||||||
|
|
||||||
const std::string reason = sep->arg[3] ? sep->argplus[3] : "";
|
const auto& e = CharacterDataRepository::FindByName(database, character_name);
|
||||||
|
|
||||||
auto l = AccountRepository::GetWhere(
|
if (!e.id) {
|
||||||
database,
|
|
||||||
fmt::format(
|
|
||||||
"LOWER(charname) = '{}'",
|
|
||||||
Strings::Escape(character_name)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (l.empty()) {
|
|
||||||
c->Message(
|
c->Message(
|
||||||
Chat::White,
|
Chat::White,
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"Character '{}' does not exist.",
|
"Character '{}' does not exist.",
|
||||||
sep->arg[1]
|
character_name
|
||||||
).c_str()
|
).c_str()
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
l[0].status = -1;
|
auto a = AccountRepository::FindOne(database, e.account_id);
|
||||||
l[0].suspendeduntil = std::time(nullptr) + (days * 86400);
|
|
||||||
l[0].suspend_reason = reason;
|
|
||||||
|
|
||||||
if (!AccountRepository::UpdateOne(database, l[0])) {
|
if (!a.id) {
|
||||||
c->Message(
|
c->Message(
|
||||||
Chat::White,
|
Chat::White,
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"Failed to suspend {}.",
|
"Character '{}' is not attached to an account.",
|
||||||
|
character_name
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32 days = Strings::ToUnsignedInt(sep->arg[2]);
|
||||||
|
const bool is_suspend = days != 0;
|
||||||
|
|
||||||
|
const std::string reason = sep->arg[3] ? sep->argplus[3] : "";
|
||||||
|
|
||||||
|
a.status = is_suspend ? -1 : 0;
|
||||||
|
a.suspendeduntil = is_suspend ? std::time(nullptr) + (days * 86400) : 0;
|
||||||
|
a.suspend_reason = is_suspend ? reason : "";
|
||||||
|
|
||||||
|
if (!AccountRepository::UpdateOne(database, a)) {
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"Failed to {}suspend {}.",
|
||||||
|
is_suspend ? "" : "un",
|
||||||
character_name
|
character_name
|
||||||
).c_str()
|
).c_str()
|
||||||
);
|
);
|
||||||
@ -56,13 +66,13 @@ void command_suspend(Client *c, const Seperator *sep)
|
|||||||
Chat::White,
|
Chat::White,
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"Account {} ({}) with the character {} {}.",
|
"Account {} ({}) with the character {} {}.",
|
||||||
l[0].name,
|
a.name,
|
||||||
l[0].id,
|
a.id,
|
||||||
character_name,
|
character_name,
|
||||||
(
|
(
|
||||||
days ?
|
is_suspend ?
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"has been temporarily suspended for {} day{}.",
|
"has been suspended for {} day{}",
|
||||||
days,
|
days,
|
||||||
days != 1 ? "s" : ""
|
days != 1 ? "s" : ""
|
||||||
) :
|
) :
|
||||||
@ -71,22 +81,24 @@ void command_suspend(Client *c, const Seperator *sep)
|
|||||||
).c_str()
|
).c_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
auto* b = entity_list.GetClientByName(character_name.c_str());
|
if (is_suspend) { // Only kick if we're suspending, otherwise there's no reason to kick someone who is already suspended
|
||||||
|
Client* b = entity_list.GetClientByName(character_name.c_str());
|
||||||
|
|
||||||
if (b) {
|
if (b) {
|
||||||
b->WorldKick();
|
b->WorldKick();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
|
||||||
|
auto* k = (ServerKickPlayer_Struct*) pack->pBuffer;
|
||||||
|
|
||||||
|
strn0cpy(k->adminname, c->GetName(), sizeof(k->adminname));
|
||||||
|
strn0cpy(k->name, character_name.c_str(), sizeof(k->name));
|
||||||
|
k->adminrank = c->Admin();
|
||||||
|
|
||||||
|
worldserver.SendPacket(pack);
|
||||||
|
|
||||||
|
safe_delete(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
|
|
||||||
auto* k = (ServerKickPlayer_Struct *) pack->pBuffer;
|
|
||||||
|
|
||||||
strn0cpy(k->adminname, c->GetName(), sizeof(k->adminname));
|
|
||||||
strn0cpy(k->name, character_name.c_str(), sizeof(k->name));
|
|
||||||
k->adminrank = c->Admin();
|
|
||||||
|
|
||||||
worldserver.SendPacket(pack);
|
|
||||||
|
|
||||||
safe_delete(pack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user