Implemented channel communication. You may now addcom/delcom and talk over channels. See @clist for master channel list, and comlist for your personal list. Still tons of work and cleanup to do, but it's in functional in its simplest form.

This commit is contained in:
Greg Taylor 2007-05-16 20:01:54 +00:00
parent 17bbc4c3b3
commit 107bd6d71a
7 changed files with 139 additions and 26 deletions

View file

@ -89,6 +89,14 @@ def handle(cdat):
parsed_input['root_chunk'] = ['pose', 'nospace']
parsed_input['splitted'][1] = parsed_input['splitted'][1][1:]
parsed_input['root_cmd'] = 'pose'
# Channel alias match.
elif session.has_user_channel(parsed_input['root_cmd'], alias_search=True, return_muted=False):
cname = session.channels_subscribed.get(parsed_input['root_cmd'])[0]
cmessage = ' '.join(parsed_input['splitted'][1:])
second_arg = "%s=%s" % (cname, cmessage)
parsed_input['splitted'] = ["@cemit/sendername", second_arg]
parsed_input['root_chunk'] = ['@cemit', 'sendername', 'quiet']
parsed_input['root_cmd'] = '@cemit'
# Get the command's function reference (Or False)
cmd = cmdtable.return_cfunc(parsed_input['root_cmd'])

View file

@ -32,6 +32,7 @@ ctable = {
"who": commands_general.cmd_who,
"@ccreate": commands_comsys.cmd_ccreate,
"@cdestroy": commands_comsys.cmd_cdestroy,
"@cemit": commands_comsys.cmd_cemit,
"@clist": commands_comsys.cmd_clist,
"@create": commands_privileged.cmd_create,
"@description": commands_privileged.cmd_description,

View file

@ -21,6 +21,7 @@ def cmd_addcom(cdat):
addcom foo=Bar
"""
session = cdat['session']
pobject = session.get_pobject()
server = cdat['server']
args = cdat['uinput']['splitted'][1:]
@ -48,8 +49,15 @@ def cmd_addcom(cdat):
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))
chan_name_parsed = name_matches[0].get_name()
session.msg("You join %s, with an alias of %s." % \
(chan_name_parsed, chan_alias))
session.set_user_channel(chan_alias, chan_name_parsed, True)
# Announce the user's joining.
join_msg = "[%s] %s has joined the channel." % \
(chan_name_parsed, pobject.get_name(show_dbref=False))
functions_comsys.send_cmessage(chan_name_parsed, join_msg)
else:
session.msg("Could not find channel %s." % (chan_name,))
@ -57,15 +65,11 @@ def cmd_delcom(cdat):
"""
delcom
Removes the specified alias to a channel. If this is the last alias,
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']
pobject = session.get_pobject()
uinput= cdat['uinput']['splitted']
chan_alias = ' '.join(uinput[1:])
@ -77,9 +81,15 @@ def cmd_delcom(cdat):
session.msg("You are not on that channel.")
return
session.msg("You have left %s." % (session.channels_subscribed[chan_alias][0],))
chan_name = session.channels_subscribed[chan_alias][0]
session.msg("You have left %s." % (chan_name,))
session.del_user_channel(chan_alias)
# Announce the user's leaving.
leave_msg = "[%s] %s has left the channel." % \
(chan_name, pobject.get_name(show_dbref=False))
functions_comsys.send_cmessage(chan_name, leave_msg)
def cmd_comlist(cdat):
"""
Lists the channels a user is subscribed to.
@ -179,11 +189,58 @@ def cmd_cboot(cdat):
def cmd_cemit(cdat):
"""
@cemit
@cemit/noheader <message>
@cemit/sendername <message>
Allows the user to send a message over a channel as long as
they own or control it. It does not show the user's name.
they own or control it. It does not show the user's name unless they
provide the /sendername switch.
"""
pass
session = cdat['session']
pobject = session.get_pobject()
server = cdat['server']
args = cdat['uinput']['splitted'][1:]
switches = cdat['uinput']['root_chunk'][1:]
if len(args) == 0:
session.msg("Channel emit what?")
return
# Combine the arguments into one string, split it by equal signs into
# channel (entry 0 in the list), and message (entry 1 and above).
eq_args = ' '.join(args).split('=')
cname = eq_args[0]
cmessage = ' '.join(eq_args[1:])
if len(eq_args) != 2:
session.msg("You must provide a channel name and a message to emit.")
return
if len(cname) == 0:
session.msg("You must provide a channel name to emit to.")
return
if len(cmessage) == 0:
session.msg("You must provide a message to emit.")
return
name_matches = functions_comsys.cname_search(cname, exact=True)
try:
# Safety first, kids!
cname_parsed = name_matches[0].get_name()
except:
session.msg("Could not find channel %s." % (cname,))
return
if "noheader" in switches:
final_cmessage = cmessage
else:
if "sendername":
final_cmessage = "[%s] %s: %s" % (cname_parsed, pobject.get_name(show_dbref=False), cmessage)
else:
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
if not "quiet" in switches:
session.msg("Sent - %s" % (name_matches[0],))
functions_comsys.send_cmessage(cname_parsed, final_cmessage)
def cmd_cwho(cdat):
"""
@ -202,6 +259,7 @@ 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:])

View file

@ -372,13 +372,13 @@ def cmd_pose(cdat):
Pose/emote command.
"""
session = cdat['session']
pobject = session.get_pobject()
switches = cdat['uinput']['root_chunk'][1:]
if not functions_general.cmd_check_num_args(session, cdat['uinput']['splitted'], 1, errortext="Do what?"):
return
session_list = session_mgr.get_session_list()
pobject = session.get_pobject()
speech = ' '.join(cdat['uinput']['splitted'][1:])
if "nospace" in switches:

View file

@ -9,20 +9,30 @@ import ansi
Comsys functions.
"""
def set_new_title(channel, player, title):
pass
def get_com_who(channel, muted=False, disconnected=False):
def get_cwho_list(channel_name, return_muted=False):
"""
Get all users on a channel.
If muted = True, return users who have it muted as well.
If disconnected = True, return users who are not connected as well.
channel_name: (string) The name of the channel.
return_muted: (bool) Return those who have the channel muted if True.
"""
pass
sess_list = session_mgr.get_session_list()
result_list = []
for sess in sess_list:
if sess.has_user_channel(channel_name, return_muted):
result_list.append(sess)
def get_user_channels(player):
pass
return result_list
def send_cmessage(channel_name, message):
"""
Sends a message to all players on the specified channel.
channel_name: (string) The name of the channel.
message: (string) Message to send.
"""
for user in get_cwho_list(channel_name, return_muted=False):
user.msg(message)
def get_all_channels():
"""

View file

@ -107,12 +107,11 @@ class Server(dispatcher):
For changes to the scheduler, server, or session_mgr modules, a cold
restart is needed.
"""
reload_list = ['ansi', 'cmdhandler', 'commands_general',
reload_list = ['ansi', 'cmdhandler', 'commands_comsys', 'commands_general',
'commands_privileged', 'commands_unloggedin', 'defines_global',
'events', 'functions_db', 'functions_general', 'functions_help',
'gameconf', 'session', 'apps.objects.models',
'apps.helpsys.models', 'apps.config.models', 'functions_comsys',
'commands_comsys']
'events', 'functions_db', 'functions_general', 'functions_comsys',
'functions_help', 'gameconf', 'session', 'apps.objects.models',
'apps.helpsys.models', 'apps.config.models']
for mod in reload_list:
reload(sys.modules[mod])

View file

@ -34,6 +34,43 @@ class PlayerSession(async_chat):
self.conn_time = time.time()
self.channels_subscribed = {}
def has_user_channel(self, cname, alias_search=False, return_muted=False):
"""
Is this session subscribed to the named channel?
return_muted: (bool) Take the user's enabling/disabling of the channel
into consideration?
"""
has_channel = False
if alias_search:
# Search by aliases only.
cdat = self.channels_subscribed.get(cname, False)
# No key match, fail immediately.
if not cdat:
return False
# If channel status is taken into consideration, see if the user
# has the channel muted or not.
if return_muted:
return cdat[1]
else:
return True
else:
# Search by complete channel name.
chan_list = self.channels_subscribed.values()
for chan in chan_list:
# Check for a name match
if cname == chan[0]:
has_channel = True
# If channel status is taken into consideration, see if the user
# has the channel muted or not.
if return_muted is False and not chan[1]:
has_channel = False
break
return has_channel
def set_user_channel(self, alias, cname, listening):
"""
Add a channel to a session's channel list.