diff --git a/changelog.txt b/changelog.txt index 6c5d695ab..cdb2fd5f8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,13 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- + +== 05/25/2015 == +Akkadius: Implemented disjointed zone based time, this can be triggered via quest methods +Akkadius: Added parameter to LUA and Perl method settime(hour, minute, [update_world = true]) + - If update_world is false, the zone will then unsubscribe itself from regular worldserver time synchronizations + - Basically this localizes the zones time and keeps it from syncing with world updates +Akkadius: Added DB ver 9082 with update to add npc_types texture columns if table does not currently have them + == 05/22/2015 == Uleat: Added null-term declaration for character names in ENCODE(OP_CharInfo) - where appropriate diff --git a/common/eqtime.cpp b/common/eqtime.cpp index 79301a28f..e504964b8 100644 --- a/common/eqtime.cpp +++ b/common/eqtime.cpp @@ -43,19 +43,19 @@ EQTime::EQTime(TimeOfDay_Struct start_eq, time_t start_real) EQTime::EQTime() { - timezone=0; + timezone = 0; memset(&eqTime, 0, sizeof(eqTime)); //Defaults for time TimeOfDay_Struct start; - start.day=1; - start.hour=9; - start.minute=0; - start.month=1; - start.year=3100; + start.day = 1; + start.hour = 9; + start.minute = 0; + start.month = 1; + start.year = 3100; //Set default time zone - timezone=0; + timezone = 0; //Start EQTimer - setEQTimeOfDay(start, time(0)); + SetCurrentEQTimeOfDay(start, time(0)); } EQTime::~EQTime() @@ -67,10 +67,10 @@ EQTime::~EQTime() //Input: Current Time (as a time_t), a pointer to the TimeOfDay_Struct that will be written to. //Output: 0=Error, 1=Sucess -int EQTime::getEQTimeOfDay( time_t timeConvert, struct TimeOfDay_Struct *eqTimeOfDay ) +int EQTime::GetCurrentEQTimeOfDay(time_t timeConvert, struct TimeOfDay_Struct *eqTimeOfDay) { /* check to see if we have a reference time to go by. */ - if( eqTime.start_realtime == 0 ) + if (eqTime.start_realtime == 0) return 0; unsigned long diff = timeConvert - eqTime.start_realtime; @@ -83,7 +83,7 @@ int EQTime::getEQTimeOfDay( time_t timeConvert, struct TimeOfDay_Struct *eqTimeO int32 ntz = timezone; /* The minutes range from 0 - 59 */ - diff += eqTime.start_eqtime.minute + (ntz%60); + diff += eqTime.start_eqtime.minute + (ntz % 60); eqTimeOfDay->minute = diff % 60; diff /= 60; ntz /= 60; @@ -97,24 +97,24 @@ int EQTime::getEQTimeOfDay( time_t timeConvert, struct TimeOfDay_Struct *eqTimeO // // Modify it so that it works from // 0-23 for our calculations - diff += ( eqTime.start_eqtime.hour - 1) + (ntz%24); - eqTimeOfDay->hour = (diff%24) + 1; + diff += (eqTime.start_eqtime.hour - 1) + (ntz % 24); + eqTimeOfDay->hour = (diff % 24) + 1; diff /= 24; ntz /= 24; // The days range from 1-28 // Modify it so that it works from // 0-27 for our calculations - diff += ( eqTime.start_eqtime.day - 1 ) + (ntz%28); - eqTimeOfDay->day = (diff%28) + 1; + diff += (eqTime.start_eqtime.day - 1) + (ntz % 28); + eqTimeOfDay->day = (diff % 28) + 1; diff /= 28; ntz /= 28; // The months range from 1-12 // Modify it so that it works from // 0-11 for our calculations - diff += ( eqTime.start_eqtime.month - 1 ) + (ntz%12); - eqTimeOfDay->month = (diff%12) + 1; + diff += (eqTime.start_eqtime.month - 1) + (ntz % 12); + eqTimeOfDay->month = (diff % 12) + 1; diff /= 12; ntz /= 12; @@ -124,12 +124,12 @@ int EQTime::getEQTimeOfDay( time_t timeConvert, struct TimeOfDay_Struct *eqTimeO } //setEQTimeOfDay -int EQTime::setEQTimeOfDay(TimeOfDay_Struct start_eq, time_t start_real) +int EQTime::SetCurrentEQTimeOfDay(TimeOfDay_Struct start_eq, time_t start_real) { - if(start_real==0) + if (start_real == 0) return 0; - eqTime.start_eqtime=start_eq; - eqTime.start_realtime=start_real; + eqTime.start_eqtime = start_eq; + eqTime.start_realtime = start_real; return 1; } @@ -139,7 +139,7 @@ bool EQTime::saveFile(const char *filename) { std::ofstream of; of.open(filename); - if(!of) + if (!of) { Log.Out(Logs::General, Logs::Error, "EQTime::saveFile failed: Unable to open file '%s'", filename); return false; @@ -200,24 +200,24 @@ bool EQTime::loadFile(const char *filename) bool EQTime::IsTimeBefore(TimeOfDay_Struct *base, TimeOfDay_Struct *test) { - if(base->year > test->year) + if (base->year > test->year) return(true); - if(base->year < test->year) + if (base->year < test->year) return(false); //same years - if(base->month > test->month) + if (base->month > test->month) return(true); - if(base->month < test->month) + if (base->month < test->month) return(false); //same month - if(base->day > test->day) + if (base->day > test->day) return(true); - if(base->day < test->day) + if (base->day < test->day) return(false); //same day - if(base->hour > test->hour) + if (base->hour > test->hour) return(true); - if(base->hour < test->hour) + if (base->hour < test->hour) return(false); //same hour... return(base->minute > test->minute); @@ -230,7 +230,7 @@ void EQTime::AddMinutes(uint32 minutes, TimeOfDay_Struct *to) { //minutes start at 0, everything else starts at 1 cur = to->minute; cur += minutes; - if(cur < 60) { + if (cur < 60) { to->minute = cur; return; } @@ -238,29 +238,29 @@ void EQTime::AddMinutes(uint32 minutes, TimeOfDay_Struct *to) { //carry hours cur /= 60; cur += to->hour; - if(cur <= 24) { + if (cur <= 24) { to->hour = cur; return; } - to->hour = ((cur-1) % 24) + 1; + to->hour = ((cur - 1) % 24) + 1; //carry days - cur = (cur-1) / 24; + cur = (cur - 1) / 24; cur += to->day; - if(cur <= 28) { + if (cur <= 28) { to->day = cur; return; } - to->day = ((cur-1) % 28) + 1; + to->day = ((cur - 1) % 28) + 1; //carry months - cur = (cur-1) / 28; + cur = (cur - 1) / 28; cur += to->month; - if(cur <= 12) { + if (cur <= 12) { to->month = cur; return; } - to->month = ((cur-1) % 12) + 1; + to->month = ((cur - 1) % 12) + 1; //carry years - to->year += (cur-1) / 12; + to->year += (cur - 1) / 12; } void EQTime::ToString(TimeOfDay_Struct *t, std::string &str) { @@ -269,5 +269,4 @@ void EQTime::ToString(TimeOfDay_Struct *t, std::string &str) { t->month, t->day, t->year, t->hour, t->minute); buf[127] = '\0'; str = buf; -} - +} \ No newline at end of file diff --git a/common/eqtime.h b/common/eqtime.h index aa608f307..aeda9f0f6 100644 --- a/common/eqtime.h +++ b/common/eqtime.h @@ -21,8 +21,8 @@ public: ~EQTime(); //Get functions - int getEQTimeOfDay( TimeOfDay_Struct *eqTimeOfDay ) { return(getEQTimeOfDay(time(nullptr), eqTimeOfDay)); } - int getEQTimeOfDay( time_t timeConvert, TimeOfDay_Struct *eqTimeOfDay ); + int GetCurrentEQTimeOfDay( TimeOfDay_Struct *eqTimeOfDay ) { return(GetCurrentEQTimeOfDay(time(nullptr), eqTimeOfDay)); } + int GetCurrentEQTimeOfDay( time_t timeConvert, TimeOfDay_Struct *eqTimeOfDay ); TimeOfDay_Struct getStartEQTime() { return eqTime.start_eqtime; } time_t getStartRealTime() { return eqTime.start_realtime; } uint32 getEQTimeZone() { return timezone; } @@ -30,7 +30,7 @@ public: uint32 getEQTimeZoneMin() { return timezone%60; } //Set functions - int setEQTimeOfDay(TimeOfDay_Struct start_eq, time_t start_real); + int SetCurrentEQTimeOfDay(TimeOfDay_Struct start_eq, time_t start_real); void setEQTimeZone(int32 in_timezone) { timezone=in_timezone; } //Time math/logic functions diff --git a/common/version.h b/common/version.h index 062afdecd..78f7a67b3 100644 --- a/common/version.h +++ b/common/version.h @@ -30,7 +30,7 @@ Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt */ -#define CURRENT_BINARY_DATABASE_VERSION 9080 +#define CURRENT_BINARY_DATABASE_VERSION 9082 #define COMPILE_DATE __DATE__ #define COMPILE_TIME __TIME__ #ifndef WIN32 diff --git a/utils/sql/db_update_manifest.txt b/utils/sql/db_update_manifest.txt index 34330f041..5ca25a029 100644 --- a/utils/sql/db_update_manifest.txt +++ b/utils/sql/db_update_manifest.txt @@ -335,6 +335,7 @@ 9079|2015_05_23_BuffDurations.sql|SHOW COLUMNS FROM `character_buffs` LIKE 'ticsremaining'|contains|unsigned| 9080|2015_05_23_PetBuffInstrumentMod.sql|SHOW COLUMNS FROM `character_pet_buffs` LIKE 'instrument_mod'|empty| 9081|2015_05_23_dbstr_us.sql|SHOW TABLES LIKE 'db_str'|empty| +9082|2015_05_25_npc_types_texture_fields.sql|SHOW COLUMNS FROM `npc_types` LIKE 'armtexture'|empty| # Upgrade conditions: # This won't be needed after this system is implemented, but it is used database that are not diff --git a/utils/sql/git/required/2015_05_25_npc_types_texture_fields.sql b/utils/sql/git/required/2015_05_25_npc_types_texture_fields.sql new file mode 100644 index 000000000..acd8d26b6 --- /dev/null +++ b/utils/sql/git/required/2015_05_25_npc_types_texture_fields.sql @@ -0,0 +1,6 @@ +ALTER TABLE npc_types +ADD COLUMN `armtexture` tinyint(2) NOT NULL DEFAULT '0' AFTER `raid_target`, +ADD COLUMN `bracertexture` tinyint(2) NOT NULL DEFAULT '0' AFTER `armtexture`, +ADD COLUMN `handtexture` tinyint(2) NOT NULL DEFAULT '0' AFTER `bracertexture`, +ADD COLUMN `legtexture` tinyint(2) NOT NULL DEFAULT '0' AFTER `handtexture`, +ADD COLUMN `feettexture` tinyint(2) NOT NULL DEFAULT '0' AFTER `legtexture`; \ No newline at end of file diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index b40f3dc04..17cac7f62 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -964,7 +964,7 @@ bool ZoneServer::Process() { case ServerOP_SetWorldTime: { Log.Out(Logs::Detail, Logs::World_Server,"Received SetWorldTime"); eqTimeOfDay* newtime = (eqTimeOfDay*) pack->pBuffer; - zoneserver_list.worldclock.setEQTimeOfDay(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); zoneserver_list.worldclock.saveFile(WorldConfig::get()->EQTimeFile.c_str()); zoneserver_list.SendTimeSync(); diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 3f40f3c00..9f527476c 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -1703,7 +1703,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) /* Time of Day packet */ outapp = new EQApplicationPacket(OP_TimeOfDay, sizeof(TimeOfDay_Struct)); TimeOfDay_Struct* tod = (TimeOfDay_Struct*)outapp->pBuffer; - zone->zone_time.getEQTimeOfDay(time(0), tod); + zone->zone_time.GetCurrentEQTimeOfDay(time(0), tod); outapp->priority = 6; FastQueuePacket(&outapp); diff --git a/zone/command.cpp b/zone/command.cpp index a62ee4ce8..a286f92bd 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -1369,7 +1369,7 @@ void command_date(Client *c, const Seperator *sep) else { int h=0, m=0; TimeOfDay_Struct eqTime; - zone->zone_time.getEQTimeOfDay( time(0), &eqTime); + zone->zone_time.GetCurrentEQTimeOfDay( time(0), &eqTime); if(!sep->IsNumber(4)) h=eqTime.hour; else @@ -1402,7 +1402,7 @@ void command_timezone(Client *c, const Seperator *sep) // Update all clients with new TZ. EQApplicationPacket* outapp = new EQApplicationPacket(OP_TimeOfDay, sizeof(TimeOfDay_Struct)); TimeOfDay_Struct* tod = (TimeOfDay_Struct*)outapp->pBuffer; - zone->zone_time.getEQTimeOfDay(time(0), tod); + zone->zone_time.GetCurrentEQTimeOfDay(time(0), tod); entity_list.QueueClients(c, outapp); safe_delete(outapp); } @@ -4393,7 +4393,7 @@ void command_time(Client *c, const Seperator *sep) else { c->Message(13, "To set the Time: #time HH [MM]"); TimeOfDay_Struct eqTime; - zone->zone_time.getEQTimeOfDay( time(0), &eqTime); + zone->zone_time.GetCurrentEQTimeOfDay( time(0), &eqTime); sprintf(timeMessage,"%02d:%s%d %s (Timezone: %ih %im)", ((eqTime.hour - 1) % 12) == 0 ? 12 : ((eqTime.hour - 1) % 12), (eqTime.minute < 10) ? "0" : "", diff --git a/zone/effects.cpp b/zone/effects.cpp index c814ea554..c1d037670 100644 --- a/zone/effects.cpp +++ b/zone/effects.cpp @@ -425,8 +425,15 @@ int32 Mob::GetActSpellDuration(uint16 spell_id, int32 duration) // a level 53 bard reported getting 2 tics if (IsShortDurationBuff(spell_id) && IsBardSong(spell_id) && spells[spell_id].mana == 0 && GetClass() == BARD && GetLevel() > 60) tic_inc++; + float focused = ((duration * increase) / 100.0f) + tic_inc; + int ifocused = static_cast(focused); - return (((duration * increase) / 100) + tic_inc); + // 7.6 is rounded to 7, 8.6 is rounded to 9 + // 6 is 6, etc + if (FCMP(focused, ifocused) || ifocused % 2) // equal or odd + return ifocused; + else // even and not equal round to odd + return ifocused + 1; } int32 Client::GetActSpellCasttime(uint16 spell_id, int32 casttime) diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 326585806..d571dce24 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -1072,7 +1072,7 @@ void PerlembParser::ExportZoneVariables(std::string &package_name) { ExportVar(package_name.c_str(), "instanceid", zone->GetInstanceID()); ExportVar(package_name.c_str(), "instanceversion", zone->GetInstanceVersion()); TimeOfDay_Struct eqTime; - zone->zone_time.getEQTimeOfDay( time(0), &eqTime); + zone->zone_time.GetCurrentEQTimeOfDay( time(0), &eqTime); ExportVar(package_name.c_str(), "zonehour", eqTime.hour - 1); ExportVar(package_name.c_str(), "zonemin", eqTime.minute); ExportVar(package_name.c_str(), "zonetime", (eqTime.hour - 1) * 100 + eqTime.minute); diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index 800ed9f83..6db7777ac 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -1182,13 +1182,26 @@ XS(XS__settime); XS(XS__settime) { dXSARGS; - if (items != 2) - Perl_croak(aTHX_ "Usage: settime(new_hour, new_min)"); + if (items < 2) + Perl_croak(aTHX_ "Usage: settime(new_hour, new_min, [update_world = true])"); - int new_hour = (int)SvIV(ST(0)); - int new_min = (int)SvIV(ST(1)); + if (items == 2){ + int new_hour = (int)SvIV(ST(0)); + int new_min = (int)SvIV(ST(1)); + quest_manager.settime(new_hour, new_min, true); + } + else if (items == 3){ + int new_hour = (int)SvIV(ST(0)); + int new_min = (int)SvIV(ST(1)); - quest_manager.settime(new_hour, new_min); + int update_world = (int)SvIV(ST(2)); + if (update_world == 1){ + quest_manager.settime(new_hour, new_min, true); + } + else{ + quest_manager.settime(new_hour, new_min, false); + } + } XSRETURN_EMPTY; } diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 59a5d3740..6b290dc03 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -386,7 +386,11 @@ void lua_create_guild(const char *name, const char *leader) { } void lua_set_time(int hour, int min) { - quest_manager.settime(hour, min); + quest_manager.settime(hour, min, true); +} + +void lua_set_time(int hour, int min, bool update_world) { + quest_manager.settime(hour, min, update_world); } void lua_signal(int npc_id, int signal_id) { @@ -979,7 +983,7 @@ int lua_get_zone_weather() { luabind::adl::object lua_get_zone_time(lua_State *L) { TimeOfDay_Struct eqTime; - zone->zone_time.getEQTimeOfDay(time(0), &eqTime); + zone->zone_time.GetCurrentEQTimeOfDay(time(0), &eqTime); luabind::adl::object ret = luabind::newtable(L); ret["zone_hour"] = eqTime.hour - 1; @@ -1467,7 +1471,8 @@ luabind::scope lua_register_general() { luabind::def("set_sky", &lua_set_sky), luabind::def("set_guild", &lua_set_guild), luabind::def("create_guild", &lua_create_guild), - luabind::def("set_time", &lua_set_time), + luabind::def("set_time", (void(*)(int, int))&lua_set_time), + luabind::def("set_time", (void(*)(int, int, bool))&lua_set_time), luabind::def("signal", (void(*)(int,int))&lua_signal), luabind::def("signal", (void(*)(int,int,int))&lua_signal), luabind::def("set_global", &lua_set_global), diff --git a/zone/perl_npc.cpp b/zone/perl_npc.cpp index 861759d12..0c9cec797 100644 --- a/zone/perl_npc.cpp +++ b/zone/perl_npc.cpp @@ -823,7 +823,7 @@ XS(XS_NPC_RemoveFromHateList) if(ent == nullptr) Perl_croak(aTHX_ "ent is nullptr, avoiding crash."); - THIS->CastToMob()->RemoveFromHateList(ent); + THIS->RemoveFromHateList(ent); } XSRETURN_EMPTY; diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index b9025956e..6b5c8978d 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -1292,9 +1292,10 @@ void QuestManager::CreateGuild(const char *guild_name, const char *leader) { } } -void QuestManager::settime(uint8 new_hour, uint8 new_min) { +void QuestManager::settime(uint8 new_hour, uint8 new_min, bool update_world /*= true*/) +{ if (zone) - zone->SetTime(new_hour + 1, new_min); + zone->SetTime(new_hour + 1, new_min, update_world); } void QuestManager::itemlink(int item_id) { diff --git a/zone/questmgr.h b/zone/questmgr.h index b278e2c2a..879407dc6 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -126,7 +126,7 @@ public: void setsky(uint8 new_sky); void setguild(uint32 new_guild_id, uint8 new_rank); void CreateGuild(const char *guild_name, const char *leader); - void settime(uint8 new_hour, uint8 new_min); + void settime(uint8 new_hour, uint8 new_min, bool update_world = true); void itemlink(int item_id); void signal(int npc_id, int wait_ms = 0); void signalwith(int npc_id, int signal_id, int wait_ms = 0); diff --git a/zone/spawn2.cpp b/zone/spawn2.cpp index c0eafea80..c42356ea9 100644 --- a/zone/spawn2.cpp +++ b/zone/spawn2.cpp @@ -624,7 +624,7 @@ void SpawnConditionManager::Process() { //get our current time TimeOfDay_Struct tod; - zone->zone_time.getEQTimeOfDay(&tod); + zone->zone_time.GetCurrentEQTimeOfDay(&tod); //see if time is past our nearest event. if(EQTime::IsTimeBefore(&next_event, &tod)) @@ -673,7 +673,7 @@ void SpawnConditionManager::ExecEvent(SpawnEvent &event, bool send_update) { } TimeOfDay_Struct tod; - zone->zone_time.getEQTimeOfDay(&tod); + zone->zone_time.GetCurrentEQTimeOfDay(&tod); if(event.strict && (event.next.hour != tod.hour || event.next.day != tod.day || event.next.month != tod.month || event.next.year != tod.year)) { Log.Out(Logs::Detail, Logs::Spawns, "Event %d: Unable to execute. Condition is strict, and event time has already passed.", event.id); @@ -871,7 +871,7 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in //better solution, and I just dont care thats much. //get our current time TimeOfDay_Struct tod; - zone->zone_time.getEQTimeOfDay(&tod); + zone->zone_time.GetCurrentEQTimeOfDay(&tod); for(auto cur = spawn_events.begin(); cur != spawn_events.end(); ++cur) { SpawnEvent &cevent = *cur; @@ -1096,7 +1096,7 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool stri if(reset_base) { Log.Out(Logs::Detail, Logs::Spawns, "Spawn event %d located in this zone. State set. Trigger time reset (period %d).", event_id, cevent.period); //start with the time now - zone->zone_time.getEQTimeOfDay(&cevent.next); + zone->zone_time.GetCurrentEQTimeOfDay(&cevent.next); //advance the next time by our period EQTime::AddMinutes(cevent.period, &cevent.next); } else { @@ -1141,7 +1141,7 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool stri if(reset_base) { Log.Out(Logs::Detail, Logs::Spawns, "Spawn event %d is in zone %s. State set. Trigger time reset (period %d). Notifying world.", event_id, zone_short_name.c_str(), e.period); //start with the time now - zone->zone_time.getEQTimeOfDay(&e.next); + zone->zone_time.GetCurrentEQTimeOfDay(&e.next); //advance the next time by our period EQTime::AddMinutes(e.period, &e.next); } else { diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index aa3e32d43..517106aca 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -742,32 +742,36 @@ void WorldServer::Process() { break; } case ServerOP_SyncWorldTime: { - if(zone!=0) { + if (zone != 0 && !zone->is_zone_time_localized) { Log.Out(Logs::Moderate, Logs::Zone_Server, "%s Received Message SyncWorldTime", __FUNCTION__); - eqTimeOfDay* newtime = (eqTimeOfDay*) pack->pBuffer; - zone->zone_time.setEQTimeOfDay(newtime->start_eqtime, newtime->start_realtime); + + eqTimeOfDay* newtime = (eqTimeOfDay*)pack->pBuffer; + zone->zone_time.SetCurrentEQTimeOfDay(newtime->start_eqtime, newtime->start_realtime); EQApplicationPacket* outapp = new EQApplicationPacket(OP_TimeOfDay, sizeof(TimeOfDay_Struct)); - TimeOfDay_Struct* tod = (TimeOfDay_Struct*)outapp->pBuffer; - zone->zone_time.getEQTimeOfDay(time(0), tod); + TimeOfDay_Struct* time_of_day = (TimeOfDay_Struct*)outapp->pBuffer; + zone->zone_time.GetCurrentEQTimeOfDay(time(0), time_of_day); entity_list.QueueClients(0, outapp, false); safe_delete(outapp); - //TEST - char timeMessage[255]; - time_t timeCurrent = time(nullptr); - TimeOfDay_Struct eqTime; - zone->zone_time.getEQTimeOfDay( timeCurrent, &eqTime); - //if ( eqTime.hour >= 0 && eqTime.minute >= 0 ) - //{ - sprintf(timeMessage,"EQTime [%02d:%s%d %s]", - ((eqTime.hour - 1) % 12) == 0 ? 12 : ((eqTime.hour - 1) % 12), - (eqTime.minute < 10) ? "0" : "", - eqTime.minute, - (eqTime.hour >= 13) ? "pm" : "am" - ); - Log.Out(Logs::General, Logs::Zone_Server, "Time Broadcast Packet: %s", timeMessage); - zone->GotCurTime(true); - //} - //Test + + /* Buffer garbage to generate debug message */ + char time_message[255]; + time_t current_time = time(nullptr); + TimeOfDay_Struct eq_time; + zone->zone_time.GetCurrentEQTimeOfDay(current_time, &eq_time); + + sprintf(time_message, "EQTime [%02d:%s%d %s]", + ((eq_time.hour - 1) % 12) == 0 ? 12 : ((eq_time.hour - 1) % 12), + (eq_time.minute < 10) ? "0" : "", + eq_time.minute, + (eq_time.hour >= 13) ? "pm" : "am" + ); + + Log.Out(Logs::General, Logs::Zone_Server, "Time Broadcast Packet: %s", time_message); + zone->SetZoneHasCurrentTime(true); + + } + if (zone->is_zone_time_localized){ + Log.Out(Logs::General, Logs::Zone_Server, "Received request to sync time from world, but our time is localized currently"); } break; } diff --git a/zone/zone.cpp b/zone/zone.cpp index 3bf2173c9..e58bea24a 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -697,7 +697,7 @@ void Zone::Shutdown(bool quite) Log.Out(Logs::General, Logs::Status, "Zone Shutdown: %s (%i)", zone->GetShortName(), zone->GetZoneID()); petition_list.ClearPetitions(); - zone->GotCurTime(false); + zone->SetZoneHasCurrentTime(false); if (!quite) Log.Out(Logs::General, Logs::Normal, "Zone shutdown: going to sleep"); ZoneLoaded = false; @@ -760,6 +760,8 @@ Zone::Zone(uint32 in_zoneid, uint32 in_instanceid, const char* in_short_name) qGlobals = nullptr; default_ruleset = 0; + is_zone_time_localized = false; + loglevelvar = 0; merchantvar = 0; tradevar = 0; @@ -805,7 +807,7 @@ Zone::Zone(uint32 in_zoneid, uint32 in_instanceid, const char* in_short_name) totalBS = 0; aas = nullptr; totalAAs = 0; - gottime = false; + zone_has_current_time = false; Instance_Shutdown_Timer = nullptr; bool is_perma = false; @@ -1484,7 +1486,7 @@ void Zone::Repop(uint32 delay) { void Zone::GetTimeSync() { - if (worldserver.Connected() && !gottime) { + if (worldserver.Connected() && !zone_has_current_time) { ServerPacket* pack = new ServerPacket(ServerOP_GetWorldTime, 0); worldserver.SendPacket(pack); safe_delete(pack); @@ -1508,17 +1510,42 @@ void Zone::SetDate(uint16 year, uint8 month, uint8 day, uint8 hour, uint8 minute } } -void Zone::SetTime(uint8 hour, uint8 minute) +void Zone::SetTime(uint8 hour, uint8 minute, bool update_world /*= true*/) { if (worldserver.Connected()) { ServerPacket* pack = new ServerPacket(ServerOP_SetWorldTime, sizeof(eqTimeOfDay)); - eqTimeOfDay* eqtod = (eqTimeOfDay*)pack->pBuffer; - zone_time.getEQTimeOfDay(time(0), &eqtod->start_eqtime); - eqtod->start_eqtime.minute=minute; - eqtod->start_eqtime.hour=hour; - eqtod->start_realtime=time(0); - printf("Setting master time on world server to: %d:%d (%d)\n", hour, minute, (int)eqtod->start_realtime); - worldserver.SendPacket(pack); + eqTimeOfDay* eq_time_of_day = (eqTimeOfDay*)pack->pBuffer; + + zone_time.GetCurrentEQTimeOfDay(time(0), &eq_time_of_day->start_eqtime); + + eq_time_of_day->start_eqtime.minute = minute; + eq_time_of_day->start_eqtime.hour = hour; + eq_time_of_day->start_realtime = time(0); + + /* By Default we update worlds time, but we can optionally no update world which updates the rest of the zone servers */ + if (update_world){ + Log.Out(Logs::General, Logs::Zone_Server, "Setting master time on world server to: %d:%d (%d)\n", hour, minute, (int)eq_time_of_day->start_realtime); + worldserver.SendPacket(pack); + + /* Set Time Localization Flag */ + zone->is_zone_time_localized = false; + } + /* When we don't update world, we are localizing ourselves, we become disjointed from normal syncs and set time locally */ + else{ + + Log.Out(Logs::General, Logs::Zone_Server, "Setting zone localized time..."); + + zone->zone_time.SetCurrentEQTimeOfDay(eq_time_of_day->start_eqtime, eq_time_of_day->start_realtime); + EQApplicationPacket* outapp = new EQApplicationPacket(OP_TimeOfDay, sizeof(TimeOfDay_Struct)); + TimeOfDay_Struct* time_of_day = (TimeOfDay_Struct*)outapp->pBuffer; + zone->zone_time.GetCurrentEQTimeOfDay(time(0), time_of_day); + entity_list.QueueClients(0, outapp, false); + safe_delete(outapp); + + /* Set Time Localization Flag */ + zone->is_zone_time_localized = true; + } + safe_delete(pack); } } diff --git a/zone/zone.h b/zone/zone.h index 80e0473f2..7b1b855a7 100644 --- a/zone/zone.h +++ b/zone/zone.h @@ -43,6 +43,7 @@ struct ZonePoint int32 target_zone_instance; uint32 client_version_mask; }; + struct ZoneClientAuth_Struct { uint32 ip; // client's IP address uint32 wid; // client's WorldID# @@ -85,6 +86,10 @@ public: Zone(uint32 in_zoneid, uint32 in_instanceid, const char* in_short_name); ~Zone(); + + /* When zone has its own version of time */ + bool is_zone_time_localized; + bool Init(bool iStaticZone); bool LoadZoneCFG(const char* filename, uint16 instance_id, bool DontLoadDefault = false); bool SaveZoneCFG(); @@ -153,7 +158,7 @@ public: inline bool InstantGrids() { return(!initgrids_timer.Enabled()); } void SetStaticZone(bool sz) { staticzone = sz; } inline bool IsStaticZone() { return staticzone; } - inline void GotCurTime(bool time) { gottime = time; } + inline void SetZoneHasCurrentTime(bool time) { zone_has_current_time = time; } void SpawnConditionChanged(const SpawnCondition &c, int16 old_value); @@ -206,7 +211,7 @@ public: EQTime zone_time; void GetTimeSync(); void SetDate(uint16 year, uint8 month, uint8 day, uint8 hour, uint8 minute); - void SetTime(uint8 hour, uint8 minute); + void SetTime(uint8 hour, uint8 minute, bool update_world = true); void weatherSend(); bool CanBind() const { return(can_bind); } @@ -319,7 +324,7 @@ private: bool staticzone; - bool gottime; + bool zone_has_current_time; uint32 pQueuedMerchantsWorkID; uint32 pQueuedTempMerchantsWorkID;