16 Sep, 2011, Valo wrote in the 1st comment:
Votes: 0
I'm wondering how to delete all the contents of a specific room. I want to setup a cronjob to get rid of idle players that haven't logged into the game in a specified time (30 days or so) that are sent to a specific room on MUX 2.9.1.8. I know how to do the cronjob, but I just can't figure out the rest of it. Any assistance would be appreciated. Thank you in advance.
17 Sep, 2011, Scandum wrote in the 2nd comment:
Votes: 0
What I do is getting all player files with scandir, then one by one load a player, delete / unload the player.
17 Sep, 2011, Idealiad wrote in the 3rd comment:
Votes: 0
This is basically what you want to do:

1. lcon() the room to get its contents
2. filter() this list to get the players with hastype(). For example:

@create Nuker
&is-player? nuker = hastype(%0, player)
&get-players nuker = filter(me/is-player?, lcon(here))


3. Get only the players that haven't logged in for however long. You could do this with the first filter, but IMO it's nicer to just apply a different function, it's clearer that way.
4. For this you'll need to compare the connlast() of each disconnected player with whatever your limit is. Just convert your limit to seconds when you write the attribute.

&seconds-before-purging nuker = 2592000
&is-connected? nuker = sign(conn(%0))
&is-nukable? nuker = gt(connlast(%0), v(seconds-before-purging))
&get-disconnected-players nuker = filter(me/is-connected?, u(me/get-players))
&get-nukable-players nuker = filter(me/is-nukable?, u(me/get-disconnected-players))


At this point you have your list of nukable players, which you can @destroy with a @dolist and set up with whatever cron system you're using. Some people @dump the player first or get whatever data they want, but that of course is up to you.
17 Sep, 2011, Idealiad wrote in the 4th comment:
Votes: 0
Sorry for the double post, but of course there's a bug in that code – get-disconnected-players returns the list of connected, not disconnected players. ;D. So you'll want to turn is-connected? into is-disconnected? by doing something like

&is-disconnected?  nuker = lt(conn(%0), 0)


which takes advantage of the fact that conn() returns -1 if the player is disconnected.

Thinking about it more you could also simplify this a bit by and()'ing the tests into one filter and you wouldn't lose clarity. So for example,

@create Nuker
&seconds-before-purging nuker = 2592000
&is-player? nuker = hastype(%0, player)
&is-disconnected? nuker = lt(conn(%0, 0)
&is-nukable? nuker = gt(connlast(%0), v(seconds-before-purging))
&nukable-players nuker = and(u(is-player?, %0), u(is-disconnected?, %0), u(is-nukable?, %0))
&get-nukable-players nuker = filter(me/nukable-players, lcon(here))


Note the %0 in the u() call just passes through the list item from the filter's lcon(here), in this case each player in that list.
11 Oct, 2011, Idealiad wrote in the 5th comment:
Votes: 0
Reading some other things today I learned some stuff that made me think of this example, and since I know thousands of Tiny coders will go astray if I don't add what I've learned I'm rewriting the example (I really wish we could edit posts here at any time – I just noticed a big bug in the old code too):

@create Nuker
&seconds-since-last-connection nuker = sub(secs(), convtime(get(%0/last)))
&seconds-before-purging nuker = 2592000
&is-disconnected? nuker = not(hasflag(%0, connected))
&is-nukable? nuker = gt(u(seconds-since-last-connection, %0), v(seconds-before-purging))
&nukable-players nuker = and(u(is-disconnected?, %0), u(is-nukable?, %0))
&get-nukable-players nuker = filter(me/nukable-players, lcon(here, player))
12 Oct, 2011, Runter wrote in the 6th comment:
Votes: 0
Off topic, but what language is this? Is it a scripting language for MUX?
12 Oct, 2011, Idealiad wrote in the 7th comment:
Votes: 0
Yeah, it's variously called mushcode and softcode. Mostly the same between the major Tiny bases (Penn, Mux, Rhost, TinyMUSH, etc.).
0.0/7