Made irc bot connect, but scripthandler lookup is causing traceback when searching for a player)

This commit is contained in:
Griatch 2014-02-24 00:37:32 +01:00
parent 8b52591c2f
commit 6c45d76b56
11 changed files with 70 additions and 37 deletions

View file

@ -472,8 +472,10 @@ class AMPProtocol(amp.AMP):
portal_sessionhandler.server_session_sync(data)
# set a flag in case we are about to shut down soon
self.factory.server_restart_mode = True
elif operation == SCONN: # server_force_connection (for irc/imc2 etc)
portal_sessionhandler.server_connect(**data)
else:
raise Exception("operation %(op)s not recognized." % {'op': operation})
return {}

View file

@ -30,11 +30,16 @@ class IRCBot(irc.IRCClient, Session):
def signedOn(self):
"""
This is called when we successfully connect to
the network. We make sure to store ourself
on the factory.
the network. We make sure to now register with
the game as a full session.
"""
self.join(self.channel)
self.factory.bot = self
self.init_session("ircbot", self.network, self.factory.sessionhandler)
# we link back to our bot and log in
self.uid = self.factory.uid
self.logged_in = True
self.factory.sessionhandler.connect(self)
def privmsg(self, user, channel, msg):
"A message was sent to channel"
@ -55,11 +60,6 @@ class IRCBot(irc.IRCClient, Session):
"Data from server-> IRC"
self.say(self.channel, text)
def start(self):
"Connect session to sessionhandler"
service = internet.TCPClient(self.network, int(self.port), self)
self.sessionhandler.portal.services.addService(service)
self.sessionhandler.connect(self)
class IRCBotFactory(protocol.ReconnectingClientFactory):
"""
@ -71,14 +71,14 @@ class IRCBotFactory(protocol.ReconnectingClientFactory):
factor = 1.5
maxDelay = 60
def __init__(self, botname=None, channel=None, network=None, port=None):
def __init__(self, uid=None, botname=None, channel=None, network=None, port=None):
"Storing some important protocol properties"
self.nickname = botname
self.logger = logger
self.channel = channel
self.network = network
self.port = port
self.bots = None
self.uid = int(uid)
self.nickname = str(botname)
self.channel = str(channel)
self.network = str(network)
self.port = int(port)
self.bot = None
def buildProtocol(self, addr):
"Build the protocol and assign it some properties"
@ -94,6 +94,10 @@ class IRCBotFactory(protocol.ReconnectingClientFactory):
"Tracks reconnections for debugging"
logger.log_infomsg("(re)connecting to %s" % self.channel)
def start(self):
"Connect session to sessionhandler"
service = internet.TCPClient(self.network, self.port, self)
self.sessionhandler.portal.services.addService(service)
#

View file

@ -69,7 +69,7 @@ class PortalSessionHandler(SessionHandler):
operation=PDISCONN)
def server_connect(self, protocol_path="", uid=None, config=dict()):
def server_connect(self, protocol_path="", config=dict()):
"""
Called by server to force the initialization of a new
protocol instance. Server wants this instance to get
@ -79,7 +79,6 @@ class PortalSessionHandler(SessionHandler):
protocol_path - full python path to the class factory
for the protocol used, eg
'src.server.portal.irc.IRCClientFactory'
uid - database uid to the connected player-bot
config - dictionary of configuration options, fed as **kwarg
to protocol class' __init__ method.
@ -91,6 +90,8 @@ class PortalSessionHandler(SessionHandler):
from src.utils.utils import variable_from_module as _MOD_IMPORT
path, clsname = protocol_path.rsplit(".", 1)
cls = _MOD_IMPORT(path, clsname)
if not cls:
raise RuntimeError("ServerConnect: protocol factory '%s' not found." % protocol_path)
protocol = cls(**config)
protocol.sessionhandler = self
protocol.start()

View file

@ -259,7 +259,7 @@ class ServerSessionHandler(SessionHandler):
# server-side access methods
def start_bot_session(self, protocol_path, uid, configdict):
def start_bot_session(self, protocol_path, 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,6 @@ class ServerSessionHandler(SessionHandler):
Server.
"""
data = {"protocol_path":protocol_path,
"uid":uid,
"config":configdict}
self.server.amp_protocol.call_remote_PortalAdmin(0,
operation=SCONN,