Back-end is in for the flag system.
This commit is contained in:
parent
4f85361f6b
commit
22edad226f
7 changed files with 138 additions and 34 deletions
|
|
@ -43,12 +43,13 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = models.CharField(maxlength=255)
|
name = models.CharField(maxlength=255)
|
||||||
owner = models.ForeignKey('self', related_name="obj_owner")
|
owner = models.ForeignKey('self', related_name="obj_owner", blank=True, null=True)
|
||||||
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)
|
||||||
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)
|
||||||
date_created = models.DateField(editable=False, auto_now_add=True)
|
date_created = models.DateField(editable=False, auto_now_add=True)
|
||||||
|
|
||||||
# Rather than keeping another relation for this, we're just going to use
|
# Rather than keeping another relation for this, we're just going to use
|
||||||
|
|
@ -57,7 +58,9 @@ class Object(models.Model):
|
||||||
# cost of a little bit more memory usage. No biggy.
|
# cost of a little bit more memory usage. No biggy.
|
||||||
|
|
||||||
# A list of objects located inside the object.
|
# A list of objects located inside the object.
|
||||||
contents_list = []
|
# TODO: Re-activate this once we get the contents loader working.
|
||||||
|
# contents_list = []
|
||||||
|
|
||||||
# A dictionary of attributes assocated with the object. The keys are the
|
# A dictionary of attributes assocated with the object. The keys are the
|
||||||
# attribute's names.
|
# attribute's names.
|
||||||
attrib_list = {}
|
attrib_list = {}
|
||||||
|
|
@ -79,6 +82,70 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
BEGIN COMMON METHODS
|
BEGIN COMMON METHODS
|
||||||
"""
|
"""
|
||||||
|
def get_flags(self):
|
||||||
|
"""
|
||||||
|
Returns an object's flag list.
|
||||||
|
"""
|
||||||
|
return self.flags
|
||||||
|
|
||||||
|
def has_flag(self, flag):
|
||||||
|
"""
|
||||||
|
Does our object have a certain flag?
|
||||||
|
"""
|
||||||
|
return flag in self.flags.split()
|
||||||
|
|
||||||
|
def set_flag(self, flag, value):
|
||||||
|
"""
|
||||||
|
Add a flag to our object's flag list.
|
||||||
|
"""
|
||||||
|
has_flag = self.has_flag(flag)
|
||||||
|
|
||||||
|
if value == False and has_flag:
|
||||||
|
# The flag is there and we want to un-set it.
|
||||||
|
flags_list = self.flags.split()
|
||||||
|
flags_list.remove(flag)
|
||||||
|
self.flags = ' '.join(flags_list)
|
||||||
|
|
||||||
|
# Not all flags are saved, such as CONNECTED.
|
||||||
|
# Don't waste queries on these things.
|
||||||
|
if flag not in global_defines.NOSAVE_FLAGS:
|
||||||
|
self.save()
|
||||||
|
elif value == False and not has_flag:
|
||||||
|
# Object doesn't have the flag to begin with.
|
||||||
|
pass
|
||||||
|
elif value == True and has_flag:
|
||||||
|
# We've already go it.
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# Add the flag.
|
||||||
|
flags_list = self.flags.split()
|
||||||
|
flags_list.append(flag.upper())
|
||||||
|
self.flags = ' '.join(flags_list)
|
||||||
|
if flag not in global_defines.NOSAVE_FLAGS:
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
def get_owner(self):
|
||||||
|
"""
|
||||||
|
Returns an object's owner.
|
||||||
|
"""
|
||||||
|
# Players always own themselves.
|
||||||
|
if self.is_player():
|
||||||
|
return self
|
||||||
|
else:
|
||||||
|
return self.owner
|
||||||
|
|
||||||
|
def get_home(self):
|
||||||
|
"""
|
||||||
|
Returns an object's home.
|
||||||
|
"""
|
||||||
|
return self.home
|
||||||
|
|
||||||
|
def get_location(self):
|
||||||
|
"""
|
||||||
|
Returns an object's location.
|
||||||
|
"""
|
||||||
|
return self.location
|
||||||
|
|
||||||
def get_attribute(self, attrib):
|
def get_attribute(self, attrib):
|
||||||
"""
|
"""
|
||||||
Returns the value of an attribute on an object.
|
Returns the value of an attribute on an object.
|
||||||
|
|
@ -101,6 +168,12 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
return list(Object.objects.filter(location__id=self.id))
|
return list(Object.objects.filter(location__id=self.id))
|
||||||
|
|
||||||
|
def get_zone(self):
|
||||||
|
"""
|
||||||
|
Returns the object that is marked as this object's zone.
|
||||||
|
"""
|
||||||
|
return self.zone
|
||||||
|
|
||||||
def move_to(self, server, target):
|
def move_to(self, server, target):
|
||||||
"""
|
"""
|
||||||
Moves the object to a new location. We're going to modify the server's
|
Moves the object to a new location. We're going to modify the server's
|
||||||
|
|
|
||||||
|
|
@ -102,8 +102,9 @@ def cmd_examine(cdat):
|
||||||
target_obj.flag_string(),
|
target_obj.flag_string(),
|
||||||
ansi["normal"],
|
ansi["normal"],
|
||||||
))
|
))
|
||||||
session.msg("Type: %s Flags: <TBI>" % (target_obj.get_type(),))
|
session.msg("Type: %s Flags: %s" % (target_obj.get_type(), target_obj.get_flags()))
|
||||||
session.msg("Zone: <TBI>")
|
session.msg("Owner: %s " % (target_obj.get_owner(),))
|
||||||
|
session.msg("Zone: %s" % (target_obj.get_zone(),))
|
||||||
|
|
||||||
for attribute in target_obj.attrib_list:
|
for attribute in target_obj.attrib_list:
|
||||||
session.msg("%s%s%s: %s" % (ansi["hilite"], attribute, ansi["normal"], target_obj.get_attribute(attribute)))
|
session.msg("%s%s%s: %s" % (ansi["hilite"], attribute, ansi["normal"], target_obj.get_attribute(attribute)))
|
||||||
|
|
@ -133,8 +134,8 @@ def cmd_examine(cdat):
|
||||||
session.msg('%s' %(exit,))
|
session.msg('%s' %(exit,))
|
||||||
|
|
||||||
if not target_obj.is_room():
|
if not target_obj.is_room():
|
||||||
session.msg("Home: <TBI>")
|
session.msg("Home: %s" % (target_obj.get_home(),))
|
||||||
session.msg("Location: %s" % (target_obj.location,))
|
session.msg("Location: %s" % (target_obj.get_location(),))
|
||||||
|
|
||||||
def cmd_quit(cdat):
|
def cmd_quit(cdat):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from apps.objects.models import Object
|
from apps.objects.models import Object
|
||||||
import functions_db
|
import functions_db
|
||||||
|
import functions_general
|
||||||
import commands_general
|
import commands_general
|
||||||
import cmdhandler
|
import cmdhandler
|
||||||
|
|
||||||
|
|
@ -141,9 +142,6 @@ def cmd_find(cdat):
|
||||||
session.msg("No search pattern given.")
|
session.msg("No search pattern given.")
|
||||||
return
|
return
|
||||||
|
|
||||||
memory_based = True
|
|
||||||
|
|
||||||
if memory_based:
|
|
||||||
results = functions_db.list_search_object_namestr(server.object_list.values(), searchstring)
|
results = functions_db.list_search_object_namestr(server.object_list.values(), searchstring)
|
||||||
|
|
||||||
if len(results) > 0:
|
if len(results) > 0:
|
||||||
|
|
@ -154,6 +152,21 @@ def cmd_find(cdat):
|
||||||
else:
|
else:
|
||||||
session.msg("No name matches found for: %s" % (searchstring,))
|
session.msg("No name matches found for: %s" % (searchstring,))
|
||||||
|
|
||||||
|
def cmd_wall(cdat):
|
||||||
|
"""
|
||||||
|
Announces a message to all connected players.
|
||||||
|
"""
|
||||||
|
session = cdat['session']
|
||||||
|
server = cdat['server']
|
||||||
|
wallstring = ' '.join(cdat['uinput']['splitted'][1:])
|
||||||
|
|
||||||
|
if wallstring == '':
|
||||||
|
session.msg("Announce what?")
|
||||||
|
return
|
||||||
|
|
||||||
|
message = "%s shouts \"%s\"" % (session.pobject.name, wallstring)
|
||||||
|
functions_general.announce_all(server, message)
|
||||||
|
|
||||||
def cmd_shutdown(cdat):
|
def cmd_shutdown(cdat):
|
||||||
"""
|
"""
|
||||||
Shut the server down gracefully.
|
Shut the server down gracefully.
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,20 @@ def cmd_connect(cdat):
|
||||||
password = cdat['uinput']['splitted'][2]
|
password = cdat['uinput']['splitted'][2]
|
||||||
|
|
||||||
account = User.objects.filter(username=uname)
|
account = User.objects.filter(username=uname)
|
||||||
user = account[0]
|
|
||||||
|
|
||||||
autherror = "Invalid username or password!"
|
autherror = "Invalid username or password!"
|
||||||
|
# No username match
|
||||||
if account.count() == 0:
|
if account.count() == 0:
|
||||||
session.msg(autherror)
|
session.msg(autherror)
|
||||||
|
return
|
||||||
|
|
||||||
|
# We have at least one result, so we can check hte password.
|
||||||
|
user = account[0]
|
||||||
|
|
||||||
if not user.check_password(password):
|
if not user.check_password(password):
|
||||||
session.msg(autherror)
|
session.msg(autherror)
|
||||||
else:
|
else:
|
||||||
|
user = account[0]
|
||||||
uname = user.username
|
uname = user.username
|
||||||
session.login(user)
|
session.login(user)
|
||||||
|
|
||||||
|
|
@ -31,6 +37,7 @@ def cmd_create(cdat):
|
||||||
Handle the creation of new accounts.
|
Handle the creation of new accounts.
|
||||||
"""
|
"""
|
||||||
session = cdat['session']
|
session = cdat['session']
|
||||||
|
server = session.server
|
||||||
uname = cdat['uinput']['splitted'][1]
|
uname = cdat['uinput']['splitted'][1]
|
||||||
email = cdat['uinput']['splitted'][2]
|
email = cdat['uinput']['splitted'][2]
|
||||||
password = cdat['uinput']['splitted'][3]
|
password = cdat['uinput']['splitted'][3]
|
||||||
|
|
|
||||||
|
|
@ -111,20 +111,22 @@ def create_object(server, odat):
|
||||||
new_object.name = odat["name"]
|
new_object.name = odat["name"]
|
||||||
new_object.type = odat["type"]
|
new_object.type = odat["type"]
|
||||||
|
|
||||||
#if odat["home"]:
|
# If this is a player, set him to own himself.
|
||||||
# new_object.home = odat["home"]
|
if odat["type"] == 1:
|
||||||
#else:
|
new_object.owner = None
|
||||||
# new_object.home = odat["location"]
|
new_object.zone = None
|
||||||
|
else:
|
||||||
|
new_object.owner = odat["owner"]
|
||||||
|
|
||||||
#if odat["owner"].zone:
|
if new_object.owner.zone:
|
||||||
# new_object.zone = odat["owner"].zone
|
new_object.zone = new_object.owner.zone
|
||||||
#else:
|
|
||||||
# new_object.zone = None
|
|
||||||
|
|
||||||
#if odat["type"] is 1:
|
# If we have a 'home' key, use that for our home value. Otherwise use
|
||||||
# new_object.owner = new_object
|
# the location key.
|
||||||
#else:
|
if odat.get("home",False):
|
||||||
# new_object.owner = odat["owner"]
|
new_object.home = odat["home"]
|
||||||
|
else:
|
||||||
|
new_object.home = odat["location"]
|
||||||
|
|
||||||
new_object.save()
|
new_object.save()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,9 @@ OBJECT_TYPES = (
|
||||||
(4, 'EXIT'),
|
(4, 'EXIT'),
|
||||||
(5, 'GARBAGE'),
|
(5, 'GARBAGE'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# This is a list of flags that the server actually uses. Anything not in this
|
||||||
|
# list is a custom flag.
|
||||||
|
SERVER_FLAGS = ["CONNECTED"]
|
||||||
|
# These flags are not saved.
|
||||||
|
NOSAVE_FLAGS = ["CONNECTED"]
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ class PlayerSession(async_chat):
|
||||||
"""
|
"""
|
||||||
Break the connection and do some accounting.
|
Break the connection and do some accounting.
|
||||||
"""
|
"""
|
||||||
|
self.pobject.set_flag("CONNECTED", False)
|
||||||
async_chat.handle_close(self)
|
async_chat.handle_close(self)
|
||||||
self.logged_in = False
|
self.logged_in = False
|
||||||
self.server.remove_session(self)
|
self.server.remove_session(self)
|
||||||
|
|
@ -83,6 +84,7 @@ class PlayerSession(async_chat):
|
||||||
self.name = user.username
|
self.name = user.username
|
||||||
self.logged_in = True
|
self.logged_in = True
|
||||||
self.conn_time = time.time()
|
self.conn_time = time.time()
|
||||||
|
self.pobject.set_flag("CONNECTED", True)
|
||||||
|
|
||||||
self.msg("You are now logged in as %s." % (self.name,))
|
self.msg("You are now logged in as %s." % (self.name,))
|
||||||
cdat = {"session": self, "uinput":'look', "server": self.server}
|
cdat = {"session": self, "uinput":'look', "server": self.server}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue