2009-01-18 04:22:58 +00:00
"""
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 ( )
"""
2007-04-25 19:39:15 +00:00
from django . contrib . auth . models import User , Group
2009-01-18 04:22:58 +00:00
from django . core import management
2008-12-15 04:35:00 +00:00
from src . objects . models import Object
2009-01-18 04:22:58 +00:00
from src . config . models import ConfigValue , CommandAlias , ConnectScreen
2009-01-18 03:14:52 +00:00
from src import comsys , defines_global
2007-04-25 19:39:15 +00:00
2009-01-18 04:22:58 +00:00
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.
2009-01-18 03:14:52 +00:00
god_user_obj = Object ( id = 1 , type = defines_global . OTYPE_PLAYER )
2008-06-13 19:52:29 +00:00
god_user_obj . set_name ( god_user . username )
2009-01-18 03:14:52 +00:00
god_user_obj . save ( )
2009-01-18 04:22:58 +00:00
# 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 ( ' %c h %c cLimbo %c n ' )
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. " )
2009-01-18 03:14:52 +00:00
limbo_obj . save ( )
2007-04-25 19:39:15 +00:00
2009-01-18 04:22:58 +00:00
# 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 .
"""
2008-06-13 19:52:29 +00:00
groups = ( " Immortals " , " Wizards " , " Builders " , " Player Helpers " )
for group in groups :
newgroup = Group ( )
newgroup . name = group
newgroup . save ( )
2009-01-18 04:22:58 +00:00
def create_channels ( ) :
"""
Creates some sensible default channels .
"""
god_user_obj = get_god_obj ( )
2009-01-18 03:14:52 +00:00
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 " )
2009-01-18 04:22:58 +00:00
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 ( )
2008-06-13 19:52:29 +00:00
# We don't want to do initial setup tasks every startup, only the first.
2009-01-18 04:22:58 +00:00
ConfigValue ( conf_key = " game_firstrun " , conf_value = " 0 " ) . save ( )
def create_connect_screens ( ) :
"""
Creates the default connect screen ( s ) .
"""
ConnectScreen ( name = " Default " ,
text = " %c h %c b================================================================== %c n \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 %c hconnect <email> <password> %c n \r \n If you need to create an account, type (without the <> ' s): \r \n %c hcreate \" <username> \" <email> <password> %c n \r \n %c h %c b================================================================== %c n \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 ( )
2009-01-20 04:18:03 +00:00
CommandAlias ( user_input = " p " , equiv_command = " page " ) . save ( )
2009-01-18 04:22:58 +00:00
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 ( )