mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 01:36:32 +01:00
Started implementing the Bot functionality.
This commit is contained in:
parent
3f1a461e29
commit
f9eece9749
8 changed files with 261 additions and 10 deletions
|
|
@ -473,7 +473,7 @@ class AMPProtocol(amp.AMP):
|
|||
# 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)
|
||||
portal_sessionhandler.server_connect(**data)
|
||||
else:
|
||||
raise Exception("operation %(op)s not recognized." % {'op': operation})
|
||||
return {}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
operation=PDISCONN)
|
||||
|
||||
|
||||
def server_connect(self, protocol_class_path):
|
||||
def server_connect(self, protocol_path="", uid=None):
|
||||
"""
|
||||
Called by server to force the initialization of a new
|
||||
protocol instance. Server wants this instance to get
|
||||
|
|
@ -83,12 +83,12 @@ class PortalSessionHandler(SessionHandler):
|
|||
in a property sessionhandler. It must have a
|
||||
connectionMade() method, responsible for configuring
|
||||
itself and then calling self.sessionhandler.connect(self)
|
||||
like any other protocol.
|
||||
like any other newly connected protocol.
|
||||
"""
|
||||
global _MOD_IMPORT
|
||||
if not _MOD_IMPORT:
|
||||
from src.utils.utils import variable_from_module as _MOD_IMPORT
|
||||
path, clsname = protocol_class_path.rsplit(".", 1)
|
||||
path, clsname = protocol_path.rsplit(".", 1)
|
||||
cls = _MOD_IMPORT(path, clsname)
|
||||
protocol = cls()
|
||||
protocol.sessionhandler = self
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ SDISCONN = chr(5) # server session disconnect
|
|||
SDISCONNALL = chr(6) # server session disconnect all
|
||||
SSHUTD = chr(7) # server shutdown
|
||||
SSYNC = chr(8) # server session sync
|
||||
SCONN = chr(9) # server portal connection (for bots)
|
||||
|
||||
# i18n
|
||||
from django.utils.translation import ugettext as _
|
||||
|
|
@ -256,6 +257,25 @@ class ServerSessionHandler(SessionHandler):
|
|||
# announce the reconnection
|
||||
self.announce_all(_(" ... Server restarted."))
|
||||
|
||||
# server-side access methods
|
||||
|
||||
def start_bot_session(self, protocol_path, uid):
|
||||
"""
|
||||
This method allows the server-side to force the Portal to create
|
||||
a new bot session using the protocol specified by protocol_path,
|
||||
which should be the full python path to the class, including the
|
||||
class name, like "src.server.portal.irc.IRCClient".
|
||||
The new session will use the supplied player-bot uid to
|
||||
initiate an already logged-in connection. The Portal will
|
||||
treat this as a normal connection and henceforth so will the
|
||||
Server.
|
||||
"""
|
||||
data = {"protocol_path":protocol_path,
|
||||
"uid":uid}
|
||||
self.server.amp_protocol.call_remote_PortalAdmin(0,
|
||||
operation=SCONN,
|
||||
data=data)
|
||||
|
||||
def portal_shutdown(self):
|
||||
"""
|
||||
Called by server when shutting down the portal.
|
||||
|
|
@ -263,7 +283,6 @@ class ServerSessionHandler(SessionHandler):
|
|||
self.server.amp_protocol.call_remote_PortalAdmin(0,
|
||||
operation=SSHUTD,
|
||||
data="")
|
||||
# server-side access methods
|
||||
|
||||
def login(self, session, player, testmode=False):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue