mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Session transition phase 1.
This commit is contained in:
parent
6bb2be6068
commit
d883d67638
6 changed files with 67 additions and 38 deletions
|
|
@ -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:])
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
53
evennia/trunk/session_mgr.py
Normal file
53
evennia/trunk/session_mgr.py
Normal file
|
|
@ -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
|
||||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue