Refactoring to go with the fixed AMP structure and methods.

This commit is contained in:
Griatch 2015-09-21 16:50:05 +02:00
parent d553c46ba5
commit 1d17302d16
6 changed files with 30 additions and 28 deletions

View file

@ -425,9 +425,6 @@ class DefaultObject(ObjectDB):
All extra kwargs will be passed on to the protocol. All extra kwargs will be passed on to the protocol.
""" """
from evennia.server.profiling.timetrace import timetrace
text = timetrace(text, "Object.msg")
text = to_str(text, force_string=True) if text != None else "" text = to_str(text, force_string=True) if text != None else ""
if from_obj: if from_obj:
# call hook # call hook

View file

@ -255,8 +255,9 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
kwargs (any): Options from the protocol. kwargs (any): Options from the protocol.
""" """
from evennia.server.profiling.timetrace import timetrace #from evennia.server.profiling.timetrace import timetrace
text = timetrace(text, "telnet.data_in") #text = timetrace(text, "telnet.data_in")
self.sessionhandler.data_in(self, text=text, **kwargs) self.sessionhandler.data_in(self, text=text, **kwargs)
def data_out(self, text=None, **kwargs): def data_out(self, text=None, **kwargs):
@ -291,8 +292,11 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
are given. are given.
""" """
from evennia.server.profiling.timetrace import timetrace ## profiling, debugging
text = timetrace(text, "telnet.data_out", final=True) #if text.startswith("TEST_MESSAGE"): 1/0
#from evennia.server.profiling.timetrace import timetrace
#text = timetrace(text, "telnet.data_out", final=True)
try: try:
text = utils.to_str(text if text else "", encoding=self.encoding) text = utils.to_str(text if text else "", encoding=self.encoding)
except Exception, e: except Exception, e:

View file

@ -32,7 +32,7 @@ def timetrace(message, idstring, tracemessage="TEST_MESSAGE", final=False):
print "** timetrace (%s): dT=%fs, total=%fs." % (idstring, t1-tlast, t1-t0) print "** timetrace (%s): dT=%fs, total=%fs." % (idstring, t1-tlast, t1-t0)
if final: if final:
message = "%s (total %f)" % (tracemessage, t1-t0) message = " **** %s (total %f) **** " % (tracemessage, t1-t0)
else: else:
message = "%s %f %f" % (tracemessage, t1, t0) message = "%s %f %f" % (tracemessage, t1, t0)
return message return message

View file

@ -228,8 +228,8 @@ class ServerSession(Session):
kwargs (any): Other parameters from the protocol. kwargs (any): Other parameters from the protocol.
""" """
from evennia.server.profiling.timetrace import timetrace #from evennia.server.profiling.timetrace import timetrace
text = timetrace(text, "ServerSession.data_in") #text = timetrace(text, "ServerSession.data_in")
#explicitly check for None since text can be an empty string, which is #explicitly check for None since text can be an empty string, which is
#also valid #also valid
@ -263,8 +263,8 @@ class ServerSession(Session):
kwargs (any): Other parameters to the protocol. kwargs (any): Other parameters to the protocol.
""" """
from evennia.server.profiling.timetrace import timetrace #from evennia.server.profiling.timetrace import timetrace
text = timetrace(text, "ServerSession.data_out") #text = timetrace(text, "ServerSession.data_out")
text = text if text else "" text = text if text else ""
if _INLINEFUNC_ENABLED and not "raw" in kwargs: if _INLINEFUNC_ENABLED and not "raw" in kwargs:

View file

@ -284,16 +284,16 @@ class ServerSessionHandler(SessionHandler):
""" """
data = {"protocol_path":protocol_path, data = {"protocol_path":protocol_path,
"config":configdict} "config":configdict}
self.server.amp_protocol.call_remote_PortalAdmin(0, self.server.amp_protocol.send_AdminServer2Portal(0,
operation=SCONN, operation=SCONN,
data=data) data=data)
def portal_shutdown(self): def portal_shutdown(self):
""" """
Called by server when shutting down the portal. Called by server when shutting down the portal.
""" """
self.server.amp_protocol.call_remote_PortalAdmin(0, self.server.amp_protocol.send_AdminServer2Portal(0,
operation=SSHUTD, operation=SSHUTD,
data="") data="")
@ -343,7 +343,7 @@ class ServerSessionHandler(SessionHandler):
# sync the portal to the session # sync the portal to the session
sessdata = {"logged_in": True} sessdata = {"logged_in": True}
if not testmode: if not testmode:
self.server.amp_protocol.call_remote_PortalAdmin(session.sessid, self.server.amp_protocol.send_AdminServer2Portal(session.sessid,
operation=SLOGIN, operation=SLOGIN,
data=sessdata) data=sessdata)
player.at_post_login(sessid=session.sessid) player.at_post_login(sessid=session.sessid)
@ -373,7 +373,7 @@ class ServerSessionHandler(SessionHandler):
sessid = session.sessid sessid = session.sessid
del self.sessions[sessid] del self.sessions[sessid]
# inform portal that session should be closed. # inform portal that session should be closed.
self.server.amp_protocol.call_remote_PortalAdmin(sessid, self.server.amp_protocol.send_AdminServer2Portal(sessid,
operation=SDISCONN, operation=SDISCONN,
data=reason) data=reason)
@ -384,7 +384,7 @@ class ServerSessionHandler(SessionHandler):
""" """
sessdata = self.get_all_sync_data() sessdata = self.get_all_sync_data()
return self.server.amp_protocol.call_remote_PortalAdmin(0, return self.server.amp_protocol.send_AdminServer2Portal(0,
operation=SSYNC, operation=SSYNC,
data=sessdata) data=sessdata)
@ -400,7 +400,7 @@ class ServerSessionHandler(SessionHandler):
for session in self.sessions: for session in self.sessions:
del session del session
# tell portal to disconnect all sessions # tell portal to disconnect all sessions
self.server.amp_protocol.call_remote_PortalAdmin(0, self.server.amp_protocol.send_AdminServer2Portal(0,
operation=SDISCONNALL, operation=SDISCONNALL,
data=reason) data=reason)
@ -555,8 +555,9 @@ class ServerSessionHandler(SessionHandler):
Useful for connection handling messages. Useful for connection handling messages.
""" """
from evennia.server.profiling.timetrace import timetrace #from evennia.server.profiling.timetrace import timetrace
text = timetrace(text, "ServerSessionHandler.data_out") #text = timetrace(text, "ServerSessionHandler.data_out")
sessions = make_iter(session) sessions = make_iter(session)
session = sessions[0] session = sessions[0]
text = text and to_str(to_unicode(text), encoding=session.encoding) text = text and to_str(to_unicode(text), encoding=session.encoding)
@ -584,9 +585,9 @@ class ServerSessionHandler(SessionHandler):
# send to all found sessions # send to all found sessions
for session in sessions: for session in sessions:
self.server.amp_protocol.call_remote_MsgServer2Portal(sessid=session.sessid, self.server.amp_protocol.send_MsgServer2Portal(sessid=session.sessid,
msg=text, msg=text,
data=kwargs) data=kwargs)
def data_in(self, sessid, text="", **kwargs): def data_in(self, sessid, text="", **kwargs):
""" """
@ -601,8 +602,8 @@ class ServerSessionHandler(SessionHandler):
kwargs (any): Other data from protocol. kwargs (any): Other data from protocol.
""" """
from evennia.server.profiling.timetrace import timetrace #from evennia.server.profiling.timetrace import timetrace
text = timetrace(text, "ServerSessionHandler.data_in") #text = timetrace(text, "ServerSessionHandler.data_in")
session = self.sessions.get(sessid, None) session = self.sessions.get(sessid, None)
if session: if session:
text = text and to_unicode(strip_control_sequences(text), encoding=session.encoding) text = text and to_unicode(strip_control_sequences(text), encoding=session.encoding)

View file

@ -183,7 +183,7 @@ IDMAPPER_CACHE_MAXSIZE = 200 # (MB)
# accept, as a DoS countermeasure. If the rate exceeds this number, incoming # accept, as a DoS countermeasure. If the rate exceeds this number, incoming
# connections will be queued to this rate, so none will be lost. # connections will be queued to this rate, so none will be lost.
# Must be set to a value > 0. # Must be set to a value > 0.
MAX_CONNECTION_RATE = 5 MAX_CONNECTION_RATE = 2
# Determine how many commands per second a given Session is allowed # Determine how many commands per second a given Session is allowed
# to send to the Portal via a connected protocol. Too high rate will # to send to the Portal via a connected protocol. Too high rate will
# drop the command and echo a warning. Note that this will also cap # drop the command and echo a warning. Note that this will also cap