Adaptations for SQLite.
This commit is contained in:
parent
c5f20f4038
commit
ec2e39fa3e
6 changed files with 63 additions and 35 deletions
|
|
@ -37,10 +37,10 @@ class Object(models.Model):
|
||||||
zone = models.ForeignKey('self', related_name="obj_zone", blank=True, null=True)
|
zone = models.ForeignKey('self', related_name="obj_zone", blank=True, null=True)
|
||||||
home = models.ForeignKey('self', related_name="obj_home", blank=True, null=True)
|
home = models.ForeignKey('self', related_name="obj_home", blank=True, null=True)
|
||||||
type = models.SmallIntegerField(choices=global_defines.OBJECT_TYPES)
|
type = models.SmallIntegerField(choices=global_defines.OBJECT_TYPES)
|
||||||
description = models.TextField(blank=True)
|
description = models.TextField(blank=True, null=True)
|
||||||
location = models.ForeignKey('self', related_name="obj_location", blank=True, null=True)
|
location = models.ForeignKey('self', related_name="obj_location", blank=True, null=True)
|
||||||
flags = models.TextField(blank=True)
|
flags = models.TextField(blank=True, null=True)
|
||||||
nosave_flags = models.TextField(blank=True)
|
nosave_flags = models.TextField(blank=True, null=True)
|
||||||
date_created = models.DateField(editable=False, auto_now_add=True)
|
date_created = models.DateField(editable=False, auto_now_add=True)
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
|
|
@ -118,7 +118,14 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
Returns an object's flag list.
|
Returns an object's flag list.
|
||||||
"""
|
"""
|
||||||
return '%s %s' % (self.flags, self.nosave_flags)
|
flags = self.flags
|
||||||
|
nosave_flags = self.nosave_flags
|
||||||
|
if not flags:
|
||||||
|
flags = ""
|
||||||
|
if not nosave_flags:
|
||||||
|
nosave_flags = ""
|
||||||
|
|
||||||
|
return '%s %s' % (flags, nosave_flags)
|
||||||
|
|
||||||
def clear_attribute(self, attribute):
|
def clear_attribute(self, attribute):
|
||||||
"""
|
"""
|
||||||
|
|
@ -224,7 +231,11 @@ class Object(models.Model):
|
||||||
|
|
||||||
flag: (str) Flag name
|
flag: (str) Flag name
|
||||||
"""
|
"""
|
||||||
return flag in self.flags or flag in self.nosave_flags
|
# For whatever reason, we have to do this so things work
|
||||||
|
# in SQLite.
|
||||||
|
flags = str(self.flags).split()
|
||||||
|
nosave_flags = str(self.nosave_flags).split()
|
||||||
|
return flag in flags or flag in nosave_flags
|
||||||
|
|
||||||
def set_flag(self, flag, value):
|
def set_flag(self, flag, value):
|
||||||
"""
|
"""
|
||||||
|
|
@ -260,12 +271,12 @@ class Object(models.Model):
|
||||||
# Setting a flag.
|
# Setting a flag.
|
||||||
if functions_db.is_unsavable_flag(flag):
|
if functions_db.is_unsavable_flag(flag):
|
||||||
# Not a savable flag (CONNECTED, etc)
|
# Not a savable flag (CONNECTED, etc)
|
||||||
flags = self.nosave_flags.split()
|
flags = str(self.nosave_flags).split()
|
||||||
flags.append(flag)
|
flags.append(flag)
|
||||||
self.nosave_flags = ' '.join(flags)
|
self.nosave_flags = ' '.join(flags)
|
||||||
else:
|
else:
|
||||||
# Is a savable flag.
|
# Is a savable flag.
|
||||||
flags = self.flags.split()
|
flags = str(self.flags).split()
|
||||||
flags.append(flag)
|
flags.append(flag)
|
||||||
self.flags = ' '.join(flags)
|
self.flags = ' '.join(flags)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
@ -284,13 +295,19 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
Returns an object's home.
|
Returns an object's home.
|
||||||
"""
|
"""
|
||||||
return self.home
|
try:
|
||||||
|
return self.home
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_location(self):
|
def get_location(self):
|
||||||
"""
|
"""
|
||||||
Returns an object's location.
|
Returns an object's location.
|
||||||
"""
|
"""
|
||||||
return self.location
|
try:
|
||||||
|
return self.location
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
def get_attribute_value(self, attrib, default=False):
|
def get_attribute_value(self, attrib, default=False):
|
||||||
"""
|
"""
|
||||||
|
|
@ -330,7 +347,10 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
Returns the object that is marked as this object's zone.
|
Returns the object that is marked as this object's zone.
|
||||||
"""
|
"""
|
||||||
return self.zone
|
try:
|
||||||
|
return self.zone
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def move_to(self, target):
|
def move_to(self, target):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ def cmd_look(cdat):
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
target_obj = pobject.get_location()
|
target_obj = pobject.get_location()
|
||||||
else:
|
else:
|
||||||
results = functions_db.local_and_global_search(pobject, ' '.join(args), searcher=pobject)
|
results = functions_db.local_and_global_search(pobject, ' '.join(args))
|
||||||
|
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
|
|
@ -101,7 +101,7 @@ def cmd_examine(cdat):
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
target_obj = pobject.get_location()
|
target_obj = pobject.get_location()
|
||||||
else:
|
else:
|
||||||
results = functions_db.local_and_global_search(pobject, ' '.join(args), searcher=pobject)
|
results = functions_db.local_and_global_search(pobject, ' '.join(args))
|
||||||
|
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ import cmdhandler
|
||||||
import session_mgr
|
import session_mgr
|
||||||
from apps.objects.models import Object
|
from apps.objects.models import Object
|
||||||
"""
|
"""
|
||||||
Staff commands may be a bad description for this file, but it'll do for now.
|
Staff commands may be a bad description for this file, but it'll do for
|
||||||
Any command here is prefixed by an '@' sign, usually denoting a builder, staff
|
now. Any command here is prefixed by an '@' sign, usually denoting a
|
||||||
or otherwise manipulative command that doesn't fall within the scope of
|
builder, staff or otherwise manipulative command that doesn't fall within
|
||||||
normal gameplay.
|
the scope of normal gameplay.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def cmd_destroy(cdat):
|
def cmd_destroy(cdat):
|
||||||
|
|
@ -28,7 +28,7 @@ def cmd_destroy(cdat):
|
||||||
session.msg("Destroy what?")
|
session.msg("Destroy what?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
results = functions_db.local_and_global_search(pobject, ' '.join(args), searcher=pobject)
|
results = functions_db.local_and_global_search(pobject, ' '.join(args))
|
||||||
|
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
|
|
@ -76,7 +76,7 @@ def cmd_name(cdat):
|
||||||
elif len(eq_args) < 2:
|
elif len(eq_args) < 2:
|
||||||
session.msg("What would you like to name that object?")
|
session.msg("What would you like to name that object?")
|
||||||
else:
|
else:
|
||||||
results = functions_db.local_and_global_search(pobject, searchstring, searcher=pobject)
|
results = functions_db.local_and_global_search(pobject, searchstring)
|
||||||
|
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
|
|
@ -176,7 +176,7 @@ def cmd_open(cdat):
|
||||||
# an un-linked exit, @open <Name>.
|
# an un-linked exit, @open <Name>.
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
|
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
|
||||||
destination = functions_db.local_and_global_search(pobject, eq_args[1], searcher=pobject)
|
destination = functions_db.local_and_global_search(pobject, eq_args[1])
|
||||||
|
|
||||||
if len(destination) == 0:
|
if len(destination) == 0:
|
||||||
session.msg("I can't find the location to link to.")
|
session.msg("I can't find the location to link to.")
|
||||||
|
|
@ -220,8 +220,8 @@ def cmd_teleport(cdat):
|
||||||
# a direct teleport, @tel <destination>.
|
# a direct teleport, @tel <destination>.
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
# Equal sign teleport.
|
# Equal sign teleport.
|
||||||
victim = functions_db.local_and_global_search(pobject, eq_args[0], searcher=pobject)
|
victim = functions_db.local_and_global_search(pobject, eq_args[0])
|
||||||
destination = functions_db.local_and_global_search(pobject, eq_args[1], searcher=pobject)
|
destination = functions_db.local_and_global_search(pobject, eq_args[1])
|
||||||
|
|
||||||
if len(victim) == 0:
|
if len(victim) == 0:
|
||||||
session.msg("I can't find the victim to teleport.")
|
session.msg("I can't find the victim to teleport.")
|
||||||
|
|
@ -254,7 +254,7 @@ def cmd_teleport(cdat):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Direct teleport (no equal sign)
|
# Direct teleport (no equal sign)
|
||||||
results = functions_db.local_and_global_search(pobject, search_str, searcher=pobject)
|
results = functions_db.local_and_global_search(pobject, search_str)
|
||||||
|
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
|
|
@ -293,7 +293,7 @@ def cmd_set(cdat):
|
||||||
session.msg("Set what?")
|
session.msg("Set what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
victim = functions_db.local_and_global_search(pobject, eq_args[0], searcher=pobject)
|
victim = functions_db.local_and_global_search(pobject, eq_args[0])
|
||||||
|
|
||||||
if len(victim) == 0:
|
if len(victim) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
|
|
@ -359,7 +359,7 @@ def cmd_find(cdat):
|
||||||
session.msg("No search pattern given.")
|
session.msg("No search pattern given.")
|
||||||
return
|
return
|
||||||
|
|
||||||
results = functions_db.list_search_object_namestr(server.object_list.values(), searchstring)
|
results = functions_db.global_object_name_search(searchstring)
|
||||||
|
|
||||||
if len(results) > 0:
|
if len(results) > 0:
|
||||||
session.msg("Name matches for: %s" % (searchstring,))
|
session.msg("Name matches for: %s" % (searchstring,))
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ def cmd_connect(cdat):
|
||||||
uname = cdat['uinput']['splitted'][1]
|
uname = cdat['uinput']['splitted'][1]
|
||||||
password = cdat['uinput']['splitted'][2]
|
password = cdat['uinput']['splitted'][2]
|
||||||
|
|
||||||
account = User.objects.filter(username=uname)
|
account = User.objects.filter(username__iexact=uname)
|
||||||
|
|
||||||
autherror = "Invalid username or password!"
|
autherror = "Invalid username or password!"
|
||||||
# No username match
|
# No username match
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ def get_server_config(configname):
|
||||||
"""
|
"""
|
||||||
Returns a server config value.
|
Returns a server config value.
|
||||||
"""
|
"""
|
||||||
return ConfigValue.objects.get(conf_key=configname).conf_value
|
return ConfigValue.objects.get(conf_key__iexact=configname).conf_value
|
||||||
|
|
||||||
def is_unsavable_flag(flagname):
|
def is_unsavable_flag(flagname):
|
||||||
"""
|
"""
|
||||||
|
|
@ -55,6 +55,12 @@ def get_nextfree_dbnum():
|
||||||
print 'NOTGARB'
|
print 'NOTGARB'
|
||||||
return int(Object.objects.order_by('-id')[0].id + 1)
|
return int(Object.objects.order_by('-id')[0].id + 1)
|
||||||
|
|
||||||
|
def global_object_name_search(ostring):
|
||||||
|
"""
|
||||||
|
Searches through all objects for a name match.
|
||||||
|
"""
|
||||||
|
return Object.objects.filter(name__icontains=ostring).exclude(type=6)
|
||||||
|
|
||||||
def list_search_object_namestr(searchlist, ostring, dbref_only=False):
|
def list_search_object_namestr(searchlist, ostring, dbref_only=False):
|
||||||
"""
|
"""
|
||||||
Iterates through a list of objects and returns a list of
|
Iterates through a list of objects and returns a list of
|
||||||
|
|
@ -65,7 +71,7 @@ def list_search_object_namestr(searchlist, ostring, dbref_only=False):
|
||||||
else:
|
else:
|
||||||
return [prospect for prospect in searchlist if prospect.name_match(ostring)]
|
return [prospect for prospect in searchlist if prospect.name_match(ostring)]
|
||||||
|
|
||||||
def local_and_global_search(object, ostring, local_only=False, searcher=None):
|
def local_and_global_search(searcher, ostring, local_only=False, dbref_only=False):
|
||||||
"""
|
"""
|
||||||
Searches an object's location then globally for a dbref or name match.
|
Searches an object's location then globally for a dbref or name match.
|
||||||
local_only: Only compare the objects in the player's location if True.
|
local_only: Only compare the objects in the player's location if True.
|
||||||
|
|
@ -78,11 +84,11 @@ def local_and_global_search(object, ostring, local_only=False, searcher=None):
|
||||||
if len(dbref_match) > 0:
|
if len(dbref_match) > 0:
|
||||||
return dbref_match
|
return dbref_match
|
||||||
|
|
||||||
local_matches = list_search_object_namestr(object.location.get_contents(), search_query)
|
local_matches = list_search_object_namestr(searcher.get_location().get_contents(), search_query) + list_search_object_namestr(searcher.get_contents(), search_query)
|
||||||
|
|
||||||
# If the object the invoker is in matches, add it as well.
|
# If the object the invoker is in matches, add it as well.
|
||||||
if object.location.dbref_match(ostring) or ostring == 'here':
|
if searcher.get_location().dbref_match(ostring) or ostring == 'here':
|
||||||
local_matches.append(object.location)
|
local_matches.append(searcher.get_location())
|
||||||
elif ostring == 'me' and searcher:
|
elif ostring == 'me' and searcher:
|
||||||
local_matches.append(searcher)
|
local_matches.append(searcher)
|
||||||
|
|
||||||
|
|
@ -132,15 +138,17 @@ def create_object(odat):
|
||||||
new_object.name = odat["name"]
|
new_object.name = odat["name"]
|
||||||
new_object.type = odat["type"]
|
new_object.type = odat["type"]
|
||||||
|
|
||||||
# If this is a player, set him to own himself.
|
# If this is a player, we don't want him owned by anyone.
|
||||||
|
# The get_owner() function will return that the player owns
|
||||||
|
# himself.
|
||||||
if odat["type"] == 1:
|
if odat["type"] == 1:
|
||||||
new_object.owner = None
|
new_object.owner = None
|
||||||
new_object.zone = None
|
new_object.zone = None
|
||||||
else:
|
else:
|
||||||
new_object.owner = odat["owner"]
|
new_object.owner = odat["owner"]
|
||||||
|
|
||||||
if new_object.owner.zone:
|
if new_object.get_owner().get_zone():
|
||||||
new_object.zone = new_object.owner.zone
|
new_object.zone = new_object.get_owner().get_zone()
|
||||||
|
|
||||||
# If we have a 'home' key, use that for our home value. Otherwise use
|
# If we have a 'home' key, use that for our home value. Otherwise use
|
||||||
# the location key.
|
# the location key.
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ ADMINS = (
|
||||||
|
|
||||||
MANAGERS = ADMINS
|
MANAGERS = ADMINS
|
||||||
|
|
||||||
DATABASE_ENGINE = 'mysql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
|
DATABASE_ENGINE = 'sqlite3' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
|
||||||
DATABASE_NAME = 'evennia' # Or path to database file if using sqlite3.
|
DATABASE_NAME = 'evennia.sql' # Or path to database file if using sqlite3.
|
||||||
DATABASE_USER = 'evennia' # Not used with sqlite3.
|
DATABASE_USER = 'evennia' # Not used with sqlite3.
|
||||||
DATABASE_PASSWORD = 'CvAPpy:FFRTmTMHf' # Not used with sqlite3.
|
DATABASE_PASSWORD = 'CvAPpy:FFRTmTMHf' # Not used with sqlite3.
|
||||||
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue