diff --git a/apps/config/sql/configvalue.sql b/apps/config/sql/configvalue.sql index d721aa18b2..fa5d8fdc96 100644 --- a/apps/config/sql/configvalue.sql +++ b/apps/config/sql/configvalue.sql @@ -3,4 +3,5 @@ INSERT INTO "config_configvalue" VALUES(1,'site_port','4000'); INSERT INTO "config_configvalue" VALUES(2,'player_dbnum_start','2'); INSERT INTO "config_configvalue" VALUES(3,'money_name_plural','Credits'); INSERT INTO "config_configvalue" VALUES(4,'money_name_singular','Credit'); -INSERT INTO "config_configvalue" VALUES(5,'game_firstrun','1'); \ No newline at end of file +INSERT INTO "config_configvalue" VALUES(5,'game_firstrun','1'); +INSERT INTO "config_configvalue" VALUES(6,'idle_timeout','1800'); diff --git a/cmdhandler.py b/cmdhandler.py index 87f2a09d60..9ebf76e0b4 100755 --- a/cmdhandler.py +++ b/cmdhandler.py @@ -1,4 +1,5 @@ from traceback import format_exc +import time import commands_privileged import commands_general import commands_unloggedin @@ -58,9 +59,18 @@ def handle(cdat): parsed_input['root_cmd'] = alias_list.get(parsed_input['root_cmd'],parsed_input['root_cmd']) if session.logged_in: + # Store the timestamp of the user's last command. + session.cmd_last = time.time() + # Lets the users get around badly configured NAT timeouts. if parsed_input['root_cmd'] == 'idle': return + + # Increment our user's command counter. + session.cmd_total += 1 + # Player-visible idle time, not used in idle timeout calcs. + session.cmd_last_visible = time.time() + # If it's prefixed by an '@', it's a staff command. if parsed_input['root_cmd'][0] != '@': # Shortened say alias. diff --git a/commands_general.py b/commands_general.py index 59f4d60dea..81c3cb971e 100644 --- a/commands_general.py +++ b/commands_general.py @@ -307,12 +307,12 @@ def cmd_who(cdat): for player in session_list: if not player.logged_in: continue - delta_cmd = time.time() - player.cmd_last + delta_cmd = time.time() - player.cmd_last_visible delta_conn = time.time() - player.conn_time plr_pobject = player.get_pobject() retval += '%-16s%9s %4s%-3s#%-6d%5d%3s%-25s\r\n' % \ - (plr_pobject.get_name()[:25].ljust(27), \ + (plr_pobject.get_name(show_dbref=False)[:25].ljust(27), \ # On-time functions_general.time_format(delta_conn,0), \ # Idle time diff --git a/server.py b/server.py index fd52336c41..42496320fa 100755 --- a/server.py +++ b/server.py @@ -1,3 +1,4 @@ +from traceback import format_exc from asyncore import dispatcher from asynchat import async_chat import socket, asyncore, time @@ -128,5 +129,6 @@ if __name__ == '__main__': print '--> Server killed by keystroke.' except: - server.shutdown(message="The server has encountered an error and has been shut down. Please check back soon.") - print '-!> Server crashed.' + server.shutdown(message="The server has encountered a fatal error and has been shut down. Please check back soon.") + functions_general.log_errmsg("Untrapped error: %s" % + (format_exc())) diff --git a/session.py b/session.py index efe5258fa2..fb20008bd8 100755 --- a/session.py +++ b/session.py @@ -25,6 +25,8 @@ class PlayerSession(async_chat): self.logged_in = False # The time the user last issued a command. self.cmd_last = time.time() + # Player-visible idle time, excluding the IDLE command. + self.cmd_last_visible = time.time() # Total number of commands issued. self.cmd_total = 0 # The time when the user connected. @@ -46,10 +48,6 @@ class PlayerSession(async_chat): uinput = line self.data = [] - # Increment our user's command counter. - self.cmd_total += 1 - # Store the timestamp of the user's last command. - self.cmd_last = time.time() # Stuff anything we need to pass in this dictionary. cdat = {"server": self.server, "uinput": uinput, "session": self} cmdhandler.handle(cdat) diff --git a/session_mgr.py b/session_mgr.py index 14c8765801..450e63d99f 100644 --- a/session_mgr.py +++ b/session_mgr.py @@ -1,4 +1,6 @@ +import time from session import PlayerSession +import gameconf """ Session manager, handles connected players. @@ -24,8 +26,18 @@ def check_all_sessions(): """ Check all currently connected sessions and see if any are dead. """ - pass - #for sess in get_session_list(): + idle_timeout = int(gameconf.get_configvalue('idle_timeout')) + + if len(session_list) <= 0: + return + + if idle_timeout <= 0: + return + + for sess in get_session_list(): + if (time.time() - sess.cmd_last) > idle_timeout: + sess.msg("Idle timeout exceeded, disconnecting.") + sess.handle_close() ## This doesn't seem to provide an accurate indication of timed out ## sessions. #if not sess.writable() or not sess.readable():