From 2ae5d56928bf4a08626b0e3a0fcb3aebe26299b4 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 22 Feb 2014 09:56:21 +0100 Subject: [PATCH] Continued work on the bots. --- src/players/bots.py | 5 +++-- src/server/portal/portalsessionhandler.py | 17 +++++++++-------- src/server/sessionhandler.py | 5 +++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/players/bots.py b/src/players/bots.py index d17f8a852c..9d73f9655e 100644 --- a/src/players/bots.py +++ b/src/players/bots.py @@ -112,7 +112,7 @@ class IRCBot(Bot): # instruct the server and portal to create a new session _SESSIONS.start_bot_session("src.server.portal.irc.IRCClient", self.id) - def connect_to_channel(self, channelname): + def connect_to_channel(self, botkey, channelname): """ Connect the bot to an Evennia channel """ @@ -130,4 +130,5 @@ class IRCBot(Bot): self.dbobj.msg(text=text) - def execute_cmd( + def execute_cmd(self): + pass diff --git a/src/server/portal/portalsessionhandler.py b/src/server/portal/portalsessionhandler.py index 8e54bf960c..3e9a8db85c 100644 --- a/src/server/portal/portalsessionhandler.py +++ b/src/server/portal/portalsessionhandler.py @@ -69,28 +69,29 @@ class PortalSessionHandler(SessionHandler): operation=PDISCONN) - def server_connect(self, protocol_path="", uid=None): + def server_connect(self, protocol_path="", uid=None, config=dict()): """ Called by server to force the initialization of a new protocol instance. Server wants this instance to get a unique sessid and to be connected back as normal. This is used to initiate irc/imc2/rss etc connections. - protocol_class_path - full python path to the class factory + protocol_path - full python path to the class factory for the protocol used, eg 'src.server.portal.irc.IRCClient' - The given class will be instantiated with this handler - in a property sessionhandler. It must have a - connectionMade() method, responsible for configuring - itself and then calling self.sessionhandler.connect(self) - like any other newly connected protocol. + uid - database uid to the connected player-bot + config - dictionary of configuration options, fed as **kwarg + to protocol class' __init__ method. + + The called protocol class must have a method ConnectionMade + that calls the portalsession.connect() as a normal protocol. """ global _MOD_IMPORT if not _MOD_IMPORT: from src.utils.utils import variable_from_module as _MOD_IMPORT path, clsname = protocol_path.rsplit(".", 1) cls = _MOD_IMPORT(path, clsname) - protocol = cls() + protocol = cls(**config) protocol.sessionhandler = self protocol.connectionMade() diff --git a/src/server/sessionhandler.py b/src/server/sessionhandler.py index 45b5337dce..38cd1d7ece 100644 --- a/src/server/sessionhandler.py +++ b/src/server/sessionhandler.py @@ -259,7 +259,7 @@ class ServerSessionHandler(SessionHandler): # server-side access methods - def start_bot_session(self, protocol_path, uid): + def start_bot_session(self, protocol_path, uid, configdict): """ This method allows the server-side to force the Portal to create a new bot session using the protocol specified by protocol_path, @@ -271,7 +271,8 @@ class ServerSessionHandler(SessionHandler): Server. """ data = {"protocol_path":protocol_path, - "uid":uid} + "uid":uid, + "config":configdict} self.server.amp_protocol.call_remote_PortalAdmin(0, operation=SCONN, data=data)