Make Send_ListChange() a little bit more generic
This commit is contained in:
parent
7ed08f01ef
commit
1afbf71236
|
@ -36,18 +36,19 @@
|
||||||
#include "irc-mode.h"
|
#include "irc-mode.h"
|
||||||
|
|
||||||
|
|
||||||
static bool Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin,
|
static bool Client_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
|
||||||
CLIENT *Target ));
|
CLIENT *Target));
|
||||||
static bool Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin,
|
static bool Channel_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
|
||||||
CHANNEL *Channel ));
|
CHANNEL *Channel));
|
||||||
|
|
||||||
static bool Add_Ban_Invite PARAMS((int what, CLIENT *Prefix, CLIENT *Client,
|
static bool Add_Ban_Invite PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
|
||||||
CHANNEL *Channel, const char *Pattern));
|
CHANNEL *Channel, const char *Pattern));
|
||||||
static bool Del_Ban_Invite PARAMS((int what, CLIENT *Prefix, CLIENT *Client,
|
static bool Del_Ban_Invite PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
|
||||||
CHANNEL *Channel, const char *Pattern));
|
CHANNEL *Channel, const char *Pattern));
|
||||||
|
|
||||||
static bool Send_ListChange PARAMS((const char *Mode, CLIENT *Prefix,
|
static bool Send_ListChange PARAMS((const bool IsAdd, const char ModeChar,
|
||||||
CLIENT *Client, CHANNEL *Channel, const char *Mask));
|
CLIENT *Prefix, CLIENT *Client,
|
||||||
|
CHANNEL *Channel, const char *Mask));
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -842,10 +843,11 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
|
||||||
* @return CONNECTED or DISCONNECTED.
|
* @return CONNECTED or DISCONNECTED.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
Add_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
|
Add_Ban_Invite(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
|
||||||
const char *Pattern)
|
const char *Pattern)
|
||||||
{
|
{
|
||||||
const char *mask;
|
const char *mask;
|
||||||
|
struct list_head *list;
|
||||||
|
|
||||||
assert(Client != NULL);
|
assert(Client != NULL);
|
||||||
assert(Channel != NULL);
|
assert(Channel != NULL);
|
||||||
|
@ -854,19 +856,22 @@ Add_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
|
||||||
|
|
||||||
mask = Lists_MakeMask(Pattern);
|
mask = Lists_MakeMask(Pattern);
|
||||||
|
|
||||||
|
if (what == 'I')
|
||||||
|
list = Channel_GetListInvites(Channel);
|
||||||
|
else
|
||||||
|
list = Channel_GetListBans(Channel);
|
||||||
|
|
||||||
|
if (Lists_CheckDupeMask(list, mask))
|
||||||
|
return CONNECTED;
|
||||||
|
|
||||||
if (what == 'I') {
|
if (what == 'I') {
|
||||||
if (Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask))
|
|
||||||
return CONNECTED;
|
|
||||||
if (!Channel_AddInvite(Channel, mask, false))
|
if (!Channel_AddInvite(Channel, mask, false))
|
||||||
return CONNECTED;
|
return CONNECTED;
|
||||||
return Send_ListChange("+I", Prefix, Client, Channel, mask);
|
|
||||||
} else {
|
} else {
|
||||||
if (Lists_CheckDupeMask(Channel_GetListBans(Channel), mask))
|
|
||||||
return CONNECTED;
|
|
||||||
if (!Channel_AddBan(Channel, mask))
|
if (!Channel_AddBan(Channel, mask))
|
||||||
return CONNECTED;
|
return CONNECTED;
|
||||||
return Send_ListChange("+b", Prefix, Client, Channel, mask);
|
|
||||||
}
|
}
|
||||||
|
return Send_ListChange(true, what, Prefix, Client, Channel, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -881,10 +886,11 @@ Add_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
|
||||||
* @return CONNECTED or DISCONNECTED.
|
* @return CONNECTED or DISCONNECTED.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
Del_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
|
Del_Ban_Invite(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
|
||||||
const char *Pattern)
|
const char *Pattern)
|
||||||
{
|
{
|
||||||
const char *mask;
|
const char *mask;
|
||||||
|
struct list_head *list;
|
||||||
|
|
||||||
assert(Client != NULL);
|
assert(Client != NULL);
|
||||||
assert(Channel != NULL);
|
assert(Channel != NULL);
|
||||||
|
@ -893,40 +899,53 @@ Del_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
|
||||||
|
|
||||||
mask = Lists_MakeMask(Pattern);
|
mask = Lists_MakeMask(Pattern);
|
||||||
|
|
||||||
if (what == 'I') {
|
if (what == 'I')
|
||||||
if (!Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask))
|
list = Channel_GetListInvites(Channel);
|
||||||
return CONNECTED;
|
else
|
||||||
Lists_Del(Channel_GetListInvites(Channel), mask);
|
list = Channel_GetListBans(Channel);
|
||||||
return Send_ListChange( "-I", Prefix, Client, Channel, mask );
|
|
||||||
} else {
|
|
||||||
if (!Lists_CheckDupeMask(Channel_GetListBans(Channel), mask))
|
|
||||||
return CONNECTED;
|
|
||||||
Lists_Del(Channel_GetListBans(Channel), mask);
|
|
||||||
return Send_ListChange( "-b", Prefix, Client, Channel, mask );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!Lists_CheckDupeMask(list, mask))
|
||||||
|
return CONNECTED;
|
||||||
|
Lists_Del(list, mask);
|
||||||
|
|
||||||
|
return Send_ListChange(false, what, Prefix, Client, Channel, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send information about changed channel ban/invite lists to clients.
|
||||||
|
*
|
||||||
|
* @param IsAdd true if the list item has been added, false otherwise.
|
||||||
|
* @param ModeChar The mode to use (e. g. 'b' or 'I')
|
||||||
|
* @param Prefix The originator of the mode list change.
|
||||||
|
* @param Client The sender of the command.
|
||||||
|
* @param Channel The channel of which the list has been modified.
|
||||||
|
* @param Mask The mask which has been added or removed.
|
||||||
|
* @return CONNECTED or DISCONNECTED.
|
||||||
|
*/
|
||||||
static bool
|
static bool
|
||||||
Send_ListChange(const char *Mode, CLIENT *Prefix, CLIENT *Client,
|
Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
|
||||||
CHANNEL *Channel, const char *Mask)
|
CLIENT *Client, CHANNEL *Channel, const char *Mask)
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok = true;
|
||||||
|
|
||||||
if( Client_Type( Client ) == CLIENT_USER )
|
/* Send confirmation to the client */
|
||||||
{
|
if (Client_Type(Client) == CLIENT_USER)
|
||||||
/* send confirmation to client */
|
ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
|
||||||
ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
|
Channel_Name(Channel),
|
||||||
}
|
IsAdd ? '+' : '-',
|
||||||
else ok = true;
|
ModeChar, Mask);
|
||||||
|
|
||||||
/* to other servers */
|
/* to other servers */
|
||||||
IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
|
IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
|
||||||
|
Channel_Name(Channel), IsAdd ? '+' : '-',
|
||||||
|
ModeChar, Mask);
|
||||||
|
|
||||||
/* and local users in channel */
|
/* and local users in channel */
|
||||||
IRC_WriteStrChannelPrefix( Client, Channel, Prefix, false, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
|
IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
|
||||||
|
"MODE %s %c%c %s", Channel_Name(Channel),
|
||||||
|
IsAdd ? '+' : '-', ModeChar, Mask );
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
} /* Send_ListChange */
|
} /* Send_ListChange */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue