From c7452e5a881edfa185822d21936537dbdc9b0ce7 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Tue, 15 May 2007 17:28:23 +0000 Subject: [PATCH] Finished up addcom/delcom. Added comlist. Fixed @list commands (still needs to sort by command name eventually). --- cmdtable.py | 3 ++ commands_comsys.py | 111 ++++++++++++++++++++++++++++------------- commands_privileged.py | 3 +- defines_global.py | 2 +- functions_general.py | 18 +------ server.py | 7 +++ session.py | 25 +++++++++- 7 files changed, 115 insertions(+), 54 deletions(-) diff --git a/cmdtable.py b/cmdtable.py index 042800686..41f319a1e 100644 --- a/cmdtable.py +++ b/cmdtable.py @@ -12,6 +12,9 @@ uncon_ctable = { # Command Table ctable = { + "addcom": commands_comsys.cmd_addcom, + "comlist": commands_comsys.cmd_comlist, + "delcom": commands_comsys.cmd_delcom, "drop": commands_general.cmd_drop, "examine": commands_general.cmd_examine, "get": commands_general.cmd_get, diff --git a/commands_comsys.py b/commands_comsys.py index e6f880df3..f3e8d333d 100644 --- a/commands_comsys.py +++ b/commands_comsys.py @@ -20,8 +20,83 @@ def cmd_addcom(cdat): Adds an alias for a channel. addcom foo=Bar """ - pass + session = cdat['session'] + server = cdat['server'] + args = cdat['uinput']['splitted'][1:] + + if len(args) == 0: + session.msg("You need to specify a channel alias and name.") + return + + eq_args = args[0].split('=') + if len(eq_args) < 2: + session.msg("You need to specify a channel name.") + return + + chan_alias = eq_args[0] + chan_name = eq_args[1] + + if len(chan_name) == 0: + session.msg("You need to specify a channel name.") + return + + if chan_alias in session.channels_subscribed: + session.msg("You are already on that channel.") + return + + name_matches = functions_comsys.cname_search(chan_name, exact=True) + + if name_matches: + session.set_user_channel(chan_alias, chan_name, True) + session.msg("You join %s, with an alias of %s." % (name_matches[0], chan_alias)) + else: + session.msg("Could not find channel %s." % (chan_name,)) + +def cmd_delcom(cdat): + """ + delcom + + Removes the specified alias to a channel. If this is the last alias, + the user is effectively removed from the channel. + """ + """ + @cdestroy + + Destroys a channel. + """ + session = cdat['session'] + uinput= cdat['uinput']['splitted'] + chan_alias = ' '.join(uinput[1:]) + + if len(chan_alias) == 0: + session.msg("You must specify a channel alias.") + return + + if chan_alias not in session.channels_subscribed: + session.msg("You are not on that channel.") + return + + session.msg("You have left %s." % (session.channels_subscribed[chan_alias][0],)) + session.del_user_channel(chan_alias) + +def cmd_comlist(cdat): + """ + Lists the channels a user is subscribed to. + """ + session = cdat['session'] + + session.msg("Alias Channel Status") + for chan in session.channels_subscribed: + if session.channels_subscribed[chan][1]: + chan_on = "On" + else: + chan_on = "Off" + + session.msg("%-9.9s %-19.19s %s" % + (chan, session.channels_subscribed[chan][0], chan_on)) + session.msg("-- End of comlist --") + def cmd_allcom(cdat): """ allcom @@ -31,14 +106,6 @@ def cmd_allcom(cdat): """ pass -def cmd_comtitle(cdat): - """ - comtitle - - Sets a prefix to the user's name on the specified channel. - """ - pass - def cmd_clearcom(cdat): """ clearcom @@ -68,7 +135,6 @@ def cmd_cdestroy(cdat): Destroys a channel. """ session = cdat['session'] - pobject = session.get_pobject() uinput= cdat['uinput']['splitted'] cname = ' '.join(uinput[1:]) @@ -93,21 +159,6 @@ def cmd_cset(cdat): """ pass -def cmd_cpflags(cdat): - """ - @cpflags - - Sets various flags on a channel relating to players. - """ - pass - -def cmd_coflags(cdat): - """ - @coflags - - Sets various flags on a channel relating to objects. - """ - pass def cmd_ccharge(cdat): """ @@ -151,7 +202,6 @@ def cmd_ccreate(cdat): Creates a new channel with the invoker being the default owner. """ session = cdat['session'] - pobject = session.get_pobject() uinput= cdat['uinput']['splitted'] cname = ' '.join(uinput[1:]) @@ -176,12 +226,3 @@ def cmd_cchown(cdat): Changes the owner of a channel. """ pass - -def cmd_delcom(cdat): - """ - delcom - - Removes the specified alias to a channel. If this is the last alias, - the user is effectively removed from the channel. - """ - pass diff --git a/commands_privileged.py b/commands_privileged.py index 4a0cab743..fed31faad 100644 --- a/commands_privileged.py +++ b/commands_privileged.py @@ -6,6 +6,7 @@ import functions_general import commands_general import commands_unloggedin import cmdhandler + import session_mgr import ansi import defines_global @@ -88,7 +89,7 @@ def cmd_list(cdat): if len(argstr) == 0: session.msg(msg_invalid) elif argstr == "commands": - session.msg('Commands: '+' '.join(functions_general.command_list())) + session.msg('Commands: '+ ' '.join(session.server.command_list())) elif argstr == "process": loadvg = os.getloadavg() psize = resource.getpagesize() diff --git a/defines_global.py b/defines_global.py index 88e4bb9c2..70c6e9dc8 100755 --- a/defines_global.py +++ b/defines_global.py @@ -30,7 +30,7 @@ NOSAVE_FLAGS = ["CONNECTED"] NOSET_FLAGS = ["CONNECTED"] # These attribute names can't be modified by players. -NOSET_ATTRIBS = ["MONEY", "ALIAS", "LASTPAGED"] +NOSET_ATTRIBS = ["MONEY", "ALIAS", "LASTPAGED", "CHANLIST"] # Server version number. EVENNIA_VERSION = 'Pre-Alpha' diff --git a/functions_general.py b/functions_general.py index 8cb391d79..e67783cba 100644 --- a/functions_general.py +++ b/functions_general.py @@ -2,6 +2,7 @@ import session_mgr import commands_privileged import commands_general import commands_unloggedin + """ General commonly used functions. """ @@ -31,21 +32,6 @@ def log_infomsg(infomsg): debugmsg: (string) The message to be logged. """ print '%s' % (infomsg,) - -def command_list(): - """ - Return a list of all commands. - """ - commands = dir(commands_unloggedin) + dir(commands_general) - stf_commands = dir(commands_privileged) - filtered = [prospect for prospect in commands if "cmd_" in prospect] - stf_filtered = [prospect for prospect in stf_commands if "cmd_" in prospect] - processed = [] - for cmd in filtered: - processed.append(cmd[4:]) - for cmd in stf_filtered: - processed.append('@%s' %(cmd[4:],)) - return processed def time_format(seconds, style=0): """ @@ -139,4 +125,4 @@ def word_wrap(text, width=78): ) >= width)], word), text.split(' ') - ) + ) \ No newline at end of file diff --git a/server.py b/server.py index b338b8b6d..08258ec69 100755 --- a/server.py +++ b/server.py @@ -12,6 +12,7 @@ import functions_general import session_mgr import gameconf import settings +import cmdtable import initial_setup class Server(dispatcher): @@ -92,6 +93,12 @@ class Server(dispatcher): self.game_running = False + def command_list(self): + """ + Return a string representing the server's command list. + """ + return cmdtable.ctable.keys() + def reload(self, session): """ Reload modules that don't have any variables that can be reset. diff --git a/session.py b/session.py index fb20008bd..a9adb554d 100755 --- a/session.py +++ b/session.py @@ -1,6 +1,7 @@ from asyncore import dispatcher from asynchat import async_chat import socket, asyncore, time, sys +import pickle import cmdhandler from apps.objects.models import Object from django.contrib.auth.models import User @@ -31,7 +32,28 @@ class PlayerSession(async_chat): self.cmd_total = 0 # The time when the user connected. self.conn_time = time.time() - + self.channels_subscribed = {} + + def set_user_channel(self, alias, cname, listening): + """ + Add a channel to a session's channel list. + """ + self.channels_subscribed[alias] = [cname, listening] + self.get_pobject().set_attribute("CHANLIST", pickle.dumps(self.channels_subscribed)) + + def del_user_channel(self, alias): + """ + Remove a channel from a session's channel list. + """ + del self.channels_subscribed[alias] + + def load_user_channels(self): + """ + Un-pickle a user's channel list from their CHANLIST attribute. + """ + chan_list = self.get_pobject().get_attribute_value("CHANLIST") + self.channels_subscribed = pickle.loads(chan_list) + def collect_incoming_data(self, data): """ Stuff any incoming data into our buffer, self.data @@ -103,6 +125,7 @@ class PlayerSession(async_chat): cdat = {"session": self, "uinput":'look', "server": self.server} cmdhandler.handle(cdat) print "Login: %s" % (self,) + self.load_user_channels() def msg(self, message): """