diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index c80b65539..a0d726a27 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -148,16 +148,14 @@ class Object(models.Model): attribs = Attribute.objects.filter(object=self) return attribs - def destroy(self, session_list): + def destroy(self): """ Destroys an object, sets it to GOING. Can still be recovered if the user decides to. - - session_list: (list) The server's session_list attribute. """ # See if we need to kick the player off. - session = functions_db.session_from_object(session_list, self) + session = session_mgr.session_from_object(self) if session: session.msg("You have been destroyed, goodbye.") session.handle_close() @@ -165,9 +163,7 @@ class Object(models.Model): # If the object is a player, set the player account object to inactive. # It can still be recovered at this point. if self.is_player(): - print 'PLAYER' uobj = User.objects.get(id=self.id) - print 'VICTIM', uobj uobj.is_active = False uobj.save() @@ -175,11 +171,9 @@ class Object(models.Model): self.type = 5 self.save() - def delete(self, session_list): + def delete(self): """ Deletes an object permanently. Marks it for re-use by a new object. - - session_list: (list) The server's session_list attribute. """ # Delete the associated player object permanently. uobj = User.objects.filter(id=self.id) @@ -445,3 +439,4 @@ class Object(models.Model): return "%s(#%d%s)" % (self.name, self.id, self.flag_string()) import functions_db +import session_mgr diff --git a/evennia/trunk/commands_staff.py b/evennia/trunk/commands_staff.py index 0a347ff26..9d99087bc 100644 --- a/evennia/trunk/commands_staff.py +++ b/evennia/trunk/commands_staff.py @@ -1,10 +1,9 @@ -from apps.objects.models import Object import functions_db import functions_general import commands_general import cmdhandler import session_mgr - +from apps.objects.models import Object """ Staff commands may be a bad description for this file, but it'll do for now. Any command here is prefixed by an '@' sign, usually denoting a builder, staff @@ -60,7 +59,7 @@ def cmd_destroy(cdat): target_obj = results[0] session.msg("You destroy %s." % (target_obj,)) - target_obj.destroy(session_mgr.get_session_list()) + target_obj.destroy() def cmd_name(cdat): """ @@ -375,7 +374,6 @@ def cmd_wall(cdat): Announces a message to all connected players. """ session = cdat['session'] - server = cdat['server'] wallstring = ' '.join(cdat['uinput']['splitted'][1:]) if wallstring == '': @@ -383,7 +381,7 @@ def cmd_wall(cdat): return message = "%s shouts \"%s\"" % (session.get_pobject().get_name(), wallstring) - functions_general.announce_all(server, message) + functions_general.announce_all(message) def cmd_shutdown(cdat): """ diff --git a/evennia/trunk/events.py b/evennia/trunk/events.py index 9a0f107b0..06357ac3c 100644 --- a/evennia/trunk/events.py +++ b/evennia/trunk/events.py @@ -2,10 +2,7 @@ This is the events module, where all of the code for periodic events needs to reside. -ADDING AN EVENT: -* Add an entry to the 'schedule' dictionary. -* Add the proper event_ function here. -* Profit. + """ schedule = { diff --git a/evennia/trunk/functions_general.py b/evennia/trunk/functions_general.py index 622d15c16..ac3e20a63 100644 --- a/evennia/trunk/functions_general.py +++ b/evennia/trunk/functions_general.py @@ -1,3 +1,4 @@ +import session_mgr """ General commonly used functions. """ @@ -62,7 +63,7 @@ def time_format(seconds, style=0): retval = '%s%s%s%s' % (days_str, hours_str, minutes_str, seconds_str,) return retval -def announce_all(server, message, with_ann_prefix=True, with_nl=True): +def announce_all(message, with_ann_prefix=True, with_nl=True): """ Announces something to all connected players. """ @@ -76,5 +77,5 @@ def announce_all(server, message, with_ann_prefix=True, with_nl=True): else: newline = '' - for session in server.get_session_list(): + for session in session_mgr.get_session_list(): session.msg_no_nl('%s %s%s' % (prefix, message,newline,)) diff --git a/evennia/trunk/scheduler.py b/evennia/trunk/scheduler.py index 5e4d472a1..9ef277215 100644 --- a/evennia/trunk/scheduler.py +++ b/evennia/trunk/scheduler.py @@ -1,36 +1,51 @@ import time -import events +""" +A really simple scheduler. We can probably get a lot fancier with this +in the future, but it'll do for now. -class Scheduler: +ADDING AN EVENT: +* Add an entry to the 'schedule' dictionary. +* Add the proper event_ function here. +* Profit. +""" + +schedule = { + 'event_example': 60, + } + +lastrun = {} + +""" +BEGIN EVENTS +""" +def event_example(): """ - A really simple scheduler. We can probably get a lot fancier with this - in the future, but it'll do for now. + This is where the example event would be placed. + """ + pass +""" +END EVENTS +""" - Open up events.py for a schedule of events and their respective functions. +# The timer method to be triggered by the main server loop. +def heartbeat(): """ - def __init__(self, server): - self.server = server + Handle one tic/heartbeat. + """ + tictime = time.time() + for event in schedule: + try: + lastrun[event] + except: + lastrun[event] = time.time() - # The timer method to be triggered by the main server loop. - def heartbeat(self): - """ - Handle one tic/heartbeat. - """ - tictime = time.time() - for event in events.schedule: - try: - events.lastrun[event] - except: - events.lastrun[event] = time.time() - - diff = tictime - events.lastrun[event] - - if diff >= events.schedule[event]: - event_func = getattr(events, event) - - if callable(event_func): - event_func(self.server) - - # We'll get a new reading for time for accuracy. - events.lastrun[event] = time.time() + diff = tictime - lastrun[event] + if diff >= schedule[event]: + event_func = getattr(self, event) + + if callable(event_func): + event_func() + + # We'll get a new reading for time for accuracy. + lastrun[event] = time.time() diff --git a/evennia/trunk/server.py b/evennia/trunk/server.py index 88dff4caf..c682ff3b6 100755 --- a/evennia/trunk/server.py +++ b/evennia/trunk/server.py @@ -3,10 +3,9 @@ from asynchat import async_chat import socket, asyncore, time, sys from django.db import models from django.db import connection -from django.contrib.auth.models import User + from apps.config.models import ConfigValue, CommandAlias -from apps.objects.models import Object, Attribute -from scheduler import Scheduler +import scheduler import functions_db import functions_general import global_defines @@ -17,8 +16,6 @@ class Server(dispatcher): The main server class from which everything branches. """ def __init__(self): - self.session_list = [] - self.object_list = {} self.cmd_alias_list = {} self.configvalue = {} self.game_running = True @@ -101,20 +98,8 @@ class Server(dispatcher): """ return self.configvalue[configname] - def get_session_list(self): - """ - Lists the server's connected session objects. - """ - return session_mgr.get_session_list() - - def remove_session(self, session): - """ - Removes a session from the server's session list. - """ - session_mgr.remove_session(session) - def shutdown(self, message='The server has been shutdown. Please check back soon.'): - functions_general.announce_all(server, message) + functions_general.announce_all(message) self.game_running = False """ END Server CLASS @@ -125,7 +110,6 @@ BEGIN MAIN APPLICATION LOGIC """ if __name__ == '__main__': server = Server() - scheduler = Scheduler(server) try: while server.game_running: