Addition of a few common commands.

This commit is contained in:
Greg Taylor 2006-12-05 22:06:50 +00:00
parent 534f008e08
commit 9f558f3b24
5 changed files with 70 additions and 24 deletions

View file

@ -79,7 +79,7 @@ def do_who(cdat):
"""
Generic WHO command.
"""
session_list = cdat['server'].session_list
session_list = cdat['server'].get_session_list()
session = cdat['session']
retval = "Player Name On For Idle Room Cmds Host\n\r"
@ -109,7 +109,7 @@ def do_say(cdat):
"""
Room-based speech command.
"""
session_list = cdat['server'].session_list
session_list = cdat['server'].get_session_list()
session = cdat['session']
speech = ''.join(cdat['uinput']['splitted'][1:])
players_present = [player for player in session_list if player.pobject.location == session.pobject.location and player != session]
@ -129,3 +129,21 @@ def do_version(cdat):
retval += "Evennia %s\n\r" % (settings.EVENNIA_VERSION,)
retval += "-"*50
session.msg(retval)
def do_time(cdat):
"""
Server local time.
"""
session = cdat['session']
session.msg('Current server time : %s' % (time.strftime('%a %b %d %H:%M %Y (%Z)', time.localtime(),)))
def do_uptime(cdat):
"""
Server uptime and stats.
"""
session = cdat['session']
server = cdat['server']
start_delta = time.time() - server.start_time
session.msg('Current server time : %s' % (time.strftime('%a %b %d %H:%M %Y (%Z)', time.localtime(),)))
session.msg('Server start time : %s' % (time.strftime('%a %b %d %H:%M %Y', time.localtime(server.start_time),)))
session.msg('Server uptime : %s' % functions_general.time_format(start_delta, style=2))

View file

@ -132,3 +132,14 @@ def do_find(cdat):
session.msg("%d matches returned." % (len(results),))
else:
session.msg("No name matches found for: %s" % (searchstring,))
def do_shutdown(cdat):
"""
Shut the server down gracefully.
"""
session = cdat['session']
server = cdat['server']
session.msg('Shutting down...')
print 'Server shutdown by %s(#%d)' % (session.name, session.pobject.id,)
server.shutdown()

View file

@ -61,3 +61,20 @@ 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):
"""
Announces something to all connected players.
"""
if with_ann_prefix:
prefix = 'Announcement:'
else:
prefix = ''
if with_nl:
newline = '\r\n'
else:
newline = ''
for session in server.get_session_list():
session.msg_no_nl('%s %s%s' % (prefix, message,newline,))

View file

@ -6,9 +6,10 @@ from django.db import models
from apps.config.models import ConfigValue, CommandAlias
from apps.objects.models import Object, Attribute
from django.contrib.auth.models import User
import functions_db
from scheduler import Scheduler
import functions_db
import functions_general
class Server(dispatcher):
"""
The main server class from which everything branches.
@ -34,6 +35,7 @@ class Server(dispatcher):
self.set_reuse_addr()
self.bind(('', int(self.configvalue['site_port'])))
self.listen(100)
self.start_time = time.time()
print ' %s started on port %s.' % (self.configvalue['site_name'], self.configvalue['site_port'],)
print '-'*50
@ -117,30 +119,28 @@ class Server(dispatcher):
Adds an object to the cached object list.
"""
self.object_list[object.id] = object
def announce_all(self, message, with_ann_prefix=True, with_nl=True):
"""
Announces something to all connected players.
"""
if with_ann_prefix:
prefix = 'Announcement:'
else:
prefix = ''
if with_nl:
newline = '\r\n'
else:
newline = ''
for session in self.session_list:
session.push('%s %s%s' % (prefix, message,newline,))
def get_configvalue(self, configname):
"""
Retrieve a configuration value.
"""
return self.configvalue[configname]
def get_session_list(self):
"""
Lists the server's connected session objects.
"""
return self.session_list
def remove_session(self, session):
"""
Removes a session from the server's session list.
"""
self.session_list.remove(session)
def shutdown(self):
functions_general.announce_all(server, 'The server has been shutdown. Please check back soon.')
self.game_running = False
"""
END Server CLASS
"""
@ -158,5 +158,5 @@ if __name__ == '__main__':
scheduler.heartbeat()
except KeyboardInterrupt:
server.announce_all('The server has been shutdown. Please check back soon.')
functions_general.announce_all(server, 'The server has been shutdown. Please check back soon.')
print '--> Server killed by keystroke.'

View file

@ -59,7 +59,7 @@ class PlayerSession(async_chat):
"""
async_chat.handle_close(self)
self.logged_in = False
self.server.session_list.remove(self)
self.server.remove_session(self)
print 'Sessions active:', len(self.server.session_list)
def game_connect_screen(self, session):