From d883d67638297dba95bb7f1bbf0aad0277e8b9b3 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Fri, 22 Dec 2006 01:40:40 +0000 Subject: [PATCH] Session transition phase 1. --- evennia/trunk/commands_general.py | 5 +-- evennia/trunk/commands_staff.py | 5 +-- evennia/trunk/functions_db.py | 26 --------------- evennia/trunk/server.py | 11 +++---- evennia/trunk/session_mgr.py | 53 +++++++++++++++++++++++++++++++ evennia/trunk/sessions.py | 5 +-- 6 files changed, 67 insertions(+), 38 deletions(-) create mode 100644 evennia/trunk/session_mgr.py diff --git a/evennia/trunk/commands_general.py b/evennia/trunk/commands_general.py index 50f90519ab..7ddfc7eb35 100644 --- a/evennia/trunk/commands_general.py +++ b/evennia/trunk/commands_general.py @@ -3,6 +3,7 @@ import time import functions_general import functions_db import global_defines +import session_mgr from ansi import * """ @@ -168,7 +169,7 @@ def cmd_who(cdat): """ Generic WHO command. """ - session_list = cdat['server'].get_session_list() + session_list = session_mgr.get_session_list() session = cdat['session'] pobject = session.get_pobject() @@ -200,7 +201,7 @@ def cmd_say(cdat): """ Room-based speech command. """ - session_list = cdat['server'].get_session_list() + session_list = session_mgr.get_session_list() session = cdat['session'] pobject = session.get_pobject() speech = ' '.join(cdat['uinput']['splitted'][1:]) diff --git a/evennia/trunk/commands_staff.py b/evennia/trunk/commands_staff.py index ca4eeda24e..0a347ff26e 100644 --- a/evennia/trunk/commands_staff.py +++ b/evennia/trunk/commands_staff.py @@ -3,6 +3,7 @@ import functions_db import functions_general import commands_general import cmdhandler +import session_mgr """ Staff commands may be a bad description for this file, but it'll do for now. @@ -59,7 +60,7 @@ def cmd_destroy(cdat): target_obj = results[0] session.msg("You destroy %s." % (target_obj,)) - target_obj.destroy(session.server.session_list) + target_obj.destroy(session_mgr.get_session_list()) def cmd_name(cdat): """ @@ -245,7 +246,7 @@ def cmd_teleport(cdat): # to do it sometime else. If we can find a session in the server's # session list matching the object we're teleporting, force it to # look. This is going to typically be a player. - victim_session = functions_db.session_from_object(server.get_session_list(), victim[0]) + victim_session = session_mgr.session_from_object(victim[0]) if victim_session: # We need to form up a new cdat dictionary to pass with the command. # Kinda yucky I guess. diff --git a/evennia/trunk/functions_db.py b/evennia/trunk/functions_db.py index 91a8d4733e..7e91a5676e 100644 --- a/evennia/trunk/functions_db.py +++ b/evennia/trunk/functions_db.py @@ -104,32 +104,6 @@ def is_dbref(dbstring): else: return True -def session_from_object(session_list, targobject): - """ - Return the session object given a object (if there is one open). - - session_list: (list) The server's session_list attribute. - targobject: (Object) The object to match. - """ - results = [prospect for prospect in session_list if prospect.get_pobject().id == targobject.id] - if results: - return results[0] - else: - return False - -def session_from_dbref(session_list, dbstring): - """ - Return the session object given a dbref (if there is one open). - - dbstring: (int) The dbref number to match against. - """ - if is_dbref(dbstring): - results = [prospect for prospect in session_list if prospect.get_pobject().dbref_match(dbstring)] - if results: - return results[0] - else: - return False - def get_object_from_dbref(dbref): """ Returns an object when given a dbref. diff --git a/evennia/trunk/server.py b/evennia/trunk/server.py index c1a2f96631..88dff4caf9 100755 --- a/evennia/trunk/server.py +++ b/evennia/trunk/server.py @@ -1,7 +1,6 @@ from asyncore import dispatcher from asynchat import async_chat import socket, asyncore, time, sys -from sessions import PlayerSession from django.db import models from django.db import connection from django.contrib.auth.models import User @@ -11,6 +10,7 @@ from scheduler import Scheduler import functions_db import functions_general import global_defines +import session_mgr class Server(dispatcher): """ @@ -72,11 +72,10 @@ class Server(dispatcher): What to do when we get a connection. """ conn, addr = self.accept() - session = PlayerSession(self, conn, addr) + session = session_mgr.new_session(self, conn, addr) session.game_connect_screen(session) print 'Connection:', str(session) - self.session_list.append(session) - print 'Sessions active:', len(self.session_list) + print 'Sessions active:', len(session_mgr.get_session_list()) """ BEGIN GENERAL METHODS @@ -106,13 +105,13 @@ class Server(dispatcher): """ Lists the server's connected session objects. """ - return self.session_list + return session_mgr.get_session_list() def remove_session(self, session): """ Removes a session from the server's session list. """ - self.session_list.remove(session) + session_mgr.remove_session(session) def shutdown(self, message='The server has been shutdown. Please check back soon.'): functions_general.announce_all(server, message) diff --git a/evennia/trunk/session_mgr.py b/evennia/trunk/session_mgr.py new file mode 100644 index 0000000000..cf8f8a03c8 --- /dev/null +++ b/evennia/trunk/session_mgr.py @@ -0,0 +1,53 @@ +from sessions import PlayerSession + +""" +Session manager, handles connected players. +""" +# Our list of connected sessions. +session_list = [] + +def new_session(server, conn, addr): + """ + Create and return a new session. + """ + session = PlayerSession(server, conn, addr) + session_list.insert(0, session) + return session + +def get_session_list(): + """ + Lists the connected session objects. + """ + return session_list + +def remove_session(session): + """ + Removes a session from the session list. + """ + session_list.remove(session) + +def session_from_object(targobject): + """ + Return the session object given a object (if there is one open). + + session_list: (list) The server's session_list attribute. + targobject: (Object) The object to match. + """ + results = [prospect for prospect in session_list if prospect.get_pobject().id == targobject.id] + if results: + return results[0] + else: + return False + +def session_from_dbref(dbstring): + """ + Return the session object given a dbref (if there is one open). + + dbstring: (int) The dbref number to match against. + """ + if is_dbref(dbstring): + results = [prospect for prospect in session_list if prospect.get_pobject().dbref_match(dbstring)] + if results: + return results[0] + else: + return False diff --git a/evennia/trunk/sessions.py b/evennia/trunk/sessions.py index 0561187edd..4290d9f03f 100755 --- a/evennia/trunk/sessions.py +++ b/evennia/trunk/sessions.py @@ -6,6 +6,7 @@ from apps.objects.models import Object from django.contrib.auth.models import User import commands_general import functions_db +import session_mgr class PlayerSession(async_chat): """ @@ -60,8 +61,8 @@ class PlayerSession(async_chat): self.get_pobject().set_flag("CONNECTED", False) async_chat.handle_close(self) self.logged_in = False - self.server.remove_session(self) - print 'Sessions active:', len(self.server.get_session_list()) + session_mgr.remove_session(self) + print 'Sessions active:', len(session_mgr.get_session_list()) def get_pobject(self): """