Further development of the reworking of systems using Sessions rather than session id.
This commit is contained in:
parent
709f5ff5b3
commit
d496606a3c
19 changed files with 166 additions and 209 deletions
|
|
@ -18,7 +18,7 @@ Server - (AMP server) Handles all mud operations. The server holds its own list
|
|||
from __future__ import print_function
|
||||
|
||||
# imports needed on both server and portal side
|
||||
import os, sys
|
||||
import os
|
||||
from time import time
|
||||
from collections import defaultdict
|
||||
from itertools import count
|
||||
|
|
@ -28,7 +28,7 @@ try:
|
|||
except ImportError:
|
||||
import pickle
|
||||
from twisted.protocols import amp
|
||||
from twisted.internet import protocol, reactor
|
||||
from twisted.internet import protocol
|
||||
from twisted.internet.defer import Deferred
|
||||
from evennia.utils import logger
|
||||
from evennia.utils.utils import to_str, variable_from_module
|
||||
|
|
@ -416,10 +416,10 @@ class AMPProtocol(amp.AMP):
|
|||
|
||||
"""
|
||||
sessid, kwargs = loads(packed_data)
|
||||
self.factory.server.sessions.data_in(sessid, **kwargs)
|
||||
self.factory.server.sessions.data_in(self.factory.server.sessions[sessid], **kwargs)
|
||||
return {}
|
||||
|
||||
def send_MsgPortal2Server(self, sessid, text="", **kwargs):
|
||||
def send_MsgPortal2Server(self, session, text="", **kwargs):
|
||||
"""
|
||||
Access method called by the Portal and executed on the Portal.
|
||||
|
||||
|
|
@ -432,7 +432,7 @@ class AMPProtocol(amp.AMP):
|
|||
deferred (Deferred): Asynchronous return.
|
||||
|
||||
"""
|
||||
return self.send_data(MsgPortal2Server, sessid, text=text, **kwargs)
|
||||
return self.send_data(MsgPortal2Server, session.sessid, text=text, **kwargs)
|
||||
|
||||
# Server -> Portal message
|
||||
|
||||
|
|
@ -442,31 +442,26 @@ class AMPProtocol(amp.AMP):
|
|||
Receives message arriving to Portal from Server.
|
||||
This method is executed on the Portal.
|
||||
|
||||
Since AMP has a limit of 65355 bytes per message, it's
|
||||
possible the data comes in multiple chunks; if so (nparts>1)
|
||||
we buffer the data and wait for the remaining parts to arrive
|
||||
before continuing.
|
||||
|
||||
Args:
|
||||
packed_data (str): Pickled data (sessid, kwargs) coming over the wire.
|
||||
"""
|
||||
sessid, kwargs = loads(packed_data)
|
||||
self.factory.portal.sessions.data_out(sessid, **kwargs)
|
||||
self.factory.portal.sessions.data_out(self.factory.portal.sessions[sessid], **kwargs)
|
||||
return {}
|
||||
|
||||
|
||||
def send_MsgServer2Portal(self, sessid, text="", **kwargs):
|
||||
def send_MsgServer2Portal(self, session, text="", **kwargs):
|
||||
"""
|
||||
Access method - executed on the Server for sending data
|
||||
to Portal.
|
||||
|
||||
Args:
|
||||
sessid (int): Unique Session id.
|
||||
session (Session): Unique Session.
|
||||
msg (str, optional): Message to send over the wire.
|
||||
kwargs (any, optiona): Extra data.
|
||||
|
||||
"""
|
||||
return self.send_data(MsgServer2Portal, sessid, text=text, **kwargs)
|
||||
return self.send_data(MsgServer2Portal, session.sessid, text=text, **kwargs)
|
||||
|
||||
# Server administration from the Portal side
|
||||
@AdminPortal2Server.responder
|
||||
|
|
@ -483,7 +478,7 @@ class AMPProtocol(amp.AMP):
|
|||
sessid, kwargs = loads(packed_data)
|
||||
operation = kwargs.pop("operation", "")
|
||||
server_sessionhandler = self.factory.server.sessions
|
||||
|
||||
session = server_sessionhandler[sessid]
|
||||
|
||||
if operation == PCONN: # portal_session_connect
|
||||
# create a new session and sync it
|
||||
|
|
@ -494,7 +489,7 @@ class AMPProtocol(amp.AMP):
|
|||
|
||||
elif operation == PDISCONN: # portal_session_disconnect
|
||||
# session closed from portal side
|
||||
self.factory.server.sessions.portal_disconnect(sessid)
|
||||
self.factory.server.sessions.portal_disconnect(session)
|
||||
|
||||
elif operation == PSYNC: # portal_session_sync
|
||||
# force a resync of sessions when portal reconnects to
|
||||
|
|
@ -507,20 +502,20 @@ class AMPProtocol(amp.AMP):
|
|||
raise Exception("operation %(op)s not recognized." % {'op': operation})
|
||||
return {}
|
||||
|
||||
def send_AdminPortal2Server(self, sessid, operation="", **kwargs):
|
||||
def send_AdminPortal2Server(self, session, operation="", **kwargs):
|
||||
"""
|
||||
Send Admin instructions from the Portal to the Server.
|
||||
Executed
|
||||
on the Portal.
|
||||
|
||||
Args:
|
||||
sessid (int): Session id.
|
||||
session (Session): Session.
|
||||
operation (char, optional): Identifier for the server operation, as defined by the
|
||||
global variables in `evennia/server/amp.py`.
|
||||
data (str or dict, optional): Data used in the administrative operation.
|
||||
|
||||
"""
|
||||
return self.send_data(AdminPortal2Server, sessid, operation=operation, **kwargs)
|
||||
return self.send_data(AdminPortal2Server, session.sessid, operation=operation, **kwargs)
|
||||
|
||||
# Portal administraton from the Server side
|
||||
|
||||
|
|
@ -539,13 +534,15 @@ class AMPProtocol(amp.AMP):
|
|||
operation = kwargs.pop("operation")
|
||||
portal_sessionhandler = self.factory.portal.sessions
|
||||
|
||||
session = portal_sessionhandler[sessid]
|
||||
|
||||
if operation == SLOGIN: # server_session_login
|
||||
# a session has authenticated; sync it.
|
||||
portal_sessionhandler.server_logged_in(sessid, kwargs.get("sessiondata"))
|
||||
portal_sessionhandler.server_logged_in(session, kwargs.get("sessiondata"))
|
||||
|
||||
elif operation == SDISCONN: # server_session_disconnect
|
||||
# the server is ordering to disconnect the session
|
||||
portal_sessionhandler.server_disconnect(sessid, reason=kwargs.get("reason"))
|
||||
portal_sessionhandler.server_disconnect(session, reason=kwargs.get("reason"))
|
||||
|
||||
elif operation == SDISCONNALL: # server_session_disconnect_all
|
||||
# server orders all sessions to disconnect
|
||||
|
|
@ -569,20 +566,20 @@ class AMPProtocol(amp.AMP):
|
|||
raise Exception("operation %(op)s not recognized." % {'op': operation})
|
||||
return {}
|
||||
|
||||
def send_AdminServer2Portal(self, sessid, operation="", **kwargs):
|
||||
def send_AdminServer2Portal(self, session, operation="", **kwargs):
|
||||
"""
|
||||
Administrative access method called by the Server to send an
|
||||
instruction to the Portal.
|
||||
|
||||
Args:
|
||||
sessid (int): Session id.
|
||||
session (Session): Session.
|
||||
operation (char, optional): Identifier for the server
|
||||
operation, as defined by the global variables in
|
||||
`evennia/server/amp.py`.
|
||||
data (str or dict, optional): Data going into the adminstrative.
|
||||
|
||||
"""
|
||||
return self.send_data(AdminServer2Portal, sessid, operation=operation, **kwargs)
|
||||
return self.send_data(AdminServer2Portal, session.sessid, operation=operation, **kwargs)
|
||||
|
||||
# Extra functions
|
||||
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ def oob_repeat(session, oobfuncname, interval, *args, **kwargs):
|
|||
interval = 20 if not interval else (max(5, interval))
|
||||
obj = session.get_puppet_or_player()
|
||||
if obj and oobfuncname != "REPEAT":
|
||||
OOB_HANDLER.add_repeater(obj, session.sessid, oobfuncname, interval, *args, **kwargs)
|
||||
OOB_HANDLER.add_repeater(obj, session, oobfuncname, interval, *args, **kwargs)
|
||||
|
||||
|
||||
##OOB{"UNREPEAT":10}
|
||||
|
|
@ -146,7 +146,7 @@ def oob_unrepeat(session, oobfuncname, interval):
|
|||
"""
|
||||
obj = session.get_puppet_or_player()
|
||||
if obj:
|
||||
OOB_HANDLER.remove_repeater(obj, session.sessid, oobfuncname, interval)
|
||||
OOB_HANDLER.remove_repeater(obj, session, oobfuncname, interval)
|
||||
|
||||
|
||||
#
|
||||
|
|
@ -251,10 +251,10 @@ def oob_report(session, *args, **kwargs):
|
|||
oob_error(session, "No Reportable property '%s'. Use LIST REPORTABLE_VARIABLES." % propname)
|
||||
# the field_monitors require an oob function as a callback when they report a change.
|
||||
elif propname.startswith("db_"):
|
||||
OOB_HANDLER.add_field_monitor(obj, session.sessid, propname, "return_field_report")
|
||||
OOB_HANDLER.add_field_monitor(obj, session, propname, "return_field_report")
|
||||
ret.append(to_str(_GA(obj, propname), force_string=True))
|
||||
else:
|
||||
OOB_HANDLER.add_attribute_monitor(obj, session.sessid, propname, "return_attribute_report")
|
||||
OOB_HANDLER.add_attribute_monitor(obj, session, propname, "return_attribute_report")
|
||||
ret.append(_GA(obj, "db_value"))
|
||||
session.msg(oob=("MSDP_ARRAY", ret))
|
||||
else:
|
||||
|
|
@ -313,9 +313,9 @@ def oob_unreport(session, *args, **kwargs):
|
|||
if not propname:
|
||||
oob_error(session, "No Un-Reportable property '%s'. Use LIST REPORTABLE_VARIABLES." % propname)
|
||||
elif propname.startswith("db_"):
|
||||
OOB_HANDLER.remove_field_monitor(obj, session.sessid, propname, "oob_return_field_report")
|
||||
OOB_HANDLER.remove_field_monitor(obj, session, propname, "oob_return_field_report")
|
||||
else: # assume attribute
|
||||
OOB_HANDLER.remove_attribute_monitor(obj, session.sessid, propname, "oob_return_attribute_report")
|
||||
OOB_HANDLER.remove_attribute_monitor(obj, session, propname, "oob_return_attribute_report")
|
||||
else:
|
||||
oob_error(session, "You must log in first.")
|
||||
|
||||
|
|
@ -358,7 +358,7 @@ def oob_list(session, mode, *args, **kwargs):
|
|||
# we need to check so as to use the right return value depending on if it is
|
||||
# an Attribute (identified by tracking the db_value field) or a normal database field
|
||||
# reported is a list of tuples (obj, propname, args, kwargs)
|
||||
reported = OOB_HANDLER.get_all_monitors(session.sessid)
|
||||
reported = OOB_HANDLER.get_all_monitors(session)
|
||||
reported = [rep[0].key if rep[1] == "db_value" else rep[1] for rep in reported]
|
||||
session.msg(oob=("REPORTED_VARIABLES", reported))
|
||||
elif mode == "SENDABLE_VARIABLES":
|
||||
|
|
|
|||
|
|
@ -70,15 +70,17 @@ class OOBFieldMonitor(object):
|
|||
# oobtuples is a list [(oobfuncname, args, kwargs), ...],
|
||||
# a potential list of oob commands to call when this
|
||||
# field changes.
|
||||
for (oobfuncname, args, kwargs) in oobtuples:
|
||||
OOB_HANDLER.execute_cmd(sessid, oobfuncname, fieldname, self.obj, *args, **kwargs)
|
||||
sessid = SESSIONS.get(sessid)
|
||||
if sessid:
|
||||
for (oobfuncname, args, kwargs) in oobtuples:
|
||||
OOB_HANDLER.execute_cmd(sessid, oobfuncname, fieldname, self.obj, *args, **kwargs)
|
||||
|
||||
def add(self, sessid, oobfuncname, *args, **kwargs):
|
||||
def add(self, session, oobfuncname, *args, **kwargs):
|
||||
"""
|
||||
Add a specific tracking callback to monitor
|
||||
|
||||
Args:
|
||||
sessid (int): Session id
|
||||
session (int): Session.
|
||||
oobfuncname (str): oob command to call when field updates
|
||||
args,kwargs (any): arguments to pass to oob commjand
|
||||
|
||||
|
|
@ -88,9 +90,9 @@ class OOBFieldMonitor(object):
|
|||
field updates.
|
||||
|
||||
"""
|
||||
self.subscribers[sessid].append((oobfuncname, args, kwargs))
|
||||
self.subscribers[session.sessid].append((oobfuncname, args, kwargs))
|
||||
|
||||
def remove(self, sessid, oobfuncname=None):
|
||||
def remove(self, session, oobfuncname=None):
|
||||
"""
|
||||
Remove a subscribing session from the monitor
|
||||
|
||||
|
|
@ -101,10 +103,10 @@ class OOBFieldMonitor(object):
|
|||
|
||||
"""
|
||||
if oobfuncname:
|
||||
self.subscribers[sessid] = [item for item in self.subscribers[sessid]
|
||||
self.subscribers[session.sessid] = [item for item in self.subscribers[session.sessid]
|
||||
if item[0] != oobfuncname]
|
||||
else:
|
||||
self.subscribers.pop(sessid, None)
|
||||
self.subscribers.pop(session.sessid, None)
|
||||
|
||||
|
||||
class OOBAtRepeater(object):
|
||||
|
|
@ -268,22 +270,20 @@ class OOBHandler(TickerHandler):
|
|||
oobfuncname = kwargs["_oobfuncname"]
|
||||
self.add_repeater(obj, sessid, oobfuncname, interval, *args, **kwargs)
|
||||
|
||||
def add_repeater(self, obj, sessid, oobfuncname, interval=20, *args, **kwargs):
|
||||
def add_repeater(self, obj, session, oobfuncname, interval=20, *args, **kwargs):
|
||||
"""
|
||||
Set an oob function to be repeatedly called.
|
||||
|
||||
Args:
|
||||
obj (Object) - the object on which to register the repeat
|
||||
sessid (int) - session id of the session registering
|
||||
oobfuncname (str) - oob function name to call every interval seconds
|
||||
interval (int, optional) - interval to call oobfunc, in seconds
|
||||
obj (Object); The object on which to register the repeat.
|
||||
session (Session): Session of the session registering.
|
||||
oobfuncname (str): Oob function name to call every interval seconds.
|
||||
interval (int, optional): Interval to call oobfunc, in seconds.
|
||||
|
||||
Notes:
|
||||
*args, **kwargs are used as extra arguments to the oobfunc.
|
||||
"""
|
||||
# check so we didn't get a session instead of a sessid
|
||||
if not isinstance(sessid, int):
|
||||
sessid = sessid.sessid
|
||||
|
||||
sessid = session
|
||||
hook = OOBAtRepeater()
|
||||
hookname = self._get_repeater_hook_name(oobfuncname, interval, sessid)
|
||||
_SA(obj, hookname, hook)
|
||||
|
|
@ -291,20 +291,18 @@ class OOBHandler(TickerHandler):
|
|||
kwargs.update({"_sessid":sessid, "_oobfuncname":oobfuncname})
|
||||
super(OOBHandler, self).add(obj, int(interval), oobfuncname, hookname, *args, **kwargs)
|
||||
|
||||
def remove_repeater(self, obj, sessid, oobfuncname, interval=20):
|
||||
def remove_repeater(self, obj, session, oobfuncname, interval=20):
|
||||
"""
|
||||
Remove the repeatedly calling oob function
|
||||
|
||||
Args:
|
||||
obj (Object): The object on which the repeater sits
|
||||
sessid (int): Session id of the Session that registered the repeater
|
||||
sessid (Session): Session that registered the repeater
|
||||
oobfuncname (str): Name of oob function to call at repeat
|
||||
interval (int, optional): Number of seconds between repeats
|
||||
|
||||
"""
|
||||
# check so we didn't get a session instead of a sessid
|
||||
if not isinstance(sessid, int):
|
||||
sessid = sessid.sessid
|
||||
sessid = session.sessid
|
||||
super(OOBHandler, self).remove(obj, interval, idstring=oobfuncname)
|
||||
hookname = self._get_repeater_hook_name(oobfuncname, interval, sessid)
|
||||
try:
|
||||
|
|
@ -312,16 +310,16 @@ class OOBHandler(TickerHandler):
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
def add_field_monitor(self, obj, sessid, field_name, oobfuncname, *args, **kwargs):
|
||||
def add_field_monitor(self, obj, session, field_name, oobfuncname, *args, **kwargs):
|
||||
"""
|
||||
Add a monitor tracking a database field
|
||||
|
||||
Args:
|
||||
obj (Object): The object who'se field is to be monitored
|
||||
sessid (int): Session if of the session monitoring
|
||||
obj (Object): The object who'se field is to be monitored.
|
||||
session (Session): Session monitoring.
|
||||
field_name (str): Name of database field to monitor. The db_* can optionally
|
||||
be skipped (it will be automatically appended if missing)
|
||||
oobfuncname (str): OOB function to call when field changes
|
||||
be skipped (it will be automatically appended if missing).
|
||||
oobfuncname (str): OOB function to call when field changes.
|
||||
|
||||
Notes:
|
||||
When the field updates the given oobfunction will be called as
|
||||
|
|
@ -333,23 +331,21 @@ class OOBHandler(TickerHandler):
|
|||
can also easily get the new field value if you want.
|
||||
|
||||
"""
|
||||
# check so we didn't get a session instead of a sessid
|
||||
if not isinstance(sessid, int):
|
||||
sessid = sessid.sessid
|
||||
sessid = session.sessid
|
||||
# all database field names starts with db_*
|
||||
field_name = field_name if field_name.startswith("db_") else "db_%s" % field_name
|
||||
self._add_monitor(obj, sessid, field_name, oobfuncname, *args, **kwargs)
|
||||
|
||||
def remove_field_monitor(self, obj, sessid, field_name, oobfuncname=None):
|
||||
def remove_field_monitor(self, obj, session, field_name, oobfuncname=None):
|
||||
"""
|
||||
Un-tracks a database field
|
||||
|
||||
Args:
|
||||
obj (Object): Entity with the monitored field
|
||||
sessid (int): Session id of session that monitors
|
||||
obj (Object): Entity with the monitored field.
|
||||
session (Session): Session that monitors.
|
||||
field_name (str): database field monitored (the db_* can optionally be
|
||||
skipped (it will be auto-appended if missing)
|
||||
oobfuncname (str, optional): OOB command to call on that field
|
||||
skipped (it will be auto-appended if missing).
|
||||
oobfuncname (str, optional): OOB command to call on that field.
|
||||
|
||||
Notes:
|
||||
When the Attributes db_value updates the given oobfunction
|
||||
|
|
@ -361,65 +357,57 @@ class OOBHandler(TickerHandler):
|
|||
`obj` is the object on which the field sits. From this you
|
||||
can also easily get the new field value if you want.
|
||||
"""
|
||||
# check so we didn't get a session instead of a sessid
|
||||
if not isinstance(sessid, int):
|
||||
sessid = sessid.sessid
|
||||
sessid = session.sessid
|
||||
field_name = field_name if field_name.startswith("db_") else "db_%s" % field_name
|
||||
self._remove_monitor(obj, sessid, field_name, oobfuncname=oobfuncname)
|
||||
|
||||
def add_attribute_monitor(self, obj, sessid, attr_name, oobfuncname, *args, **kwargs):
|
||||
def add_attribute_monitor(self, obj, session, attr_name, oobfuncname, *args, **kwargs):
|
||||
"""
|
||||
Monitor the changes of an Attribute on an object. Will trigger when
|
||||
the Attribute's `db_value` field updates.
|
||||
|
||||
Args:
|
||||
obj (Object): Object with the Attribute to monitor.
|
||||
sessid (int): Session id of monitoring Session.
|
||||
session (Session): Session monitoring Session.
|
||||
attr_name (str): Name (key) of Attribute to monitor.
|
||||
oobfuncname (str): OOB function to call when Attribute updates.
|
||||
|
||||
"""
|
||||
# check so we didn't get a session instead of a sessid
|
||||
if not isinstance(sessid, int):
|
||||
sessid = sessid.sessid
|
||||
sessid = session.sessid
|
||||
# get the attribute object if we can
|
||||
attrobj = obj.attributes.get(attr_name, return_obj=True)
|
||||
if attrobj:
|
||||
self._add_monitor(attrobj, sessid, "db_value", oobfuncname)
|
||||
|
||||
def remove_attribute_monitor(self, obj, sessid, attr_name, oobfuncname):
|
||||
def remove_attribute_monitor(self, obj, session, attr_name, oobfuncname):
|
||||
"""
|
||||
Deactivate tracking for a given object's Attribute
|
||||
|
||||
Args:
|
||||
obj (Object): Object monitored.
|
||||
sessid (int): Session id of monitoring Session.
|
||||
session (Session): Session monitoring.
|
||||
attr_name (str): Name of Attribute monitored.
|
||||
oobfuncname (str): OOB function name called when Attribute updates.
|
||||
|
||||
"""
|
||||
# check so we didn't get a session instead of a sessid
|
||||
if not isinstance(sessid, int):
|
||||
sessid = sessid.sessid
|
||||
sessid = session.sessid
|
||||
attrobj = obj.attributes.get(attr_name, return_obj=True)
|
||||
if attrobj:
|
||||
self._remove_monitor(attrobj, sessid, "db_value", oobfuncname)
|
||||
|
||||
def get_all_monitors(self, sessid):
|
||||
def get_all_monitors(self, session):
|
||||
"""
|
||||
Get the names of all variables this session is tracking.
|
||||
|
||||
Args:
|
||||
sessid (id): Session id of monitoring Session
|
||||
session (Session): Session monitoring.
|
||||
Returns:
|
||||
stored monitors (tuple): A list of tuples
|
||||
`(obj, fieldname, args, kwargs)` representing all
|
||||
the monitoring the Session with the given sessid is doing.
|
||||
`(obj, fieldname, args, kwargs)` representing all
|
||||
the monitoring the Session with the given sessid is doing.
|
||||
|
||||
"""
|
||||
# check so we didn't get a session instead of a sessid
|
||||
if not isinstance(sessid, int):
|
||||
sessid = sessid.sessid
|
||||
sessid = session.sessid
|
||||
# [(obj, fieldname, args, kwargs), ...]
|
||||
return [(unpack_dbobj(key[0]), key[2], stored[0], stored[1])
|
||||
for key, stored in self.oob_monitor_storage.items() if key[1] == sessid]
|
||||
|
|
@ -441,9 +429,6 @@ class OOBHandler(TickerHandler):
|
|||
`kwargs` are passed into the oob command.
|
||||
|
||||
"""
|
||||
if isinstance(session, int):
|
||||
# a sessid. Convert to a session
|
||||
session = SESSIONS.session_from_sessid(session)
|
||||
if not session:
|
||||
errmsg = "OOB Error: execute_cmd(%s,%s,%s,%s) - no valid session" % \
|
||||
(session, oobfuncname, args, kwargs)
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
protocol = cls(self, **config)
|
||||
protocol.start()
|
||||
|
||||
def server_disconnect(self, sessid, reason=""):
|
||||
def server_disconnect(self, session, reason=""):
|
||||
"""
|
||||
Called by server to force a disconnect by sessid.
|
||||
|
||||
|
|
@ -204,12 +204,11 @@ class PortalSessionHandler(SessionHandler):
|
|||
reason (str, optional): Motivation for disconect.
|
||||
|
||||
"""
|
||||
session = self.get(sessid, None)
|
||||
if session:
|
||||
session.disconnect(reason)
|
||||
if sessid in self:
|
||||
if session.sessid in self:
|
||||
# in case sess.disconnect doesn't delete it
|
||||
del self[sessid]
|
||||
del self[session.sessid]
|
||||
del session
|
||||
|
||||
def server_disconnect_all(self, reason=""):
|
||||
|
|
@ -225,18 +224,17 @@ class PortalSessionHandler(SessionHandler):
|
|||
del session
|
||||
self = {}
|
||||
|
||||
def server_logged_in(self, sessid, data):
|
||||
def server_logged_in(self, session, data):
|
||||
"""
|
||||
The server tells us that the session has been authenticated.
|
||||
Update it. Called by the Server.
|
||||
|
||||
Args:
|
||||
sessid (int): Session id logging in.
|
||||
session (Session): Session logging in.
|
||||
data (dict): The session sync data.
|
||||
|
||||
"""
|
||||
sess = self.get_session(sessid)
|
||||
sess.load_sync_data(data)
|
||||
session.load_sync_data(data)
|
||||
|
||||
def server_session_sync(self, serversessions):
|
||||
"""
|
||||
|
|
@ -395,7 +393,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
if self.command_overflow:
|
||||
reactor.callLater(1.0, self.data_in, None)
|
||||
if self.command_overflow:
|
||||
self.data_out(session.sessid, text=_ERROR_COMMAND_OVERFLOW)
|
||||
self.data_out(session, text=_ERROR_COMMAND_OVERFLOW)
|
||||
return
|
||||
# relay data to Server
|
||||
self.command_counter += 1
|
||||
|
|
@ -409,14 +407,14 @@ class PortalSessionHandler(SessionHandler):
|
|||
reactor.callLater(1.0, self.data_in, None)
|
||||
|
||||
|
||||
def data_out(self, sessid, text=None, **kwargs):
|
||||
def data_out(self, session, text=None, **kwargs):
|
||||
"""
|
||||
Called by server for having the portal relay messages and data
|
||||
to the correct session protocol. We also convert oob input to
|
||||
a generic form here.
|
||||
|
||||
Args:
|
||||
sessid (int): Session id sending data.
|
||||
session (Session): Session sending data.
|
||||
|
||||
Kwargs:
|
||||
text (str): Text from protocol.
|
||||
|
|
@ -426,7 +424,6 @@ class PortalSessionHandler(SessionHandler):
|
|||
#from evennia.server.profiling.timetrace import timetrace
|
||||
#text = timetrace(text, "portalsessionhandler.data_out")
|
||||
|
||||
session = self.get(sessid, None)
|
||||
if session:
|
||||
# convert oob to the generic format
|
||||
if "oob" in kwargs:
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class ServerSession(Session):
|
|||
# done in the default @ic command but without any
|
||||
# hooks, echoes or access checks.
|
||||
obj = _ObjectDB.objects.get(id=self.puid)
|
||||
obj.sessid.add(self.sessid)
|
||||
obj.sessions.add(self)
|
||||
obj.player = self.player
|
||||
self.puid = obj.id
|
||||
self.puppet = obj
|
||||
|
|
@ -239,10 +239,9 @@ class ServerSession(Session):
|
|||
|
||||
"""
|
||||
if self.logged_in:
|
||||
sessid = self.sessid
|
||||
player = self.player
|
||||
if self.puppet:
|
||||
player.unpuppet_object(sessid)
|
||||
player.unpuppet_object(self)
|
||||
uaccount = player
|
||||
uaccount.last_login = timezone.now()
|
||||
uaccount.save()
|
||||
|
|
@ -363,14 +362,14 @@ class ServerSession(Session):
|
|||
return
|
||||
if self.player:
|
||||
# nick replacement
|
||||
puppet = self.player.get_puppet(self.sessid)
|
||||
puppet = self.puppet
|
||||
if puppet:
|
||||
text = puppet.nicks.nickreplace(text,
|
||||
categories=("inputline", "channel"), include_player=True)
|
||||
else:
|
||||
text = self.player.nicks.nickreplace(text,
|
||||
categories=("inputline", "channels"), include_player=False)
|
||||
cmdhandler(self, text, callertype="session", sessid=self.sessid)
|
||||
cmdhandler(self, text, callertype="session", session=self)
|
||||
self.update_session_counters()
|
||||
|
||||
execute_cmd = data_in # alias
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ _ServerConfig = None
|
|||
_ScriptDB = None
|
||||
_OOB_HANDLER = None
|
||||
|
||||
class DummySession(object):
|
||||
sessid = 0
|
||||
DUMMYSESSION = DummySession()
|
||||
|
||||
# AMP signals
|
||||
PCONN = chr(1) # portal session connect
|
||||
|
|
@ -55,6 +58,7 @@ _IDLE_TIMEOUT = settings.IDLE_TIMEOUT
|
|||
_MAX_SERVER_COMMANDS_PER_SECOND = 100.0
|
||||
_MAX_SESSION_COMMANDS_PER_SECOND = 5.0
|
||||
|
||||
|
||||
def delayed_import():
|
||||
"""
|
||||
Helper method for delayed import of all needed entities.
|
||||
|
|
@ -264,7 +268,7 @@ class ServerSessionHandler(SessionHandler):
|
|||
the Server.
|
||||
|
||||
"""
|
||||
self.server.amp_protocol.send_AdminServer2Portal(0, operation=SCONN,
|
||||
self.server.amp_protocol.send_AdminServer2Portal(DUMMYSESSION, operation=SCONN,
|
||||
protocol_path=protocol_path, config=configdict)
|
||||
|
||||
def portal_shutdown(self):
|
||||
|
|
@ -272,7 +276,7 @@ class ServerSessionHandler(SessionHandler):
|
|||
Called by server when shutting down the portal.
|
||||
|
||||
"""
|
||||
self.server.amp_protocol.send_AdminServer2Portal(0,
|
||||
self.server.amp_protocol.send_AdminServer2Portal(DUMMYSESSION,
|
||||
operation=SSHUTD)
|
||||
|
||||
def login(self, session, player, testmode=False):
|
||||
|
|
@ -319,7 +323,7 @@ class ServerSessionHandler(SessionHandler):
|
|||
session.logged_in = True
|
||||
# sync the portal to the session
|
||||
if not testmode:
|
||||
self.server.amp_protocol.send_AdminServer2Portal(session.sessid,
|
||||
self.server.amp_protocol.send_AdminServer2Portal(session,
|
||||
operation=SLOGIN,
|
||||
sessiondata={"logged_in": True})
|
||||
player.at_post_login(sessid=session.sessid)
|
||||
|
|
@ -349,7 +353,7 @@ class ServerSessionHandler(SessionHandler):
|
|||
sessid = session.sessid
|
||||
del self[sessid]
|
||||
# inform portal that session should be closed.
|
||||
self.server.amp_protocol.send_AdminServer2Portal(sessid,
|
||||
self.server.amp_protocol.send_AdminServer2Portal(session,
|
||||
operation=SDISCONN,
|
||||
reason=reason)
|
||||
|
||||
|
|
@ -360,7 +364,7 @@ class ServerSessionHandler(SessionHandler):
|
|||
|
||||
"""
|
||||
sessdata = self.get_all_sync_data()
|
||||
return self.server.amp_protocol.send_AdminServer2Portal(0,
|
||||
return self.server.amp_protocol.send_AdminServer2Portal(DUMMYSESSION,
|
||||
operation=SSYNC,
|
||||
sessiondata=sessdata)
|
||||
|
||||
|
|
@ -376,7 +380,7 @@ class ServerSessionHandler(SessionHandler):
|
|||
for session in self:
|
||||
del session
|
||||
# tell portal to disconnect all sessions
|
||||
self.server.amp_protocol.send_AdminServer2Portal(0,
|
||||
self.server.amp_protocol.send_AdminServer2Portal(DUMMYSESSION,
|
||||
operation=SDISCONNALL,
|
||||
reason=reason)
|
||||
|
||||
|
|
@ -462,12 +466,9 @@ class ServerSessionHandler(SessionHandler):
|
|||
sessions (Session or list): Session(s) found.
|
||||
|
||||
"""
|
||||
if is_iter(sessid):
|
||||
sessions = [self.get(sid) for sid in sessid]
|
||||
s = [sess for sess in sessions if sess and sess.logged_in and player.uid == sess.uid]
|
||||
return s
|
||||
session = self.get(sessid)
|
||||
return session and session.logged_in and player.uid == session.uid and session or None
|
||||
sessions = [self[sid] for sid in make_iter(sessid)
|
||||
if sid in self and self[sid].logged_in and player.uid == self[sid].uid]
|
||||
return sessions[0] if len(sessions) == 1 else sessions
|
||||
|
||||
def sessions_from_player(self, player):
|
||||
"""
|
||||
|
|
@ -495,10 +496,8 @@ class ServerSessionHandler(SessionHandler):
|
|||
more than one Session (MULTISESSION_MODE > 1).
|
||||
|
||||
"""
|
||||
sessid = puppet.sessid.get()
|
||||
if is_iter(sessid):
|
||||
return [self.get(sid) for sid in sessid if sid in self]
|
||||
return self.get(sessid)
|
||||
sessions = puppet.sessid.get()
|
||||
return sessions[0] if len(sessions) == 1 else sessions
|
||||
sessions_from_character = sessions_from_puppet
|
||||
|
||||
def announce_all(self, message):
|
||||
|
|
@ -527,17 +526,17 @@ class ServerSessionHandler(SessionHandler):
|
|||
text = text and to_str(to_unicode(text), encoding=session.encoding)
|
||||
|
||||
# send across AMP
|
||||
self.server.amp_protocol.send_MsgServer2Portal(sessid=session.sessid,
|
||||
self.server.amp_protocol.send_MsgServer2Portal(session,
|
||||
text=text,
|
||||
**kwargs)
|
||||
|
||||
def data_in(self, sessid, text="", **kwargs):
|
||||
def data_in(self, session, text="", **kwargs):
|
||||
"""
|
||||
Data Portal -> Server.
|
||||
We also intercept OOB communication here.
|
||||
|
||||
Args:
|
||||
sessid (int): Session id.
|
||||
sessions (Session): Session.
|
||||
|
||||
Kwargs:
|
||||
text (str): Text from protocol.
|
||||
|
|
@ -546,7 +545,6 @@ class ServerSessionHandler(SessionHandler):
|
|||
"""
|
||||
#from evennia.server.profiling.timetrace import timetrace
|
||||
#text = timetrace(text, "ServerSessionHandler.data_in")
|
||||
session = self.get(sessid, None)
|
||||
if session:
|
||||
text = text and to_unicode(strip_control_sequences(text), encoding=session.encoding)
|
||||
if "oob" in kwargs:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue