I'm looking for a way to show the MUD uptime in the "time" command, but not sure how to record it. Increase a variable saved in system data every update?
Also, with the "last" command, I am wondering if there is a way to also display the IP that was last logged on, along with the last logon time. If not, I may just install the finger snippet for Immortals.
The MUD stores its startup time, doesn't it? Can't you just take current time, subtract startup time, and there you go? Making a whole new variable in update really seems like a lot of effort for a really simple problem - even if the MUD doesn't already store the startup time (and I think it does) you can just store it yourself.
For your modification to 'last', you'll have to go in and actually read the file, I think. Just make sure you don't save it or anything, because that will break the last command, which, IIRC, works by looking at when the file was last written.
Now, I've edited it all, so it's probably not called secBootTime on your version... but I'm pretty darn sure it's still there one way or another.
So, to do the uptime, you would use time(0), subtract from that the boot time, and you obtain the number of seconds you have been running. (To be perfectly correct, you should use the difftime function, but since a time_t is a number on any POSIX system, normal subtraction is fine.)
From the number of seconds, getting the number of days/hours/minutes should be fairly straightforward.
In fact, I think I'm going to add this functionality to my MUD - good idea. :-)
Yeah, I figured it out while I was about to go to sleep. I love it how I couldn't figure it out while staring at the problem/code, but got it when I was trying to sleep. I thought "Wait, I just multiplay 24 by 3600, and divide the number by that." Thanks for the detailed explaination.
Well, you can't just get the number of days. If you compute the number of days, you have to adjust the number of hours as well (since 25 hours is no longer 25 but instead 1 day and 1 hour).
But yes, as they say, sometimes problems are best solved when you're sleeping, or about to sleep. Which is why I wish I could get some sleep these days, and not be forced to be up for nearly the entire night. :-)
Quote: Well, you can't just get the number of days. If you compute the number of days, you have to adjust the number of hours as well (since 25 hours is no longer 25 but instead 1 day and 1 hour).
Yeah, I didn't mention that because I had thought it was obvious/assumed.
Ok, now I'm very curious what you've come up with as the final product so that do_time will display the mud's uptime correctly even if it's been multiple days.. would you be willing to post it?
Also, Zeno, in answer to your other question about having the IP display in your last command, I use Xerves' logon history snippet on my mud and it works very well. I can do 'last 10' to see the last 10 logons (with IP) or 'last today' to see everyone who's logged on since midnight, or 'last <player> #' to see a particular player's last # of logons (up to the limit of my last log file which I have set to 5000, but the default in the snippet is 500) or I can do 'last -1' to see the last 5000 logons or I can do 'last <player>' to see the old version that you're used to. Was a fairly easy snippet and has never given me any problems at all.
With the code using ch_printf, it's fine. But using sprintf, I get these warnings:
update.c:3806: warning: format '%d' expects type 'int', but argument 3 has type 'long int'
update.c:3806: warning: format '%d' expects type 'int', but argument 5 has type 'long int'
update.c:3806: warning: format '%d' expects type 'int', but argument 7 has type 'long int'
update.c:3806: warning: format '%d' expects type 'int', but argument 9 has type 'long int'
Doesn't make much sense, except ch_printf is being used and not sprintf. How would I fix those warnings?
Try to be to totally off the subject here.. well I kinda am since you mentioned finger, but if you can make finger work in smaugfuss... would you post it or something? I've tried for the life of me, but cant seem to do it.
A point of efficiency, even if it's a slight one. Smaug has the current_time variable declared globally and it is updated every game_loop, which is roughly 0.25sec. So this bit here:
current = time(0);
diff = current - boot_time
Could be done as:
diff = current_time - boot_time;
One less variable to declare and use, and one less function call to make each time the command is issued. It's little things like this to keep in mind for overall resource efficiency :)
It's true that that would be more efficient, technically speaking, but the gain would be negligible. time(0) is a very cheap operation and this function is not called very frequently. In a sense it's not even a blip on the radar in terms of efficiency, even if it is faster. If you think about it in assembly terms, it's clearer why it's not very important. One function call every once in a while is really nothing. If this function were called very often (as in several thousand times per second or even more), this optimization would be more important.
I would argue that it's important to use the global variable to ensure that you're operating on the same time units. If the time were to be changed and counted in, say, nanoseconds, then using time(0) would break things whereas using the global would be somewhat easier to fix. (Your end result would be off, instead of subtracting nanoseconds from milliseconds or something weird like that.)