Fixed a bug in amp that made reloading not work.

This commit is contained in:
Griatch 2013-09-21 22:00:46 +02:00
parent e36c7d5cc1
commit 2ba16e155e
8 changed files with 39 additions and 43 deletions

View file

@ -1,5 +1,5 @@
"""
This defines some generally useful scripts for the tutorial world.
This defines some generally useful scripts for the tutorial world.
"""
import random
@ -9,11 +9,11 @@ from ev import Script
#
# IrregularEvent - script firing at random intervals
#
# This is a generally useful script for updating
# This is a generally useful script for updating
# objects at irregular intervals. This is used by as diverse
# entities as Weather rooms and mobs.
# entities as Weather rooms and mobs.
#
#
#
#
#------------------------------------------------------------
@ -22,7 +22,7 @@ class IrregularEvent(Script):
This script, which should be tied to a particular object upon
instantiation, calls update_irregular on the object at random
intervals.
"""
"""
def at_script_creation(self):
"This setups the script"
@ -30,7 +30,7 @@ class IrregularEvent(Script):
self.desc = "Updates at irregular intervals"
self.interval = random.randint(30, 70) # interval to call.
self.start_delay = True # wait at least self.interval seconds before calling at_repeat the first time
self.persistent = True
self.persistent = True
# this attribute determines how likely it is the
# 'update_irregular' method gets called on self.obj (value is
@ -69,7 +69,7 @@ class FastIrregularEvent(IrregularEvent):
# #
# # Note that this will of course allow a single player to end up with multiple versions of objects if
# # they just wait around between resets; In a real game environment this would have to be resolved e.g.
# # with custom versions of the 'get' command not accepting doublets.
# # with custom versions of the 'get' command not accepting doublets.
# #
# # setting up an event for reseting the world.
@ -91,20 +91,20 @@ class FastIrregularEvent(IrregularEvent):
# #this you see when running @ps in game:
# self.description = 'Reset the tutorial world .'
# self.interval = UPDATE_INTERVAL
# self.persistent = True
# self.persistent = True
# def event_function(self):
# """
# This is called every self.interval seconds.
# """
# #find all objects inheriting the subscribing parents
# for parent in RESET_SUBSCRIBERS:
# for parent in RESET_SUBSCRIBERS:
# objects = Object.objects.global_object_script_parent_search(parent)
# for obj in objects:
# try:
# try:
# obj.scriptlink.reset()
# except:
# logger.log_errmsg(traceback.print_exc())

View file

@ -272,10 +272,11 @@ class CmdChannels(MuxPlayerCommand):
# full listing (of channels caller is able to listen to)
comtable = prettytable.PrettyTable(["{wsub","{wchannel","{wmy aliases","{wlocks","{wdescription"])
for chan in channels:
nicks = [nick for nick in caller.nicks.get(category="channel")]
comtable.add_row([chan in subs and "{gYes{n" or "{rNo{n",
nicks = caller.nicks.get(category="channel")
if nicks:
comtable.add_row([chan in subs and "{gYes{n" or "{rNo{n",
"%s%s" % (chan.key, chan.aliases and "(%s)" % ",".join(chan.aliases) or ""),
"%s".join(nick.db_nick for nick in nicks if nick.db_real.lower()==clower()),
"%s".join(nick.db_nick for nick in make_iter(nicks) if nick.db_real.lower()==clower()),
chan.locks,
chan.desc])
caller.msg("\n{wAvailable channels{n (use {wcomlist{n,{waddcom{n and {wdelcom{n to manage subscriptions):\n%s" % comtable)

View file

@ -17,6 +17,7 @@ from src.scripts.models import ScriptDB
from src.objects.models import ObjectDB
from src.players.models import PlayerDB
from src.utils import logger, utils, gametime, create, is_pypy, prettytable
from src.utils.utils import crop
from src.commands.default.muxcommand import MuxCommand
# delayed imports
@ -213,24 +214,17 @@ def format_script_list(scripts):
table.align = 'r'
for script in scripts:
nextrep = script.time_until_next_repeat()
#print ([script.id,
# (not hasattr(script, 'obj') or not script.obj) and "<Global>" or script.obj.key,
# script.key,
# (not hasattr(script, 'interval') or script.interval < 0) and "--" or "%ss" % script.interval,
# not nextrep and "--" or "%ss" % nextrep,
# (not hasattr(script, 'repeats') or not script.repeats) and "--" or "%i" % script.repeats,
# script.persistent and "*" or "-",
# script.typeclass_path.rsplit('.', 1)[-1],
# script.desc])
print type(script),
print script.key
table.add_row([script.id,
(not hasattr(script, 'obj') or not script.obj) and "<Global>" or script.obj.key,
script.obj.key if (hasattr(script, 'obj') and script.obj) else "<Global>",
script.key,
(not hasattr(script, 'interval') or script.interval < 0) and "--" or "%ss" % script.interval,
not nextrep and "--" or "%ss" % nextrep,
(not hasattr(script, 'repeats') or not script.repeats) and "--" or "%i" % script.repeats,
script.persistent and "*" or "-",
script.interval if script.interval > 0 else "--",
"%ss" % nextrep if nextrep else "--",
"%i" % script.repeats if script.repeats else "--",
"*" if script.persistent else "-",
script.typeclass_path.rsplit('.', 1)[-1],
script.desc])
crop(script.desc, width=20)])
return "%s" % table

View file

@ -31,11 +31,11 @@ _RE = re.compile(r"^\+|-+\+|\+-+|--*|\|", re.MULTILINE)
# ------------------------------------------------------------
class TestPlayerClass(Player):
def msg(self, message, **kwargs):
def msg(self, text="", **kwargs):
"test message"
if not self.ndb.stored_msg:
self.ndb.stored_msg = []
self.ndb.stored_msg.append(message)
self.ndb.stored_msg.append(text)
def _get_superuser(self):
"test with superuser flag"
return self.ndb.is_superuser

View file

@ -677,7 +677,6 @@ class ObjectDB(TypedObject):
if isinstance(data, dict):
kwargs.update(data)
if _GA(self, 'player'):
# note that we must call the player *typeclass'* msg(), otherwise one couldn't overload it.
if not sessid:

View file

@ -347,7 +347,7 @@ class AMPProtocol(amp.AMP):
"""
Access method called by the Server and executed on the Server.
"""
#print "msg server->portal (server side):", sessid, msg, data
#print "msg server->portal (server side):", sessid, msg, kwargs
try:
return self.callRemote(MsgServer2Portal,
sessid=sessid,
@ -370,7 +370,7 @@ class AMPProtocol(amp.AMP):
data = loads(data)
server_sessionhandler = self.factory.server.sessions
#print "serveradmin (server side):", sessid, operation, data
#print "serveradmin (server side):", sessid, ord(operation), data
if operation == PCONN: #portal_session_connect
# create a new session and sync it
@ -395,7 +395,7 @@ class AMPProtocol(amp.AMP):
"""
Access method called by the Portal and Executed on the Portal.
"""
#print "serveradmin (portal side):", sessid, operation, data
#print "serveradmin (portal side):", sessid, ord(operation), data
data = dumps(data)
return self.callRemote(ServerAdmin,
@ -441,7 +441,7 @@ class AMPProtocol(amp.AMP):
return {}
PortalAdmin.responder(amp_portal_admin)
def call_remote_PortalAdmin(self, sessid, operation="", **kwargs):
def call_remote_PortalAdmin(self, sessid, operation="", data=""):
"""
Access method called by the server side.
"""
@ -449,7 +449,7 @@ class AMPProtocol(amp.AMP):
return self.callRemote(PortalAdmin,
sessid=sessid,
operation=operation,
data=dumps(kwargs)).addErrback(self.errback, "PortalAdmin")
data=dumps(data)).addErrback(self.errback, "PortalAdmin")
# Extra functions

View file

@ -295,7 +295,7 @@ class AttributeHandler(object):
ret.append(True if _GA(self.obj, self._m2m_fieldname).filter(Q(db_key__iexact=keystr) & category_cond) else False)
return ret[0] if len(ret)==1 else ret
def get(self, key, category=None, default=None, return_obj=False, strattr=False,
def get(self, key=None, category=None, default=None, return_obj=False, strattr=False,
raise_exception=False, accessing_obj=None, default_access=True):
"""
Returns the value of the given Attribute or list of Attributes.
@ -316,8 +316,9 @@ class AttributeHandler(object):
for keystr in make_iter(key):
cachekey = "%s%s" % (category if category else "", keystr)
attr_obj = get_attr_cache(self.obj, cachekey)
key_cond = Q(db_key__iexact=keystr) if key!=None else Q()
if not attr_obj:
attr_obj = _GA(self.obj, "db_attributes").filter(Q(db_key__iexact=keystr) & category_cond)
attr_obj = _GA(self.obj, "db_attributes").filter(key_cond & category_cond)
if not attr_obj:
if raise_exception:
raise AttributeError
@ -439,10 +440,10 @@ class NickHandler(AttributeHandler):
"Add a new nick"
category = "nick_%s" % category
super(NickHandler, self).add(key, replacement, category=category, strattr=True, **kwargs)
def get(self, key, category="inputline", **kwargs):
def get(self, key=None, category="inputline", **kwargs):
"Get the replacement value matching the given key and category"
category = "nick_%s" % category
return super(NickHandler, self).get(key, category=category, strattr=True, **kwargs)
return super(NickHandler, self).get(key=key, category=category, strattr=True, **kwargs)
def remove(self, key, category="inputline", **kwargs):
"Remove Nick with matching category"
category = "nick_%s" % category

View file

@ -110,9 +110,10 @@ class SharedMemoryModelBase(ModelBase):
if dbid:
try:
value = cls._default_manager.get(id=dbid)
except ObjectDoesNotExist:
except ObjectDoesNotExist,e:
# maybe it is just a name that happens to look like a dbid
pass
from src.utils.logger import log_trace
log_trace()
#print "_set wrapper:", fname, value, type(value), cls._get_pk_val(cls._meta)
_SA(cls, fname, value)
# only use explicit update_fields in save if we actually have a