diff --git a/common/database.cpp b/common/database.cpp index 475b48258..b8ea025ae 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -2182,3 +2182,42 @@ void Database::ClearInvSnapshots(bool use_rule) std::string query = StringFormat("DELETE FROM inventory_snapshots WHERE time_index <= %lu", (unsigned long)del_time); QueryDatabase(query); } + +struct TimeOfDay_Struct Database::LoadTime(time_t &realtime) +{ + + TimeOfDay_Struct eqTime; + std::string query = StringFormat("SELECT minute,hour,day,month,year,realtime FROM eqtime limit 1"); + auto results = QueryDatabase(query); + + if (!results.Success() || results.RowCount() == 0) + { + Log.Out(Logs::Detail, Logs::World_Server, "Loading EQ time of day failed. Using defaults."); + eqTime.minute = 0; + eqTime.hour = 9; + eqTime.day = 1; + eqTime.month = 1; + eqTime.year = 3100; + realtime = time(0); + } + + auto row = results.begin(); + + eqTime.minute = atoi(row[0]); + eqTime.hour = atoi(row[1]); + eqTime.day = atoi(row[2]); + eqTime.month = atoi(row[3]); + eqTime.year = atoi(row[4]); + realtime = atoi(row[5]); + + return eqTime; +} + +bool Database::SaveTime(int8 minute, int8 hour, int8 day, int8 month, int16 year) +{ + std::string query = StringFormat("UPDATE eqtime set minute = %d, hour = %d, day = %d, month = %d, year = %d, realtime = %d limit 1", minute, hour, day, month, year, time(0)); + auto results = QueryDatabase(query); + + return results.Success(); + +} \ No newline at end of file diff --git a/common/database.h b/common/database.h index f066cb417..02110b9a6 100644 --- a/common/database.h +++ b/common/database.h @@ -241,6 +241,8 @@ public: uint8 GetSkillCap(uint8 skillid, uint8 in_race, uint8 in_class, uint16 in_level); void AddReport(std::string who, std::string against, std::string lines); + struct TimeOfDay_Struct LoadTime(time_t &realtime); + bool SaveTime(int8 minute, int8 hour, int8 day, int8 month, int16 year); void ClearMerchantTemp(); void ClearPTimers(uint32 charid); void SetFirstLogon(uint32 CharID, uint8 firstlogon); diff --git a/common/eqemu_config.cpp b/common/eqemu_config.cpp index 6e1400904..fb295cec1 100644 --- a/common/eqemu_config.cpp +++ b/common/eqemu_config.cpp @@ -254,10 +254,6 @@ void EQEmuConfig::do_files(TiXmlElement *ele) if (text) { OpCodesFile = text; } - text = ParseTextBlock(ele, "eqtime", true); - if (text) { - EQTimeFile = text; - } } void EQEmuConfig::do_directories(TiXmlElement *ele) @@ -408,9 +404,6 @@ std::string EQEmuConfig::GetByName(const std::string &var_name) const if (var_name == "OpCodesFile") { return (OpCodesFile); } - if (var_name == "EQTimeFile") { - return (EQTimeFile); - } if (var_name == "MapDir") { return (MapDir); } @@ -475,7 +468,6 @@ void EQEmuConfig::Dump() const std::cout << "QSDatabasePort = " << QSDatabasePort << std::endl; std::cout << "SpellsFile = " << SpellsFile << std::endl; std::cout << "OpCodesFile = " << OpCodesFile << std::endl; - std::cout << "EQTimeFile = " << EQTimeFile << std::endl; std::cout << "MapDir = " << MapDir << std::endl; std::cout << "QuestDir = " << QuestDir << std::endl; std::cout << "PluginDir = " << PluginDir << std::endl; diff --git a/common/eqemu_config.h b/common/eqemu_config.h index 1ad2174dc..039b6c327 100644 --- a/common/eqemu_config.h +++ b/common/eqemu_config.h @@ -79,7 +79,6 @@ class EQEmuConfig : public XMLParser // From std::string SpellsFile; std::string OpCodesFile; - std::string EQTimeFile; // From std::string MapDir; @@ -154,7 +153,6 @@ class EQEmuConfig : public XMLParser // Files SpellsFile = "spells_us.txt"; OpCodesFile = "opcodes.conf"; - EQTimeFile = "eqtime.cfg"; // Dirs MapDir = "Maps"; QuestDir = "quests"; diff --git a/common/eqtime.cpp b/common/eqtime.cpp index e504964b8..8ece4ad69 100644 --- a/common/eqtime.cpp +++ b/common/eqtime.cpp @@ -133,72 +133,6 @@ int EQTime::SetCurrentEQTimeOfDay(TimeOfDay_Struct start_eq, time_t start_real) return 1; } -//saveFile and loadFile need to use long for the save datatype... -//For some reason, ifstream/ofstream have problems with EQEmu datatypes in files. -bool EQTime::saveFile(const char *filename) -{ - std::ofstream of; - of.open(filename); - if (!of) - { - Log.Out(Logs::General, Logs::Error, "EQTime::saveFile failed: Unable to open file '%s'", filename); - return false; - } - //Enable for debugging - of << EQT_VERSION << std::endl; - of << (long)eqTime.start_eqtime.day << std::endl; - of << (long)eqTime.start_eqtime.hour << std::endl; - of << (long)eqTime.start_eqtime.minute << std::endl; - of << (long)eqTime.start_eqtime.month << std::endl; - of << eqTime.start_eqtime.year << std::endl; - of << eqTime.start_realtime << std::endl; - of.close(); - return true; -} - -bool EQTime::loadFile(const char *filename) -{ - int version=0; - long in_data=0; - std::ifstream in; - in.open(filename); - if(!in) - { - Log.Out(Logs::General, Logs::Error, "Could not load EQTime file %s", filename); - return false; - } - in >> version; - in.ignore(80, '\n'); - if(version != EQT_VERSION) - { - Log.Out(Logs::General, Logs::Error, "'%s' is NOT a valid EQTime file. File version is %i, EQTime version is %i", filename, version, EQT_VERSION); - return false; - } - //in >> eqTime.start_eqtime.day; - in >> in_data; - in.ignore(80, '\n'); - eqTime.start_eqtime.day = in_data; - //in >> eqTime.start_eqtime.hour; - in >> in_data; - eqTime.start_eqtime.hour = in_data; - in.ignore(80, '\n'); - //in >> eqTime.start_eqtime.minute; - in >> in_data; - in.ignore(80, '\n'); - eqTime.start_eqtime.minute = in_data; - //in >> eqTime.start_eqtime.month; - in >> in_data; - in.ignore(80, '\n'); - eqTime.start_eqtime.month = in_data; - in >> eqTime.start_eqtime.year; - in.ignore(80, '\n'); - in >> eqTime.start_realtime; - //Enable for debugging... - in.close(); - return true; -} - - bool EQTime::IsTimeBefore(TimeOfDay_Struct *base, TimeOfDay_Struct *test) { if (base->year > test->year) return(true); diff --git a/common/eqtime.h b/common/eqtime.h index aeda9f0f6..f40b855f6 100644 --- a/common/eqtime.h +++ b/common/eqtime.h @@ -39,12 +39,6 @@ public: static void ToString(TimeOfDay_Struct *t, std::string &str); - //Database functions - //bool loadDB(Database q); - //bool setDB(Database q); - bool loadFile(const char *filename); - bool saveFile(const char *filename); - private: //This is our reference clock. eqTimeOfDay eqTime; diff --git a/utils/sql/git/required/2015_12_17_eqtime.sql b/utils/sql/git/required/2015_12_17_eqtime.sql new file mode 100644 index 000000000..c264edf27 --- /dev/null +++ b/utils/sql/git/required/2015_12_17_eqtime.sql @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS `eqtime`; +CREATE TABLE `eqtime` ( + `minute` tinyint(4) not null default 0, + `hour` tinyint(4) not null default 0, + `day` tinyint(4) not null default 0, + `month` tinyint(4) not null default 0, + `year` int(4) not null default 0, + `realtime` int(11) not null default 0 +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +INSERT INTO eqtime values (0,1,28,12,3766,1444035661); \ No newline at end of file diff --git a/world/net.cpp b/world/net.cpp index d7669ce12..b5c29fecb 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -345,8 +345,11 @@ int main(int argc, char** argv) { database.ClearMerchantTemp(); } Log.Out(Logs::General, Logs::World_Server, "Loading EQ time of day.."); - if (!zoneserver_list.worldclock.loadFile(Config->EQTimeFile.c_str())) - Log.Out(Logs::General, Logs::World_Server, "Unable to load %s", Config->EQTimeFile.c_str()); + TimeOfDay_Struct eqTime; + time_t realtime; + eqTime = database.LoadTime(realtime); + zoneserver_list.worldclock.SetCurrentEQTimeOfDay(eqTime, realtime); + Log.Out(Logs::General, Logs::World_Server, "Loading launcher list.."); launcher_list.LoadList(); @@ -519,8 +522,10 @@ int main(int argc, char** argv) { void CatchSignal(int sig_num) { Log.Out(Logs::General, Logs::World_Server,"Caught signal %d",sig_num); - if(zoneserver_list.worldclock.saveFile(WorldConfig::get()->EQTimeFile.c_str())==false) - Log.Out(Logs::General, Logs::World_Server,"Failed to save time file."); + TimeOfDay_Struct eqTime; + zoneserver_list.worldclock.GetCurrentEQTimeOfDay(time(0), &eqTime); + if (!database.SaveTime(eqTime.minute, eqTime.hour, eqTime.day, eqTime.month, eqTime.year)) + Log.Out(Logs::General, Logs::World_Server, "Failed to save eqtime."); RunLoops = false; } diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index f6447f3f4..580053a3b 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -989,8 +989,8 @@ bool ZoneServer::Process() { Log.Out(Logs::Detail, Logs::World_Server,"Received SetWorldTime"); eqTimeOfDay* newtime = (eqTimeOfDay*) pack->pBuffer; zoneserver_list.worldclock.SetCurrentEQTimeOfDay(newtime->start_eqtime, newtime->start_realtime); - Log.Out(Logs::Detail, Logs::World_Server,"New time = %d-%d-%d %d:%d (%d)\n", newtime->start_eqtime.year, newtime->start_eqtime.month, (int)newtime->start_eqtime.day, (int)newtime->start_eqtime.hour, (int)newtime->start_eqtime.minute, (int)newtime->start_realtime); - zoneserver_list.worldclock.saveFile(WorldConfig::get()->EQTimeFile.c_str()); + Log.Out(Logs::Detail, Logs::World_Server, "New time = %d-%d-%d %d:%d (%d)\n", newtime->start_eqtime.year, newtime->start_eqtime.month, (int)newtime->start_eqtime.day, (int)newtime->start_eqtime.hour, (int)newtime->start_eqtime.minute, (int)newtime->start_realtime); + database.SaveTime((int)newtime->start_eqtime.minute, (int)newtime->start_eqtime.hour, (int)newtime->start_eqtime.day, newtime->start_eqtime.month, newtime->start_eqtime.year); zoneserver_list.SendTimeSync(); break; }