2006-12-22 01:40:40 +00:00
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
This module defines handlers for storing sessions when handles
|
|
|
|
|
sessions of users connecting to the server.
|
2010-12-07 02:34:59 +00:00
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
There are two similar but separate stores of sessions:
|
|
|
|
|
ServerSessionHandler - this stores generic game sessions
|
|
|
|
|
for the game. These sessions has no knowledge about
|
|
|
|
|
how they are connected to the world.
|
|
|
|
|
PortalSessionHandler - this stores sessions created by
|
|
|
|
|
twisted protocols. These are dumb connectors that
|
|
|
|
|
handle network communication but holds no game info.
|
|
|
|
|
|
2006-12-22 01:40:40 +00:00
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
|
|
|
|
|
import time
|
2010-12-07 02:34:59 +00:00
|
|
|
from django.conf import settings
|
2009-04-20 22:34:16 +00:00
|
|
|
from django.contrib.auth.models import User
|
2011-04-12 21:43:57 +00:00
|
|
|
from src.server.models import ServerConfig
|
2011-09-03 10:22:19 +00:00
|
|
|
from src.utils import utils
|
|
|
|
|
|
2011-11-06 18:53:10 +01:00
|
|
|
from src.commands.cmdhandler import CMD_LOGINSTART
|
|
|
|
|
|
2012-02-25 19:26:54 +01:00
|
|
|
# AMP signals
|
|
|
|
|
PCONN = chr(1) # portal session connect
|
|
|
|
|
PDISCONN = chr(2) # portal session disconnect
|
|
|
|
|
PSYNC = chr(3) # portal session sync
|
|
|
|
|
SLOGIN = chr(4) # server session login
|
|
|
|
|
SDISCONN = chr(5) # server session disconnect
|
|
|
|
|
SDISCONNALL = chr(6) # server session disconnect all
|
|
|
|
|
SSHUTD = chr(7) # server shutdown
|
|
|
|
|
SSYNC = chr(8) # server session sync
|
|
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
# i18n
|
|
|
|
|
from django.utils.translation import ugettext as _
|
2008-06-15 17:21:02 +00:00
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
ALLOW_MULTISESSION = settings.ALLOW_MULTISESSION
|
2011-09-03 10:22:19 +00:00
|
|
|
IDLE_TIMEOUT = settings.IDLE_TIMEOUT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SessionHandler(object):
|
|
|
|
|
"""
|
|
|
|
|
This handler holds a stack of sessions.
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
"""
|
|
|
|
|
Init the handler.
|
|
|
|
|
"""
|
|
|
|
|
self.sessions = {}
|
|
|
|
|
|
|
|
|
|
def get_sessions(self, include_unloggedin=False):
|
|
|
|
|
"""
|
|
|
|
|
Returns the connected session objects.
|
|
|
|
|
"""
|
|
|
|
|
if include_unloggedin:
|
|
|
|
|
return self.sessions.values()
|
|
|
|
|
else:
|
|
|
|
|
return [session for session in self.sessions.values() if session.logged_in]
|
|
|
|
|
|
|
|
|
|
def get_session(self, sessid):
|
|
|
|
|
"""
|
|
|
|
|
Get session by sessid
|
|
|
|
|
"""
|
|
|
|
|
return self.sessions.get(sessid, None)
|
|
|
|
|
|
|
|
|
|
def get_all_sync_data(self):
|
|
|
|
|
"""
|
|
|
|
|
Create a dictionary of sessdata dicts representing all
|
|
|
|
|
sessions in store.
|
|
|
|
|
"""
|
|
|
|
|
sessdict = {}
|
|
|
|
|
for sess in self.sessions.values():
|
|
|
|
|
# copy all relevant data from all sessions
|
|
|
|
|
sessdict[sess.sessid] = sess.get_sync_data()
|
|
|
|
|
return sessdict
|
2009-04-20 22:34:16 +00:00
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
#------------------------------------------------------------
|
2011-09-03 10:22:19 +00:00
|
|
|
# Server-SessionHandler class
|
2010-12-07 02:34:59 +00:00
|
|
|
#------------------------------------------------------------
|
2007-04-25 20:11:29 +00:00
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
class ServerSessionHandler(SessionHandler):
|
2008-06-13 19:52:29 +00:00
|
|
|
"""
|
2010-12-07 02:34:59 +00:00
|
|
|
This object holds the stack of sessions active in the game at
|
|
|
|
|
any time.
|
|
|
|
|
|
|
|
|
|
A session register with the handler in two steps, first by
|
|
|
|
|
registering itself with the connect() method. This indicates an
|
|
|
|
|
non-authenticated session. Whenever the session is authenticated
|
|
|
|
|
the session together with the related player is sent to the login()
|
|
|
|
|
method.
|
2007-05-21 20:52:05 +00:00
|
|
|
|
2008-06-13 19:52:29 +00:00
|
|
|
"""
|
2007-05-09 15:28:12 +00:00
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
# AMP communication methods
|
|
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
def __init__(self):
|
|
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
Init the handler.
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
self.sessions = {}
|
2011-02-21 12:56:44 +00:00
|
|
|
self.server = None
|
2011-11-20 11:52:01 +01:00
|
|
|
self.server_data = {"servername":settings.SERVERNAME}
|
2011-02-21 12:56:44 +00:00
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
def portal_connect(self, sessid, session):
|
|
|
|
|
"""
|
|
|
|
|
Called by Portal when a new session has connected.
|
|
|
|
|
Creates a new, unlogged-in game session.
|
|
|
|
|
"""
|
|
|
|
|
self.sessions[sessid] = session
|
2011-11-06 18:53:10 +01:00
|
|
|
session.execute_cmd(CMD_LOGINSTART)
|
2011-09-03 10:22:19 +00:00
|
|
|
|
|
|
|
|
def portal_disconnect(self, sessid):
|
|
|
|
|
"""
|
|
|
|
|
Called by Portal when portal reports a closing of a session
|
|
|
|
|
from the portal side.
|
|
|
|
|
"""
|
|
|
|
|
session = self.sessions.get(sessid, None)
|
|
|
|
|
if session:
|
|
|
|
|
del self.sessions[session.sessid]
|
|
|
|
|
self.session_count(-1)
|
|
|
|
|
|
|
|
|
|
def portal_session_sync(self, sesslist):
|
|
|
|
|
"""
|
|
|
|
|
Syncing all session ids of the portal with the ones of the server. This is instantiated
|
|
|
|
|
by the portal when reconnecting.
|
|
|
|
|
|
|
|
|
|
sesslist is a complete list of (sessid, session) pairs, matching the list on the portal.
|
|
|
|
|
if session was logged in, the amp handler will have logged them in before this point.
|
|
|
|
|
"""
|
|
|
|
|
for sess in self.sessions.values():
|
|
|
|
|
# we delete the old session to make sure to catch eventual lingering references.
|
|
|
|
|
del sess
|
|
|
|
|
for sess in sesslist:
|
|
|
|
|
self.sessions[sess.sessid] = sess
|
|
|
|
|
sess.at_sync()
|
|
|
|
|
|
|
|
|
|
def portal_shutdown(self):
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
Called by server when shutting down the portal.
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
self.server.amp_protocol.call_remote_PortalAdmin(0,
|
2012-02-25 19:26:54 +01:00
|
|
|
operation=SSHUTD,
|
2011-09-03 10:22:19 +00:00
|
|
|
data="")
|
|
|
|
|
# server-side access methods
|
|
|
|
|
|
|
|
|
|
def disconnect(self, session, reason=""):
|
|
|
|
|
"""
|
|
|
|
|
Called from server side to remove session and inform portal
|
|
|
|
|
of this fact.
|
|
|
|
|
"""
|
|
|
|
|
session = self.sessions.get(session.sessid, None)
|
|
|
|
|
if session:
|
|
|
|
|
sessid = session.sessid
|
|
|
|
|
del self.sessions[sessid]
|
|
|
|
|
# inform portal that session should be closed.
|
|
|
|
|
self.server.amp_protocol.call_remote_PortalAdmin(sessid,
|
2012-02-25 19:26:54 +01:00
|
|
|
operation=SDISCONN,
|
2011-09-03 10:22:19 +00:00
|
|
|
data=reason)
|
|
|
|
|
self.session_count(-1)
|
|
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
def login(self, session):
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
|
|
|
|
Log in the previously unloggedin session and the player we by
|
|
|
|
|
now should know is connected to it. After this point we
|
|
|
|
|
assume the session to be logged in one way or another.
|
|
|
|
|
"""
|
|
|
|
|
# prep the session with player/user info
|
2011-09-03 10:22:19 +00:00
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
if not ALLOW_MULTISESSION:
|
|
|
|
|
# disconnect previous sessions.
|
|
|
|
|
self.disconnect_duplicate_sessions(session)
|
2011-09-03 10:22:19 +00:00
|
|
|
session.logged_in = True
|
2010-12-07 02:34:59 +00:00
|
|
|
self.session_count(1)
|
2011-09-03 10:22:19 +00:00
|
|
|
# sync the portal to this session
|
|
|
|
|
sessdata = session.get_sync_data()
|
|
|
|
|
self.server.amp_protocol.call_remote_PortalAdmin(session.sessid,
|
2012-02-25 19:26:54 +01:00
|
|
|
operation=SLOGIN,
|
2011-09-03 10:22:19 +00:00
|
|
|
data=sessdata)
|
|
|
|
|
|
|
|
|
|
def session_sync(self):
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
This is called by the server when it reboots. It syncs all session data
|
|
|
|
|
to the portal.
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
sessdata = self.get_all_sync_data()
|
|
|
|
|
self.server.amp_protocol.call_remote_PortalAdmin(0,
|
2012-02-25 19:26:54 +01:00
|
|
|
SSYNC,
|
2011-09-03 10:22:19 +00:00
|
|
|
data=sessdata)
|
2010-08-29 18:46:58 +00:00
|
|
|
|
|
|
|
|
|
2012-02-25 19:26:54 +01:00
|
|
|
def disconnect_all_sessions(self, reason=_("You have been disconnected.")):
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
|
|
|
|
Cleanly disconnect all of the connected sessions.
|
|
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
|
|
|
|
|
for session in self.sessions:
|
|
|
|
|
del session
|
2010-12-07 02:34:59 +00:00
|
|
|
self.session_count(0)
|
2011-09-03 10:22:19 +00:00
|
|
|
# tell portal to disconnect all sessions
|
|
|
|
|
self.server.amp_protocol.call_remote_PortalAdmin(0,
|
2012-02-25 19:26:54 +01:00
|
|
|
operation=SDISCONNALL,
|
2011-09-03 10:22:19 +00:00
|
|
|
data=reason)
|
2010-12-07 02:34:59 +00:00
|
|
|
|
2012-02-25 19:26:54 +01:00
|
|
|
def disconnect_duplicate_sessions(self, curr_session, reason = _("Logged in from elsewhere. Disconnecting.") ):
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
2011-02-23 19:19:39 +00:00
|
|
|
Disconnects any existing sessions with the same game object.
|
2010-12-07 02:34:59 +00:00
|
|
|
"""
|
2011-02-23 19:19:39 +00:00
|
|
|
curr_char = curr_session.get_character()
|
2011-09-03 10:22:19 +00:00
|
|
|
doublet_sessions = [sess for sess in self.sessions
|
|
|
|
|
if sess.logged_in
|
|
|
|
|
and sess.get_character() == curr_char
|
|
|
|
|
and sess != curr_session]
|
|
|
|
|
for sessid in doublet_sessions:
|
|
|
|
|
self.disconnect(session, reason)
|
|
|
|
|
self.session_count(-1)
|
|
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
|
|
|
|
|
def validate_sessions(self):
|
|
|
|
|
"""
|
|
|
|
|
Check all currently connected sessions (logged in and not)
|
|
|
|
|
and see if any are dead.
|
|
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
tcurr = time.time()
|
2012-02-25 21:15:58 +01:00
|
|
|
reason= _("Idle timeout exceeded, disconnecting.")
|
2012-02-25 19:26:54 +01:00
|
|
|
for session in (session for session in self.sessions.values()
|
|
|
|
|
if session.logged_in and IDLE_TIMEOUT > 0
|
|
|
|
|
and (tcurr - session.cmd_last) > IDLE_TIMEOUT):
|
|
|
|
|
self.disconnect(session, reason=reason)
|
2011-09-03 10:22:19 +00:00
|
|
|
self.session_count(-1)
|
|
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
def session_count(self, num=None):
|
|
|
|
|
"""
|
|
|
|
|
Count up/down the number of connected, authenticated users.
|
|
|
|
|
If num is None, the current number of sessions is returned.
|
|
|
|
|
|
|
|
|
|
num can be a positive or negative value to be added to the current count.
|
|
|
|
|
If 0, the counter will be reset to 0.
|
|
|
|
|
"""
|
|
|
|
|
if num == None:
|
|
|
|
|
# show the current value. This also syncs it.
|
2011-04-12 21:43:57 +00:00
|
|
|
return int(ServerConfig.objects.conf('nr_sessions', default=0))
|
2010-12-07 02:34:59 +00:00
|
|
|
elif num == 0:
|
|
|
|
|
# reset value to 0
|
2011-04-12 21:43:57 +00:00
|
|
|
ServerConfig.objects.conf('nr_sessions', 0)
|
2010-12-07 02:34:59 +00:00
|
|
|
else:
|
|
|
|
|
# add/remove session count from value
|
2011-04-12 21:43:57 +00:00
|
|
|
add = int(ServerConfig.objects.conf('nr_sessions', default=0))
|
2010-12-07 02:34:59 +00:00
|
|
|
num = max(0, num + add)
|
2011-04-12 21:43:57 +00:00
|
|
|
ServerConfig.objects.conf('nr_sessions', str(num))
|
2010-12-07 02:34:59 +00:00
|
|
|
|
2010-12-11 13:37:26 +00:00
|
|
|
def player_count(self):
|
|
|
|
|
"""
|
|
|
|
|
Get the number of connected players (not sessions since a player
|
|
|
|
|
may have more than one session connected if ALLOW_MULTISESSION is True)
|
|
|
|
|
Only logged-in players are counted here.
|
|
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
return len(set(session.uid for session in self.sessions.values() if session.logged_in))
|
2010-12-11 13:37:26 +00:00
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
def sessions_from_player(self, player):
|
|
|
|
|
"""
|
|
|
|
|
Given a player, return any matching sessions.
|
|
|
|
|
"""
|
|
|
|
|
username = player.user.username
|
|
|
|
|
try:
|
|
|
|
|
uobj = User.objects.get(username=username)
|
|
|
|
|
except User.DoesNotExist:
|
|
|
|
|
return None
|
2010-08-29 18:46:58 +00:00
|
|
|
uid = uobj.id
|
2011-09-03 10:22:19 +00:00
|
|
|
return [session for session in self.sessions.values() if session.logged_in and session.uid == uid]
|
2010-12-07 02:34:59 +00:00
|
|
|
|
|
|
|
|
def sessions_from_character(self, character):
|
|
|
|
|
"""
|
|
|
|
|
Given a game character, return any matching sessions.
|
|
|
|
|
"""
|
|
|
|
|
player = character.player
|
|
|
|
|
if player:
|
|
|
|
|
return self.sessions_from_player(player)
|
|
|
|
|
return None
|
|
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
|
|
|
|
|
def announce_all(self, message):
|
|
|
|
|
"""
|
|
|
|
|
Send message to all connected sessions
|
|
|
|
|
"""
|
|
|
|
|
for sess in self.sessions.values():
|
|
|
|
|
self.data_out(sess, message)
|
|
|
|
|
|
|
|
|
|
def data_out(self, session, string="", data=""):
|
|
|
|
|
"""
|
|
|
|
|
Sending data Server -> Portal
|
|
|
|
|
"""
|
|
|
|
|
self.server.amp_protocol.call_remote_MsgServer2Portal(sessid=session.sessid,
|
|
|
|
|
msg=string,
|
|
|
|
|
data=data)
|
|
|
|
|
def data_in(self, sessid, string="", data=""):
|
|
|
|
|
"""
|
|
|
|
|
Data Portal -> Server
|
|
|
|
|
"""
|
|
|
|
|
session = self.sessions.get(sessid, None)
|
|
|
|
|
if session:
|
|
|
|
|
session.execute_cmd(string)
|
|
|
|
|
|
|
|
|
|
# ignore 'data' argument for now; this is otherwise the place
|
|
|
|
|
# to put custom effects on the server due to data input, e.g.
|
|
|
|
|
# from a custom client.
|
|
|
|
|
|
2011-11-08 22:54:02 +01:00
|
|
|
def oob_data_in(self, sessid, data):
|
|
|
|
|
"""
|
|
|
|
|
OOB (Out-of-band) Data Portal -> Server
|
|
|
|
|
"""
|
|
|
|
|
session = self.sessions.get(sessid, None)
|
|
|
|
|
if session:
|
|
|
|
|
session.oob_data_in(data)
|
|
|
|
|
|
|
|
|
|
def oob_data_out(self, session, data):
|
|
|
|
|
"""
|
|
|
|
|
OOB (Out-of-band) Data Server -> Portal
|
|
|
|
|
"""
|
|
|
|
|
self.server.amp_protocol.call_remote_OOBServer2Portal(session.sessid,
|
|
|
|
|
data=data)
|
2011-09-03 10:22:19 +00:00
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
|
# Portal-SessionHandler class
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class PortalSessionHandler(SessionHandler):
|
|
|
|
|
"""
|
|
|
|
|
This object holds the sessions connected to the portal at any time.
|
|
|
|
|
It is synced with the server's equivalent SessionHandler over the AMP
|
|
|
|
|
connection.
|
|
|
|
|
|
|
|
|
|
Sessions register with the handler using the connect() method. This
|
|
|
|
|
will assign a new unique sessionid to the session and send that sessid
|
|
|
|
|
to the server using the AMP connection.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
"""
|
|
|
|
|
Init the handler
|
|
|
|
|
"""
|
|
|
|
|
self.portal = None
|
|
|
|
|
self.sessions = {}
|
|
|
|
|
self.latest_sessid = 0
|
2011-11-20 11:52:01 +01:00
|
|
|
self.uptime = time.time()
|
|
|
|
|
self.connection_time = 0
|
|
|
|
|
|
|
|
|
|
def at_server_connection(self):
|
|
|
|
|
"""
|
|
|
|
|
Called when the Portal establishes connection with the
|
|
|
|
|
Server. At this point, the AMP connection is already
|
|
|
|
|
established.
|
|
|
|
|
"""
|
|
|
|
|
self.connection_time = time.time()
|
2011-09-03 10:22:19 +00:00
|
|
|
|
|
|
|
|
def connect(self, session):
|
|
|
|
|
"""
|
|
|
|
|
Called by protocol at first connect. This adds a not-yet authenticated session
|
|
|
|
|
using an ever-increasing counter for sessid.
|
|
|
|
|
"""
|
|
|
|
|
self.latest_sessid += 1
|
|
|
|
|
sessid = self.latest_sessid
|
|
|
|
|
session.sessid = sessid
|
|
|
|
|
sessdata = session.get_sync_data()
|
|
|
|
|
self.sessions[sessid] = session
|
|
|
|
|
# sync with server-side
|
|
|
|
|
self.portal.amp_protocol.call_remote_ServerAdmin(sessid,
|
2012-02-25 19:26:54 +01:00
|
|
|
operation=PCONN,
|
2011-09-03 10:22:19 +00:00
|
|
|
data=sessdata)
|
|
|
|
|
def disconnect(self, session):
|
|
|
|
|
"""
|
|
|
|
|
Called from portal side when the connection is closed from the portal side.
|
|
|
|
|
"""
|
|
|
|
|
sessid = session.sessid
|
|
|
|
|
self.portal.amp_protocol.call_remote_ServerAdmin(sessid,
|
2012-02-25 19:26:54 +01:00
|
|
|
operation=PDISCONN)
|
2011-09-03 10:22:19 +00:00
|
|
|
|
|
|
|
|
def server_disconnect(self, sessid, reason=""):
|
|
|
|
|
"""
|
|
|
|
|
Called by server to force a disconnect by sessid
|
|
|
|
|
"""
|
|
|
|
|
session = self.sessions.get(sessid, None)
|
|
|
|
|
if session:
|
|
|
|
|
session.disconnect(reason)
|
|
|
|
|
del session
|
|
|
|
|
|
|
|
|
|
def server_disconnect_all(self, reason=""):
|
|
|
|
|
"""
|
|
|
|
|
Called by server when forcing a clean disconnect for everyone.
|
|
|
|
|
"""
|
|
|
|
|
for session in self.sessions.values():
|
|
|
|
|
session.disconnect(reason)
|
|
|
|
|
del session
|
|
|
|
|
|
2011-11-20 11:52:01 +01:00
|
|
|
|
|
|
|
|
def count_loggedin(self, include_unloggedin=False):
|
|
|
|
|
"""
|
|
|
|
|
Count loggedin connections, alternatively count all connections.
|
|
|
|
|
"""
|
|
|
|
|
return len(self.get_sessions(include_unloggedin=include_unloggedin))
|
|
|
|
|
|
|
|
|
|
|
2010-12-07 02:34:59 +00:00
|
|
|
def session_from_suid(self, suid):
|
|
|
|
|
"""
|
|
|
|
|
Given a session id, retrieve the session (this is primarily
|
|
|
|
|
intended to be called by web clients)
|
|
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
return [sess for sess in self.get_sessions(include_unloggedin=True)
|
|
|
|
|
if hasattr(sess, 'suid') and sess.suid == suid]
|
2010-12-07 02:34:59 +00:00
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
def data_in(self, session, string="", data=""):
|
|
|
|
|
"""
|
|
|
|
|
Called by portal sessions for relaying data coming
|
|
|
|
|
in from the protocol to the server. data is
|
|
|
|
|
serialized before passed on.
|
|
|
|
|
"""
|
|
|
|
|
self.portal.amp_protocol.call_remote_MsgPortal2Server(session.sessid,
|
|
|
|
|
msg=string,
|
|
|
|
|
data=data)
|
2010-12-11 13:37:26 +00:00
|
|
|
def announce_all(self, message):
|
|
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
Send message to all connection sessions
|
2010-12-11 13:37:26 +00:00
|
|
|
"""
|
2011-09-03 10:22:19 +00:00
|
|
|
for session in self.sessions.values():
|
|
|
|
|
session.data_out(message)
|
2010-12-07 02:34:59 +00:00
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
def data_out(self, sessid, string="", data=""):
|
|
|
|
|
"""
|
|
|
|
|
Called by server for having the portal relay messages and data
|
|
|
|
|
to the correct session protocol.
|
|
|
|
|
"""
|
|
|
|
|
session = self.sessions.get(sessid, None)
|
|
|
|
|
if session:
|
|
|
|
|
session.data_out(string, data=data)
|
2010-12-07 02:34:59 +00:00
|
|
|
|
2011-11-08 22:54:02 +01:00
|
|
|
def oob_data_in(self, session, data):
|
|
|
|
|
"""
|
|
|
|
|
OOB (Out-of-band) data Portal -> Server
|
|
|
|
|
"""
|
|
|
|
|
self.portal.amp_protocol.call_remote_OOBPortal2Server(session.sessid,
|
|
|
|
|
data=data)
|
|
|
|
|
|
|
|
|
|
def oob_data_out(self, sessid, data):
|
|
|
|
|
"""
|
|
|
|
|
OOB (Out-of-band) data Server -> Portal
|
|
|
|
|
"""
|
|
|
|
|
session = self.sessions.get(sessid, None)
|
|
|
|
|
if session:
|
|
|
|
|
session.oob_data_out(data)
|
|
|
|
|
|
2011-09-03 10:22:19 +00:00
|
|
|
SESSIONS = ServerSessionHandler()
|
|
|
|
|
PORTAL_SESSIONS = PortalSessionHandler()
|