Fixed a bug in amp that made reloading not work.
This commit is contained in:
parent
e36c7d5cc1
commit
2ba16e155e
8 changed files with 39 additions and 43 deletions
|
|
@ -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
|
import random
|
||||||
|
|
@ -9,11 +9,11 @@ from ev import Script
|
||||||
#
|
#
|
||||||
# IrregularEvent - script firing at random intervals
|
# 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
|
# 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
|
This script, which should be tied to a particular object upon
|
||||||
instantiation, calls update_irregular on the object at random
|
instantiation, calls update_irregular on the object at random
|
||||||
intervals.
|
intervals.
|
||||||
"""
|
"""
|
||||||
def at_script_creation(self):
|
def at_script_creation(self):
|
||||||
"This setups the script"
|
"This setups the script"
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ class IrregularEvent(Script):
|
||||||
self.desc = "Updates at irregular intervals"
|
self.desc = "Updates at irregular intervals"
|
||||||
self.interval = random.randint(30, 70) # interval to call.
|
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.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
|
# this attribute determines how likely it is the
|
||||||
# 'update_irregular' method gets called on self.obj (value is
|
# '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
|
# # 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.
|
# # 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.
|
# # setting up an event for reseting the world.
|
||||||
|
|
@ -91,20 +91,20 @@ class FastIrregularEvent(IrregularEvent):
|
||||||
# #this you see when running @ps in game:
|
# #this you see when running @ps in game:
|
||||||
# self.description = 'Reset the tutorial world .'
|
# self.description = 'Reset the tutorial world .'
|
||||||
# self.interval = UPDATE_INTERVAL
|
# self.interval = UPDATE_INTERVAL
|
||||||
# self.persistent = True
|
# self.persistent = True
|
||||||
|
|
||||||
# def event_function(self):
|
# def event_function(self):
|
||||||
# """
|
# """
|
||||||
# This is called every self.interval seconds.
|
# This is called every self.interval seconds.
|
||||||
# """
|
# """
|
||||||
# #find all objects inheriting the subscribing parents
|
# #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)
|
# objects = Object.objects.global_object_script_parent_search(parent)
|
||||||
# for obj in objects:
|
# for obj in objects:
|
||||||
# try:
|
# try:
|
||||||
# obj.scriptlink.reset()
|
# obj.scriptlink.reset()
|
||||||
# except:
|
# except:
|
||||||
# logger.log_errmsg(traceback.print_exc())
|
# logger.log_errmsg(traceback.print_exc())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -272,10 +272,11 @@ class CmdChannels(MuxPlayerCommand):
|
||||||
# full listing (of channels caller is able to listen to)
|
# full listing (of channels caller is able to listen to)
|
||||||
comtable = prettytable.PrettyTable(["{wsub","{wchannel","{wmy aliases","{wlocks","{wdescription"])
|
comtable = prettytable.PrettyTable(["{wsub","{wchannel","{wmy aliases","{wlocks","{wdescription"])
|
||||||
for chan in channels:
|
for chan in channels:
|
||||||
nicks = [nick for nick in caller.nicks.get(category="channel")]
|
nicks = caller.nicks.get(category="channel")
|
||||||
comtable.add_row([chan in subs and "{gYes{n" or "{rNo{n",
|
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%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.locks,
|
||||||
chan.desc])
|
chan.desc])
|
||||||
caller.msg("\n{wAvailable channels{n (use {wcomlist{n,{waddcom{n and {wdelcom{n to manage subscriptions):\n%s" % comtable)
|
caller.msg("\n{wAvailable channels{n (use {wcomlist{n,{waddcom{n and {wdelcom{n to manage subscriptions):\n%s" % comtable)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from src.scripts.models import ScriptDB
|
||||||
from src.objects.models import ObjectDB
|
from src.objects.models import ObjectDB
|
||||||
from src.players.models import PlayerDB
|
from src.players.models import PlayerDB
|
||||||
from src.utils import logger, utils, gametime, create, is_pypy, prettytable
|
from src.utils import logger, utils, gametime, create, is_pypy, prettytable
|
||||||
|
from src.utils.utils import crop
|
||||||
from src.commands.default.muxcommand import MuxCommand
|
from src.commands.default.muxcommand import MuxCommand
|
||||||
|
|
||||||
# delayed imports
|
# delayed imports
|
||||||
|
|
@ -213,24 +214,17 @@ def format_script_list(scripts):
|
||||||
table.align = 'r'
|
table.align = 'r'
|
||||||
for script in scripts:
|
for script in scripts:
|
||||||
nextrep = script.time_until_next_repeat()
|
nextrep = script.time_until_next_repeat()
|
||||||
#print ([script.id,
|
print type(script),
|
||||||
# (not hasattr(script, 'obj') or not script.obj) and "<Global>" or script.obj.key,
|
print script.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])
|
|
||||||
table.add_row([script.id,
|
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,
|
script.key,
|
||||||
(not hasattr(script, 'interval') or script.interval < 0) and "--" or "%ss" % script.interval,
|
script.interval if script.interval > 0 else "--",
|
||||||
not nextrep and "--" or "%ss" % nextrep,
|
"%ss" % nextrep if nextrep else "--",
|
||||||
(not hasattr(script, 'repeats') or not script.repeats) and "--" or "%i" % script.repeats,
|
"%i" % script.repeats if script.repeats else "--",
|
||||||
script.persistent and "*" or "-",
|
"*" if script.persistent else "-",
|
||||||
script.typeclass_path.rsplit('.', 1)[-1],
|
script.typeclass_path.rsplit('.', 1)[-1],
|
||||||
script.desc])
|
crop(script.desc, width=20)])
|
||||||
return "%s" % table
|
return "%s" % table
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@ _RE = re.compile(r"^\+|-+\+|\+-+|--*|\|", re.MULTILINE)
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
class TestPlayerClass(Player):
|
class TestPlayerClass(Player):
|
||||||
def msg(self, message, **kwargs):
|
def msg(self, text="", **kwargs):
|
||||||
"test message"
|
"test message"
|
||||||
if not self.ndb.stored_msg:
|
if not self.ndb.stored_msg:
|
||||||
self.ndb.stored_msg = []
|
self.ndb.stored_msg = []
|
||||||
self.ndb.stored_msg.append(message)
|
self.ndb.stored_msg.append(text)
|
||||||
def _get_superuser(self):
|
def _get_superuser(self):
|
||||||
"test with superuser flag"
|
"test with superuser flag"
|
||||||
return self.ndb.is_superuser
|
return self.ndb.is_superuser
|
||||||
|
|
|
||||||
|
|
@ -677,7 +677,6 @@ class ObjectDB(TypedObject):
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
kwargs.update(data)
|
kwargs.update(data)
|
||||||
|
|
||||||
|
|
||||||
if _GA(self, 'player'):
|
if _GA(self, 'player'):
|
||||||
# note that we must call the player *typeclass'* msg(), otherwise one couldn't overload it.
|
# note that we must call the player *typeclass'* msg(), otherwise one couldn't overload it.
|
||||||
if not sessid:
|
if not sessid:
|
||||||
|
|
|
||||||
|
|
@ -347,7 +347,7 @@ class AMPProtocol(amp.AMP):
|
||||||
"""
|
"""
|
||||||
Access method called by the Server and executed on the Server.
|
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:
|
try:
|
||||||
return self.callRemote(MsgServer2Portal,
|
return self.callRemote(MsgServer2Portal,
|
||||||
sessid=sessid,
|
sessid=sessid,
|
||||||
|
|
@ -370,7 +370,7 @@ class AMPProtocol(amp.AMP):
|
||||||
data = loads(data)
|
data = loads(data)
|
||||||
server_sessionhandler = self.factory.server.sessions
|
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
|
if operation == PCONN: #portal_session_connect
|
||||||
# create a new session and sync it
|
# 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.
|
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)
|
data = dumps(data)
|
||||||
|
|
||||||
return self.callRemote(ServerAdmin,
|
return self.callRemote(ServerAdmin,
|
||||||
|
|
@ -441,7 +441,7 @@ class AMPProtocol(amp.AMP):
|
||||||
return {}
|
return {}
|
||||||
PortalAdmin.responder(amp_portal_admin)
|
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.
|
Access method called by the server side.
|
||||||
"""
|
"""
|
||||||
|
|
@ -449,7 +449,7 @@ class AMPProtocol(amp.AMP):
|
||||||
return self.callRemote(PortalAdmin,
|
return self.callRemote(PortalAdmin,
|
||||||
sessid=sessid,
|
sessid=sessid,
|
||||||
operation=operation,
|
operation=operation,
|
||||||
data=dumps(kwargs)).addErrback(self.errback, "PortalAdmin")
|
data=dumps(data)).addErrback(self.errback, "PortalAdmin")
|
||||||
|
|
||||||
# Extra functions
|
# Extra functions
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
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
|
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):
|
raise_exception=False, accessing_obj=None, default_access=True):
|
||||||
"""
|
"""
|
||||||
Returns the value of the given Attribute or list of Attributes.
|
Returns the value of the given Attribute or list of Attributes.
|
||||||
|
|
@ -316,8 +316,9 @@ class AttributeHandler(object):
|
||||||
for keystr in make_iter(key):
|
for keystr in make_iter(key):
|
||||||
cachekey = "%s%s" % (category if category else "", keystr)
|
cachekey = "%s%s" % (category if category else "", keystr)
|
||||||
attr_obj = get_attr_cache(self.obj, cachekey)
|
attr_obj = get_attr_cache(self.obj, cachekey)
|
||||||
|
key_cond = Q(db_key__iexact=keystr) if key!=None else Q()
|
||||||
if not attr_obj:
|
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 not attr_obj:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
|
|
@ -439,10 +440,10 @@ class NickHandler(AttributeHandler):
|
||||||
"Add a new nick"
|
"Add a new nick"
|
||||||
category = "nick_%s" % category
|
category = "nick_%s" % category
|
||||||
super(NickHandler, self).add(key, replacement, category=category, strattr=True, **kwargs)
|
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"
|
"Get the replacement value matching the given key and category"
|
||||||
category = "nick_%s" % 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):
|
def remove(self, key, category="inputline", **kwargs):
|
||||||
"Remove Nick with matching category"
|
"Remove Nick with matching category"
|
||||||
category = "nick_%s" % category
|
category = "nick_%s" % category
|
||||||
|
|
|
||||||
|
|
@ -110,9 +110,10 @@ class SharedMemoryModelBase(ModelBase):
|
||||||
if dbid:
|
if dbid:
|
||||||
try:
|
try:
|
||||||
value = cls._default_manager.get(id=dbid)
|
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
|
# 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)
|
#print "_set wrapper:", fname, value, type(value), cls._get_pk_val(cls._meta)
|
||||||
_SA(cls, fname, value)
|
_SA(cls, fname, value)
|
||||||
# only use explicit update_fields in save if we actually have a
|
# only use explicit update_fields in save if we actually have a
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue