mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 23:01:30 +00:00
eqtime is now stored in the DB.
required/2015_12_17_eqtime.sql
This commit is contained in:
parent
78f22599f4
commit
17bbd8dfbe
@ -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);
|
std::string query = StringFormat("DELETE FROM inventory_snapshots WHERE time_index <= %lu", (unsigned long)del_time);
|
||||||
QueryDatabase(query);
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
@ -241,6 +241,8 @@ public:
|
|||||||
uint8 GetSkillCap(uint8 skillid, uint8 in_race, uint8 in_class, uint16 in_level);
|
uint8 GetSkillCap(uint8 skillid, uint8 in_race, uint8 in_class, uint16 in_level);
|
||||||
|
|
||||||
void AddReport(std::string who, std::string against, std::string lines);
|
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 ClearMerchantTemp();
|
||||||
void ClearPTimers(uint32 charid);
|
void ClearPTimers(uint32 charid);
|
||||||
void SetFirstLogon(uint32 CharID, uint8 firstlogon);
|
void SetFirstLogon(uint32 CharID, uint8 firstlogon);
|
||||||
|
|||||||
@ -254,10 +254,6 @@ void EQEmuConfig::do_files(TiXmlElement *ele)
|
|||||||
if (text) {
|
if (text) {
|
||||||
OpCodesFile = text;
|
OpCodesFile = text;
|
||||||
}
|
}
|
||||||
text = ParseTextBlock(ele, "eqtime", true);
|
|
||||||
if (text) {
|
|
||||||
EQTimeFile = text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQEmuConfig::do_directories(TiXmlElement *ele)
|
void EQEmuConfig::do_directories(TiXmlElement *ele)
|
||||||
@ -408,9 +404,6 @@ std::string EQEmuConfig::GetByName(const std::string &var_name) const
|
|||||||
if (var_name == "OpCodesFile") {
|
if (var_name == "OpCodesFile") {
|
||||||
return (OpCodesFile);
|
return (OpCodesFile);
|
||||||
}
|
}
|
||||||
if (var_name == "EQTimeFile") {
|
|
||||||
return (EQTimeFile);
|
|
||||||
}
|
|
||||||
if (var_name == "MapDir") {
|
if (var_name == "MapDir") {
|
||||||
return (MapDir);
|
return (MapDir);
|
||||||
}
|
}
|
||||||
@ -475,7 +468,6 @@ void EQEmuConfig::Dump() const
|
|||||||
std::cout << "QSDatabasePort = " << QSDatabasePort << std::endl;
|
std::cout << "QSDatabasePort = " << QSDatabasePort << std::endl;
|
||||||
std::cout << "SpellsFile = " << SpellsFile << std::endl;
|
std::cout << "SpellsFile = " << SpellsFile << std::endl;
|
||||||
std::cout << "OpCodesFile = " << OpCodesFile << std::endl;
|
std::cout << "OpCodesFile = " << OpCodesFile << std::endl;
|
||||||
std::cout << "EQTimeFile = " << EQTimeFile << std::endl;
|
|
||||||
std::cout << "MapDir = " << MapDir << std::endl;
|
std::cout << "MapDir = " << MapDir << std::endl;
|
||||||
std::cout << "QuestDir = " << QuestDir << std::endl;
|
std::cout << "QuestDir = " << QuestDir << std::endl;
|
||||||
std::cout << "PluginDir = " << PluginDir << std::endl;
|
std::cout << "PluginDir = " << PluginDir << std::endl;
|
||||||
|
|||||||
@ -79,7 +79,6 @@ class EQEmuConfig : public XMLParser
|
|||||||
// From <files/>
|
// From <files/>
|
||||||
std::string SpellsFile;
|
std::string SpellsFile;
|
||||||
std::string OpCodesFile;
|
std::string OpCodesFile;
|
||||||
std::string EQTimeFile;
|
|
||||||
|
|
||||||
// From <directories/>
|
// From <directories/>
|
||||||
std::string MapDir;
|
std::string MapDir;
|
||||||
@ -154,7 +153,6 @@ class EQEmuConfig : public XMLParser
|
|||||||
// Files
|
// Files
|
||||||
SpellsFile = "spells_us.txt";
|
SpellsFile = "spells_us.txt";
|
||||||
OpCodesFile = "opcodes.conf";
|
OpCodesFile = "opcodes.conf";
|
||||||
EQTimeFile = "eqtime.cfg";
|
|
||||||
// Dirs
|
// Dirs
|
||||||
MapDir = "Maps";
|
MapDir = "Maps";
|
||||||
QuestDir = "quests";
|
QuestDir = "quests";
|
||||||
|
|||||||
@ -133,72 +133,6 @@ int EQTime::SetCurrentEQTimeOfDay(TimeOfDay_Struct start_eq, time_t start_real)
|
|||||||
return 1;
|
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) {
|
bool EQTime::IsTimeBefore(TimeOfDay_Struct *base, TimeOfDay_Struct *test) {
|
||||||
if (base->year > test->year)
|
if (base->year > test->year)
|
||||||
return(true);
|
return(true);
|
||||||
|
|||||||
@ -39,12 +39,6 @@ public:
|
|||||||
|
|
||||||
static void ToString(TimeOfDay_Struct *t, std::string &str);
|
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:
|
private:
|
||||||
//This is our reference clock.
|
//This is our reference clock.
|
||||||
eqTimeOfDay eqTime;
|
eqTimeOfDay eqTime;
|
||||||
|
|||||||
11
utils/sql/git/required/2015_12_17_eqtime.sql
Normal file
11
utils/sql/git/required/2015_12_17_eqtime.sql
Normal file
@ -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);
|
||||||
@ -345,8 +345,11 @@ int main(int argc, char** argv) {
|
|||||||
database.ClearMerchantTemp();
|
database.ClearMerchantTemp();
|
||||||
}
|
}
|
||||||
Log.Out(Logs::General, Logs::World_Server, "Loading EQ time of day..");
|
Log.Out(Logs::General, Logs::World_Server, "Loading EQ time of day..");
|
||||||
if (!zoneserver_list.worldclock.loadFile(Config->EQTimeFile.c_str()))
|
TimeOfDay_Struct eqTime;
|
||||||
Log.Out(Logs::General, Logs::World_Server, "Unable to load %s", Config->EQTimeFile.c_str());
|
time_t realtime;
|
||||||
|
eqTime = database.LoadTime(realtime);
|
||||||
|
zoneserver_list.worldclock.SetCurrentEQTimeOfDay(eqTime, realtime);
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
@ -519,8 +522,10 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
void CatchSignal(int sig_num) {
|
void CatchSignal(int sig_num) {
|
||||||
Log.Out(Logs::General, Logs::World_Server,"Caught signal %d",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)
|
TimeOfDay_Struct eqTime;
|
||||||
Log.Out(Logs::General, Logs::World_Server,"Failed to save time file.");
|
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;
|
RunLoops = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -989,8 +989,8 @@ bool ZoneServer::Process() {
|
|||||||
Log.Out(Logs::Detail, Logs::World_Server,"Received SetWorldTime");
|
Log.Out(Logs::Detail, Logs::World_Server,"Received SetWorldTime");
|
||||||
eqTimeOfDay* newtime = (eqTimeOfDay*) pack->pBuffer;
|
eqTimeOfDay* newtime = (eqTimeOfDay*) pack->pBuffer;
|
||||||
zoneserver_list.worldclock.SetCurrentEQTimeOfDay(newtime->start_eqtime, newtime->start_realtime);
|
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);
|
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());
|
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();
|
zoneserver_list.SendTimeSync();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user