mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
Rewrite VarCache_Struct
Basically just remove manual memory management
This commit is contained in:
parent
59728c5115
commit
c159b89e79
@ -23,6 +23,7 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <mysqld_error.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -48,7 +49,6 @@
|
||||
extern Client client;
|
||||
|
||||
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)
|
||||
{
|
||||
DBInitVars();
|
||||
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
|
||||
*/
|
||||
|
||||
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);
|
||||
auto results = QueryDatabase(query);
|
||||
|
||||
@ -860,139 +846,69 @@ void Database::GetCharName(uint32 char_id, char* name) {
|
||||
}
|
||||
|
||||
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())
|
||||
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)
|
||||
return true;
|
||||
|
||||
if (!varcache_array) {
|
||||
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;
|
||||
}
|
||||
LockMutex lock(&Mvarcache);
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row)
|
||||
{
|
||||
varcache_lastupdate = atoi(row[2]);
|
||||
for (i=0; i<varcache_max; i++) {
|
||||
if (varcache_array[i]) {
|
||||
if (strcasecmp(varcache_array[i]->varname, row[0]) == 0) {
|
||||
delete varcache_array[i];
|
||||
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;
|
||||
}
|
||||
}
|
||||
std::string key, value;
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
varcache.last_update = atoi(row[2]); // ahh should we be comparing if this is newer?
|
||||
key = row[0];
|
||||
value = row[1];
|
||||
std::transform(std::begin(key), std::end(key), std::begin(key), ::tolower); // keys are lower case, DB doesn't have to be
|
||||
varcache.Add(key, value);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Gets variable from 'variables' table
|
||||
bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_len) {
|
||||
varvalue[0] = '\0';
|
||||
bool Database::GetVariable(std::string varname, std::string &varvalue)
|
||||
{
|
||||
varvalue.clear();
|
||||
|
||||
LockMutex lock(&Mvarcache);
|
||||
if (strlen(varname) <= 1)
|
||||
return false;
|
||||
for (uint32 i=0; i<varcache_max; i++) {
|
||||
|
||||
if (varcache_array[i]) {
|
||||
if (strcasecmp(varcache_array[i]->varname, varname) == 0) {
|
||||
snprintf(varvalue, varvalue_len, "%s", varcache_array[i]->value);
|
||||
varvalue[varvalue_len-1] = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if (varname.empty())
|
||||
return false;
|
||||
|
||||
std::transform(std::begin(varname), std::end(varname), std::begin(varname), ::tolower); // all keys are lower case
|
||||
auto tmp = varcache.Get(varname);
|
||||
if (tmp) {
|
||||
varvalue = *tmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Database::SetVariable(const char* varname_in, const char* varvalue_in) {
|
||||
|
||||
char *varname,*varvalue;
|
||||
|
||||
varname=(char *)malloc(strlen(varname_in)*2+1);
|
||||
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);
|
||||
bool Database::SetVariable(const std::string varname, const std::string &varvalue)
|
||||
{
|
||||
std::string escaped_name = EscapeString(varname);
|
||||
std::string escaped_value = EscapeString(varvalue);
|
||||
std::string query = StringFormat("Update variables set value='%s' WHERE varname like '%s'", escaped_value.c_str(), escaped_name.c_str());
|
||||
auto results = QueryDatabase(query);
|
||||
|
||||
if (!results.Success())
|
||||
{
|
||||
free(varname);
|
||||
free(varvalue);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (results.RowsAffected() == 1)
|
||||
{
|
||||
LoadVariables(); // refresh cache
|
||||
free(varname);
|
||||
free(varvalue);
|
||||
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);
|
||||
free(varname);
|
||||
free(varvalue);
|
||||
|
||||
if (results.RowsAffected() != 1)
|
||||
return false;
|
||||
|
||||
|
||||
LoadVariables(); // refresh cache
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -67,8 +67,14 @@ struct npcDecayTimes_Struct {
|
||||
|
||||
|
||||
struct VarCache_Struct {
|
||||
char varname[26];
|
||||
char value[0];
|
||||
std::map<std::string, std::string> m_cache;
|
||||
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;
|
||||
@ -215,11 +221,9 @@ public:
|
||||
|
||||
/* Database Variables */
|
||||
|
||||
bool GetVariable(const char* varname, char* varvalue, uint16 varvalue_len);
|
||||
bool SetVariable(const char* varname, const char* varvalue);
|
||||
bool GetVariable(std::string varname, std::string &varvalue);
|
||||
bool SetVariable(const std::string varname, const std::string &varvalue);
|
||||
bool LoadVariables();
|
||||
uint32 LoadVariables_MQ(char** query);
|
||||
bool LoadVariables_result(MySQLRequestResult results);
|
||||
|
||||
/* General Queries */
|
||||
|
||||
@ -256,14 +260,10 @@ public:
|
||||
void LoadLogSettings(EQEmuLogSys::LogSettings* log_settings);
|
||||
|
||||
private:
|
||||
void DBInitVars();
|
||||
|
||||
std::map<uint32,std::string> zonename_array;
|
||||
|
||||
Mutex Mvarcache;
|
||||
uint32 varcache_max;
|
||||
VarCache_Struct** varcache_array;
|
||||
uint32 varcache_lastupdate;
|
||||
Mutex Mvarcache;
|
||||
VarCache_Struct varcache;
|
||||
|
||||
/* Groups, utility methods. */
|
||||
void ClearAllGroupLeaders();
|
||||
|
||||
@ -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);
|
||||
|
||||
char ndbuffer[4];
|
||||
std::string ndbuffer;
|
||||
bool disableNoRent = false;
|
||||
if (GetVariable("disablenorent", ndbuffer, 4)) {
|
||||
if (GetVariable("disablenorent", ndbuffer)) {
|
||||
if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') {
|
||||
disableNoRent = true;
|
||||
}
|
||||
}
|
||||
bool disableNoDrop = false;
|
||||
if (GetVariable("disablenodrop", ndbuffer, 4)) {
|
||||
if (GetVariable("disablenodrop", ndbuffer)) {
|
||||
if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') {
|
||||
disableNoDrop = true;
|
||||
}
|
||||
}
|
||||
bool disableLoreGroup = false;
|
||||
if (GetVariable("disablelore", ndbuffer, 4)) {
|
||||
if (GetVariable("disablelore", ndbuffer)) {
|
||||
if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') {
|
||||
disableLoreGroup = true;
|
||||
}
|
||||
}
|
||||
bool disableNoTransfer = false;
|
||||
if (GetVariable("disablenotransfer", ndbuffer, 4)) {
|
||||
if (GetVariable("disablenotransfer", ndbuffer)) {
|
||||
if (ndbuffer[0] == '1' && ndbuffer[1] == '\0') {
|
||||
disableNoTransfer = true;
|
||||
}
|
||||
|
||||
@ -65,10 +65,10 @@ int main(int argc, char **argv) {
|
||||
database.LoadVariables();
|
||||
|
||||
/* 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 };
|
||||
if (database.GetVariable("hotfix_name", db_hotfix_name, 256)) {
|
||||
if (strlen(db_hotfix_name) > 0 && strcasecmp("hotfix_", db_hotfix_name) == 0) {
|
||||
Log.Out(Logs::General, Logs::Status, "Current hotfix in variables is the default %s, clearing out variable", db_hotfix_name);
|
||||
std::string db_hotfix_name;
|
||||
if (database.GetVariable("hotfix_name", db_hotfix_name)) {
|
||||
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.c_str());
|
||||
std::string query = StringFormat("UPDATE `variables` SET `value`='' WHERE (`varname`='hotfix_name')");
|
||||
database.QueryDatabase(query);
|
||||
}
|
||||
|
||||
@ -857,12 +857,12 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) {
|
||||
}
|
||||
|
||||
outapp = new EQApplicationPacket(OP_MOTD);
|
||||
char tmp[500] = {0};
|
||||
if (database.GetVariable("MOTD", tmp, 500)) {
|
||||
outapp->size = strlen(tmp)+1;
|
||||
std::string tmp;
|
||||
if (database.GetVariable("MOTD", tmp)) {
|
||||
outapp->size = tmp.length();
|
||||
outapp->pBuffer = new uchar[outapp->size];
|
||||
memset(outapp->pBuffer,0,outapp->size);
|
||||
strcpy((char*)outapp->pBuffer, tmp);
|
||||
strcpy((char*)outapp->pBuffer, tmp.c_str());
|
||||
|
||||
} else {
|
||||
// Null Message of the Day. :)
|
||||
|
||||
@ -277,10 +277,10 @@ bool ClientListEntry::CheckAuth(uint32 iLSID, const char* iKey) {
|
||||
strn0cpy(paccountname, plsname, sizeof(paccountname));
|
||||
padmin = tmpStatus;
|
||||
}
|
||||
char lsworldadmin[15] = "0";
|
||||
database.GetVariable("honorlsworldadmin", lsworldadmin, sizeof(lsworldadmin));
|
||||
if (atoi(lsworldadmin) == 1 && pworldadmin != 0 && (padmin < pworldadmin || padmin == 0))
|
||||
padmin = pworldadmin;
|
||||
std::string lsworldadmin;
|
||||
if (database.GetVariable("honorlsworldadmin", lsworldadmin))
|
||||
if (atoi(lsworldadmin.c_str()) == 1 && pworldadmin != 0 && (padmin < pworldadmin || padmin == 0))
|
||||
padmin = pworldadmin;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -212,8 +212,8 @@ bool LoginServer::InitLoginServer() {
|
||||
}
|
||||
|
||||
bool LoginServer::Connect() {
|
||||
char tmp[25];
|
||||
if(database.GetVariable("loginType",tmp,sizeof(tmp)) && strcasecmp(tmp,"MinILogin") == 0){
|
||||
std::string tmp;
|
||||
if(database.GetVariable("loginType", tmp) && strcasecmp(tmp.c_str(), "MinILogin") == 0) {
|
||||
minilogin = true;
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Setting World to MiniLogin Server type");
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
bool ignore_db = false;
|
||||
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) {
|
||||
std::cout << "Worldserver command line commands:" << 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;
|
||||
holdzones = true;
|
||||
}
|
||||
else if (database.GetVariable("disablecommandline", tmp, 2)) {
|
||||
if (strlen(tmp) == 1) {
|
||||
else if (database.GetVariable("disablecommandline", tmp)) {
|
||||
if (tmp.length() == 1) {
|
||||
if (tmp[0] == '1') {
|
||||
std::cerr << "Command line disabled in database... exiting" << std::endl;
|
||||
return 1;
|
||||
@ -299,10 +299,10 @@ int main(int argc, char** argv) {
|
||||
Log.Out(Logs::General, Logs::World_Server, "Loading variables..");
|
||||
database.LoadVariables();
|
||||
|
||||
char hotfix_name[256] = { 0 };
|
||||
if(database.GetVariable("hotfix_name", hotfix_name, 256)) {
|
||||
if(strlen(hotfix_name) > 0) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name);
|
||||
std::string hotfix_name;
|
||||
if(database.GetVariable("hotfix_name", hotfix_name)) {
|
||||
if (!hotfix_name.empty()) {
|
||||
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();
|
||||
//rules:
|
||||
{
|
||||
char tmp[64];
|
||||
if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) {
|
||||
Log.Out(Logs::General, Logs::World_Server, "Loading rule set '%s'", tmp);
|
||||
if(!RuleManager::Instance()->LoadRules(&database, tmp)) {
|
||||
Log.Out(Logs::General, Logs::World_Server, "Failed to load ruleset '%s', falling back to defaults.", tmp);
|
||||
std::string tmp;
|
||||
if (database.GetVariable("RuleSet", tmp)) {
|
||||
Log.Out(Logs::General, Logs::World_Server, "Loading rule set '%s'", tmp.c_str());
|
||||
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.c_str());
|
||||
}
|
||||
} else {
|
||||
if(!RuleManager::Instance()->LoadRules(&database, "default")) {
|
||||
Log.Out(Logs::General, Logs::World_Server, "No rule set configured, using default rules");
|
||||
} 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..");
|
||||
launcher_list.LoadList();
|
||||
|
||||
char tmp[20];
|
||||
tmp[0] = '\0';
|
||||
database.GetVariable("holdzones",tmp, 20);
|
||||
if ((strcasecmp(tmp, "1") == 0)) {
|
||||
std::string tmp;
|
||||
database.GetVariable("holdzones",tmp);
|
||||
if (tmp.length() == 1 && tmp[0] == '1') {
|
||||
holdzones = true;
|
||||
}
|
||||
Log.Out(Logs::General, Logs::World_Server, "Reboot zone modes %s",holdzones ? "ON" : "OFF");
|
||||
|
||||
@ -687,25 +687,25 @@ void Mob::MeleeMitigation(Mob *attacker, int32 &damage, int32 minhit, ExtraAttac
|
||||
|
||||
if (damage > 0 && myac > 0) {
|
||||
int acfail=1000;
|
||||
char tmp[10];
|
||||
std::string tmp;
|
||||
|
||||
if (database.GetVariable("ACfail", tmp, 9)) {
|
||||
acfail = (int) (atof(tmp) * 100);
|
||||
if (database.GetVariable("ACfail", tmp)) {
|
||||
acfail = (int) (atof(tmp.c_str()) * 100);
|
||||
if (acfail>100) acfail=100;
|
||||
}
|
||||
|
||||
if (acfail<=0 || zone->random.Int(0, 100)>acfail) {
|
||||
float acreduction=1;
|
||||
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 (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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
Corpse *new_corpse = new Corpse(this, exploss);
|
||||
|
||||
char tmp[20];
|
||||
database.GetVariable("ServerType", tmp, 9);
|
||||
if(atoi(tmp)==1 && killerMob != nullptr && killerMob->IsClient()){
|
||||
char tmp2[10] = {0};
|
||||
database.GetVariable("PvPreward", tmp, 9);
|
||||
int reward = atoi(tmp);
|
||||
std::string tmp;
|
||||
database.GetVariable("ServerType", tmp);
|
||||
if(tmp[0] == '1' && tmp[1] == '\0' && killerMob != nullptr && killerMob->IsClient()){
|
||||
database.GetVariable("PvPreward", tmp);
|
||||
int reward = atoi(tmp.c_str());
|
||||
if(reward==3){
|
||||
database.GetVariable("PvPitem", tmp2, 9);
|
||||
int pvpitem = atoi(tmp2);
|
||||
database.GetVariable("PvPitem", tmp);
|
||||
int pvpitem = atoi(tmp.c_str());
|
||||
if(pvpitem>0 && pvpitem<200000)
|
||||
new_corpse->SetPlayerKillItemID(pvpitem);
|
||||
}
|
||||
|
||||
@ -3598,10 +3598,8 @@ void Client::GetRaidAAs(RaidLeadershipAA_Struct *into) const {
|
||||
void Client::EnteringMessages(Client* client)
|
||||
{
|
||||
//server rules
|
||||
char *rules;
|
||||
rules = new char [4096];
|
||||
|
||||
if(database.GetVariable("Rules", rules, 4096))
|
||||
std::string rules;
|
||||
if(database.GetVariable("Rules", rules))
|
||||
{
|
||||
uint8 flag = database.GetAgreementFlag(client->AccountID());
|
||||
if(!flag)
|
||||
@ -3612,25 +3610,18 @@ void Client::EnteringMessages(Client* client)
|
||||
client->SendAppearancePacket(AT_Anim, ANIM_FREEZE);
|
||||
}
|
||||
}
|
||||
safe_delete_array(rules);
|
||||
}
|
||||
|
||||
void Client::SendRules(Client* client)
|
||||
{
|
||||
char *rules;
|
||||
rules = new char [4096];
|
||||
char *ptr;
|
||||
std::string rules;
|
||||
|
||||
database.GetVariable("Rules", rules, 4096);
|
||||
if (!database.GetVariable("Rules", rules))
|
||||
return;
|
||||
|
||||
ptr = strtok(rules, "\n");
|
||||
while(ptr != nullptr)
|
||||
{
|
||||
|
||||
client->Message(0,"%s",ptr);
|
||||
ptr = strtok(nullptr, "\n");
|
||||
}
|
||||
safe_delete_array(rules);
|
||||
auto lines = SplitString(rules, '\n');
|
||||
for (auto&& e : lines)
|
||||
client->Message(0, "%s", e.c_str());
|
||||
}
|
||||
|
||||
void Client::SetEndurance(int32 newEnd)
|
||||
|
||||
@ -856,9 +856,9 @@ char buffer[255];
|
||||
|
||||
void command_getvariable(Client *c, const Seperator *sep)
|
||||
{
|
||||
char tmp[512];
|
||||
if (database.GetVariable(sep->argplus[1], tmp, sizeof(tmp)))
|
||||
c->Message(0, "%s = %s", sep->argplus[1], tmp);
|
||||
std::string tmp;
|
||||
if (database.GetVariable(sep->argplus[1], tmp))
|
||||
c->Message(0, "%s = %s", sep->argplus[1], tmp.c_str());
|
||||
else
|
||||
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) {
|
||||
char hotfix[256] = { 0 };
|
||||
database.GetVariable("hotfix_name", hotfix, 256);
|
||||
std::string current_hotfix = hotfix;
|
||||
std::string hotfix;
|
||||
database.GetVariable("hotfix_name", hotfix);
|
||||
|
||||
std::string hotfix_name;
|
||||
if(!strcasecmp(current_hotfix.c_str(), "hotfix_")) {
|
||||
if(!strcasecmp(hotfix.c_str(), "hotfix_")) {
|
||||
hotfix_name = "";
|
||||
} else {
|
||||
hotfix_name = "hotfix_";
|
||||
@ -10762,7 +10761,7 @@ void command_hotfix(Client *c, const Seperator *sep) {
|
||||
system(StringFormat("./shared_memory").c_str());
|
||||
}
|
||||
#endif
|
||||
database.SetVariable("hotfix_name", hotfix_name.c_str());
|
||||
database.SetVariable("hotfix_name", hotfix_name);
|
||||
|
||||
ServerPacket pack(ServerOP_ChangeSharedMem, hotfix_name.length() + 1);
|
||||
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) {
|
||||
char hotfix[256] = { 0 };
|
||||
database.GetVariable("hotfix_name", hotfix, 256);
|
||||
std::string current_hotfix = hotfix;
|
||||
std::string hotfix;
|
||||
database.GetVariable("hotfix_name", hotfix);
|
||||
|
||||
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.");
|
||||
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) {
|
||||
char hotfix[256] = { 0 };
|
||||
database.GetVariable("hotfix_name", hotfix, 256);
|
||||
std::string hotfix;
|
||||
database.GetVariable("hotfix_name", hotfix);
|
||||
std::string hotfix_name = sep->arg[1];
|
||||
|
||||
|
||||
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);
|
||||
if(hotfix_name.length() > 0) {
|
||||
|
||||
@ -883,7 +883,6 @@ void Corpse::AllowPlayerLoot(Mob *them, uint8 slot) {
|
||||
|
||||
void Corpse::MakeLootRequestPackets(Client* client, const EQApplicationPacket* app) {
|
||||
// Added 12/08. Started compressing loot struct on live.
|
||||
char tmp[10];
|
||||
if(player_corpse_depop) {
|
||||
SendLootReqErrorPacket(client, 0);
|
||||
return;
|
||||
@ -914,8 +913,9 @@ void Corpse::MakeLootRequestPackets(Client* client, const EQApplicationPacket* a
|
||||
|
||||
uint8 Loot_Request_Type = 1;
|
||||
bool loot_coin = false;
|
||||
if(database.GetVariable("LootCoin", tmp, 9))
|
||||
loot_coin = (atoi(tmp) == 1);
|
||||
std::string tmp;
|
||||
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()) {
|
||||
SendLootReqErrorPacket(client, 0);
|
||||
|
||||
@ -1406,8 +1406,9 @@ bool GuildApproval::ProcessApproval()
|
||||
|
||||
GuildApproval::GuildApproval(const char* guildname, Client* owner,uint32 id)
|
||||
{
|
||||
database.GetVariable("GuildCreation", founders, 3);
|
||||
uint8 tmp = atoi(founders);
|
||||
std::string founders;
|
||||
database.GetVariable("GuildCreation", founders);
|
||||
uint8 tmp = atoi(founders.c_str());
|
||||
deletion_timer = new Timer(1800000);
|
||||
strcpy(guild,guildname);
|
||||
this->owner = owner;
|
||||
@ -1425,8 +1426,9 @@ GuildApproval::~GuildApproval()
|
||||
|
||||
bool GuildApproval::AddMemberApproval(Client* addition)
|
||||
{
|
||||
database.GetVariable("GuildCreation", founders, 3);
|
||||
uint8 tmp = atoi(founders);
|
||||
std::string founders;
|
||||
database.GetVariable("GuildCreation", founders);
|
||||
uint8 tmp = atoi(founders.c_str());
|
||||
for(int i=0;i<tmp;i++)
|
||||
{
|
||||
if(members[i] && members[i] == addition)
|
||||
@ -1455,8 +1457,9 @@ bool GuildApproval::AddMemberApproval(Client* addition)
|
||||
|
||||
void GuildApproval::ApprovedMembers(Client* requestee)
|
||||
{
|
||||
database.GetVariable("GuildCreation", founders, 3);
|
||||
uint8 tmp = atoi(founders);
|
||||
std::string founders;
|
||||
database.GetVariable("GuildCreation", founders);
|
||||
uint8 tmp = atoi(founders.c_str());
|
||||
for(int i=0;i<tmp;i++)
|
||||
{
|
||||
if(members[i])
|
||||
@ -1471,8 +1474,9 @@ void GuildApproval::GuildApproved()
|
||||
|
||||
if(!owner)
|
||||
return;
|
||||
database.GetVariable("GuildCreation", founders, 3);
|
||||
uint8 tmp = atoi(founders);
|
||||
std::string founders;
|
||||
database.GetVariable("GuildCreation", founders);
|
||||
uint8 tmp = atoi(founders.c_str());
|
||||
uint32 tmpeq = guild_mgr.CreateGuild(guild, owner->CharacterID());
|
||||
guild_mgr.SetGuild(owner->CharacterID(),tmpeq,2);
|
||||
owner->SendAppearancePacket(AT_GuildID,true,false);
|
||||
|
||||
@ -61,7 +61,6 @@ public:
|
||||
private:
|
||||
Timer* deletion_timer;
|
||||
char guild[16];
|
||||
char founders[3];
|
||||
Client* owner;
|
||||
Client* members[6];
|
||||
uint32 refid;
|
||||
|
||||
26
zone/net.cpp
26
zone/net.cpp
@ -254,20 +254,20 @@ int main(int argc, char** argv) {
|
||||
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Mapping Incoming Opcodes");
|
||||
MapOpcodes();
|
||||
|
||||
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading Variables");
|
||||
database.LoadVariables();
|
||||
|
||||
char hotfix_name[256] = { 0 };
|
||||
if(database.GetVariable("hotfix_name", hotfix_name, 256)) {
|
||||
if(strlen(hotfix_name) > 0) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name);
|
||||
|
||||
std::string hotfix_name;
|
||||
if(database.GetVariable("hotfix_name", hotfix_name)) {
|
||||
if(!hotfix_name.empty()) {
|
||||
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");
|
||||
database.LoadZoneNames();
|
||||
|
||||
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading items");
|
||||
if(!database.LoadItems(hotfix_name)) {
|
||||
Log.Out(Logs::General, Logs::Error, "Loading items FAILED!");
|
||||
@ -326,17 +326,17 @@ int main(int argc, char** argv) {
|
||||
|
||||
//rules:
|
||||
{
|
||||
char tmp[64];
|
||||
if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading rule set '%s'", tmp);
|
||||
if(!RuleManager::Instance()->LoadRules(&database, tmp)) {
|
||||
Log.Out(Logs::General, Logs::Error, "Failed to load ruleset '%s', falling back to defaults.", tmp);
|
||||
std::string tmp;
|
||||
if (database.GetVariable("RuleSet", tmp)) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading rule set '%s'", tmp.c_str());
|
||||
if(!RuleManager::Instance()->LoadRules(&database, tmp.c_str())) {
|
||||
Log.Out(Logs::General, Logs::Error, "Failed to load ruleset '%s', falling back to defaults.", tmp.c_str());
|
||||
}
|
||||
} else {
|
||||
if(!RuleManager::Instance()->LoadRules(&database, "default")) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "No rule set configured, using default rules");
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,10 +104,11 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
|
||||
zone->watermap = WaterMap::LoadWaterMapfile(zone->map_name);
|
||||
zone->pathing = PathManager::LoadPathFile(zone->map_name);
|
||||
|
||||
char tmp[10];
|
||||
if (database.GetVariable("loglevel",tmp, 9)) {
|
||||
std::string tmp;
|
||||
if (database.GetVariable("loglevel", tmp)) {
|
||||
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++){
|
||||
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
|
||||
@ -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);
|
||||
}
|
||||
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->tradevar = 0;
|
||||
zone->lootvar = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is_zone_loaded = true;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user