Rewrite VarCache_Struct

Basically just remove manual memory management
This commit is contained in:
Michael Cook (mackal) 2016-05-09 14:23:27 -04:00
parent 59728c5115
commit c159b89e79
16 changed files with 146 additions and 239 deletions

View File

@ -23,6 +23,7 @@
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <algorithm>
#include <mysqld_error.h> #include <mysqld_error.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -48,7 +49,6 @@
extern Client client; extern Client client;
Database::Database () { Database::Database () {
DBInitVars();
} }
/* /*
@ -57,7 +57,6 @@ Establish a connection to a mysql database with the supplied parameters
Database::Database(const char* host, const char* user, const char* passwd, const char* database, uint32 port) Database::Database(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
{ {
DBInitVars();
Connect(host, user, passwd, database, port); Connect(host, user, passwd, database, port);
} }
@ -74,25 +73,12 @@ bool Database::Connect(const char* host, const char* user, const char* passwd, c
} }
} }
void Database::DBInitVars() {
varcache_array = 0;
varcache_max = 0;
varcache_lastupdate = 0;
}
/* /*
Close the connection to the database Close the connection to the database
*/ */
Database::~Database() Database::~Database()
{ {
unsigned int x;
if (varcache_array) {
for (x=0; x<varcache_max; x++) {
safe_delete_array(varcache_array[x]);
}
safe_delete_array(varcache_array);
}
} }
/* /*
@ -845,7 +831,7 @@ void Database::GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID
} }
void Database::GetCharName(uint32 char_id, char* name) { void Database::GetCharName(uint32 char_id, char* name) {
std::string query = StringFormat("SELECT `name` FROM `character_data` WHERE id='%i'", char_id); std::string query = StringFormat("SELECT `name` FROM `character_data` WHERE id='%i'", char_id);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
@ -860,139 +846,69 @@ void Database::GetCharName(uint32 char_id, char* name) {
} }
bool Database::LoadVariables() { bool Database::LoadVariables() {
auto results = QueryDatabase(StringFormat("SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache_lastupdate)); auto results = QueryDatabase(StringFormat("SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache.last_update));
if (!results.Success()) if (!results.Success())
return false; return false;
return LoadVariables_result(std::move(results));
}
uint32 Database::LoadVariables_MQ(char** query)
{
return MakeAnyLenString(query, "SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache_lastupdate);
}
// always returns true? not sure about this.
bool Database::LoadVariables_result(MySQLRequestResult results)
{
uint32 i = 0;
LockMutex lock(&Mvarcache);
if (results.RowCount() == 0) if (results.RowCount() == 0)
return true; return true;
if (!varcache_array) { LockMutex lock(&Mvarcache);
varcache_max = results.RowCount();
varcache_array = new VarCache_Struct*[varcache_max];
for (i=0; i<varcache_max; i++)
varcache_array[i] = 0;
}
else {
uint32 tmpnewmax = varcache_max + results.RowCount();
VarCache_Struct** tmp = new VarCache_Struct*[tmpnewmax];
for (i=0; i<tmpnewmax; i++)
tmp[i] = 0;
for (i=0; i<varcache_max; i++)
tmp[i] = varcache_array[i];
VarCache_Struct** tmpdel = varcache_array;
varcache_array = tmp;
varcache_max = tmpnewmax;
delete [] tmpdel;
}
for (auto row = results.begin(); row != results.end(); ++row) std::string key, value;
{ for (auto row = results.begin(); row != results.end(); ++row) {
varcache_lastupdate = atoi(row[2]); varcache.last_update = atoi(row[2]); // ahh should we be comparing if this is newer?
for (i=0; i<varcache_max; i++) { key = row[0];
if (varcache_array[i]) { value = row[1];
if (strcasecmp(varcache_array[i]->varname, row[0]) == 0) { std::transform(std::begin(key), std::end(key), std::begin(key), ::tolower); // keys are lower case, DB doesn't have to be
delete varcache_array[i]; varcache.Add(key, value);
varcache_array[i] = (VarCache_Struct*) new uint8[sizeof(VarCache_Struct) + strlen(row[1]) + 1];
strn0cpy(varcache_array[i]->varname, row[0], sizeof(varcache_array[i]->varname));
strcpy(varcache_array[i]->value, row[1]);
break;
}
}
else {
varcache_array[i] = (VarCache_Struct*) new uint8[sizeof(VarCache_Struct) + strlen(row[1]) + 1];
strcpy(varcache_array[i]->varname, row[0]);
strcpy(varcache_array[i]->value, row[1]);
break;
}
}
} }
uint32 max_used = 0;
for (i=0; i<varcache_max; i++) {
if (varcache_array[i]) {
if (i > max_used)
max_used = i;
}
}
varcache_max = max_used + 1;
return true; return true;
} }
// Gets variable from 'variables' table // Gets variable from 'variables' table
bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_len) { bool Database::GetVariable(std::string varname, std::string &varvalue)
varvalue[0] = '\0'; {
varvalue.clear();
LockMutex lock(&Mvarcache); LockMutex lock(&Mvarcache);
if (strlen(varname) <= 1)
return false;
for (uint32 i=0; i<varcache_max; i++) {
if (varcache_array[i]) { if (varname.empty())
if (strcasecmp(varcache_array[i]->varname, varname) == 0) { return false;
snprintf(varvalue, varvalue_len, "%s", varcache_array[i]->value);
varvalue[varvalue_len-1] = 0; std::transform(std::begin(varname), std::end(varname), std::begin(varname), ::tolower); // all keys are lower case
return true; auto tmp = varcache.Get(varname);
} if (tmp) {
} varvalue = *tmp;
else return true;
return false;
} }
return false; return false;
} }
bool Database::SetVariable(const char* varname_in, const char* varvalue_in) { bool Database::SetVariable(const std::string varname, const std::string &varvalue)
{
char *varname,*varvalue; std::string escaped_name = EscapeString(varname);
std::string escaped_value = EscapeString(varvalue);
varname=(char *)malloc(strlen(varname_in)*2+1); std::string query = StringFormat("Update variables set value='%s' WHERE varname like '%s'", escaped_value.c_str(), escaped_name.c_str());
varvalue=(char *)malloc(strlen(varvalue_in)*2+1);
DoEscapeString(varname, varname_in, strlen(varname_in));
DoEscapeString(varvalue, varvalue_in, strlen(varvalue_in));
std::string query = StringFormat("Update variables set value='%s' WHERE varname like '%s'", varvalue, varname);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()) if (!results.Success())
{
free(varname);
free(varvalue);
return false; return false;
}
if (results.RowsAffected() == 1) if (results.RowsAffected() == 1)
{ {
LoadVariables(); // refresh cache LoadVariables(); // refresh cache
free(varname);
free(varvalue);
return true; return true;
} }
query = StringFormat("Insert Into variables (varname, value) values ('%s', '%s')", varname, varvalue); query = StringFormat("Insert Into variables (varname, value) values ('%s', '%s')", escaped_name.c_str(), escaped_value.c_str());
results = QueryDatabase(query); results = QueryDatabase(query);
free(varname);
free(varvalue);
if (results.RowsAffected() != 1) if (results.RowsAffected() != 1)
return false; return false;
LoadVariables(); // refresh cache LoadVariables(); // refresh cache
return true; return true;
} }

View File

@ -67,8 +67,14 @@ struct npcDecayTimes_Struct {
struct VarCache_Struct { struct VarCache_Struct {
char varname[26]; std::map<std::string, std::string> m_cache;
char value[0]; uint32 last_update;
VarCache_Struct() : last_update(0) { }
void Add(const std::string &key, const std::string &value) { m_cache[key] = value; }
const std::string *Get(const std::string &key) {
auto it = m_cache.find(key);
return (it != m_cache.end() ? &it->second : nullptr);
}
}; };
class PTimerList; class PTimerList;
@ -215,11 +221,9 @@ public:
/* Database Variables */ /* Database Variables */
bool GetVariable(const char* varname, char* varvalue, uint16 varvalue_len); bool GetVariable(std::string varname, std::string &varvalue);
bool SetVariable(const char* varname, const char* varvalue); bool SetVariable(const std::string varname, const std::string &varvalue);
bool LoadVariables(); bool LoadVariables();
uint32 LoadVariables_MQ(char** query);
bool LoadVariables_result(MySQLRequestResult results);
/* General Queries */ /* General Queries */
@ -256,14 +260,10 @@ public:
void LoadLogSettings(EQEmuLogSys::LogSettings* log_settings); void LoadLogSettings(EQEmuLogSys::LogSettings* log_settings);
private: private:
void DBInitVars();
std::map<uint32,std::string> zonename_array; std::map<uint32,std::string> zonename_array;
Mutex Mvarcache; Mutex Mvarcache;
uint32 varcache_max; VarCache_Struct varcache;
VarCache_Struct** varcache_array;
uint32 varcache_lastupdate;
/* Groups, utility methods. */ /* Groups, utility methods. */
void ClearAllGroupLeaders(); void ClearAllGroupLeaders();

View File

@ -828,27 +828,27 @@ void SharedDatabase::LoadItems(void *data, uint32 size, int32 items, uint32 max_
{ {
EQEmu::FixedMemoryHashSet<Item_Struct> hash(reinterpret_cast<uint8 *>(data), size, items, max_item_id); EQEmu::FixedMemoryHashSet<Item_Struct> hash(reinterpret_cast<uint8 *>(data), size, items, max_item_id);
char ndbuffer[4]; std::string ndbuffer;
bool disableNoRent = false; bool disableNoRent = false;
if (GetVariable("disablenorent", ndbuffer, 4)) { if (GetVariable("disablenorent", ndbuffer)) {
if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') { if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') {
disableNoRent = true; disableNoRent = true;
} }
} }
bool disableNoDrop = false; bool disableNoDrop = false;
if (GetVariable("disablenodrop", ndbuffer, 4)) { if (GetVariable("disablenodrop", ndbuffer)) {
if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') { if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') {
disableNoDrop = true; disableNoDrop = true;
} }
} }
bool disableLoreGroup = false; bool disableLoreGroup = false;
if (GetVariable("disablelore", ndbuffer, 4)) { if (GetVariable("disablelore", ndbuffer)) {
if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') { if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') {
disableLoreGroup = true; disableLoreGroup = true;
} }
} }
bool disableNoTransfer = false; bool disableNoTransfer = false;
if (GetVariable("disablenotransfer", ndbuffer, 4)) { if (GetVariable("disablenotransfer", ndbuffer)) {
if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') { if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') {
disableNoTransfer = true; disableNoTransfer = true;
} }

View File

@ -65,10 +65,10 @@ int main(int argc, char **argv) {
database.LoadVariables(); database.LoadVariables();
/* If we're running shared memory and hotfix has no custom name, we probably want to start from scratch... */ /* If we're running shared memory and hotfix has no custom name, we probably want to start from scratch... */
char db_hotfix_name[256] = { 0 }; std::string db_hotfix_name;
if (database.GetVariable("hotfix_name", db_hotfix_name, 256)) { if (database.GetVariable("hotfix_name", db_hotfix_name)) {
if (strlen(db_hotfix_name) > 0 && strcasecmp("hotfix_", db_hotfix_name) == 0) { if (!db_hotfix_name.empty() && strcasecmp("hotfix_", db_hotfix_name.c_str()) == 0) {
Log.Out(Logs::General, Logs::Status, "Current hotfix in variables is the default %s, clearing out variable", db_hotfix_name); Log.Out(Logs::General, Logs::Status, "Current hotfix in variables is the default %s, clearing out variable", db_hotfix_name.c_str());
std::string query = StringFormat("UPDATE `variables` SET `value`='' WHERE (`varname`='hotfix_name')"); std::string query = StringFormat("UPDATE `variables` SET `value`='' WHERE (`varname`='hotfix_name')");
database.QueryDatabase(query); database.QueryDatabase(query);
} }

View File

@ -857,12 +857,12 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) {
} }
outapp = new EQApplicationPacket(OP_MOTD); outapp = new EQApplicationPacket(OP_MOTD);
char tmp[500] = {0}; std::string tmp;
if (database.GetVariable("MOTD", tmp, 500)) { if (database.GetVariable("MOTD", tmp)) {
outapp->size = strlen(tmp)+1; outapp->size = tmp.length();
outapp->pBuffer = new uchar[outapp->size]; outapp->pBuffer = new uchar[outapp->size];
memset(outapp->pBuffer,0,outapp->size); memset(outapp->pBuffer,0,outapp->size);
strcpy((char*)outapp->pBuffer, tmp); strcpy((char*)outapp->pBuffer, tmp.c_str());
} else { } else {
// Null Message of the Day. :) // Null Message of the Day. :)

View File

@ -277,10 +277,10 @@ bool ClientListEntry::CheckAuth(uint32 iLSID, const char* iKey) {
strn0cpy(paccountname, plsname, sizeof(paccountname)); strn0cpy(paccountname, plsname, sizeof(paccountname));
padmin = tmpStatus; padmin = tmpStatus;
} }
char lsworldadmin[15] = "0"; std::string lsworldadmin;
database.GetVariable("honorlsworldadmin", lsworldadmin, sizeof(lsworldadmin)); if (database.GetVariable("honorlsworldadmin", lsworldadmin))
if (atoi(lsworldadmin) == 1 && pworldadmin != 0 && (padmin < pworldadmin || padmin == 0)) if (atoi(lsworldadmin.c_str()) == 1 && pworldadmin != 0 && (padmin < pworldadmin || padmin == 0))
padmin = pworldadmin; padmin = pworldadmin;
return true; return true;
} }
return false; return false;

View File

@ -212,8 +212,8 @@ bool LoginServer::InitLoginServer() {
} }
bool LoginServer::Connect() { bool LoginServer::Connect() {
char tmp[25]; std::string tmp;
if(database.GetVariable("loginType",tmp,sizeof(tmp)) && strcasecmp(tmp,"MinILogin") == 0){ if(database.GetVariable("loginType", tmp) && strcasecmp(tmp.c_str(), "MinILogin") == 0) {
minilogin = true; minilogin = true;
Log.Out(Logs::Detail, Logs::World_Server, "Setting World to MiniLogin Server type"); Log.Out(Logs::Detail, Logs::World_Server, "Setting World to MiniLogin Server type");
} }

View File

@ -193,7 +193,7 @@ int main(int argc, char** argv) {
bool ignore_db = false; bool ignore_db = false;
if (argc >= 2) { if (argc >= 2) {
char tmp[2]; std::string tmp;
if (strcasecmp(argv[1], "help") == 0 || strcasecmp(argv[1], "?") == 0 || strcasecmp(argv[1], "/?") == 0 || strcasecmp(argv[1], "-?") == 0 || strcasecmp(argv[1], "-h") == 0 || strcasecmp(argv[1], "-help") == 0) { if (strcasecmp(argv[1], "help") == 0 || strcasecmp(argv[1], "?") == 0 || strcasecmp(argv[1], "/?") == 0 || strcasecmp(argv[1], "-?") == 0 || strcasecmp(argv[1], "-h") == 0 || strcasecmp(argv[1], "-help") == 0) {
std::cout << "Worldserver command line commands:" << std::endl; std::cout << "Worldserver command line commands:" << std::endl;
std::cout << "adduser username password flag - adds a user account" << std::endl; std::cout << "adduser username password flag - adds a user account" << std::endl;
@ -206,8 +206,8 @@ int main(int argc, char** argv) {
std::cout << "Reboot Zones mode ON" << std::endl; std::cout << "Reboot Zones mode ON" << std::endl;
holdzones = true; holdzones = true;
} }
else if (database.GetVariable("disablecommandline", tmp, 2)) { else if (database.GetVariable("disablecommandline", tmp)) {
if (strlen(tmp) == 1) { if (tmp.length() == 1) {
if (tmp[0] == '1') { if (tmp[0] == '1') {
std::cerr << "Command line disabled in database... exiting" << std::endl; std::cerr << "Command line disabled in database... exiting" << std::endl;
return 1; return 1;
@ -299,10 +299,10 @@ int main(int argc, char** argv) {
Log.Out(Logs::General, Logs::World_Server, "Loading variables.."); Log.Out(Logs::General, Logs::World_Server, "Loading variables..");
database.LoadVariables(); database.LoadVariables();
char hotfix_name[256] = { 0 }; std::string hotfix_name;
if(database.GetVariable("hotfix_name", hotfix_name, 256)) { if(database.GetVariable("hotfix_name", hotfix_name)) {
if(strlen(hotfix_name) > 0) { if (!hotfix_name.empty()) {
Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name); Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name.c_str());
} }
} }
@ -326,17 +326,17 @@ int main(int argc, char** argv) {
guild_mgr.LoadGuilds(); guild_mgr.LoadGuilds();
//rules: //rules:
{ {
char tmp[64]; std::string tmp;
if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) { if (database.GetVariable("RuleSet", tmp)) {
Log.Out(Logs::General, Logs::World_Server, "Loading rule set '%s'", tmp); Log.Out(Logs::General, Logs::World_Server, "Loading rule set '%s'", tmp.c_str());
if(!RuleManager::Instance()->LoadRules(&database, tmp)) { if(!RuleManager::Instance()->LoadRules(&database, tmp.c_str())) {
Log.Out(Logs::General, Logs::World_Server, "Failed to load ruleset '%s', falling back to defaults.", tmp); Log.Out(Logs::General, Logs::World_Server, "Failed to load ruleset '%s', falling back to defaults.", tmp.c_str());
} }
} else { } else {
if(!RuleManager::Instance()->LoadRules(&database, "default")) { if(!RuleManager::Instance()->LoadRules(&database, "default")) {
Log.Out(Logs::General, Logs::World_Server, "No rule set configured, using default rules"); Log.Out(Logs::General, Logs::World_Server, "No rule set configured, using default rules");
} else { } else {
Log.Out(Logs::General, Logs::World_Server, "Loaded default rule set 'default'", tmp); Log.Out(Logs::General, Logs::World_Server, "Loaded default rule set 'default'", tmp.c_str());
} }
} }
} }
@ -355,10 +355,9 @@ int main(int argc, char** argv) {
Log.Out(Logs::General, Logs::World_Server, "Loading launcher list.."); Log.Out(Logs::General, Logs::World_Server, "Loading launcher list..");
launcher_list.LoadList(); launcher_list.LoadList();
char tmp[20]; std::string tmp;
tmp[0] = '\0'; database.GetVariable("holdzones",tmp);
database.GetVariable("holdzones",tmp, 20); if (tmp.length() == 1 && tmp[0] == '1') {
if ((strcasecmp(tmp, "1") == 0)) {
holdzones = true; holdzones = true;
} }
Log.Out(Logs::General, Logs::World_Server, "Reboot zone modes %s",holdzones ? "ON" : "OFF"); Log.Out(Logs::General, Logs::World_Server, "Reboot zone modes %s",holdzones ? "ON" : "OFF");

View File

@ -687,25 +687,25 @@ void Mob::MeleeMitigation(Mob *attacker, int32 &damage, int32 minhit, ExtraAttac
if (damage > 0 && myac > 0) { if (damage > 0 && myac > 0) {
int acfail=1000; int acfail=1000;
char tmp[10]; std::string tmp;
if (database.GetVariable("ACfail", tmp, 9)) { if (database.GetVariable("ACfail", tmp)) {
acfail = (int) (atof(tmp) * 100); acfail = (int) (atof(tmp.c_str()) * 100);
if (acfail>100) acfail=100; if (acfail>100) acfail=100;
} }
if (acfail<=0 || zone->random.Int(0, 100)>acfail) { if (acfail<=0 || zone->random.Int(0, 100)>acfail) {
float acreduction=1; float acreduction=1;
int acrandom=300; int acrandom=300;
if (database.GetVariable("ACreduction", tmp, 9)) if (database.GetVariable("ACreduction", tmp))
{ {
acreduction=atof(tmp); acreduction=atof(tmp.c_str());
if (acreduction>100) acreduction=100; if (acreduction>100) acreduction=100;
} }
if (database.GetVariable("ACrandom", tmp, 9)) if (database.GetVariable("ACrandom", tmp))
{ {
acrandom = (int) ((atof(tmp)+1) * 100); acrandom = (int) ((atof(tmp.c_str())+1) * 100);
if (acrandom>10100) acrandom=10100; if (acrandom>10100) acrandom=10100;
} }
@ -1497,15 +1497,14 @@ bool Client::Death(Mob* killerMob, int32 damage, uint16 spell, SkillUseTypes att
// creating the corpse takes the cash/items off the player too // creating the corpse takes the cash/items off the player too
Corpse *new_corpse = new Corpse(this, exploss); Corpse *new_corpse = new Corpse(this, exploss);
char tmp[20]; std::string tmp;
database.GetVariable("ServerType", tmp, 9); database.GetVariable("ServerType", tmp);
if(atoi(tmp)==1 && killerMob != nullptr && killerMob->IsClient()){ if(tmp[0] == '1' && tmp[1] == '\0' && killerMob != nullptr && killerMob->IsClient()){
char tmp2[10] = {0}; database.GetVariable("PvPreward", tmp);
database.GetVariable("PvPreward", tmp, 9); int reward = atoi(tmp.c_str());
int reward = atoi(tmp);
if(reward==3){ if(reward==3){
database.GetVariable("PvPitem", tmp2, 9); database.GetVariable("PvPitem", tmp);
int pvpitem = atoi(tmp2); int pvpitem = atoi(tmp.c_str());
if(pvpitem>0 && pvpitem<200000) if(pvpitem>0 && pvpitem<200000)
new_corpse->SetPlayerKillItemID(pvpitem); new_corpse->SetPlayerKillItemID(pvpitem);
} }

View File

@ -3598,10 +3598,8 @@ void Client::GetRaidAAs(RaidLeadershipAA_Struct *into) const {
void Client::EnteringMessages(Client* client) void Client::EnteringMessages(Client* client)
{ {
//server rules //server rules
char *rules; std::string rules;
rules = new char [4096]; if(database.GetVariable("Rules", rules))
if(database.GetVariable("Rules", rules, 4096))
{ {
uint8 flag = database.GetAgreementFlag(client->AccountID()); uint8 flag = database.GetAgreementFlag(client->AccountID());
if(!flag) if(!flag)
@ -3612,25 +3610,18 @@ void Client::EnteringMessages(Client* client)
client->SendAppearancePacket(AT_Anim, ANIM_FREEZE); client->SendAppearancePacket(AT_Anim, ANIM_FREEZE);
} }
} }
safe_delete_array(rules);
} }
void Client::SendRules(Client* client) void Client::SendRules(Client* client)
{ {
char *rules; std::string rules;
rules = new char [4096];
char *ptr;
database.GetVariable("Rules", rules, 4096); if (!database.GetVariable("Rules", rules))
return;
ptr = strtok(rules, "\n"); auto lines = SplitString(rules, '\n');
while(ptr != nullptr) for (auto&& e : lines)
{ client->Message(0, "%s", e.c_str());
client->Message(0,"%s",ptr);
ptr = strtok(nullptr, "\n");
}
safe_delete_array(rules);
} }
void Client::SetEndurance(int32 newEnd) void Client::SetEndurance(int32 newEnd)

View File

@ -856,9 +856,9 @@ char buffer[255];
void command_getvariable(Client *c, const Seperator *sep) void command_getvariable(Client *c, const Seperator *sep)
{ {
char tmp[512]; std::string tmp;
if (database.GetVariable(sep->argplus[1], tmp, sizeof(tmp))) if (database.GetVariable(sep->argplus[1], tmp))
c->Message(0, "%s = %s", sep->argplus[1], tmp); c->Message(0, "%s = %s", sep->argplus[1], tmp.c_str());
else else
c->Message(0, "GetVariable(%s) returned false", sep->argplus[1]); c->Message(0, "GetVariable(%s) returned false", sep->argplus[1]);
} }
@ -10735,12 +10735,11 @@ void command_reloadaa(Client *c, const Seperator *sep) {
} }
void command_hotfix(Client *c, const Seperator *sep) { void command_hotfix(Client *c, const Seperator *sep) {
char hotfix[256] = { 0 }; std::string hotfix;
database.GetVariable("hotfix_name", hotfix, 256); database.GetVariable("hotfix_name", hotfix);
std::string current_hotfix = hotfix;
std::string hotfix_name; std::string hotfix_name;
if(!strcasecmp(current_hotfix.c_str(), "hotfix_")) { if(!strcasecmp(hotfix.c_str(), "hotfix_")) {
hotfix_name = ""; hotfix_name = "";
} else { } else {
hotfix_name = "hotfix_"; hotfix_name = "hotfix_";
@ -10762,7 +10761,7 @@ void command_hotfix(Client *c, const Seperator *sep) {
system(StringFormat("./shared_memory").c_str()); system(StringFormat("./shared_memory").c_str());
} }
#endif #endif
database.SetVariable("hotfix_name", hotfix_name.c_str()); database.SetVariable("hotfix_name", hotfix_name);
ServerPacket pack(ServerOP_ChangeSharedMem, hotfix_name.length() + 1); ServerPacket pack(ServerOP_ChangeSharedMem, hotfix_name.length() + 1);
if(hotfix_name.length() > 0) { if(hotfix_name.length() > 0) {
@ -10777,12 +10776,11 @@ void command_hotfix(Client *c, const Seperator *sep) {
} }
void command_load_shared_memory(Client *c, const Seperator *sep) { void command_load_shared_memory(Client *c, const Seperator *sep) {
char hotfix[256] = { 0 }; std::string hotfix;
database.GetVariable("hotfix_name", hotfix, 256); database.GetVariable("hotfix_name", hotfix);
std::string current_hotfix = hotfix;
std::string hotfix_name; std::string hotfix_name;
if(strcasecmp(current_hotfix.c_str(), sep->arg[1]) == 0) { if(strcasecmp(hotfix.c_str(), sep->arg[1]) == 0) {
c->Message(0, "Cannot attempt to load this shared memory segment as it is already loaded."); c->Message(0, "Cannot attempt to load this shared memory segment as it is already loaded.");
return; return;
} }
@ -10811,12 +10809,12 @@ void command_load_shared_memory(Client *c, const Seperator *sep) {
} }
void command_apply_shared_memory(Client *c, const Seperator *sep) { void command_apply_shared_memory(Client *c, const Seperator *sep) {
char hotfix[256] = { 0 }; std::string hotfix;
database.GetVariable("hotfix_name", hotfix, 256); database.GetVariable("hotfix_name", hotfix);
std::string hotfix_name = sep->arg[1]; std::string hotfix_name = sep->arg[1];
c->Message(0, "Applying shared memory segment %s", hotfix_name.c_str()); c->Message(0, "Applying shared memory segment %s", hotfix_name.c_str());
database.SetVariable("hotfix_name", hotfix_name.c_str()); database.SetVariable("hotfix_name", hotfix_name);
ServerPacket pack(ServerOP_ChangeSharedMem, hotfix_name.length() + 1); ServerPacket pack(ServerOP_ChangeSharedMem, hotfix_name.length() + 1);
if(hotfix_name.length() > 0) { if(hotfix_name.length() > 0) {

View File

@ -883,7 +883,6 @@ void Corpse::AllowPlayerLoot(Mob *them, uint8 slot) {
void Corpse::MakeLootRequestPackets(Client* client, const EQApplicationPacket* app) { void Corpse::MakeLootRequestPackets(Client* client, const EQApplicationPacket* app) {
// Added 12/08. Started compressing loot struct on live. // Added 12/08. Started compressing loot struct on live.
char tmp[10];
if(player_corpse_depop) { if(player_corpse_depop) {
SendLootReqErrorPacket(client, 0); SendLootReqErrorPacket(client, 0);
return; return;
@ -914,8 +913,9 @@ void Corpse::MakeLootRequestPackets(Client* client, const EQApplicationPacket* a
uint8 Loot_Request_Type = 1; uint8 Loot_Request_Type = 1;
bool loot_coin = false; bool loot_coin = false;
if(database.GetVariable("LootCoin", tmp, 9)) std::string tmp;
loot_coin = (atoi(tmp) == 1); if(database.GetVariable("LootCoin", tmp))
loot_coin = tmp[0] == 1 && tmp[1] == '\0';
if (this->being_looted_by != 0xFFFFFFFF && this->being_looted_by != client->GetID()) { if (this->being_looted_by != 0xFFFFFFFF && this->being_looted_by != client->GetID()) {
SendLootReqErrorPacket(client, 0); SendLootReqErrorPacket(client, 0);

View File

@ -1406,8 +1406,9 @@ bool GuildApproval::ProcessApproval()
GuildApproval::GuildApproval(const char* guildname, Client* owner,uint32 id) GuildApproval::GuildApproval(const char* guildname, Client* owner,uint32 id)
{ {
database.GetVariable("GuildCreation", founders, 3); std::string founders;
uint8 tmp = atoi(founders); database.GetVariable("GuildCreation", founders);
uint8 tmp = atoi(founders.c_str());
deletion_timer = new Timer(1800000); deletion_timer = new Timer(1800000);
strcpy(guild,guildname); strcpy(guild,guildname);
this->owner = owner; this->owner = owner;
@ -1425,8 +1426,9 @@ GuildApproval::~GuildApproval()
bool GuildApproval::AddMemberApproval(Client* addition) bool GuildApproval::AddMemberApproval(Client* addition)
{ {
database.GetVariable("GuildCreation", founders, 3); std::string founders;
uint8 tmp = atoi(founders); database.GetVariable("GuildCreation", founders);
uint8 tmp = atoi(founders.c_str());
for(int i=0;i<tmp;i++) for(int i=0;i<tmp;i++)
{ {
if(members[i] && members[i] == addition) if(members[i] && members[i] == addition)
@ -1455,8 +1457,9 @@ bool GuildApproval::AddMemberApproval(Client* addition)
void GuildApproval::ApprovedMembers(Client* requestee) void GuildApproval::ApprovedMembers(Client* requestee)
{ {
database.GetVariable("GuildCreation", founders, 3); std::string founders;
uint8 tmp = atoi(founders); database.GetVariable("GuildCreation", founders);
uint8 tmp = atoi(founders.c_str());
for(int i=0;i<tmp;i++) for(int i=0;i<tmp;i++)
{ {
if(members[i]) if(members[i])
@ -1471,8 +1474,9 @@ void GuildApproval::GuildApproved()
if(!owner) if(!owner)
return; return;
database.GetVariable("GuildCreation", founders, 3); std::string founders;
uint8 tmp = atoi(founders); database.GetVariable("GuildCreation", founders);
uint8 tmp = atoi(founders.c_str());
uint32 tmpeq = guild_mgr.CreateGuild(guild, owner->CharacterID()); uint32 tmpeq = guild_mgr.CreateGuild(guild, owner->CharacterID());
guild_mgr.SetGuild(owner->CharacterID(),tmpeq,2); guild_mgr.SetGuild(owner->CharacterID(),tmpeq,2);
owner->SendAppearancePacket(AT_GuildID,true,false); owner->SendAppearancePacket(AT_GuildID,true,false);

View File

@ -61,7 +61,6 @@ public:
private: private:
Timer* deletion_timer; Timer* deletion_timer;
char guild[16]; char guild[16];
char founders[3];
Client* owner; Client* owner;
Client* members[6]; Client* members[6];
uint32 refid; uint32 refid;

View File

@ -254,20 +254,20 @@ int main(int argc, char** argv) {
Log.Out(Logs::General, Logs::Zone_Server, "Mapping Incoming Opcodes"); Log.Out(Logs::General, Logs::Zone_Server, "Mapping Incoming Opcodes");
MapOpcodes(); MapOpcodes();
Log.Out(Logs::General, Logs::Zone_Server, "Loading Variables"); Log.Out(Logs::General, Logs::Zone_Server, "Loading Variables");
database.LoadVariables(); database.LoadVariables();
char hotfix_name[256] = { 0 }; std::string hotfix_name;
if(database.GetVariable("hotfix_name", hotfix_name, 256)) { if(database.GetVariable("hotfix_name", hotfix_name)) {
if(strlen(hotfix_name) > 0) { if(!hotfix_name.empty()) {
Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name); Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name.c_str());
} }
} }
Log.Out(Logs::General, Logs::Zone_Server, "Loading zone names"); Log.Out(Logs::General, Logs::Zone_Server, "Loading zone names");
database.LoadZoneNames(); database.LoadZoneNames();
Log.Out(Logs::General, Logs::Zone_Server, "Loading items"); Log.Out(Logs::General, Logs::Zone_Server, "Loading items");
if(!database.LoadItems(hotfix_name)) { if(!database.LoadItems(hotfix_name)) {
Log.Out(Logs::General, Logs::Error, "Loading items FAILED!"); Log.Out(Logs::General, Logs::Error, "Loading items FAILED!");
@ -326,17 +326,17 @@ int main(int argc, char** argv) {
//rules: //rules:
{ {
char tmp[64]; std::string tmp;
if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) { if (database.GetVariable("RuleSet", tmp)) {
Log.Out(Logs::General, Logs::Zone_Server, "Loading rule set '%s'", tmp); Log.Out(Logs::General, Logs::Zone_Server, "Loading rule set '%s'", tmp.c_str());
if(!RuleManager::Instance()->LoadRules(&database, tmp)) { if(!RuleManager::Instance()->LoadRules(&database, tmp.c_str())) {
Log.Out(Logs::General, Logs::Error, "Failed to load ruleset '%s', falling back to defaults.", tmp); Log.Out(Logs::General, Logs::Error, "Failed to load ruleset '%s', falling back to defaults.", tmp.c_str());
} }
} else { } else {
if(!RuleManager::Instance()->LoadRules(&database, "default")) { if(!RuleManager::Instance()->LoadRules(&database, "default")) {
Log.Out(Logs::General, Logs::Zone_Server, "No rule set configured, using default rules"); Log.Out(Logs::General, Logs::Zone_Server, "No rule set configured, using default rules");
} else { } else {
Log.Out(Logs::General, Logs::Zone_Server, "Loaded default rule set 'default'", tmp); Log.Out(Logs::General, Logs::Zone_Server, "Loaded default rule set 'default'", tmp.c_str());
} }
} }
} }

View File

@ -104,10 +104,11 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
zone->watermap = WaterMap::LoadWaterMapfile(zone->map_name); zone->watermap = WaterMap::LoadWaterMapfile(zone->map_name);
zone->pathing = PathManager::LoadPathFile(zone->map_name); zone->pathing = PathManager::LoadPathFile(zone->map_name);
char tmp[10]; std::string tmp;
if (database.GetVariable("loglevel",tmp, 9)) { if (database.GetVariable("loglevel", tmp)) {
int log_levels[4]; int log_levels[4];
if (atoi(tmp)>9){ //Server is using the new code int tmp_i = atoi(tmp.c_str());
if (tmp_i>9){ //Server is using the new code
for(int i=0;i<4;i++){ for(int i=0;i<4;i++){
if (((int)tmp[i]>=48) && ((int)tmp[i]<=57)) if (((int)tmp[i]>=48) && ((int)tmp[i]<=57))
log_levels[i]=(int)tmp[i]-48; //get the value to convert it to an int from the ascii value log_levels[i]=(int)tmp[i]-48; //get the value to convert it to an int from the ascii value
@ -124,12 +125,12 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
Log.Out(Logs::General, Logs::Status, "Loot logging level: %i", zone->lootvar); Log.Out(Logs::General, Logs::Status, "Loot logging level: %i", zone->lootvar);
} }
else { else {
zone->loglevelvar = uint8(atoi(tmp)); //continue supporting only command logging (for now) zone->loglevelvar = uint8(tmp_i); //continue supporting only command logging (for now)
zone->merchantvar = 0; zone->merchantvar = 0;
zone->tradevar = 0; zone->tradevar = 0;
zone->lootvar = 0; zone->lootvar = 0;
} }
} }
is_zone_loaded = true; is_zone_loaded = true;