Added the last migrations needed to fully convert the Attribute system. Cleaned up the @ooclook command a bit as well as tidied up the who command a bit.

This commit is contained in:
Griatch 2013-04-14 13:35:25 +02:00
parent 1a00797021
commit 8d48aa5a06
6 changed files with 362 additions and 191 deletions

View file

@ -72,36 +72,42 @@ class CmdOOCLook(MuxPlayerCommand):
characters = player.db._playable_characters
sessions = player.get_all_sessions()
sessidstr = sessid and " (session id %i)" % sessid or ""
string = "You are logged in as {g%s{n%s." % (player.key, sessidstr)
# text shown when looking in the ooc area
string = "Account {g%s{n (you are Out-of-Character)" % (player.key)
string += "\n\nSession(s) connected:"
for sess in sessions:
nsess = len(sessions)
string += nsess == 1 and "\n\n{wConnected session:{n" or "\n\n{wConnected sessions (%i):{n" % nsess
for isess, sess in enumerate(sessions):
csessid = sess.sessid
string += "\n %s %s" % (sessid == csessid and "{w%i{n" % csessid or csessid, sess.address)
string += "\n\nUse {w@ic <character>{n to enter the game, {w@occ{n to get back here."
if not characters:
string += "\nYou don't have any character yet. Use {w@charcreate <name> [=description]{n to create one."
elif len(characters) < MAX_NR_CHARACTERS:
string += "\nUse {w@charcreate <name> [=description]{n to create a new character (max %i)" % MAX_NR_CHARACTERS
addr = "%s (%s)" % (sess.protocol_key, isinstance(sess.address, tuple) and str(sess.address[0]) or str(sess.address))
string += "\n %s %s" % (sessid == csessid and "{w%s{n" % (isess + 1) or (isess + 1), addr)
string += "\n\n {whelp{n - more commands"
string += "\n {wooc <Text>{n - talk on public channel"
if len(characters) < MAX_NR_CHARACTERS:
if not characters:
string += "\n\n You don't have any character yet. See {whelp @charcreate{n for creating one."
else:
string += "\n {w@charcreate <name> [=description]{n - create new character (max %i)" % MAX_NR_CHARACTERS
if characters:
string += "\n {w@ic <character>{n - enter the game ({w@ooc{n to get back here)"
string += "\n\nAvailable character%s%s:" % (len(characters) > 1 and "s" or "",
MAX_NR_CHARACTERS > 1 and " (out of a maximum of %i)" % MAX_NR_CHARACTERS or "")
MAX_NR_CHARACTERS > 1 and " (%i/%i)" % (len(characters), MAX_NR_CHARACTERS) or "")
for char in characters:
csessid = char.sessid
if csessid:
# character is already puppeted
sess = player.get_session(csessid)
sid = sess in sessions and sessions.index(sess) + 1
if hasattr(char.locks, "lock_bypass") and char.locks.lock_bypass:
string += "\n - {G%s{n [superuser character] (played by you from session with id %i)" % (char.key, sess.sessid)
string += "\n - {G%s{n [superuser character] (played by you in session %i)" % (char.key, sid)
elif sess:
string += "\n - {G%s{n [%s] (played by you session id %i)" % (char.key, ", ".join(char.permissions), sess.sessid)
string += "\n - {G%s{n [%s] (played by you in session %i)" % (char.key, ", ".join(char.permissions), sid)
else:
string += "\n - {R%s{n [%s] (played by someone else)" % (char.key, ", ".join(char.permissions))
else:
# character is "free to puppet"
if player.is_superuser and char.get_attribute("_superuser_character"):
string += "\n - %s [Superuser character]" % (char.key)
string += "\n - %s [superuser character]" % (char.key)
else:
string += "\n - %s [%s]" % (char.key, ", ".join(char.permissions))
string = ("-" * 68) + "\n" + string + "\n" + ("-" * 68)
@ -109,7 +115,6 @@ class CmdOOCLook(MuxPlayerCommand):
def func(self):
"implement the ooc look command"
if MULTISESSION_MODE < 2:
# only one character allowed
string = "You are out-of-character (OOC).\nUse {w@ic{n to get back into the game."
@ -123,6 +128,7 @@ class CmdOOCLook(MuxPlayerCommand):
else:
self.no_look_target()
class CmdCharCreate(MuxPlayerCommand):
"""
Create a character
@ -130,7 +136,10 @@ class CmdCharCreate(MuxPlayerCommand):
Usage:
@charcreate <charname> [= desc]
Create a new character, optionally giving it a description.
Create a new character, optionally giving it a description. You
may use upper-case letters in the name - you will nevertheless
always be able to access your character using lower-case letters
if you want.
"""
key = "@charcreate"
locks = "cmd:all()"
@ -164,7 +173,7 @@ class CmdCharCreate(MuxPlayerCommand):
new_character.db.desc = desc
else:
new_character.db.desc = "This is a Player."
self.msg("Created new character %s." % new_character.key)
self.msg("Created new character %s. Use {w@ic %s{n to enter the game as this character." % (new_character.key, new_character.key))
class CmdIC(MuxPlayerCommand):
@ -340,6 +349,8 @@ class CmdWho(MuxPlayerCommand):
player = self.caller
session_list = SESSIONS.get_sessions()
session_list = sorted(session_list, key=lambda o: o.player.key)
if self.cmdstring == "doing":
show_session_data = False
else:
@ -347,7 +358,7 @@ class CmdWho(MuxPlayerCommand):
nplayers = (SESSIONS.player_count())
if show_session_data:
table = prettytable.PrettyTable(["{wPlayer Name","{wOn for", "{wIdle", "{wRoom", "{wCmds", "{wHost"])
table = prettytable.PrettyTable(["{wPlayer Name","{wOn for", "{wIdle", "{wRoom", "{wCmds", "{wProtocol", "{wHost"])
for session in session_list:
if not session.logged_in: continue
delta_cmd = time.time() - session.cmd_last_visible
@ -358,7 +369,9 @@ class CmdWho(MuxPlayerCommand):
utils.time_format(delta_conn, 0),
utils.time_format(delta_cmd, 1),
hasattr(plr_pobject, "location") and plr_pobject.location or "None",
session.cmd_total, type(session.address==tuple) and session.address[0] or session.address])
session.cmd_total,
session.protocol_key,
isinstance(session.address, tuple) and session.address[0] or session.address])
else:
table = prettytable.PrettyTable(["{wPlayer name", "{wOn for", "{Idle"])
for session in session_list:
@ -371,7 +384,7 @@ class CmdWho(MuxPlayerCommand):
utils.time.format(delta_conn, 0),
utils,time_format(delta_cmd, 1)])
string = "{wPlayers:\n%s\n%s logged in." % (table, nplayers==1 and "One player" or nplayer)
string = "{wPlayers:\n%s\n%s unique accounts logged in." % (table, nplayers==1 and "One player" or nplayers)
self.msg(string)

View file

@ -0,0 +1,114 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'ObjAttribute.db_value'
db.delete_column('objects_objattribute', 'db_value')
db.rename_column('objects_objattribute', 'db_value2', 'db_value')
def backwards(self, orm):
# Adding field 'ObjAttribute.db_value'
db.add_column('objects_objattribute', 'db_value',
self.gf('django.db.models.fields.TextField')(null=True, blank=True),
keep_default=False)
db.rename_column('objects_objattribute', 'db_value', 'db_value2')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'objects.alias': {
'Meta': {'object_name': 'Alias'},
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['objects.ObjectDB']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'objects.objattribute': {
'Meta': {'object_name': 'ObjAttribute'},
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['objects.ObjectDB']"}),
'db_value2': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'objects.objectdb': {
'Meta': {'object_name': 'ObjectDB'},
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_destination': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'destinations_set'", 'null': 'True', 'to': "orm['objects.ObjectDB']"}),
'db_home': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'homes_set'", 'null': 'True', 'to': "orm['objects.ObjectDB']"}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_location': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locations_set'", 'null': 'True', 'to': "orm['objects.ObjectDB']"}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'db_player': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['players.PlayerDB']", 'null': 'True', 'blank': 'True'}),
'db_sessid': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'objects.objectnick': {
'Meta': {'unique_together': "(('db_nick', 'db_type', 'db_obj'),)", 'object_name': 'ObjectNick'},
'db_nick': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['objects.ObjectDB']"}),
'db_real': ('django.db.models.fields.TextField', [], {}),
'db_type': ('django.db.models.fields.CharField', [], {'default': "'inputline'", 'max_length': '16', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'players.playerdb': {
'Meta': {'object_name': 'PlayerDB'},
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
}
}
complete_apps = ['objects']

View file

@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'PlayerAttribute.db_value'
db.delete_column('players_playerattribute', 'db_value')
db.rename_column('players_playerattribute', 'db_value2', 'db_value')
def backwards(self, orm):
# Adding field 'PlayerAttribute.db_value'
db.add_column('players_playerattribute', 'db_value',
self.gf('django.db.models.fields.TextField')(null=True, blank=True),
keep_default=False)
db.rename_column('players_playerattribute', 'db_value', 'db_value2')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'players.playerattribute': {
'Meta': {'object_name': 'PlayerAttribute'},
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['players.PlayerDB']"}),
'db_value2': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'players.playerdb': {
'Meta': {'object_name': 'PlayerDB'},
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
},
'players.playernick': {
'Meta': {'unique_together': "(('db_nick', 'db_type', 'db_obj'),)", 'object_name': 'PlayerNick'},
'db_nick': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['players.PlayerDB']"}),
'db_real': ('django.db.models.fields.TextField', [], {}),
'db_type': ('django.db.models.fields.CharField', [], {'default': "'inputline'", 'max_length': '16', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
}
}
complete_apps = ['players']

View file

@ -0,0 +1,113 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'ScriptAttribute.db_value'
db.delete_column('scripts_scriptattribute', 'db_value')
db.rename_column('scripts_scriptattribute', 'db_value2', 'db_value')
def backwards(self, orm):
# Adding field 'ScriptAttribute.db_value'
db.add_column('scripts_scriptattribute', 'db_value',
self.gf('django.db.models.fields.TextField')(null=True, blank=True),
keep_default=False)
db.rename_column('scripts_scriptattribute', 'db_value', 'db_value2')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'objects.objectdb': {
'Meta': {'object_name': 'ObjectDB'},
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_destination': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'destinations_set'", 'null': 'True', 'to': "orm['objects.ObjectDB']"}),
'db_home': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'homes_set'", 'null': 'True', 'to': "orm['objects.ObjectDB']"}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_location': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locations_set'", 'null': 'True', 'to': "orm['objects.ObjectDB']"}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'db_player': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['players.PlayerDB']", 'null': 'True', 'blank': 'True'}),
'db_sessid': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'players.playerdb': {
'Meta': {'object_name': 'PlayerDB'},
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
},
'scripts.scriptattribute': {
'Meta': {'object_name': 'ScriptAttribute'},
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['scripts.ScriptDB']"}),
'db_value2': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'scripts.scriptdb': {
'Meta': {'object_name': 'ScriptDB'},
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'db_desc': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'db_interval': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
'db_is_active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['objects.ObjectDB']", 'null': 'True', 'blank': 'True'}),
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'db_persistent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'db_repeats': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'db_start_delay': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
}
}
complete_apps = ['scripts']

View file

@ -107,8 +107,7 @@ class Attribute(SharedMemoryModel):
db_key = models.CharField('key', max_length=255, db_index=True)
# access through the value property
db_value = models.TextField('value', blank=True, null=True)
db_value2 = PickledObjectField('value2', null=True)
db_value = PickledObjectField('value2', null=True)
# Lock storage
db_lock_storage = models.TextField('locks', blank=True)
# references the object the attribute is linked to (this is set
@ -196,24 +195,11 @@ class Attribute(SharedMemoryModel):
"""
if self.no_cache:
# re-create data from database and cache it
value = from_pickle(self.db_value2, db_obj=self)
value = from_pickle(self.db_value, db_obj=self)
self.cached_value = value
self.no_cache = False
return self.cached_value
#if self.no_cache:
# # re-create data from database and cache it
# try:
# value = self.__from_attr(_PLOADS(to_str(self.db_value)))
# except pickle.UnpicklingError:
# value = self.db_value
# self.cached_value = value
# self.no_cache = False
# return value
#else:
# # normally the memory cache holds the latest data so no db access is needed.
# return self.cached_value
#@value.setter
def __value_set(self, new_value):
"""
@ -222,18 +208,10 @@ class Attribute(SharedMemoryModel):
to_store = to_pickle(new_value)
self.cached_value = from_pickle(to_store, db_obj=self)
self.no_cache = False
self.db_value2 = to_store
self.db_value = to_store
self.save()
self.at_set(self.cached_value)
#new_value = self.__to_attr(new_value)
#self.cached_value = self.__from_attr(new_value)
#self.no_cache = False
#self.db_value = to_unicode(_PDUMPS(to_str(new_value)))
#self.save()
## call attribute hook
#self.at_set(new_value)
#@value.deleter
def __value_del(self):
"Deleter. Allows for del attr.value. This removes the entire attribute."
@ -269,151 +247,6 @@ class Attribute(SharedMemoryModel):
def __unicode__(self):
return u"%s(%s)" % (self.key, self.id)
# operators on various data
#def __to_attr(self, data):
# """
# Convert data to proper attr data format before saving
# We have to make sure to not store database objects raw, since
# this will crash the system. Instead we must store their IDs
# and make sure to convert back when the attribute is read back
# later.
# Due to this it's criticial that we check all iterables
# recursively, converting all found database objects to a form
# the database can handle. We handle lists, tuples and dicts
# (and any nested combination of them) this way, all other
# iterables are stored and returned as lists.
# data storage format:
# (simple|dbobj|iter, <data>)
# where
# simple - a single non-db object, like a string or number
# dbobj - a single dbobj
# iter - any iterable object - will be looped over recursively
# to convert dbobj->id.
# """
# def iter_db2id(item):
# """
# recursively looping through stored iterables, replacing objects with ids.
# (Python only builds nested functions once, so there is no overhead for nesting)
# """
# dtype = type(item)
# if dtype in (basestring, int, float): # check the most common types first, for speed
# return item
# elif hasattr(item, "id") and hasattr(item, "_db_model_name") and hasattr(item, "db_key"):
# db_model_name = item._db_model_name # don't use _GA here, could be typeclass
# if db_model_name == "typeclass":
# db_model_name = _GA(item.dbobj, "_db_model_name")
# return PackedDBobject(item.id, db_model_name, item.db_key)
# elif dtype == tuple:
# return tuple(iter_db2id(val) for val in item)
# elif dtype in (dict, PackedDict):
# return dict((key, iter_db2id(val)) for key, val in item.items())
# elif dtype in (set, PackedSet):
# return set(iter_db2id(val) for val in item)
# elif hasattr(item, '__iter__'):
# return list(iter_db2id(val) for val in item)
# else:
# return item
# dtype = type(data)
# if dtype in (basestring, int, float):
# return ("simple",data)
# elif hasattr(data, "id") and hasattr(data, "_db_model_name") and hasattr(data, 'db_key'):
# # all django models (objectdb,scriptdb,playerdb,channel,msg,typeclass)
# # have the protected property _db_model_name hardcoded on themselves for speed.
# db_model_name = data._db_model_name # don't use _GA here, could be typeclass
# if db_model_name == "typeclass":
# # typeclass cannot help us, we want the actual child object model name
# db_model_name = _GA(data.dbobj,"_db_model_name")
# return ("dbobj", PackedDBobject(data.id, db_model_name, data.db_key))
# elif hasattr(data, "__iter__"):
# return ("iter", iter_db2id(data))
# else:
# return ("simple", data)
#def __from_attr(self, datatuple):
# """
# Retrieve data from a previously stored attribute. This
# is always a dict with keys type and data.
# datatuple comes from the database storage and has
# the following format:
# (simple|dbobj|iter, <data>)
# where
# simple - a single non-db object, like a string. is returned as-is.
# dbobj - a single dbobj-id. This id is retrieved back from the database.
# iter - an iterable. This is traversed iteratively, converting all found
# dbobj-ids back to objects. Also, all lists and dictionaries are
# returned as their PackedList/PackedDict counterparts in order to
# allow in-place assignment such as obj.db.mylist[3] = val. Mylist
# is then a PackedList that saves the data on the fly.
# """
# # nested functions
# def id2db(data):
# """
# Convert db-stored dbref back to object
# """
# mclass = _CTYPEGET(model=data.db_model).model_class()
# try:
# return mclass.objects.dbref_search(data.id)
# except AttributeError:
# try:
# return mclass.objects.get(id=data.id)
# except mclass.DoesNotExist: # could happen if object was deleted in the interim.
# return None
# def iter_id2db(item, parent=None):
# """
# Recursively looping through stored iterables, replacing ids with actual objects.
# We return PackedDict and PackedLists instead of normal lists; this is needed in order for
# the user to do dynamic saving of nested in-place, such as obj.db.attrlist[2]=3. What is
# stored in the database are however always normal python primitives.
# """
# dtype = type(item)
# if dtype in (basestring, int, float): # check the most common types first, for speed
# return item
# elif dtype == PackedDBobject:
# return id2db(item)
# elif dtype == tuple:
# return tuple([iter_id2db(val) for val in item])
# elif dtype in (dict, PackedDict):
# pdict = PackedDict(self)
# pdict.update(dict(zip([key for key in item.keys()],
# [iter_id2db(val, pdict) for val in item.values()])))
# pdict.parent = parent
# return pdict
# elif dtype in (set, PackedSet):
# pset = PackedSet(self)
# pset.update(set(iter_id2db(val) for val in item))
# return pset
# elif hasattr(item, '__iter__'):
# plist = PackedList(self)
# plist.extend(list(iter_id2db(val, plist) for val in item))
# plist.parent = parent
# return plist
# else:
# return item
# typ, data = datatuple
# if typ == 'simple':
# # single non-db objects
# return data
# elif typ == 'dbobj':
# # a single stored dbobj
# return id2db(data)
# elif typ == 'iter':
# # all types of iterables
# return iter_id2db(data)
def access(self, accessing_obj, access_type='read', default=False):
"""
Determines if another object has permission to access.

View file

@ -22,8 +22,13 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
"""
Pickle field implementation for Django.
Modified for Evennia by Griatch.
"""
"""Pickle field implementation for Django."""
from copy import deepcopy
from base64 import b64encode, b64decode
from zlib import compress, decompress
@ -31,6 +36,8 @@ import six
import django
from django.db import models
from src.utils.dbserialize import to_pickle
# django 1.5 introduces force_text instead of force_unicode
try:
from django.utils.encoding import force_text