* Fixed channel history to show in the correct order now.

* Two channels are now created by initial_setup.py for informative emits: MUDConnections and MUDInfo.
* MUDConnections now shows a connection/login/logout log.
* MUDInfo shows general informative messages about the server state. For now IMC emits here when things happen (connection, disconnection, etc.).
Eventually we'll want to restrict these to staff only, but it's not high priority atm.
This commit is contained in:
Greg Taylor 2009-04-29 00:50:44 +00:00
parent 566a02b848
commit 547a5dd139
7 changed files with 86 additions and 23 deletions

View file

@ -6,5 +6,5 @@ class CommChannelAdmin(admin.ModelAdmin):
admin.site.register(CommChannel, CommChannelAdmin) admin.site.register(CommChannel, CommChannelAdmin)
class CommChannelMessageAdmin(admin.ModelAdmin): class CommChannelMessageAdmin(admin.ModelAdmin):
list_display = ('channel', 'message') list_display = ('channel', 'date_sent', 'message')
admin.site.register(CommChannelMessage, CommChannelMessageAdmin) admin.site.register(CommChannelMessage, CommChannelMessageAdmin)

View file

@ -101,7 +101,7 @@ class CommChannelMessage(models.Model):
date_sent = models.DateTimeField(editable=False, auto_now_add=True) date_sent = models.DateTimeField(editable=False, auto_now_add=True)
def __str__(self): def __str__(self):
return "%s: %s" % (self.sender.name, self.message) return "%s: %s" % (self.channel.name, self.message)
class Meta: class Meta:
ordering = ['-date_sent'] ordering = ['-date_sent']

View file

@ -7,6 +7,7 @@ from django.utils import simplejson
from src.channels.models import CommChannel, CommChannelMessage from src.channels.models import CommChannel, CommChannelMessage
from src import session_mgr from src import session_mgr
from src import ansi from src import ansi
from src import logger
def plr_get_cdict(session): def plr_get_cdict(session):
""" """
@ -165,13 +166,25 @@ def msg_chan_hist(target_obj, channel_name):
channel_name: (str) The channel's full name. channel_name: (str) The channel's full name.
""" """
cobj = get_cobj_from_name(channel_name) cobj = get_cobj_from_name(channel_name)
hist_list = CommChannelMessage.objects.filter(channel=cobj).order_by('date_sent')[0:20] hist_list = CommChannelMessage.objects.filter(channel=cobj).order_by('date_sent')
for entry in hist_list:
# Negative indexing is not currently supported with QuerySet objects.
# Figure out what the first CommChannelMessage is to return and grab the
# next 20.
first_msg = hist_list.count() - 20
# Prevent a negative index from being called on.
if first_msg < 0:
first_msg = 0
# Slice and dice, display last 20 messages.
for entry in hist_list[first_msg:]:
delta_days = datetime.datetime.now() - entry.date_sent delta_days = datetime.datetime.now() - entry.date_sent
days_elapsed = delta_days.days days_elapsed = delta_days.days
if days_elapsed > 0: if days_elapsed > 0:
# Message happened more than a day ago, show the date.
time_str = entry.date_sent.strftime("%m.%d / %H:%M") time_str = entry.date_sent.strftime("%m.%d / %H:%M")
else: else:
# Recent message (within last 24 hours), show hour:minute.
time_str = entry.date_sent.strftime("%H:%M") time_str = entry.date_sent.strftime("%H:%M")
target_obj.emit_to("[%s] %s" % (time_str, entry.message)) target_obj.emit_to("[%s] %s" % (time_str, entry.message))
@ -207,22 +220,30 @@ def load_object_channels(pobject):
for session in sessions: for session in sessions:
session.channels_subscribed = simplejson.loads(chan_list) session.channels_subscribed = simplejson.loads(chan_list)
def send_cmessage(channel_name, message): def send_cmessage(channel_name, message, noheader=True):
""" """
Sends a message to all players on the specified channel. Sends a message to all players on the specified channel.
channel_name: (string) The name of the channel. channel_name: (string) The name of the channel.
message: (string) Message to send. message: (string) Message to send.
noheader: (bool) If False, prefix the message with the channel's name.
""" """
try:
channel_obj = get_cobj_from_name(channel_name)
except:
logger.log_errmsg("send_cmessage(): Can't find channel: %s" % (channel_name,))
return
if noheader == False:
message = "%s %s" % (channel_obj.ansi_name, message)
for user in get_cwho_list(channel_name, return_muted=False): for user in get_cwho_list(channel_name, return_muted=False):
user.msg(message) user.msg(message)
try:
chan_message = CommChannelMessage() chan_message = CommChannelMessage()
chan_message.channel = get_cobj_from_name(channel_name) chan_message.channel = channel_obj
chan_message.message = message chan_message.message = message
chan_message.save() chan_message.save()
except:
print "send_cmessage(): Can't find channel: %s" % (channel_name,)
def get_all_channels(): def get_all_channels():
""" """

View file

@ -97,6 +97,13 @@ IMC2_SERVER_PW = None
# This isn't something you should generally change. # This isn't something you should generally change.
IMC2_PROTOCOL_VERSION = '2' IMC2_PROTOCOL_VERSION = '2'
"""
Various comm channels for emitting debug or informative messages.
"""
COMMCHAN_IMC2_INFO = 'MUDInfo'
COMMCHAN_MUD_INFO = 'MUDInfo'
COMMCHAN_MUD_CONNECTIONS = 'MUDConnections'
# Local time zone for this installation. All choices can be found here: # Local time zone for this installation. All choices can be found here:
# http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE # http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
TIME_ZONE = 'America/New_York' TIME_ZONE = 'America/New_York'

View file

@ -19,15 +19,25 @@ from src import comsys
# The active instance of IMC2Protocol. Set at server startup. # The active instance of IMC2Protocol. Set at server startup.
IMC2_PROTOCOL_INSTANCE = None IMC2_PROTOCOL_INSTANCE = None
def cemit_info(message):
"""
Channel emits info to the appropriate info channel. By default, this
is MUDInfo.
"""
comsys.send_cmessage(settings.COMMCHAN_IMC2_INFO, 'IMC: %s' % message,
noheader=False)
class IMC2Protocol(StatefulTelnetProtocol): class IMC2Protocol(StatefulTelnetProtocol):
""" """
Provides the abstraction for the IMC2 protocol. Handles connection, Provides the abstraction for the IMC2 protocol. Handles connection,
authentication, and all necessary packets. authentication, and all necessary packets.
""" """
def __init__(self): def __init__(self):
logger.log_infomsg("IMC2: Client connecting to %s:%s..." % ( message = "Client connecting to %s:%s..." % (
settings.IMC2_SERVER_ADDRESS, settings.IMC2_SERVER_ADDRESS,
settings.IMC2_SERVER_PORT)) settings.IMC2_SERVER_PORT)
logger.log_infomsg('IMC2: %s' % message)
cemit_info(message)
global IMC2_PROTOCOL_INSTANCE global IMC2_PROTOCOL_INSTANCE
IMC2_PROTOCOL_INSTANCE = self IMC2_PROTOCOL_INSTANCE = self
self.is_authenticated = False self.is_authenticated = False
@ -80,7 +90,12 @@ class IMC2Protocol(StatefulTelnetProtocol):
self.network_name = line_split[3] self.network_name = line_split[3]
self.is_authenticated = True self.is_authenticated = True
self.sequence = int(time()) self.sequence = int(time())
logger.log_infomsg("IMC2: Successfully authenticated to the '%s' network." % self.network_name)
# Log to stdout and notify over MUDInfo.
auth_message = "Successfully authenticated to the '%s' network." % self.network_name
logger.log_infomsg('IMC2: %s' % auth_message)
cemit_info(auth_message)
# Ask to see what other MUDs are connected. # Ask to see what other MUDs are connected.
self.send_packet(IMC2PacketKeepAliveRequest()) self.send_packet(IMC2PacketKeepAliveRequest())
# IMC2 protocol states that KeepAliveRequests should be followed # IMC2 protocol states that KeepAliveRequests should be followed
@ -151,7 +166,11 @@ class IMC2ClientFactory(ClientFactory):
protocol = IMC2Protocol protocol = IMC2Protocol
def clientConnectionFailed(self, connector, reason): def clientConnectionFailed(self, connector, reason):
logger.log_errmsg('connection failed: %s' % reason.getErrorMessage()) message = 'Connection failed: %s' % reason.getErrorMessage()
cemit_info(message)
logger.log_errmsg('IMC2: %s' % message)
def clientConnectionLost(self, connector, reason): def clientConnectionLost(self, connector, reason):
logger.log_errmsg('connection lost: %s' % reason.getErrorMessage()) message = 'Connection lost: %s' % reason.getErrorMessage()
cemit_info(message)
logger.log_errmsg('IMC2: %s' % message)

View file

@ -7,6 +7,7 @@ Everything starts at handle_setup()
""" """
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.core import management from django.core import management
from django.conf import settings
from src.objects.models import Object from src.objects.models import Object
from src.config.models import ConfigValue, CommandAlias, ConnectScreen from src.config.models import ConfigValue, CommandAlias, ConnectScreen
from src import comsys, defines_global from src import comsys, defines_global
@ -65,8 +66,10 @@ def create_channels():
chan_pub = comsys.create_channel("Public", god_user_obj, description="Public Discussion") chan_pub = comsys.create_channel("Public", god_user_obj, description="Public Discussion")
chan_pub.is_joined_by_default = True chan_pub.is_joined_by_default = True
chan_pub.save() chan_pub.save()
comsys.create_channel("Errors", god_user_obj, description="Error log") comsys.create_channel(settings.COMMCHAN_MUD_INFO, god_user_obj,
comsys.create_channel("Info", god_user_obj, description="Informative messages") description="Informative messages")
comsys.create_channel(settings.COMMCHAN_MUD_CONNECTIONS, god_user_obj,
description="Connection log")
def create_config_values(): def create_config_values():
""" """

View file

@ -7,6 +7,7 @@ import sys
from datetime import datetime from datetime import datetime
from twisted.conch.telnet import StatefulTelnetProtocol from twisted.conch.telnet import StatefulTelnetProtocol
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings
from src.objects.models import Object from src.objects.models import Object
from src.channels.models import CommChannel from src.channels.models import CommChannel
from src.config.models import ConnectScreen, ConfigValue from src.config.models import ConnectScreen, ConfigValue
@ -28,7 +29,8 @@ class SessionProtocol(StatefulTelnetProtocol):
What to do when we get a connection. What to do when we get a connection.
""" """
self.prep_session() self.prep_session()
logger.log_infomsg('Connection: %s' % (self,)) logger.log_infomsg('New connection: %s' % self)
self.cemit_info('New connection: %s' % self)
session_mgr.add_session(self) session_mgr.add_session(self)
self.game_connect_screen() self.game_connect_screen()
@ -66,7 +68,8 @@ class SessionProtocol(StatefulTelnetProtocol):
""" """
Execute this when a client abruplty loses their connection. Execute this when a client abruplty loses their connection.
""" """
logger.log_infomsg('Disconnect: %s' % (self,)) logger.log_infomsg('Disconnected: %s' % self)
self.cemit_info('Disconnected: %s.' % self)
self.handle_close() self.handle_close()
def lineReceived(self, data): def lineReceived(self, data):
@ -170,7 +173,8 @@ class SessionProtocol(StatefulTelnetProtocol):
self.pobject.scriptlink.at_pre_login(self) self.pobject.scriptlink.at_pre_login(self)
self.pobject.scriptlink.at_post_login(self) self.pobject.scriptlink.at_post_login(self)
logger.log_infomsg("Login: %s" % (self,)) logger.log_infomsg("Loged in: %s" % self)
self.cemit_info('Logged in: %s' % self)
# Update their account's last login time. # Update their account's last login time.
user.last_login = datetime.now() user.last_login = datetime.now()
@ -208,3 +212,12 @@ class SessionProtocol(StatefulTelnetProtocol):
else: else:
symbol = '?' symbol = '?'
return "<%s> %s@%s" % (symbol, self.name, self.address,) return "<%s> %s@%s" % (symbol, self.name, self.address,)
def cemit_info(self, message):
"""
Channel emits info to the appropriate info channel. By default, this
is MUDConnections.
"""
src.comsys.send_cmessage(settings.COMMCHAN_MUD_CONNECTIONS,
'Session: %s' % message,
noheader=False)