mirror of
https://github.com/evennia/evennia.git
synced 2026-03-18 05:46:31 +01:00
Move away from fixtures in favor of src/initial_setup.py, which makes it a little easier to change stuff like this. It also avoids over-writing stuff when syncdb is ran. This commit features database layout changes to ConnectScreen and CommChannel. It is recommended that you drop your database and re-sync. If this is not acceptable, talk to me about a migration plan. We will be investigating schema evolution down the road.
This commit is contained in:
parent
c0ebbc3967
commit
f6ee697e04
8 changed files with 119 additions and 38 deletions
|
|
@ -1 +0,0 @@
|
|||
[{"pk": 1, "model": "config.connectscreen", "fields": {"is_active": 1, "name": "Default", "connect_screen_text": "%ch%cb==================================================================%cn\r\n Welcome to Evennia! Please type one of the following to begin:\r\n\r\n If you have an existing account, connect to it by typing:\r\n %chconnect <email> <password2>%cn\r\n If you need to create an account, type (without the <>'s):\r\n %chcreate \"<username>\" <email> <password>%cn\r\n%ch%cb==================================================================%cn\r\n"}}, {"pk": 9, "model": "config.commandalias", "fields": {"user_input": "@desc", "equiv_command": "@describe"}}, {"pk": 3, "model": "config.commandalias", "fields": {"user_input": "@dest", "equiv_command": "@destroy"}}, {"pk": 4, "model": "config.commandalias", "fields": {"user_input": "@nuke", "equiv_command": "@destroy"}}, {"pk": 6, "model": "config.commandalias", "fields": {"user_input": "@tel", "equiv_command": "@teleport"}}, {"pk": 2, "model": "config.commandalias", "fields": {"user_input": "ex", "equiv_command": "examine"}}, {"pk": 7, "model": "config.commandalias", "fields": {"user_input": "i", "equiv_command": "inventory"}}, {"pk": 8, "model": "config.commandalias", "fields": {"user_input": "inv", "equiv_command": "inventory"}}, {"pk": 1, "model": "config.commandalias", "fields": {"user_input": "l", "equiv_command": "look"}}, {"pk": 5, "model": "config.commandalias", "fields": {"user_input": "sa", "equiv_command": "say"}}, {"pk": 1, "model": "config.configvalue", "fields": {"conf_value": "Evennia Test Site", "conf_key": "site_name"}}, {"pk": 2, "model": "config.configvalue", "fields": {"conf_value": "2", "conf_key": "player_dbnum_start"}}, {"pk": 3, "model": "config.configvalue", "fields": {"conf_value": "Credits", "conf_key": "money_name_plural"}}, {"pk": 4, "model": "config.configvalue", "fields": {"conf_value": "Credit", "conf_key": "money_name_singular"}}, {"pk": 5, "model": "config.configvalue", "fields": {"conf_value": "1", "conf_key": "game_firstrun"}}, {"pk": 6, "model": "config.configvalue", "fields": {"conf_value": "1800", "conf_key": "idle_timeout"}}, {"pk": 7, "model": "config.configvalue", "fields": {"conf_value": "2", "conf_key": "default_home"}}]
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
"""
|
||||
Custom manager for ConfigValue objects.
|
||||
"""
|
||||
from traceback import format_exc
|
||||
from django.db import models
|
||||
from src import logger
|
||||
|
||||
|
|
@ -13,8 +12,9 @@ class ConfigValueManager(models.Manager):
|
|||
try:
|
||||
return self.get(conf_key__iexact=configname).conf_value
|
||||
except self.model.DoesNotExist:
|
||||
logger.log_errmsg("Unable to get config value for %s (does not exist):\n%s" % (
|
||||
configname, (format_exc())))
|
||||
logger.log_errmsg("Unable to get config value for %s (does not exist).\n" % (
|
||||
configname))
|
||||
raise
|
||||
|
||||
def set_configvalue(self, configname, newvalue):
|
||||
"""
|
||||
|
|
@ -29,4 +29,5 @@ class ConfigValueManager(models.Manager):
|
|||
return newvalue
|
||||
except self.model.DoesNotExist:
|
||||
logger.log_errmsg("Unable to set config value for %s (does not exist):\n%s" % (
|
||||
configname, (format_exc())))
|
||||
configname))
|
||||
raise
|
||||
|
|
@ -12,6 +12,7 @@ class ConnectScreenManager(models.Manager):
|
|||
return self.filter(is_active=True).order_by('?')[0]
|
||||
except IndexError:
|
||||
new_screen = ConnectScreen(name='Default',
|
||||
connect_screen_text='This is a placeholder connect screen. Remind your admin to edit it through the Admin interface.')
|
||||
text='This is a placeholder connect screen. Remind your admin to edit it through the Admin interface.',
|
||||
is_active=True)
|
||||
new_screen.save()
|
||||
return new_screen
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class ConnectScreen(models.Model):
|
|||
will cycle randomly.
|
||||
"""
|
||||
name = models.CharField(max_length=255, help_text="An optional name for this screen (for organizational purposes).", blank=True)
|
||||
connect_screen_text = models.TextField(help_text="The text for the connect screen. Color codes and substitutions are evaluated.")
|
||||
text = models.TextField(help_text="The text for the connect screen. Color codes and substitutions are evaluated.")
|
||||
is_active = models.BooleanField(default=1, help_text="Only active connect screens are placed in the rotation")
|
||||
|
||||
objects = ConnectScreenManager()
|
||||
|
|
|
|||
|
|
@ -1,35 +1,121 @@
|
|||
"""
|
||||
This module handles initial database propagation, which is only ran the first
|
||||
time the game starts. It will create some default channels, objects, and
|
||||
other things.
|
||||
|
||||
Everything starts at handle_setup()
|
||||
"""
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.core import management
|
||||
from src.objects.models import Object
|
||||
from src.config.models import ConfigValue
|
||||
from src.config.models import ConfigValue, CommandAlias, ConnectScreen
|
||||
from src import comsys, defines_global
|
||||
|
||||
def handle_setup():
|
||||
# Set the initial user's username on the #1 object.
|
||||
god_user = User.objects.get(id=1)
|
||||
def get_god_user():
|
||||
"""
|
||||
Returns the initially created 'god' User object.
|
||||
"""
|
||||
return User.objects.get(id=1)
|
||||
|
||||
def get_god_obj():
|
||||
"""
|
||||
Returns the initially created 'god' user's PLAYER object.
|
||||
"""
|
||||
return Object.objects.get(id=1)
|
||||
|
||||
def create_objects():
|
||||
"""
|
||||
Creates the #1 player and Limbo room.
|
||||
"""
|
||||
# Set the initial User's account object's username on the #1 object.
|
||||
god_user = get_god_user()
|
||||
# Create the matching PLAYER object in the object DB.
|
||||
god_user_obj = Object(id=1, type=defines_global.OTYPE_PLAYER)
|
||||
god_user_obj.set_name(god_user.username)
|
||||
god_user_obj.save()
|
||||
|
||||
limbo_obj = Object()
|
||||
limbo_obj.type = defines_global.OTYPE_ROOM
|
||||
limbo_obj.owner = god_user_obj
|
||||
limbo_obj.set_name('Limbo')
|
||||
# Limbo is the initial starting room.
|
||||
limbo_obj = Object(type = defines_global.OTYPE_ROOM)
|
||||
limbo_obj.set_owner(god_user_obj)
|
||||
limbo_obj.set_name('%ch%ccLimbo%cn')
|
||||
limbo_obj.set_description("Welcome to your new Evennia-based game. From here you are ready to begin development. If you should need help or would like to participate in community discussions, visit http://evennia.com.")
|
||||
limbo_obj.save()
|
||||
|
||||
god_user_obj.home = limbo_obj
|
||||
god_user_obj.save()
|
||||
|
||||
# Now that Limbo exists, set the user up in Limbo.
|
||||
god_user_obj.location = limbo_obj
|
||||
god_user_obj.set_home(limbo_obj)
|
||||
|
||||
def create_groups():
|
||||
"""
|
||||
Creates the default permissions groups.
|
||||
"""
|
||||
groups = ("Immortals", "Wizards", "Builders", "Player Helpers")
|
||||
for group in groups:
|
||||
newgroup = Group()
|
||||
newgroup.name = group
|
||||
newgroup.save()
|
||||
|
||||
|
||||
def create_channels():
|
||||
"""
|
||||
Creates some sensible default channels.
|
||||
"""
|
||||
god_user_obj = get_god_obj()
|
||||
chan_pub = comsys.create_channel("Public", god_user_obj, description="Public Discussion")
|
||||
chan_pub.is_joined_by_default = True
|
||||
chan_pub.save()
|
||||
comsys.create_channel("Errors", god_user_obj, description="Error log")
|
||||
comsys.create_channel("Info", god_user_obj, description="Informative messages")
|
||||
|
||||
|
||||
def create_config_values():
|
||||
"""
|
||||
Creates the initial config values.
|
||||
"""
|
||||
ConfigValue(conf_key="default_home", conf_value="2").save()
|
||||
ConfigValue(conf_key="idle_timeout", conf_value="1800").save()
|
||||
ConfigValue(conf_key="money_name_singular", conf_value="Credit").save()
|
||||
ConfigValue(conf_key="money_name_plural", conf_value="Credits").save()
|
||||
ConfigValue(conf_key="player_dbnum_start", conf_value="2").save()
|
||||
ConfigValue(conf_key="site_name", conf_value="Evennia Test Site").save()
|
||||
# We don't want to do initial setup tasks every startup, only the first.
|
||||
ConfigValue.objects.set_configvalue('game_firstrun', '0')
|
||||
ConfigValue(conf_key="game_firstrun", conf_value="0").save()
|
||||
|
||||
def create_connect_screens():
|
||||
"""
|
||||
Creates the default connect screen(s).
|
||||
"""
|
||||
ConnectScreen(name="Default",
|
||||
text="%ch%cb==================================================================%cn\r\n Welcome to Evennia! Please type one of the following to begin:\r\n\r\n If you have an existing account, connect to it by typing:\r\n %chconnect <email> <password>%cn\r\n If you need to create an account, type (without the <>'s):\r\n %chcreate \"<username>\" <email> <password>%cn\r\n%ch%cb==================================================================%cn\r\n",
|
||||
is_active=True).save()
|
||||
|
||||
def create_aliases():
|
||||
"""
|
||||
Populates the standard aliases.
|
||||
"""
|
||||
CommandAlias(user_input="@desc", equiv_command="@describe").save()
|
||||
CommandAlias(user_input="@dest", equiv_command="@destroy").save()
|
||||
CommandAlias(user_input="@nuke", equiv_command="@destroy").save()
|
||||
CommandAlias(user_input="@tel", equiv_command="@teleport").save()
|
||||
CommandAlias(user_input="i", equiv_command="inventory").save()
|
||||
CommandAlias(user_input="inv", equiv_command="inventory").save()
|
||||
CommandAlias(user_input="l", equiv_command="look").save()
|
||||
CommandAlias(user_input="ex", equiv_command="examine").save()
|
||||
CommandAlias(user_input="sa", equiv_command="say").save()
|
||||
CommandAlias(user_input="emote", equiv_command="pose").save()
|
||||
|
||||
def import_help_files():
|
||||
"""
|
||||
Imports the help files.
|
||||
"""
|
||||
management.call_command('loaddata', '../docs/help_files.json', verbosity=0)
|
||||
|
||||
def handle_setup():
|
||||
"""
|
||||
Main logic for the module.
|
||||
"""
|
||||
create_config_values()
|
||||
create_aliases()
|
||||
create_connect_screens()
|
||||
create_objects()
|
||||
create_groups()
|
||||
create_channels()
|
||||
import_help_files()
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
INSERT INTO objects_object VALUES(1,'Wizard','Wizard',1,0,'',2,1,'',2,'','CONNECTED','2007-04-25');
|
||||
INSERT INTO objects_object VALUES(2,'Limbo','Limbo',1,NULL,'',NULL,2,'Welcome to your new Evennia-based game. From here you are ready to begin development. If you should need help or would like to participate in community discussions, visit http://evennia.com.',NULL,'','','2007-04-25');
|
||||
INSERT INTO objects_commchannel VALUES(1,'Public','Public',1,'Public Discussion', false);
|
||||
INSERT INTO objects_commchannel VALUES(2,'Errors','Errors',1,'Error Log', false);
|
||||
INSERT INTO objects_commchannel VALUES(3,'Info','Info',1,'Info Log', false);
|
||||
|
|
@ -1,14 +1,9 @@
|
|||
from traceback import format_exc
|
||||
import time
|
||||
import sys
|
||||
|
||||
from twisted.application import internet, service
|
||||
from twisted.internet import protocol, reactor, defer
|
||||
|
||||
from django.db import models
|
||||
from django.db import connection
|
||||
from django.conf import settings
|
||||
|
||||
from src.config.models import CommandAlias, ConfigValue
|
||||
from src.session import SessionProtocol
|
||||
from src import scheduler
|
||||
|
|
@ -19,8 +14,8 @@ from src import initial_setup
|
|||
from src.util import functions_general
|
||||
|
||||
class EvenniaService(service.Service):
|
||||
|
||||
def __init__(self, filename="blah"):
|
||||
def __init__(self):
|
||||
# This holds a dictionary of command aliases for cmdhandler.py
|
||||
self.cmd_alias_list = {}
|
||||
self.game_running = True
|
||||
sys.path.append('.')
|
||||
|
|
@ -33,14 +28,18 @@ class EvenniaService(service.Service):
|
|||
cursor = connection.cursor()
|
||||
cursor.execute("UPDATE objects_object SET nosave_flags=''")
|
||||
|
||||
# Begin startup debug output.
|
||||
print '-'*50
|
||||
# Load command aliases into memory for easy/quick access.
|
||||
self.load_cmd_aliases()
|
||||
|
||||
if ConfigValue.objects.get_configvalue('game_firstrun') == '1':
|
||||
try:
|
||||
# If this fails, this is an empty DB that needs populating.
|
||||
ConfigValue.objects.get_configvalue('game_firstrun')
|
||||
except ConfigValue.DoesNotExist:
|
||||
print ' Game started for the first time, setting defaults.'
|
||||
initial_setup.handle_setup()
|
||||
|
||||
# Load command aliases into memory for easy/quick access.
|
||||
self.load_cmd_aliases()
|
||||
self.start_time = time.time()
|
||||
|
||||
print ' %s started on port(s):' % (ConfigValue.objects.get_configvalue('site_name'),)
|
||||
|
|
@ -114,7 +113,7 @@ class EvenniaService(service.Service):
|
|||
"""
|
||||
|
||||
application = service.Application('Evennia')
|
||||
mud_service = EvenniaService('Evennia Server')
|
||||
mud_service = EvenniaService()
|
||||
|
||||
# Sheet sheet, fire ze missiles!
|
||||
serviceCollection = service.IServiceCollection(application)
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class SessionProtocol(StatefulTelnetProtocol):
|
|||
Show the banner screen. Grab from the 'connect_screen' config directive.
|
||||
"""
|
||||
screen = ConnectScreen.objects.get_random_connect_screen()
|
||||
buffer = ansi.parse_ansi(screen.connect_screen_text)
|
||||
buffer = ansi.parse_ansi(screen.text)
|
||||
self.msg(buffer)
|
||||
|
||||
def is_loggedin(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue