2007-05-09 15:28:12 +00:00
|
|
|
from traceback import format_exc
|
2008-06-15 19:55:38 +00:00
|
|
|
import time
|
|
|
|
|
import sys
|
2007-05-21 20:52:05 +00:00
|
|
|
|
|
|
|
|
from twisted.application import internet, service
|
|
|
|
|
from twisted.internet import protocol, reactor, defer
|
|
|
|
|
|
2006-11-20 18:54:10 +00:00
|
|
|
from django.db import models
|
2006-12-21 09:12:38 +00:00
|
|
|
from django.db import connection
|
2008-06-15 17:21:02 +00:00
|
|
|
from django.conf import settings
|
2006-12-22 02:43:29 +00:00
|
|
|
|
2008-12-15 04:35:00 +00:00
|
|
|
from src.config.models import CommandAlias, ConfigValue
|
2008-06-15 19:38:39 +00:00
|
|
|
from src.session import SessionProtocol
|
|
|
|
|
from src import scheduler
|
2008-06-15 20:31:25 +00:00
|
|
|
from src import logger
|
2008-06-15 19:38:39 +00:00
|
|
|
from src import session_mgr
|
|
|
|
|
from src import cmdtable
|
|
|
|
|
from src import initial_setup
|
2008-06-15 20:31:25 +00:00
|
|
|
from src.util import functions_general
|
2006-12-05 22:06:50 +00:00
|
|
|
|
2007-05-21 20:52:05 +00:00
|
|
|
class EvenniaService(service.Service):
|
|
|
|
|
|
2008-06-13 19:52:29 +00:00
|
|
|
def __init__(self, filename="blah"):
|
|
|
|
|
self.cmd_alias_list = {}
|
|
|
|
|
self.game_running = True
|
|
|
|
|
sys.path.append('.')
|
|
|
|
|
|
|
|
|
|
# Database-specific startup optimizations.
|
|
|
|
|
if settings.DATABASE_ENGINE == "sqlite3":
|
|
|
|
|
self.sqlite3_prep()
|
|
|
|
|
|
|
|
|
|
# Wipe our temporary flags on all of the objects.
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
cursor.execute("UPDATE objects_object SET nosave_flags=''")
|
|
|
|
|
|
|
|
|
|
print '-'*50
|
|
|
|
|
# Load command aliases into memory for easy/quick access.
|
|
|
|
|
self.load_cmd_aliases()
|
|
|
|
|
|
2008-06-15 17:21:02 +00:00
|
|
|
if ConfigValue.objects.get_configvalue('game_firstrun') == '1':
|
2008-06-13 19:52:29 +00:00
|
|
|
print ' Game started for the first time, setting defaults.'
|
|
|
|
|
initial_setup.handle_setup()
|
|
|
|
|
|
|
|
|
|
self.start_time = time.time()
|
|
|
|
|
|
2008-06-15 17:21:02 +00:00
|
|
|
print ' %s started on port(s):' % (ConfigValue.objects.get_configvalue('site_name'),)
|
2008-06-13 19:52:29 +00:00
|
|
|
for port in settings.GAMEPORTS:
|
|
|
|
|
print ' * %s' % (port)
|
|
|
|
|
print '-'*50
|
|
|
|
|
scheduler.start_events()
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
BEGIN SERVER STARTUP METHODS
|
|
|
|
|
"""
|
|
|
|
|
def load_cmd_aliases(self):
|
|
|
|
|
"""
|
|
|
|
|
Load up our command aliases.
|
|
|
|
|
"""
|
|
|
|
|
alias_list = CommandAlias.objects.all()
|
|
|
|
|
for alias in alias_list:
|
|
|
|
|
self.cmd_alias_list[alias.user_input] = alias.equiv_command
|
|
|
|
|
print ' Command Aliases Loaded: %i' % (len(self.cmd_alias_list),)
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def sqlite3_prep(self):
|
|
|
|
|
"""
|
|
|
|
|
Optimize some SQLite stuff at startup since we can't save it to the
|
|
|
|
|
database.
|
|
|
|
|
"""
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
cursor.execute("PRAGMA cache_size=10000")
|
|
|
|
|
cursor.execute("PRAGMA synchronous=OFF")
|
|
|
|
|
cursor.execute("PRAGMA count_changes=OFF")
|
|
|
|
|
cursor.execute("PRAGMA temp_store=2")
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
BEGIN GENERAL METHODS
|
|
|
|
|
"""
|
|
|
|
|
def shutdown(self, message='The server has been shutdown. Please check back soon.'):
|
2008-06-15 20:31:25 +00:00
|
|
|
session_mgr.announce_all(message)
|
2008-06-13 19:52:29 +00:00
|
|
|
session_mgr.disconnect_all_sessions()
|
|
|
|
|
reactor.callLater(0, reactor.stop)
|
|
|
|
|
|
|
|
|
|
def command_list(self):
|
|
|
|
|
"""
|
|
|
|
|
Return a string representing the server's command list.
|
|
|
|
|
"""
|
2008-12-14 20:21:02 +00:00
|
|
|
clist = cmdtable.GLOBAL_CMD_TABLE.ctable.keys()
|
2008-06-13 19:52:29 +00:00
|
|
|
clist.sort()
|
|
|
|
|
return clist
|
|
|
|
|
|
|
|
|
|
def reload(self, session):
|
|
|
|
|
"""
|
|
|
|
|
Reload modules that don't have any variables that can be reset.
|
|
|
|
|
For changes to the scheduler, server, or session_mgr modules, a cold
|
|
|
|
|
restart is needed.
|
|
|
|
|
"""
|
2008-06-15 17:21:02 +00:00
|
|
|
reload_list = []
|
2008-06-13 19:52:29 +00:00
|
|
|
|
|
|
|
|
for mod in reload_list:
|
|
|
|
|
reload(sys.modules[mod])
|
|
|
|
|
|
|
|
|
|
session.msg("Modules reloaded.")
|
2008-06-15 20:31:25 +00:00
|
|
|
logger.log_infomsg("Modules reloaded by %s." % (session,))
|
2008-06-13 19:52:29 +00:00
|
|
|
|
|
|
|
|
def getEvenniaServiceFactory(self):
|
|
|
|
|
f = protocol.ServerFactory()
|
|
|
|
|
f.protocol = SessionProtocol
|
|
|
|
|
f.server = self
|
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
END Server CLASS
|
|
|
|
|
"""
|
2007-05-21 20:52:05 +00:00
|
|
|
|
|
|
|
|
application = service.Application('Evennia')
|
|
|
|
|
mud_service = EvenniaService('Evennia Server')
|
|
|
|
|
|
|
|
|
|
# Sheet sheet, fire ze missiles!
|
|
|
|
|
serviceCollection = service.IServiceCollection(application)
|
2007-07-15 01:16:02 +00:00
|
|
|
for port in settings.GAMEPORTS:
|
2008-06-13 19:52:29 +00:00
|
|
|
internet.TCPServer(port, mud_service.getEvenniaServiceFactory()).setServiceParent(serviceCollection)
|