;"MidgardCORE Generic Daemon" ;"Copyright 1997, 1998 Midgard Systems and Adam 'Martian' Smyth" ;"This code is free software; you can redistribute it and/or" ;"modify it under the terms of the GNU General Public License" ;"as published by the Free Software Foundation; either version 2" ;"of the License, or (at your option) any later version." ;"This program is distributed in the hope that it will be useful," ;"but WITHOUT ANY WARRANTY; without even the implied warranty of" ;"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" ;"GNU General Public License for more details." ;"The License is available at http://www.gnu.org/copyleft/gpl.html" ;"The author can be contacted at martian@midgard.org" ;"It is *strongly requested* that users of this code register with the author." ;"The latest release of this code can be found at" ;" http://www.midgard.org:8080/~martian/Code/MOO/daemon.moo" ;" This module is designed to be pasted as-is into a connection to a MOO server." ;" To install this module, you must be a wizard."; ;"Dependancy checks" ;"Wizperms are required for installation" ;if(!`player.wizard ! ANY');while(read()!=";\"End of Module\"");endwhile;endif ;"Begining installation..." ;"Simple sanity check. Don't make more than one, if it already exists."; ;if(`valid($daemon) ! ANY');while(read()!=";\"-----\"");endwhile;endif @create $root_class called Generic System Daemon,System Daemon,Daemon,Demon @corify Demon as $daemon ;"-----" ;$daemon.description=$command_utils:read() Placeholder for the MidgardCORE Networking Utilities. @prop $daemon."ListenPort" 0 rc @prop $daemon."busy" 0 c @prop $daemon."connections" {} c @prop $daemon."debug" 0 "" @prop $daemon."service" "" rc @prop $daemon."enabled" 0 rc @prop $daemon."idle_timeout" 300 rc @prop $daemon."version" "" rc @prop $daemon."help_msg" {} rc @verb $daemon:"server_started" this none this rxd @program $daemon:server_started if (!caller_perms().wizard) return E_PERM; elseif (this.enabled && this.ListenPort && !$list_utils:iassoc(this, listeners())) this.busy = 0; this.connections = {}; return `listen(this, this.ListenPort) ! E_QUOTA => 0'; else return 0; endif . @verb $daemon:"server_shutdown" this none this rxd @program $daemon:server_shutdown if (!caller_perms().wizard) return E_PERM; else if (!(this.connections = $set_utils:intersection(connected_players(1), setremove(this.connections, player)))) this.busy = 0; endif while (a = $list_utils:assoc(this, listeners())) unlisten(a[2]); endwhile endif . @verb $daemon:"do_login_command" this none this rxd @program $daemon:do_login_command if (callers()) return E_PERM; endif host = $string_utils:connection_hostname(`connection_name(player) ! E_INVARG => ""'); if ($login:redlisted(host)) boot_player(player); server_log(tostr("REDLISTED: ", player, " from ", host, " to ", this)); return 0; elseif (!host) return 0; endif this.busy = 1; this.connections = setadd(this.connections, player); set_connection_option(player, "hold-input", 1); this:process_session(); if (!(this.connections = $set_utils:intersection(connected_players(1), setremove(this.connections, player)))) this.busy = 0; endif . @verb $daemon:"debug" this none this rxd @program $daemon:debug if (this.debug && caller == this) notify(this.owner, tostr(this, ":", callers()[1][2], "> ", @args)); endif . @verb $daemon:"process_session" this none this rxd @program $daemon:process_session boot_player(player); return; . @verb $daemon:"send" this none this rxd @program $daemon:send if (caller != this) return E_PERM; endif notify(player, tostr(@args)); this:debug("SEND: ", @args); . @verb $daemon:"reset_timeout" this none this rxd @program $daemon:reset_timeout if (caller != this) raise(E_PERM); endif {task, who} = args; if (task) kill_task(task); endif fork timeout_task (this.idle_timeout) boot_player(who); endfork return timeout_task; . ;"End of Module"