mirror of
https://github.com/evennia/evennia.git
synced 2026-03-24 16:56:32 +01:00
Added idle timeout code to help combat the screwed up session situation. Some admins would've wanted this eventually, but it'll help until I figure out how to close dead sessions that look like they're still alive. Added a new server config directive, idle_timeout. If the value is non-zero, the idle timeout is the respective number of seconds between commands. Also, the IDLE command will save you from idle timeouts but won't modify your publicly visible idle time.
This commit is contained in:
parent
32fa9e419a
commit
f1dd985294
6 changed files with 34 additions and 11 deletions
|
|
@ -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');
|
||||
INSERT INTO "config_configvalue" VALUES(5,'game_firstrun','1');
|
||||
INSERT INTO "config_configvalue" VALUES(6,'idle_timeout','1800');
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue