Re-arrangement. I almost have things organized how I want them.

This commit is contained in:
Greg Taylor 2006-12-05 20:25:07 +00:00
parent 0696575786
commit d7cf02e8c0
5 changed files with 63 additions and 56 deletions

View file

@ -1,7 +1,6 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
class ObjectClass(models.Model): class ObjectClass(models.Model):
""" """
Each object class can have different behaviors to apply to it. Each object class can have different behaviors to apply to it.
@ -111,12 +110,11 @@ class Object(models.Model):
# self.location.contents_list.remove(self) # self.location.contents_list.remove(self)
#target.contents_list.append(self) #target.contents_list.append(self)
cached_object = server.get_object_from_dbref(self.id) cached_object = functions_db.get_object_from_dbref(server, self.id)
cached_object.location = target cached_object.location = target
cached_object.save() cached_object.save()
def dbref_match(self, oname): def dbref_match(self, oname):
import functions_db
""" """
Check if the input (oname) can be used to identify this particular object Check if the input (oname) can be used to identify this particular object
by means of a dbref match. by means of a dbref match.
@ -132,7 +130,6 @@ class Object(models.Model):
return is_match return is_match
def name_match(self, oname): def name_match(self, oname):
import functions_db
""" """
See if the input (oname) can be used to identify this particular object. See if the input (oname) can be used to identify this particular object.
Check the # sign for dbref (exact) reference, and anything else is a Check the # sign for dbref (exact) reference, and anything else is a
@ -184,3 +181,5 @@ class Object(models.Model):
def __str__(self): def __str__(self):
return "%s(%d)" % (self.name, self.id,) return "%s(%d)" % (self.name, self.id,)
import functions_db

View file

@ -1,4 +1,5 @@
from django.contrib.auth.models import User from django.contrib.auth.models import User
import functions_db
""" """
Commands that are available from the connect screen. Commands that are available from the connect screen.
@ -30,10 +31,11 @@ def do_create(cdat):
Handle the creation of new accounts. Handle the creation of new accounts.
""" """
session = cdat['session'] session = cdat['session']
server = cdat['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]
# Search for a user object with the specified username.
account = User.objects.filter(username=uname) account = User.objects.filter(username=uname)
if not account.count() == 0: if not account.count() == 0:
@ -41,7 +43,7 @@ def do_create(cdat):
elif len(password) < 3: elif len(password) < 3:
session.msg("Your password must be 3 characters or longer.") session.msg("Your password must be 3 characters or longer.")
else: else:
server.create_user(session, uname, email, password) functions_db.create_user(cdat, uname, email, password)
def do_quit(cdat): def do_quit(cdat):
""" """

View file

@ -1,6 +1,23 @@
import sets import sets
from django.contrib.auth.models import User
from apps.objects.models import Object from apps.objects.models import Object
def get_nextfree_dbnum():
"""
Figure out what our next free database reference number is.
"""
# First we'll see if there's an object of type 5 (GARBAGE) that we
# can recycle.
nextfree = Object.objects.filter(type__exact=5)
if nextfree:
# We've got at least one garbage object to recycle.
#return nextfree.id
return nextfree[0].id
else:
# No garbage to recycle, find the highest dbnum and increment it
# for our next free.
return Object.objects.order_by('-id')[0].id + 1
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
@ -68,3 +85,38 @@ def session_from_dbref(session_list, dbstring):
return results[0] return results[0]
else: else:
return False return False
def get_object_from_dbref(server, dbref):
"""
Returns an object when given a dbref.
"""
return server.object_list.get(dbref, False)
def create_user(cdat, uname, email, password):
"""
Handles the creation of new users.
"""
session = cdat['session']
server = cdat['server']
start_room = int(server.get_configvalue('player_dbnum_start'))
start_room_obj = get_object_from_dbref(server, start_room)
# The user's entry in the User table must match up to an object
# on the object table. The id's are the same, we need to figure out
# the next free unique ID to use and make sure the two entries are
# the same number.
uid = get_nextfree_dbnum()
user = User.objects.create_user(uname, email, password)
# It stinks to have to do this but it's the only trivial way now.
user.id = uid
user.save
# Create a player object of the same ID in the Objects table.
user_object = Object(id=uid, type=1, name=uname, location=start_room_obj)
user_object.save()
server.add_object_to_cache(user_object)
# Activate the player's session and set them loose.
session.login(user)
print 'Registration: %s' % (session,)
session.push("Welcome to %s, %s.\n\r" % (server.get_configvalue('site_name'), session.name,))

View file

@ -6,6 +6,7 @@ from django.db import models
from apps.config.models import ConfigValue, CommandAlias from apps.config.models import ConfigValue, CommandAlias
from apps.objects.models import Object, Attribute from apps.objects.models import Object, Attribute
from django.contrib.auth.models import User from django.contrib.auth.models import User
import functions_db
# #
## Begin: Time Functions ## Begin: Time Functions
@ -145,39 +146,6 @@ class Server(dispatcher):
""" """
self.object_list[object.id] = object self.object_list[object.id] = object
def get_object_from_dbref(self, dbref):
"""
Returns an object when given a dbref.
"""
return self.object_list.get(dbref, False)
def create_user(self, session, uname, email, password):
"""
Handles the creation of new users.
"""
start_room = int(self.get_configvalue('player_dbnum_start'))
start_room_obj = self.get_object_from_dbref(start_room)
# The user's entry in the User table must match up to an object
# on the object table. The id's are the same, we need to figure out
# the next free unique ID to use and make sure the two entries are
# the same number.
uid = self.get_nextfree_dbnum()
user = User.objects.create_user(uname, email, password)
# It stinks to have to do this but it's the only trivial way now.
user.id = uid
user.save
# Create a player object of the same ID in the Objects table.
user_object = Object(id=uid, type=1, name=uname, location=start_room_obj)
user_object.save()
self.add_object_to_cache(user_object)
# Activate the player's session and set them loose.
session.login(user)
print 'Registration: %s' % (session,)
session.push("Welcome to %s, %s.\n\r" % (self.get_configvalue('site_name'), session.name,))
def announce_all(self, message, with_ann_prefix=True): def announce_all(self, message, with_ann_prefix=True):
""" """
Announces something to all connected players. Announces something to all connected players.
@ -196,21 +164,6 @@ class Server(dispatcher):
""" """
return self.configvalue[configname] return self.configvalue[configname]
def get_nextfree_dbnum(self):
"""
Figure out what our next free database reference number is.
"""
# First we'll see if there's an object of type 5 (GARBAGE) that we
# can recycle.
nextfree = Object.objects.filter(type__exact=5)
if nextfree:
# We've got at least one garbage object to recycle.
#return nextfree.id
return nextfree[0].id
else:
# No garbage to recycle, find the highest dbnum and increment it
# for our next free.
return Object.objects.order_by('-id')[0].id + 1
""" """
END Server CLASS END Server CLASS
""" """

View file

@ -5,6 +5,7 @@ import cmdhandler
from apps.objects.models import Object from apps.objects.models import Object
from django.contrib.auth.models import User from django.contrib.auth.models import User
import commands_general import commands_general
import functions_db
class PlayerSession(async_chat): class PlayerSession(async_chat):
""" """
@ -78,7 +79,7 @@ class PlayerSession(async_chat):
""" """
After the user has authenticated, handle logging him in. After the user has authenticated, handle logging him in.
""" """
self.pobject = self.server.get_object_from_dbref(user.id) self.pobject = functions_db.get_object_from_dbref(self.server, user.id)
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()