Improve /mode behavior

This fixes /mode using the name of invalid contexts
and also adds some documentation to what is happening.

In the end though it still must guess between modes
and nicks if ran in a valid context.

Fixes #1470
This commit is contained in:
TingPing 2015-09-03 02:28:25 -04:00
parent 9664b1b7e3
commit e7003ef9c6
1 changed files with 15 additions and 6 deletions

View File

@ -2679,17 +2679,26 @@ cmd_me (struct session *sess, char *tbuf, char *word[], char *word_eol[])
static int static int
cmd_mode (struct session *sess, char *tbuf, char *word[], char *word_eol[]) cmd_mode (struct session *sess, char *tbuf, char *word[], char *word_eol[])
{ {
/* +channel channels are dying, let those servers whine about modes. /* We allow omitting the target, so we have to figure it out:
* return info about current channel if available and no info is given */ * - Can only use info from channels or dialogs
if ((*word[2] == '+') || (*word[2] == 0) || (!is_channel(sess->server, word[2]) && * - Empty arg is always sess info
!(rfc_casecmp(sess->server->nick, word[2]) == 0))) * - Assume + is mode not channel
* - We know valid channels and our nick
* - We cannot easily know if other nick or valid mode (Need to store 004)
*/
if ((sess->type != SESS_CHANNEL && sess->type != SESS_DIALOG)
|| (!(*word[2] == '-' || *word[2] == '+' || *word[2] == '\0')
&& (is_channel (sess->server, word[2]) || !rfc_casecmp (sess->server->nick, word[2])))
)
{
sess->server->p_mode (sess->server, word[2], word_eol[3]);
}
else
{ {
if(sess->channel[0] == 0) if(sess->channel[0] == 0)
return FALSE; return FALSE;
sess->server->p_mode (sess->server, sess->channel, word_eol[2]); sess->server->p_mode (sess->server, sess->channel, word_eol[2]);
} }
else
sess->server->p_mode (sess->server, word[2], word_eol[3]);
return TRUE; return TRUE;
} }