View previous topic :: View next topic |
Author |
Message |
Clisair
Joined: 27 Jun 2006 Posts: 9
|
Posted: Wed Jan 02, 2008 21:41 Post subject: Need to find real time for resets - NWNX2 |
|
|
I need a way to do resets on the server at a given time of day. I have the reset plugin and will be using that, but have no idea how to get the real time of the server in a reliable way.
I have searched the forums and I know there is a plugin for it, but it requires too much other stuff to be installed, stuff that I would never even use at all - ever...
Anyway, how do I do this so that I can reboot nwserver at a set time every day? _________________ Firinn Of Elisair
http://www.elisair.com/ |
|
Back to top |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Thu Jan 03, 2008 12:06 Post subject: |
|
|
Unix timestamp is probably your best bet if you are using MySQL. Here's a couple functions using them, authored by acaos:
Code: | void ListServers (object oPC) {
int nCheck, nUptime;
object oMod = GetModule();
string sServer = GetLocalString(oMod, "ServerNumber");
string sMessage = "It is currently " + GetLocalString(oMod, "utctime") + " UTC.\n";
SQLExecDirect("SELECT server, boottime, uptime, UNIX_TIMESTAMP() - boottime " +
"FROM servers WHERE server <> '" + sServer + "' ORDER BY server");
while (SQLFetch() != SQL_ERROR) {
sServer = SQLGetData(1);
nUptime = StringToInt(SQLGetData(3));
nCheck = StringToInt(SQLGetData(4));
if (nCheck > nUptime + 60)
sMessage += COLOR_RED;
else if (nUptime >= 43200)
sMessage += COLOR_ORANGE;
else
sMessage += COLOR_GOLD;
sMessage += " Server " + sServer +" has been up for " + FormatTime(nUptime - (nUptime % 60)) + ".</c>\n";
}
nUptime = GetLocalInt(oMod, "uptime");
sMessage += "\n" + COLOR_WHITE + " This server has been up for " + FormatTime(nUptime - (nUptime % 60)) + ".</c>";
SendChatLogMessage(oPC, sMessage, oPC, 5);
} |
In modload:
Code: | /* load boot time into the boottime variable */
SQLExecDirect("SELECT UNIX_TIMESTAMP()");
if (SQLFetch() == SQL_SUCCESS) {
string sBootTime = SQLGetData(1);
SetLocalInt(oMod, "boottime", StringToInt(sBootTime));
SQLExecDirect("REPLACE INTO servers VALUES ('" + sR3ServerIP + "', " + sBootTime + ", 0, 0)");
}
|
And on mod heartbeat:
Code: | void main() {
object oMod = GetModule();
object oMes = GetMessenger();
int nUptime = GetLocalInt(oMod, "uptime");
int nMemory = GetMemoryUsage();
int nMessages = 0;
string sServer = GetLocalString(oMod, "ServerNumber");
string sBootTime = IntToString(GetLocalInt(oMod, "boottime"));
SQLExecDirect("SELECT UNIX_TIMESTAMP() - " + sBootTime +
", UTC_TIMESTAMP(), COUNT(*) FROM user_messages WHERE um_recipient = '*" + sServer + "'");
if (SQLFetch() == SQL_SUCCESS) {
nUptime = StringToInt(SQLGetData(1));
nMessages = StringToInt(SQLGetData(3));
SetLocalInt(oMod, "uptime", nUptime);
SetLocalString(oMod, "utctime", SQLGetData(2));
SQLExecDirect("UPDATE servers SET uptime = " + IntToString(nUptime) + ", memory = " +
IntToString(nMemory) + " WHERE server = '" + sServer + "'");
} |
Don't fret about having that in your mod heartbeat, or something like it anyway. It's a tiny franction of ours, and ours has no real impact on the server.
Funky |
|
Back to top |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Thu Jan 03, 2008 12:10 Post subject: |
|
|
Oops, seeing as it's on topic, here's our autoreset code (still acaos' work):
Code: |
/* check for automatic reset */
int nResetUptime = GetLocalInt(oMod, "resetuptime");
if (nResetUptime > 0 && nUptime > nResetUptime) {
if (!GetIsObjectValid(GetFirstPC()))
SetLocalString(oMod, "NWNX!RESETPLUGIN!SHUTDOWN", "1");
if (nUptime > nResetUptime + 900) {
SendResetBroadcast("SERVER RESET IN 10 SECONDS - SERVER REBOOT IS NOW COMMITTED - CANCELLATION " +
"IS NO LONGER POSSIBLE - PLEASE STAY OUT OF BANK CHESTS - HAVE A NICE DAY!", 1, oMes);
DelayCommand(10.0, SetLocalString(oMod, "NWNX!RESETPLUGIN!SHUTDOWN", "1"));
} else {
int bTell = 0;
int nSeconds = (nResetUptime + 900) - nUptime;
string sMinutes = IntToString((nSeconds / 60) + 1);
if (sMinutes == "1" || sMinutes == "5" || sMinutes == "10" || sMinutes == "15")
bTell = 1;
if (GetLocalInt(oMod, "resetforce"))
SendResetBroadcast("AUTOMATIC SERVER RESET IN " + sMinutes + " MINUTE" +
(sMinutes != "1" ? "S" : "") + " - THIS CANNOT BE ABORTED DUE TO A LOW MEMORY CONDITION", bTell, oMes);
else
SendResetBroadcast("AUTOMATIC SERVER RESET IN " + sMinutes + " MINUTE" +
(sMinutes != "1" ? "S" : "") + " - USE !delayreset TO DELAY THE RESET", bTell, oMes);
}
}
|
Players are able to delay normal resets using a SIMTools custom command, the code for which is here:
Code: | else if (sCText == "delayreset") {
DeleteLocalString(oCPC, "FKY_CHAT_LOCAL_CTEXT");
object oMod = GetModule();
if (GetLocalInt(oMod, "uptime") < GetLocalInt(oMod, "resetuptime")) {
if (GetLocalInt(oMod, "ResetEarlyCount") > 0) {
SetLocalInt(oMod, "ResetEarlyCount", -1);
SendResetDelayBroadcast(GetName(oCPC) + " has vetoed the early reset!");
} else
FloatingTextStringOnCreature(COLOR_RED + "There is no reset in progress!" + COLOR_END, oCPC, FALSE);
return;
}
if (GetLocalInt(oMod, "resetforce") && !(VerifyDMKey(oCPC) || VerifyAdminKey(oCPC))) {
FloatingTextStringOnCreature(COLOR_RED + "This reset cannot be cancelled!" + COLOR_END, oCPC, FALSE);
return;
}
string sKey = " " + GetPCPublicCDKey(oCPC) + " ";
string sAddr = " " + GetPCIPAddress(oCPC) + " ";
string sKeyCheck = GetLocalString(oMod, "ResetDelayKeys");
string sAddrCheck = GetLocalString(oMod, "ResetDelayAddrs");
if (FindSubString(sKeyCheck, sKey) >= 0 || FindSubString(sAddrCheck, sAddr) >= 0) {
FloatingTextStringOnCreature(COLOR_RED + "You have already asked to delay this reset!" +
COLOR_END, oCPC, FALSE);
return;
}
int nDelayCount = GetLocalInt(oMod, "ResetDelayCount") + 1;
if (nDelayCount >= 3 || VerifyDMKey(oCPC) || VerifyAdminKey(oCPC)) {
DeleteLocalInt(oMod, "ResetDelayCount");
DeleteLocalString(oMod, "ResetDelayKeys");
DeleteLocalString(oMod, "ResetDelayAddrs");
SetLocalInt(oMod, "resetuptime", GetLocalInt(oMod, "resetuptime") + 900);
SendResetDelayBroadcast("The reset has been delayed for 15 minutes!");
} else {
SetLocalInt(oMod, "ResetDelayCount", nDelayCount);
SetLocalString(oMod, "ResetDelayKeys", sKeyCheck + sKey);
SetLocalString(oMod, "ResetDelayAddrs", sAddrCheck + sAddr);
FloatingTextStringOnCreature(COLOR_YELLOW + "You have asked to delay the automatic reset. " +
IntToString(nDelayCount) + " of 3 required players have asked so far." + COLOR_END, oCPC, FALSE);
}
} |
HTH,
Funky |
|
Back to top |
|
|
Clisair
Joined: 27 Jun 2006 Posts: 9
|
Posted: Thu Jan 03, 2008 18:04 Post subject: |
|
|
Will this work with windows and sqlite? If it can, I will start working it in and get things going. I plan on using the reset plugin that was posted, just have to make sure I get the times right in doing it. _________________ Firinn Of Elisair
http://www.elisair.com/ |
|
Back to top |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Thu Jan 03, 2008 23:58 Post subject: |
|
|
I don't know. A quick search turned up a few sites that make me think the answer is yes, but you'll need someone else to give a definitive answer - or just try it yourself.
Funky |
|
Back to top |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Fri Jan 04, 2008 5:01 Post subject: |
|
|
Sorry, should have been clearer. As far as I know, this will all work, with the possible exception of UNIX_TIMESTAMP(). I THINK it will work, but I'm not positive.
Funky |
|
Back to top |
|
|
ronchese
Joined: 30 Dec 2007 Posts: 30
|
Posted: Wed Feb 20, 2008 15:32 Post subject: |
|
|
Could use now() MySQL function, this works well in Windows.
Also, with .NET plugin it is possible to get the machine time straigth from Windows, with just one call. ^^
Cesar |
|
Back to top |
|
|
Tempest
Joined: 26 Feb 2008 Posts: 32
|
Posted: Thu Feb 28, 2008 22:12 Post subject: |
|
|
Would anyone have this code for a windows machine? I know with our huge world the only way I can prevent "ghosting" from the resource issue is to have a server reset at some set point twice a day.
Thanks!
"T" |
|
Back to top |
|
|
Squatting Monk
Joined: 28 Jun 2007 Posts: 76
|
Posted: Sat Mar 01, 2008 17:48 Post subject: |
|
|
IIRC, UNIX_TIMESTAMP() works fine with Windows, the function name notwithstanding. Am I correct here, guys? |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Sat Mar 01, 2008 23:01 Post subject: |
|
|
It does, but only with the MySQL plugin, as SQLite does not have that function. _________________ Papillon |
|
Back to top |
|
|
hedgehog
Joined: 05 Jun 2008 Posts: 2
|
Posted: Thu Jun 05, 2008 18:17 Post subject: |
|
|
Have a look at:
nwnx.org Forum Index -> Database related -> Real World Time
for SQLite and also in Windows.
Für Papillon hätte ich ja nichts in englisch machen müssen, |
|
Back to top |
|
|
Mikel of Avalon
Joined: 29 Dec 2004 Posts: 72 Location: Germany
|
Posted: Fri Jun 06, 2008 10:57 Post subject: |
|
|
Nice to see there are more germans here...
Schönen Gruß aus dem warmen Norden _________________ Mikel of Avalon
Kalandur - Die vergessene Welt |
|
Back to top |
|
|
Terra_777
Joined: 27 Jun 2008 Posts: 216 Location: Sweden
|
Posted: Fri Jun 27, 2008 23:12 Post subject: |
|
|
I got just the stuff you guys need.
Time plugin
Has unix timestamps all other time functions you might need such as GetRunTime() which will return the seconds that has passed since startup. _________________ I dun have any signature, I'm happy anyway. |
|
Back to top |
|
|
Disco
Joined: 06 Dec 2006 Posts: 152
|
Posted: Wed Jul 02, 2008 12:07 Post subject: |
|
|
Tested Terra's plugin and it works like a breeze. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|