mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 13:30:06 +00:00
Compare commits
No commits in common. "47dbc6d35e47666ddebc4b9c45aa1876a1d0ae62" and "003186d97ae52c78bc8da0444dd3f2890f1457bc" have entirely different histories.
47dbc6d35e
...
003186d97a
@ -83,77 +83,7 @@ static void helpCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
}
|
||||
|
||||
static void accessCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||
if (args.size() < 2) {
|
||||
Chat::sendServerMessage(sock, "Usage: /access <id> [new_level]");
|
||||
Chat::sendServerMessage(sock, "Use . for id to select yourself");
|
||||
return;
|
||||
}
|
||||
|
||||
char *tmp;
|
||||
|
||||
Player* self = PlayerManager::getPlayer(sock);
|
||||
int selfAccess = self->accountLevel;
|
||||
|
||||
Player* player;
|
||||
if (args[1].compare(".") == 0) {
|
||||
player = self;
|
||||
} else {
|
||||
int id = std::strtol(args[1].c_str(), &tmp, 10);
|
||||
if (*tmp) {
|
||||
Chat::sendServerMessage(sock, "Invalid player ID " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
player = PlayerManager::getPlayerFromID(id);
|
||||
if (player == nullptr) {
|
||||
Chat::sendServerMessage(sock, "Could not find player with ID " + std::to_string(id));
|
||||
return;
|
||||
}
|
||||
|
||||
// Messing with other players requires a baseline access of 30
|
||||
if (player != self && selfAccess > 30) {
|
||||
Chat::sendServerMessage(sock, "Can't check or change other players access levels (insufficient privileges)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::string playerName = PlayerManager::getPlayerName(player);
|
||||
int currentAccess = player->accountLevel;
|
||||
if (args.size() < 3) {
|
||||
// just check
|
||||
Chat::sendServerMessage(sock, playerName + " has access level " + std::to_string(currentAccess));
|
||||
return;
|
||||
}
|
||||
|
||||
// Can't change the access level of someone with stronger privileges
|
||||
// N.B. lower value = stronger privileges
|
||||
if (currentAccess <= selfAccess) {
|
||||
Chat::sendServerMessage(sock, "Can't change this player's access level (insufficient privileges)");
|
||||
return;
|
||||
}
|
||||
|
||||
int newAccess = std::strtol(args[2].c_str(), &tmp, 10);
|
||||
if (*tmp) {
|
||||
Chat::sendServerMessage(sock, "Invalid access level " + args[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Can only assign an access level weaker than yours
|
||||
if (newAccess <= selfAccess) {
|
||||
Chat::sendServerMessage(sock, "Can only assign privileges weaker than your own");
|
||||
return;
|
||||
}
|
||||
|
||||
player->accountLevel = newAccess;
|
||||
|
||||
// Save to database
|
||||
int accountId = Database::getAccountIdForPlayer(player->iID);
|
||||
Database::updateAccountLevel(accountId, newAccess);
|
||||
|
||||
std::string msg = "Changed access level for " + playerName + " from " + std::to_string(currentAccess) + " to " + std::to_string(newAccess);
|
||||
if (newAccess <= 50 && currentAccess > 50)
|
||||
msg += " (they must log out and back in for some commands to be enabled)";
|
||||
Chat::sendServerMessage(sock, msg);
|
||||
Chat::sendServerMessage(sock, "Your access level is " + std::to_string(PlayerManager::getPlayer(sock)->accountLevel));
|
||||
}
|
||||
|
||||
static void populationCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||
@ -1270,7 +1200,7 @@ static void registerCommand(std::string cmd, int requiredLevel, CommandHandler h
|
||||
|
||||
void CustomCommands::init() {
|
||||
registerCommand("help", 100, helpCommand, "list all unlocked server-side commands");
|
||||
registerCommand("access", 100, accessCommand, "check or change access levels");
|
||||
registerCommand("access", 100, accessCommand, "print your access level");
|
||||
registerCommand("instance", 30, instanceCommand, "print or change your current instance");
|
||||
registerCommand("mss", 30, mssCommand, "edit Monkey Skyway routes");
|
||||
registerCommand("npcr", 30, npcRotateCommand, "rotate NPCs");
|
||||
|
@ -212,7 +212,6 @@ static void enterPlayer(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
response.iID = plr->iID;
|
||||
response.uiSvrTime = getTime();
|
||||
|
||||
response.PCLoadData2CL.iUserLevel = plr->accountLevel;
|
||||
response.PCLoadData2CL.iHP = plr->HP;
|
||||
response.PCLoadData2CL.iLevel = plr->level;
|
||||
|
@ -46,13 +46,9 @@ namespace Database {
|
||||
void close();
|
||||
|
||||
void findAccount(Account* account, std::string login);
|
||||
|
||||
// return ID, 0 if something failed
|
||||
int getAccountIdForPlayer(int playerId);
|
||||
// returns ID, 0 if something failed
|
||||
int addAccount(std::string login, std::string password);
|
||||
|
||||
void updateAccountLevel(int accountId, int accountLevel);
|
||||
|
||||
// interface for the /ban command
|
||||
bool banPlayer(int playerId, std::string& reason);
|
||||
bool unbanPlayer(int playerId);
|
||||
|
@ -27,32 +27,6 @@ void Database::findAccount(Account* account, std::string login) {
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
int Database::getAccountIdForPlayer(int playerId) {
|
||||
std::lock_guard<std::mutex> lock(dbCrit);
|
||||
|
||||
const char* sql = R"(
|
||||
SELECT AccountID
|
||||
FROM Players
|
||||
WHERE PlayerID = ?
|
||||
LIMIT 1;
|
||||
)";
|
||||
sqlite3_stmt* stmt;
|
||||
|
||||
sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
sqlite3_bind_int(stmt, 1, playerId);
|
||||
|
||||
int rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_ROW) {
|
||||
std::cout << "[WARN] Database: couldn't get account id for player " << playerId << std::endl;
|
||||
sqlite3_finalize(stmt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int accountId = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return accountId;
|
||||
}
|
||||
|
||||
int Database::addAccount(std::string login, std::string password) {
|
||||
std::lock_guard<std::mutex> lock(dbCrit);
|
||||
|
||||
@ -78,26 +52,6 @@ int Database::addAccount(std::string login, std::string password) {
|
||||
return sqlite3_last_insert_rowid(db);
|
||||
}
|
||||
|
||||
void Database::updateAccountLevel(int accountId, int accountLevel) {
|
||||
std::lock_guard<std::mutex> lock(dbCrit);
|
||||
|
||||
const char* sql = R"(
|
||||
UPDATE Accounts SET
|
||||
AccountLevel = ?
|
||||
WHERE AccountID = ?;
|
||||
)";
|
||||
sqlite3_stmt* stmt;
|
||||
|
||||
sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
sqlite3_bind_int(stmt, 1, accountLevel);
|
||||
sqlite3_bind_int(stmt, 2, accountId);
|
||||
|
||||
int rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE)
|
||||
std::cout << "[WARN] Database fail on updateAccountLevel(): " << sqlite3_errmsg(db) << std::endl;
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
void Database::updateSelected(int accountId, int slot) {
|
||||
std::lock_guard<std::mutex> lock(dbCrit);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user