Author Topic: what function for server start up and shutdown?  (Read 749 times)

Code: [Select]
active ServerTime

  %time = getRealTime();
   %elapsed = mSub(%time, %serverID.creationTime);
   %fixed = mFloatLength(%elapsed * 0.001, 0);
  
   if(%fixed >= 60) {
      if(%fixed >= 3600) {
         %minutes = %fixed / 60;
         %hours = mFloor(%minutes / 60);
         %hours = mFloatLength(%hours, 0);
         if(%hours == 1) {
            return "   Server time" SPC %hours SPC "hour ago.";
         } else {
            if(%hours >= 24) {
               %days = mFloatLength(%hours / 24, 0);
               if(%hours <= 168) {
                  %days = mFloatLength(%hours / 24, 0);
                  %weeks = mFloatLength(%days / 7, 0);
                  return "   Server time" SPC %days SPC "weeks(s) ago.";
               }
               %days = mFloatLength(%hours / 24, 0);
               return "   Server time" SPC %days SPC "day(s) ago.";
            }
         }
      } else {
         %minutes = %fixed / 60;
         return "   Server time" SPC mFloatLength(%minutes, 0) SPC "minute(s) ago.";
      }
   } else {
      return "   Server time" SPC %fixed SPC "seconds ago.";
   }
}
deactive ServerTime


GUI Script
Code: [Select]
JS_window.extent = "800 480";
JS_window.getObject(1).extent = "782 372";
JS_window.getObject(7).position = "687 440";
JS_window.getObject(11).command = "JS_sortList(13);";
JS_serverList.extent = "765 10";
JS_serverList.columns = "0 34 65 340 385 404 415 445 510 9000 9000 620 9000 9000";

JS_window.add(
new GuiBitmapButtonCtrl() {
profile = "BlockButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "670 34";
extent = "86 19";
minExtent = "8 2";
visible = "1";
command = "JS_sortList(12);";
text = "Server Time";
groupNum = "-1";
buttonType = "PushButton";
bitmap = "base/client/ui/button1";
lockAspectRatio = "0";
alignLeft = "0";
overflowImage = "0";
mKeepCached = "1";
mColor = "255 255 255 255";
wrap = "0";
}
);

package ServerTimeSerialize
{
function ServerSO::serialize(%this)
{
%s = Parent::serialize(%this);
%serv = getField(%s,2);
%h1 = strpos(%serv,"'s ");
%h2 = strpos(%serv,"s' ");
if(%h1 == -1)
%h1 = 999;
else if(%h2 == -1)
%h2 = 999;
if(%h1 < %h2)
{
%host = stripFirstSpaces(stripTrailingSpaces(getSubStr(%serv,0,%h1)));
%sname = stripFirstSpaces(stripTrailingSpaces(getSubStr(%serv,strLen(%server)+3,strLen(%serv)-strLen(%host)-3)));
}
else
{
%h2++;
%server = stripFirstSpaces(stripTrailingSpaces(getSubStr(%serv,0,%h2)));
%sserver = stripFirstSpaces(stripTrailingSpaces(getSubStr(%serv,strLen(%host)+2,strLen(%serv)-strLen(%host)-2)));
}
%chars = "\x09\x21\x22\x23\x24\x25\x26\x27\x28\x29\x40\x60\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99`~!@#$%^&*()-=_+[]{}\\|;:'\",./<>?";
%nch = stripFirstSpaces(stripTrailingSpaces(stripChars(%server,%chars)));
%ncs = stripFirstSpaces(stripTrailingSpaces(stripChars(%sname,%chars)));
return getFields(%s,0,1) TAB %sname TAB getFields(%s,3) TAB %server TAB %nch TAB %ncs;
}
};
activatePackage(ServerTimeSerialize);

function stripFirstSpaces(%str)
{
while(getSubStr(%str,0,1) $= " ")
%str = getSubStr(%str,1,strLen(%str)-1);
return %str;
}

When server start up. It will show server list show the time. how long the server stay up second, minutes, hour, day, week, month and year.
When the server shut down. It will deactive the server time. I did try test it. it not work.
« Last Edit: August 09, 2012, 12:45:36 PM by Cubelands »

Code: [Select]
active ServerTime

  %time = getRealTime();
   %elapsed = mSub(%time, %serverID.creationTime);
   %fixed = mFloatLength(%elapsed * 0.001, 0);
   
   if(%fixed >= 60) {
      if(%fixed >= 3600) {
         %minutes = %fixed / 60;
         %hours = mFloor(%minutes / 60);
         %hours = mFloatLength(%hours, 0);
         if(%hours == 1) {
            return "   Server time" SPC %hours SPC "hour ago.";
         } else {
            if(%hours >= 24) {
               %days = mFloatLength(%hours / 24, 0);
               if(%hours <= 168) {
                  %days = mFloatLength(%hours / 24, 0);
                  %weeks = mFloatLength(%days / 7, 0);
                  return "   Server time" SPC %days SPC "weeks(s) ago.";
               }
               %days = mFloatLength(%hours / 24, 0);
               return "   Server time" SPC %days SPC "day(s) ago.";
            }
         }
      } else {
         %minutes = %fixed / 60;
         return "   Brick created" SPC mFloatLength(%minutes, 0) SPC "minute(s) ago.";
      }
   } else {
      return "   Server time" SPC %fixed SPC "seconds ago.";
   }
}
deactive ServerTime
You've packaged this incorrectly and you left no function for it to operate in.

I think the functions I would use are onServerCreated and onServerDestroyed

Also if you're trying to add a column for server age to joinServerGui, I'm pretty sure you can't force the master server to accept additional server properties.

I think the functions I would use are onServerCreated and onServerDestroyed

Also if you're trying to add a column for server age to joinServerGui, I'm pretty sure you can't force the master server to accept additional server properties.
Like what, give me example.

Something like this should be enough for server age:

Code: [Select]
package serverAge
{
function onServerCreated()
{
$ServerCreationTime = getSimTime() / 1000;
Parent::onServerCreated();
}
};
ActivatePackage(serverAge);

function getServerAge()
{
return timeDiffString(getSimTime()/1000,$ServerCreationTime);
}

timeDiffString is a function provided by RTB, make sure you have RTB installed
Note that I'm not 100% positive that onServerCreated isn't protected from being packaged, though I wouldn't think that it would


Also, I know getSimTime measures the time in ms that the game has been running, but what does getRealTime measure? I'm guessing how long in ms the computer has been running?
« Last Edit: August 09, 2012, 01:31:17 PM by Headcrab Zombie »

Okay. I will try this later. If i have time put add for joinserver list gui.

getRealTime gets the real time displayed on your computer, but in milliseconds. getDateTime gets the display and date used by your computer.

getRealTime gets the real time displayed on your computer, but in milliseconds. getDateTime gets the display and date used by your computer.
Excellent idea!

EDIT NINJA: When I want start server, then the time will show on the server list, let people know how long my server run time, like 3 hour or 4 day either 2 week something like that. I already made gui for server list. soon I will show you the picture.
« Last Edit: August 09, 2012, 06:08:22 PM by Cubelands »

Excellent idea!

EDIT NINJA: When I want start server, then the time will show on the server list, let people know how long my server run time, like 3 hour or 4 day either 2 week something like that. I already made gui for server list. soon I will show you the picture.

Also if you're trying to add a column for server age to joinServerGui, I'm pretty sure you can't force the master server to accept additional server properties.