Time in a multiserver environment
Moderators: ALFA Administrators, Staff - Technical
- AcadiusLost
- Chosen of Forumamus, God of Forums
- Posts: 5061
- Joined: Tue Oct 19, 2004 8:38 am
- Location: Montara, CA [GMT -8]
- Contact:
Time in a multiserver environment
OK, persistent time is poised to get a good deal more complicated once we bring Baldur's Gate online. So far, the eccentricities of the server time/date haven't been a serious inconvenience, since the skips were always skips forward. So, you might log in to get fully healed when you might have only justified one days' rest worth by the amount of time you'd been logged out, etc. No big deal.
However, if we imagine two servers running independent "clocks/calenders", we run into a more serious problem. PC A leaves TSM having rested and prayed for spells on "April 15th" server-time, and portals into Baldur's Gate, only to find it's still February on the game-calendar there. Suddenly instead of having to wait 24 game-hours (2.8 RL hours) to get spell restoration, PC A might be looking at having to wait 2+ "game months" to catch up to that resting timestamp. Needless to say, that's not really what we want.
We could juggle the timestamps for resting/praying/studying OnEnter of at the destination server, but that's an extra pile of work to manage.
Alternatively, we could "start" BG from the same servertimestamp as TSM when it goes Live. However, that would just mean it would get progressively further out of sync from there as time goes on (depending which server ends up with more uptime). Probably the easiest solution, though.
Or, we could designate one server as the "time reference server", and match to the current timestamp from that server with each module reset of others. This wouldn't be much work, but could pose problems if the "reference" server was offline for any significant amount of time.
Lastly, we could try to tie the server time to the real-world time we can obtain from the SQL database; since the servers already rely on this DB for all other persistency matters. Might be the best way to go about things (certainly the best if we wanted to start mapping actual game-dates to actual RL calendar dates), but also would be a nontrivial amount of coding and testing involved.
Thoughts, opinions? I'm a bit tempted to just slave other servers to TSM's timestamp for now, maybe with some accounting for how to switch master servers down the line if necessary. But; it's certainly up for discussion and suggestions at this point.
However, if we imagine two servers running independent "clocks/calenders", we run into a more serious problem. PC A leaves TSM having rested and prayed for spells on "April 15th" server-time, and portals into Baldur's Gate, only to find it's still February on the game-calendar there. Suddenly instead of having to wait 24 game-hours (2.8 RL hours) to get spell restoration, PC A might be looking at having to wait 2+ "game months" to catch up to that resting timestamp. Needless to say, that's not really what we want.
We could juggle the timestamps for resting/praying/studying OnEnter of at the destination server, but that's an extra pile of work to manage.
Alternatively, we could "start" BG from the same servertimestamp as TSM when it goes Live. However, that would just mean it would get progressively further out of sync from there as time goes on (depending which server ends up with more uptime). Probably the easiest solution, though.
Or, we could designate one server as the "time reference server", and match to the current timestamp from that server with each module reset of others. This wouldn't be much work, but could pose problems if the "reference" server was offline for any significant amount of time.
Lastly, we could try to tie the server time to the real-world time we can obtain from the SQL database; since the servers already rely on this DB for all other persistency matters. Might be the best way to go about things (certainly the best if we wanted to start mapping actual game-dates to actual RL calendar dates), but also would be a nontrivial amount of coding and testing involved.
Thoughts, opinions? I'm a bit tempted to just slave other servers to TSM's timestamp for now, maybe with some accounting for how to switch master servers down the line if necessary. But; it's certainly up for discussion and suggestions at this point.
Re: Time in a multiserver environment
Is there a central SQL database stored somewhere (like the vault?) If so, this would be the cleanest solution, esp if the central server could use something like NTP.
If the time would be pulled from local timestamps it gets a lot messier, with conversions, clock drift, etc.
If the time would be pulled from local timestamps it gets a lot messier, with conversions, clock drift, etc.
- AcadiusLost
- Chosen of Forumamus, God of Forums
- Posts: 5061
- Joined: Tue Oct 19, 2004 8:38 am
- Location: Montara, CA [GMT -8]
- Contact:
Re: Time in a multiserver environment
We know the server clock slips forward. So, yes, real-world timestamps from the SQL database would be more reliable.
However, we run into problems any time we have the clock/calender moving backwards on a mod reset. PC's start needing to wait > 24 game-hours to rest, offline resting calculations fail, etc. The clock running forward doesn't really inconvenience anyone in-game.
We could check for the server with the largest timestamp, then use that one, I suppose... it'd accelerate the clock drift forward, but it would keep us safely out of the mess.
However, we run into problems any time we have the clock/calender moving backwards on a mod reset. PC's start needing to wait > 24 game-hours to rest, offline resting calculations fail, etc. The clock running forward doesn't really inconvenience anyone in-game.
We could check for the server with the largest timestamp, then use that one, I suppose... it'd accelerate the clock drift forward, but it would keep us safely out of the mess.
Re: Time in a multiserver environment
Hmm, I would think it would be best to use a system that is as simple to maintain as possible. I'm not opposed to syncing BG to TSM as a master time reference, if that is simple and will work well enough. Might run it by Ayergo though. I don't really understand the mechanics of all this, but perhaps the KISS principle applies.
- Brokenbone
- Chosen of Forumamus, God of Forums
- Posts: 5771
- Joined: Mon May 16, 2005 1:07 am
- Location: London, Ontario, Canada
Re: Time in a multiserver environment
KISS sounds like tying somehow to a RL clock... synching multiple fantasy gaming environments to each other, even with one as a "master" = WTF.
Knowing "hey it's been about 24 hours since I played, odds are my PC's been having a good restful nap" regardless of whether the logout was on server A, B, or C, seems simple. Otherwise what are you supposed to do, have data stored on each character file based on the time they logged into a server (depending even on how portalling works, I remember people who'd jump into Q just to say hi to friends in game in NWN1, wouldn't want them to attract "clock attention" for a Q visit)...?
Anyhow, some thoughts probably rife with ignorance, take them for the little they're worth. Server uptime, downtime, ill advised jumps of the clock and whatnot, if your DB can look at a RL clock instead of unreliable IG ones, more power to you.
Knowing "hey it's been about 24 hours since I played, odds are my PC's been having a good restful nap" regardless of whether the logout was on server A, B, or C, seems simple. Otherwise what are you supposed to do, have data stored on each character file based on the time they logged into a server (depending even on how portalling works, I remember people who'd jump into Q just to say hi to friends in game in NWN1, wouldn't want them to attract "clock attention" for a Q visit)...?
Anyhow, some thoughts probably rife with ignorance, take them for the little they're worth. Server uptime, downtime, ill advised jumps of the clock and whatnot, if your DB can look at a RL clock instead of unreliable IG ones, more power to you.
ALFA NWN2 PCs: Rhaggot of the Bruised-Eye, and Bamshogbo
ALFA NWN1 PC: Jacobim Foxmantle
ALFA NWN1 Dead PC: Jon Shieldjack
DMA Staff
ALFA NWN1 PC: Jacobim Foxmantle
ALFA NWN1 Dead PC: Jon Shieldjack
DMA Staff
Re: Time in a multiserver environment
My initial thought was just to trust the players, but I think it's too far gone for that. Really just don't have a clue on the mechanics so I think I'll bow out. I think it might be worth asking Ayergo and Curm what they think?
- Curmudgeon
- Gadfly
- Posts: 4312
- Joined: Thu Oct 07, 2004 12:07 am
- Location: East coast US
Re: Time in a multiserver environment
I'm in favor of synching either to the SQL server clock or to my favorite clock standard: the USNO Master Clock, whichever is easier.
- Curmudgeon
HDM ALFA 03 - The Silver Marches
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Maxim #12: A soft answer turneth away wrath. Once wrath is looking the other way, shoot it in the head." - The Seventy Maxims of Maximally Effective Mercenaries
"This is not my circus. These are not my monkeys."
Realmslore: Daily Dwarf Common
HDM ALFA 03 - The Silver Marches
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Maxim #12: A soft answer turneth away wrath. Once wrath is looking the other way, shoot it in the head." - The Seventy Maxims of Maximally Effective Mercenaries
"This is not my circus. These are not my monkeys."
Realmslore: Daily Dwarf Common
Re: Time in a multiserver environment
I'd have to see the code, but I'd think the simplest solution would be that if time since last rest is in the negatives, time since last rest should be set to 0. That way, the worst case scenario would be that the player has to wait for 24 hours before they can rest again. Setting it to 24 hours would work as well.
Giant skips ahead in time on a server transition wouldn't mean much as it'd take days to travel between servers anyway.
I'd do it on all PC server entry events, even if not portalling between servers. That way you'd avoid the situation from tonight where it tells me it will be 127000 odd hours before I can rest again.
Giant skips ahead in time on a server transition wouldn't mean much as it'd take days to travel between servers anyway.
I'd do it on all PC server entry events, even if not portalling between servers. That way you'd avoid the situation from tonight where it tells me it will be 127000 odd hours before I can rest again.
Current PCs:
NWN1: Soppi Widenbottle, High Priestess of Yondalla.
NWN2: Gruuhilda, Tree Hugging Half-Orc
NWN1: Soppi Widenbottle, High Priestess of Yondalla.
NWN2: Gruuhilda, Tree Hugging Half-Orc
- AcadiusLost
- Chosen of Forumamus, God of Forums
- Posts: 5061
- Joined: Tue Oct 19, 2004 8:38 am
- Location: Montara, CA [GMT -8]
- Contact:
Re: Time in a multiserver environment
Still uncertain about this: I don't much like the idea of compounding the clock creep by syncing any reloading server to the highest timestamp in the database, but TSM's random server calender reset (after which the ACR was telling everyone they couldn't rest for another 27900 hours) reinforced the problems we face with relative clock rollbacks.
Seems like querying the DB for all server timestamps, then picking the highest to sync to is the most robust and interchangable approach. Let's just hope DMs aren't using the "Adjust Time" options in the DMFI, since they'll be pushing the clock on /all/ the servers when they do so (albeit in a delayed-effect manner).
I'll need to code this up briefly before we get crosserver portalling testing, but it should be a quick fix.
Seems like querying the DB for all server timestamps, then picking the highest to sync to is the most robust and interchangable approach. Let's just hope DMs aren't using the "Adjust Time" options in the DMFI, since they'll be pushing the clock on /all/ the servers when they do so (albeit in a delayed-effect manner).
I'll need to code this up briefly before we get crosserver portalling testing, but it should be a quick fix.
Re: Time in a multiserver environment
OK, I had a look for the code, but couldn't find the last rest time code on PC enter. So I derived this from the resting scripts. Even if you don't use it as the final solution, you should probably use it as a backup validation check and resolution.
Just slot it in before refreshing HPs, spells, uses/day thing. (Which is the part I couldn't find...)
(untested)
Code: Select all
// Get the time the PC last rested and compare it to the current server time. If the last rest time is in the future, set the last rest time to the current time.
int nLastRestTimeStamp = ACR_GetPersistentInt(oPC, ACR_REST_TIMER);
if ((ACR_GetTimeStampInHours() - nLastRestTimeStamp) < 0) {
ACR_SetPersistentInt(oPC, ACR_REST_TIMER, ACR_GetTimeStampInHours()); // Maybe use: ACR_GetTimeStampInHours() - 24
}
(untested)
Current PCs:
NWN1: Soppi Widenbottle, High Priestess of Yondalla.
NWN2: Gruuhilda, Tree Hugging Half-Orc
NWN1: Soppi Widenbottle, High Priestess of Yondalla.
NWN2: Gruuhilda, Tree Hugging Half-Orc
Re: Time in a multiserver environment
Is there any option that permits DMs to advance time? I'd be in favor of a system that gives players the benefit of the doubt when it comes to resting, if it allows DMs to control the day/night cycle. I trust our screening system and players enough to relax the resting/praying mechanics in order to allow DMs to alter time.AcadiusLost wrote:Let's just hope DMs aren't using the "Adjust Time" options in the DMFI, since they'll be pushing the clock on /all/ the servers when they do so (albeit in a delayed-effect manner).
Re: Time in a multiserver environment
Assuming you are referring to game time as opposed to real time. Real time was pulled from the database any time it was needed.
I coded a system for the Realms of the Dragon Reach, hereafter the RDR, that kept the servers synched both to time as well as to Seconds Since Began (SSB ). In its simplest form when a server came on line, it checked the database to see if it was the only one online. If so, it picked up the latest time and set itself to that time.
Regularly, each server sent its time to the database updating it. This was about every 15 seconds or so if I remember correctly. Any servers coming on line after that point simply pulled the time and set themselves.
Thus, if there were one or more servers down, the player’s status based on time (wounds, rest, etc) would be very close to correct when the server came up.
If players left the server, it was also recorded into their record when they did and then the time was synched appropriately when they returned.
I’ll dig into my code and pull up the scripts. I still need to figure out your coding and systems before I can suggest if my stuff could be easily pulled into the environment.
Stormsong Wyndsinger
Bard at large and
Adventurer for hire
I coded a system for the Realms of the Dragon Reach, hereafter the RDR, that kept the servers synched both to time as well as to Seconds Since Began (SSB ). In its simplest form when a server came on line, it checked the database to see if it was the only one online. If so, it picked up the latest time and set itself to that time.
Regularly, each server sent its time to the database updating it. This was about every 15 seconds or so if I remember correctly. Any servers coming on line after that point simply pulled the time and set themselves.
Thus, if there were one or more servers down, the player’s status based on time (wounds, rest, etc) would be very close to correct when the server came up.
If players left the server, it was also recorded into their record when they did and then the time was synched appropriately when they returned.
I’ll dig into my code and pull up the scripts. I still need to figure out your coding and systems before I can suggest if my stuff could be easily pulled into the environment.
Stormsong Wyndsinger
Bard at large and
Adventurer for hire
Stormsong Wyndsinger
- Bard at large, Adventurer for hire,
Scripter, Builder and Silly Person
Re: Time in a multiserver environment
I would recommend chatting with AcadiusLost on IRC as he is our foremost tech guy and will be able to give you the straightest answers on what we are using, and where to find our current scripts, etc.