Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2008, 07:10 PM
Knightly
Accomplished Programmer
 
Join Date: Nov 2006
Location: Honolulu, HI
Posts: 91
Default #time off by an hour

The #time command is off by an hour. If you use #time it will return the current time, but that's one hour behind /time. This is because the code for #time counts from 0 to 23 (like a military clock) but eqTime.hour returns 1 - 24 due to the way the rest of EQ handles time.

This also happens when you use #time to set the time. If you say #time 23 then the time is set to 10pm (when it should be 11pm).

It's not really a bug and I'm sure that most people who use it are pretty good at taking it into account. However, I suck at it. I have enough trouble adding and subtracting 12 to get PM time in military time =P.

So, after that diatribe, the fix follows.

in zone\command.cpp we need to modify the command_time function from:
Code:
void command_time(Client *c, const Seperator *sep)
{
	// image - Redone by Scruffy
	char timeMessage[255];
	int minutes=0;
	if(sep->IsNumber(1)) {
		if(sep->IsNumber(2)) {
			minutes=atoi(sep->arg[2]);
		}
		c->Message(13, "Setting world time to %s:%i (Timezone: 0)...", sep->arg[1], minutes);
		zone->SetTime(atoi(sep->arg[1]), minutes);
	}
	else {
		c->Message(13, "To set the Time: #time HH [MM]");
		TimeOfDay_Struct eqTime;
		zone->zone_time.getEQTimeOfDay( time(0), &eqTime);
		sprintf(timeMessage,"%02d:%s%d %s (Timezone: %ih %im)",
			(eqTime.hour % 12) == 0 ? 12 : (eqTime.hour % 12),
			(eqTime.minute < 10) ? "0" : "",
			eqTime.minute,
			(eqTime.hour >= 12) ? "pm" : "am",
			zone->zone_time.getEQTimeZoneHr(),
			zone->zone_time.getEQTimeZoneMin()
			);
		c->Message(13, "It is now %s.", timeMessage);
#if EQDEBUG >= 11
		LogFile->write(EQEMuLog::Debug,"Recieved timeMessage:%s", timeMessage);
#endif
	}
}
To (changes in red):
Code:
void command_time(Client *c, const Seperator *sep)
{
	// image - Redone by Scruffy
	char timeMessage[255];
	int minutes=0;
	if(sep->IsNumber(1)) {
		if(sep->IsNumber(2)) {
			minutes=atoi(sep->arg[2]);
		}
		c->Message(13, "Setting world time to %s:%i (Timezone: 0)...", sep->arg[1], minutes);
		zone->SetTime(atoi(sep->arg[1])+1, minutes);
	}
	else {
		c->Message(13, "To set the Time: #time HH [MM]");
		TimeOfDay_Struct eqTime;
		zone->zone_time.getEQTimeOfDay( 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" : "",
			eqTime.minute,
			(eqTime.hour >= 13) ? "pm" : "am",
			zone->zone_time.getEQTimeZoneHr(),
			zone->zone_time.getEQTimeZoneMin()
			);
		c->Message(13, "It is now %s.", timeMessage);
#if EQDEBUG >= 11
		LogFile->write(EQEMuLog::Debug,"Recieved timeMessage:%s", timeMessage);
#endif
	}
}
I know there's some duplication of this code in zone\worldserver.cpp, so I assume that it can be changed as well. However I didn't test it. The change would be:
Code:
					sprintf(timeMessage,"EQTime [%02d:%s%d %s]",
						(eqTime.hour % 12) == 0 ? 12 : (eqTime.hour % 12),
						(eqTime.minute < 10) ? "0" : "",
						eqTime.minute,
						(eqTime.hour >= 12) ? "pm" : "am"
						);
To:
Code:
					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"
						);
Reply With Quote
  #2  
Old 01-13-2008, 09:11 PM
Knightly
Accomplished Programmer
 
Join Date: Nov 2006
Location: Honolulu, HI
Posts: 91
Default corollary

The corollary to this, of course, is that if you want Quests to use the same time settings when you are using quest::settime then you have to make a change to questmgr.cpp.

The change is from:
Code:
void QuestManager::settime(int8 new_hour, int8 new_min) {
	if (zone)
		zone->SetTime(new_hour, new_min);
}
to:
Code:
void QuestManager::settime(int8 new_hour, int8 new_min) {
	if (zone)
		zone->SetTime(new_hour + 1, new_min);
}
If you're using the PEQ Quests then you'll need to adjust the following files if you want things to stay the same:
iceclad\110115.pl
kithicor\20250.pl
lakerathe\51150.pl
timorous\#_#_4.pl

However, in looking at kithicor\20250.pl:
Code:
if ($shifter==20) {										#start night spawn
	quest::spawn_condition(kithicor, 2,0); #live are 2
	quest::spawn_condition(kithicor, 1,1); #undead are 1
	quest::settime(20,0);
}
This code actually starts night at 7:00pm before my questmgr change above. I always thought night started at 8:00pm, but I may be getting old. If you don't make the changes in the quests above, the only difference is that instead of night being 7pm to 7am, night is 8pm to 8am.

The quest:settime(24,0); line later in the file would normally be out of place (military time is 0:00 - 23:59 in a day so there is no 24). However, due to the way that the emulator handles the time code...24 actually becomes midnight, or 0 with the questmgr change above so there's nothing to worry about and in my laziness I just left it. So on my server, with unchanged PEQ Quest files, night starts at 8pm.
Reply With Quote
  #3  
Old 01-13-2008, 09:19 PM
Knightly
Accomplished Programmer
 
Join Date: Nov 2006
Location: Honolulu, HI
Posts: 91
Default

I should clarify the difference between 0 and 24 just for posterity:

Due to the way that the emulator handles the time code...after the questmgr change 24 actually becomes midnight on the next day (whereas 0 is midnight on the same day).

But you know, now that I've explained the difference between 24 and 0 on the new code...does that mean that the old shifter functions kept resetting the time to midnight on the same day? It's groundhog day!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 04:28 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3