[Feature] Add Character Auto Login (#4216)

* [Feature] Add Character Auto Login

* Add commands and finalize.

* Add methods without character name.

* Update perl_client.cpp

* Add other methods.

* Repository methods.

* Update account_repository.h

* Update command_subsettings_repository.h

* Update command_subsettings_repository.h

* Update client.cpp
This commit is contained in:
Alex King
2024-04-15 06:13:39 -04:00
committed by GitHub
parent ac12ba153e
commit 0a3f1d3c41
19 changed files with 346 additions and 121 deletions
+2
View File
@@ -5,6 +5,7 @@
#include "set/alternate_currency.cpp"
#include "set/animation.cpp"
#include "set/anon.cpp"
#include "set/auto_login.cpp"
#include "set/bind_point.cpp"
#include "set/checksum.cpp"
#include "set/class_permanent.cpp"
@@ -71,6 +72,7 @@ void command_set(Client *c, const Seperator *sep)
Cmd{.cmd = "alternate_currency", .u = "alternate_currency [Currency ID] [Amount]", .fn = SetAlternateCurrency, .a = {"#setaltcurrency"}},
Cmd{.cmd = "animation", .u = "animation [Animation ID]", .fn = SetAnimation, .a = {"#setanim"}},
Cmd{.cmd = "anon", .u = "anon [Character ID] [Anonymous Flag] or #set anon [Anonymous Flag]", .fn = SetAnon, .a = {"#setanon"}},
Cmd{.cmd = "auto_login", .u = "auto_login [0|1]", .fn = SetAutoLogin, .a = {"#setautologin"}},
Cmd{.cmd = "bind_point", .u = "bind_point", .fn = SetBindPoint, .a = {"#setbind"}},
Cmd{.cmd = "checksum", .u = "checksum", .fn = SetChecksum, .a = {"#updatechecksum"}},
Cmd{.cmd = "class_permanent", .u = "class_permanent [Class ID]", .fn = SetClassPermanent, .a = {"#permaclass"}},
+54
View File
@@ -0,0 +1,54 @@
#include "../../client.h"
#include "../../groups.h"
#include "../../raids.h"
#include "../../raids.h"
#include "../../common/repositories/account_repository.h"
void SetAutoLogin(Client* c, const Seperator* sep)
{
if (!RuleB(World, EnableAutoLogin)) {
c->Message(Chat::White, "Auto login is disabled.");
return;
}
const uint16 arguments = sep->argnum;
if (arguments < 2 || !sep->IsNumber(2)) {
c->Message(Chat::White, "Usage: #set auto_login [0|1]");
c->Message(Chat::White, "0 = Disable auto login for your account");
c->Message(Chat::White, "1 = Set auto login character to your current character");
return;
}
Client* t = c;
if (c->GetGM() && c->GetTarget() && c->GetTarget()->IsClient()) {
t = c->GetTarget()->CastToClient();
}
auto e = AccountRepository::FindOne(database, t->AccountID());
if (!e.id) {
c->Message(
Chat::White,
fmt::format(
"Failed to find an account entry for {}.",
c->GetTargetDescription(t)
).c_str()
);
return;
}
const bool set_login = Strings::ToBool(sep->arg[2]);
e.auto_login_charname = set_login ? t->GetCleanName() : std::string();
AccountRepository::UpdateOne(database, e);
c->Message(
Chat::White,
fmt::format(
"Auto login character has been set to '{}' for {}.",
e.auto_login_charname,
c->GetTargetDescription(t)
).c_str()
);
}
+2
View File
@@ -2,6 +2,7 @@
#include "show/aas.cpp"
#include "show/aa_points.cpp"
#include "show/aggro.cpp"
#include "show/auto_login.cpp"
#include "show/buffs.cpp"
#include "show/buried_corpse_count.cpp"
#include "show/client_version_summary.cpp"
@@ -62,6 +63,7 @@ void command_show(Client *c, const Seperator *sep)
Cmd{.cmd = "aas", .u = "aas", .fn = ShowAAs, .a = {"#showaas"}},
Cmd{.cmd = "aa_points", .u = "aa_points", .fn = ShowAAPoints, .a = {"#showaapoints", "#showaapts"}},
Cmd{.cmd = "aggro", .u = "aggro [Distance] [-v] (-v is verbose Faction Information)", .fn = ShowAggro, .a = {"#aggro"}},
Cmd{.cmd = "auto_login", .u = "auto_login", .fn = ShowAutoLogin, .a = {"#showautologin"}},
Cmd{.cmd = "buffs", .u = "buffs", .fn = ShowBuffs, .a = {"#showbuffs"}},
Cmd{.cmd = "buried_corpse_count", .u = "buried_corpse_count", .fn = ShowBuriedCorpseCount, .a = {"#getplayerburiedcorpsecount"}},
Cmd{.cmd = "client_version_summary", .u = "client_version_summary", .fn = ShowClientVersionSummary, .a = {"#cvs"}},
+37
View File
@@ -0,0 +1,37 @@
#include "../../client.h"
#include "../../common/repositories/account_repository.h"
void ShowAutoLogin(Client* c, const Seperator* sep)
{
if (!RuleB(World, EnableAutoLogin)) {
c->Message(Chat::White, "Auto login is disabled.");
return;
}
Client* t = c;
if (c->GetGM() && c->GetTarget() && c->GetTarget()->IsClient()) {
t = c->GetTarget()->CastToClient();
}
const auto& e = AccountRepository::FindOne(database, t->AccountID());
if (!e.id) {
c->Message(
Chat::White,
fmt::format(
"Failed to find an account entry for {}.",
c->GetTargetDescription(t)
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Auto login character for {} is set to '{}'.",
c->GetTargetDescription(t),
e.auto_login_charname
).c_str()
);
}