Skip to content

Commit

Permalink
Implemented disjointed zone based time, this can be triggered via que…
Browse files Browse the repository at this point in the history
…st methods

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
Added DB ver 9082 with update to add npc_types texture columns if table does not currently have them
  • Loading branch information
Akkadius committed May 26, 2015
1 parent b06e1c2 commit ee13688
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 65 deletions.
7 changes: 7 additions & 0 deletions changelog.txt
@@ -1,5 +1,12 @@
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
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

Expand Down
6 changes: 3 additions & 3 deletions common/eqtime.cpp
Expand Up @@ -55,7 +55,7 @@ EQTime::EQTime()
//Set default time zone
timezone=0;
//Start EQTimer
setEQTimeOfDay(start, time(0));
SetCurrentEQTimeOfDay(start, time(0));
}

EQTime::~EQTime()
Expand All @@ -67,7 +67,7 @@ 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 )
Expand Down Expand Up @@ -124,7 +124,7 @@ 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)
return 0;
Expand Down
6 changes: 3 additions & 3 deletions common/eqtime.h
Expand Up @@ -21,16 +21,16 @@ class EQTime
~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; }
uint32 getEQTimeZoneHr() { return timezone/60; }
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
Expand Down
2 changes: 1 addition & 1 deletion common/version.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions utils/sql/db_update_manifest.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion world/zoneserver.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion zone/client_packet.cpp
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions zone/command.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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" : "",
Expand Down
2 changes: 1 addition & 1 deletion zone/embparser.cpp
Expand Up @@ -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);
Expand Down
23 changes: 18 additions & 5 deletions zone/embparser_api.cpp
Expand Up @@ -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;
}
Expand Down
11 changes: 8 additions & 3 deletions zone/lua_general.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions zone/questmgr.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion zone/questmgr.h
Expand Up @@ -126,7 +126,7 @@ class QuestManager {
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);
Expand Down
10 changes: 5 additions & 5 deletions zone/spawn2.cpp
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
48 changes: 26 additions & 22 deletions zone/worldserver.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit ee13688

Please sign in to comment.