Consolidate duplicate channel mode flags tables to one.

This commit is contained in:
Jilles Tjoelker 2007-12-25 01:00:20 +01:00
parent 757f5aa8fc
commit 2a719c44c0
4 changed files with 24 additions and 68 deletions

View File

@ -102,6 +102,12 @@ struct Ban
dlink_node node;
};
struct mode_letter
{
int mode;
char letter;
};
struct ChModeChange
{
char letter;
@ -254,6 +260,8 @@ extern void send_cap_mode_changes(struct Client *client_p, struct Client *source
extern void set_channel_mode(struct Client *client_p, struct Client *source_p,
struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]);
extern const struct mode_letter chmode_flags[];
extern struct ChannelMode chmode_table[256];
extern int add_id(struct Client *source_p, struct Channel *chptr, const char *banid,

View File

@ -584,30 +584,6 @@ check_channel_name_loc(struct Client *source_p, const char *name)
return 1;
}
struct mode_letter
{
int mode;
char letter;
};
static struct mode_letter flags[] = {
{MODE_NOPRIVMSGS, 'n'},
{MODE_TOPICLIMIT, 't'},
{MODE_SECRET, 's'},
{MODE_MODERATED, 'm'},
{MODE_INVITEONLY, 'i'},
{MODE_PRIVATE, 'p'},
{MODE_REGONLY, 'r'},
{MODE_EXLIMIT, 'L'},
{MODE_PERMANENT, 'P'},
{MODE_NOCOLOR, 'c'},
{MODE_FREEINVITE, 'g'},
{MODE_OPMODERATE, 'z'},
{MODE_FREETARGET, 'F'},
{MODE_DISFORWARD, 'Q'},
{0, 0}
};
static void
set_final_mode(struct Mode *mode, struct Mode *oldmode)
{
@ -617,30 +593,30 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
int i;
/* ok, first get a list of modes we need to add */
for(i = 0; flags[i].letter; i++)
for(i = 0; chmode_flags[i].letter; i++)
{
if((mode->mode & flags[i].mode) && !(oldmode->mode & flags[i].mode))
if((mode->mode & chmode_flags[i].mode) && !(oldmode->mode & chmode_flags[i].mode))
{
if(dir != MODE_ADD)
{
*mbuf++ = '+';
dir = MODE_ADD;
}
*mbuf++ = flags[i].letter;
*mbuf++ = chmode_flags[i].letter;
}
}
/* now the ones we need to remove. */
for(i = 0; flags[i].letter; i++)
for(i = 0; chmode_flags[i].letter; i++)
{
if((oldmode->mode & flags[i].mode) && !(mode->mode & flags[i].mode))
if((oldmode->mode & chmode_flags[i].mode) && !(mode->mode & chmode_flags[i].mode))
{
if(dir != MODE_DEL)
{
*mbuf++ = '-';
dir = MODE_DEL;
}
*mbuf++ = flags[i].letter;
*mbuf++ = chmode_flags[i].letter;
}
}

View File

@ -603,30 +603,6 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
return 0;
}
struct mode_letter
{
int mode;
char letter;
};
static struct mode_letter flags[] = {
{MODE_NOPRIVMSGS, 'n'},
{MODE_TOPICLIMIT, 't'},
{MODE_SECRET, 's'},
{MODE_MODERATED, 'm'},
{MODE_INVITEONLY, 'i'},
{MODE_PRIVATE, 'p'},
{MODE_REGONLY, 'r'},
{MODE_EXLIMIT, 'L'},
{MODE_PERMANENT, 'P'},
{MODE_NOCOLOR, 'c'},
{MODE_FREEINVITE, 'g'},
{MODE_OPMODERATE, 'z'},
{MODE_FREETARGET, 'F'},
{MODE_DISFORWARD, 'Q'},
{0, 0}
};
static void
set_final_mode(struct Mode *mode, struct Mode *oldmode)
{
@ -636,30 +612,30 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
int i;
/* ok, first get a list of modes we need to add */
for (i = 0; flags[i].letter; i++)
for (i = 0; chmode_flags[i].letter; i++)
{
if((mode->mode & flags[i].mode) && !(oldmode->mode & flags[i].mode))
if((mode->mode & chmode_flags[i].mode) && !(oldmode->mode & chmode_flags[i].mode))
{
if(dir != MODE_ADD)
{
*mbuf++ = '+';
dir = MODE_ADD;
}
*mbuf++ = flags[i].letter;
*mbuf++ = chmode_flags[i].letter;
}
}
/* now the ones we need to remove. */
for (i = 0; flags[i].letter; i++)
for (i = 0; chmode_flags[i].letter; i++)
{
if((oldmode->mode & flags[i].mode) && !(mode->mode & flags[i].mode))
if((oldmode->mode & chmode_flags[i].mode) && !(mode->mode & chmode_flags[i].mode))
{
if(dir != MODE_DEL)
{
*mbuf++ = '-';
dir = MODE_DEL;
}
*mbuf++ = flags[i].letter;
*mbuf++ = chmode_flags[i].letter;
}
}

View File

@ -1084,11 +1084,7 @@ set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_in
}
}
static const struct mode_letter
{
const unsigned int mode;
const unsigned char letter;
} flags[] =
const struct mode_letter chmode_flags[] =
{
{MODE_INVITEONLY, 'i'},
{MODE_MODERATED, 'm'},
@ -1129,9 +1125,9 @@ channel_modes(struct Channel *chptr, struct Client *client_p)
*mbuf++ = '+';
*pbuf = '\0';
for (i = 0; flags[i].mode; ++i)
if(chptr->mode.mode & flags[i].mode)
*mbuf++ = flags[i].letter;
for (i = 0; chmode_flags[i].mode; ++i)
if(chptr->mode.mode & chmode_flags[i].mode)
*mbuf++ = chmode_flags[i].letter;
if(chptr->mode.limit)
{