Finished up addcom/delcom. Added comlist. Fixed @list commands (still needs to sort by command name eventually).
This commit is contained in:
parent
e1f4c2e0da
commit
c7452e5a88
7 changed files with 115 additions and 54 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,82 @@ 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):
|
||||
"""
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import session_mgr
|
|||
import commands_privileged
|
||||
import commands_general
|
||||
import commands_unloggedin
|
||||
|
||||
"""
|
||||
General commonly used functions.
|
||||
"""
|
||||
|
|
@ -32,21 +33,6 @@ def log_infomsg(infomsg):
|
|||
"""
|
||||
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):
|
||||
"""
|
||||
Function to return a 'prettified' version of a value in seconds.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
23
session.py
23
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,6 +32,27 @@ 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):
|
||||
"""
|
||||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue