mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-21 21:17:25 +00:00
feat: add admin account creation options from cli (GM level) (#1620)
* add admin account creation options from cli * use actual gm levels felt under delivered in previous iteration. * Update dMasterServer/MasterServer.cpp Co-authored-by: Daniel Seiler <me@xiphoseer.de> --------- Co-authored-by: Daniel Seiler <me@xiphoseer.de>
This commit is contained in:
parent
84fff7c380
commit
c3f6ef5a1d
@ -33,6 +33,9 @@ public:
|
|||||||
|
|
||||||
// Add a new account to the database.
|
// Add a new account to the database.
|
||||||
virtual void InsertNewAccount(const std::string_view username, const std::string_view bcryptpassword) = 0;
|
virtual void InsertNewAccount(const std::string_view username, const std::string_view bcryptpassword) = 0;
|
||||||
|
|
||||||
|
// Update the GameMaster level of an account.
|
||||||
|
virtual void UpdateAccountGmLevel(const uint32_t accountId, const eGameMasterLevel gmLevel) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__IACCOUNTS__H__
|
#endif //!__IACCOUNTS__H__
|
||||||
|
@ -111,6 +111,7 @@ public:
|
|||||||
void AddBehavior(const IBehaviors::Info& info) override;
|
void AddBehavior(const IBehaviors::Info& info) override;
|
||||||
std::string GetBehavior(const int32_t behaviorId) override;
|
std::string GetBehavior(const int32_t behaviorId) override;
|
||||||
void RemoveBehavior(const int32_t characterId) override;
|
void RemoveBehavior(const int32_t characterId) override;
|
||||||
|
void UpdateAccountGmLevel(const uint32_t accountId, const eGameMasterLevel gmLevel) override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Generic query functions that can be used for any query.
|
// Generic query functions that can be used for any query.
|
||||||
|
@ -35,3 +35,7 @@ void MySQLDatabase::UpdateAccountPassword(const uint32_t accountId, const std::s
|
|||||||
void MySQLDatabase::InsertNewAccount(const std::string_view username, const std::string_view bcryptpassword) {
|
void MySQLDatabase::InsertNewAccount(const std::string_view username, const std::string_view bcryptpassword) {
|
||||||
ExecuteInsert("INSERT INTO accounts (name, password, gm_level) VALUES (?, ?, ?);", username, bcryptpassword, static_cast<int32_t>(eGameMasterLevel::OPERATOR));
|
ExecuteInsert("INSERT INTO accounts (name, password, gm_level) VALUES (?, ?, ?);", username, bcryptpassword, static_cast<int32_t>(eGameMasterLevel::OPERATOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MySQLDatabase::UpdateAccountGmLevel(const uint32_t accountId, const eGameMasterLevel gmLevel) {
|
||||||
|
ExecuteUpdate("UPDATE accounts SET gm_level = ? WHERE id = ?;", static_cast<int32_t>(gmLevel), accountId);
|
||||||
|
}
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "Start.h"
|
#include "Start.h"
|
||||||
#include "Server.h"
|
#include "Server.h"
|
||||||
#include "CDZoneTableTable.h"
|
#include "CDZoneTableTable.h"
|
||||||
|
#include "eGameMasterLevel.h"
|
||||||
|
|
||||||
namespace Game {
|
namespace Game {
|
||||||
Logger* logger = nullptr;
|
Logger* logger = nullptr;
|
||||||
@ -187,15 +188,20 @@ int main(int argc, char** argv) {
|
|||||||
std::cout << "Enter a username: ";
|
std::cout << "Enter a username: ";
|
||||||
std::cin >> username;
|
std::cin >> username;
|
||||||
|
|
||||||
|
const auto checkIsAdmin = []() {
|
||||||
|
std::string admin;
|
||||||
|
std::cout << "What level of privilege should this account have? Please enter a number between 0 (Player) and 9 (Admin) inclusive. No entry will default to 0." << std::endl;
|
||||||
|
std::cin >> admin;
|
||||||
|
return admin;
|
||||||
|
};
|
||||||
|
|
||||||
auto accountId = Database::Get()->GetAccountInfo(username);
|
auto accountId = Database::Get()->GetAccountInfo(username);
|
||||||
if (accountId) {
|
if (accountId && accountId->id != 0) {
|
||||||
LOG("Account with name \"%s\" already exists", username.c_str());
|
LOG("Account with name \"%s\" already exists", username.c_str());
|
||||||
std::cout << "Do you want to change the password of that account? [y/n]?";
|
std::cout << "Do you want to change the password of that account? [y/n]?";
|
||||||
std::string prompt = "";
|
std::string prompt = "";
|
||||||
std::cin >> prompt;
|
std::cin >> prompt;
|
||||||
if (prompt == "y" || prompt == "yes") {
|
if (prompt == "y" || prompt == "yes") {
|
||||||
if (accountId->id == 0) return EXIT_FAILURE;
|
|
||||||
|
|
||||||
//Read the password from the console without echoing it.
|
//Read the password from the console without echoing it.
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
//This function is obsolete, but it only meant to be used by the
|
//This function is obsolete, but it only meant to be used by the
|
||||||
@ -220,6 +226,20 @@ int main(int argc, char** argv) {
|
|||||||
} else {
|
} else {
|
||||||
LOG("Account \"%s\" was not updated.", username.c_str());
|
LOG("Account \"%s\" was not updated.", username.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "Update admin privileges? [y/n]? ";
|
||||||
|
std::string admin;
|
||||||
|
std::cin >> admin;
|
||||||
|
bool updateAdmin = admin == "y" || admin == "yes";
|
||||||
|
if (updateAdmin) {
|
||||||
|
auto gmLevel = GeneralUtils::TryParse<int32_t>(checkIsAdmin()).value_or(0);
|
||||||
|
if (gmLevel > 9 || gmLevel < 0) {
|
||||||
|
LOG("Invalid admin level. Defaulting to 0");
|
||||||
|
gmLevel = 0;
|
||||||
|
}
|
||||||
|
Database::Get()->UpdateAccountGmLevel(accountId->id, static_cast<eGameMasterLevel>(gmLevel));
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,6 +270,17 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG("Account created successfully!");
|
LOG("Account created successfully!");
|
||||||
|
|
||||||
|
accountId = Database::Get()->GetAccountInfo(username);
|
||||||
|
if (accountId) {
|
||||||
|
auto gmLevel = GeneralUtils::TryParse<int32_t>(checkIsAdmin()).value_or(0);
|
||||||
|
if (gmLevel > 9 || gmLevel < 0) {
|
||||||
|
LOG("Invalid admin level. Defaulting to 0");
|
||||||
|
gmLevel = 0;
|
||||||
|
}
|
||||||
|
Database::Get()->UpdateAccountGmLevel(accountId->id, static_cast<eGameMasterLevel>(gmLevel));
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,7 +589,7 @@ void HandlePacket(Packet* packet) {
|
|||||||
inStream.Read(sessionKey);
|
inStream.Read(sessionKey);
|
||||||
LUString username;
|
LUString username;
|
||||||
inStream.Read(username);
|
inStream.Read(username);
|
||||||
|
|
||||||
for (auto it : activeSessions) {
|
for (auto it : activeSessions) {
|
||||||
if (it.second == username.string) {
|
if (it.second == username.string) {
|
||||||
activeSessions.erase(it.first);
|
activeSessions.erase(it.first);
|
||||||
|
Loading…
Reference in New Issue
Block a user