1
0
mirror of https://github.com/anope/anope.git synced 2026-07-02 09:06:38 +02:00

Cleaned up a lot of the channel access reordering code, properly change users with less than voice access on channels to XOP, and fix a potential crashbug after switching to XOP on IRCds that do not support halfop

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/stable@2667 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
Adam-
2009-11-25 04:52:49 +00:00
parent fdcc5b5ee1
commit e2c6825cd2
6 changed files with 61 additions and 146 deletions
+1
View File
@@ -224,6 +224,7 @@ E int levelinfo_maxwidth;
E ChannelInfo *makechan(const char *chan);
E int is_identified(User * user, ChannelInfo * ci);
E char *get_mlock_modes(ChannelInfo * ci, int complete);
E void CleanAccess(ChannelInfo *ci);
/**** compat.c ****/
+45
View File
@@ -2747,3 +2747,48 @@ void stick_all(ChannelInfo * ci)
free(av[0]);
}
}
/** Reorder the access list to get rid of unused entries
* @param ci The channel to reorder the access of
*/
void CleanAccess(ChannelInfo *ci)
{
int a, b;
if (!ci)
return;
for (b = 0; b < ci->accesscount; b++)
{
if (ci->access[b].in_use)
{
for (a = 0; a < ci->accesscount; a++)
{
if (a > b)
break;
if (!ci->access[a].in_use)
{
ci->access[a].in_use = 1;
ci->access[a].level = ci->access[b].level;
ci->access[a].nc = ci->access[b].nc;
ci->access[a].last_seen = ci->access[b].last_seen;
ci->access[b].nc = NULL;
ci->access[b].in_use = 0;
break;
}
}
}
}
/* After reordering, entries on the end of the list may be empty, remove them */
for (b = ci->accesscount - 1; b >= 0; --b)
{
if (ci->access[b].in_use)
break;
ci->accesscount--;
}
/* Reallocate the access list to only use the memory we need */
ci->access = srealloc(ci->access, sizeof(ChanAccess) * ci->accesscount);
}
+7 -79
View File
@@ -236,14 +236,6 @@ int do_access(User * u)
}
}
/* All entries should be in use so we no longer need
* to go over the entire list..
for (i = 0; i < ci->accesscount; i++) {
if (!ci->access[i].in_use)
break;
}
*/
if (i < CSAccessMax) {
ci->accesscount++;
ci->access =
@@ -268,8 +260,9 @@ int do_access(User * u)
notice_lang(s_ChanServ, u, CHAN_ACCESS_ADDED, nc->display,
ci->name, access->level);
} else if (stricmp(cmd, "DEL") == 0) {
int deleted, a, b;
if (readonly) {
int deleted;
if (readonly) {
notice_lang(s_ChanServ, u, CHAN_ACCESS_DISABLED);
return MOD_CONT;
}
@@ -279,24 +272,8 @@ int do_access(User * u)
return MOD_CONT;
}
for (b = 0; b < ci->accesscount; b++) {
if (ci->access[b].in_use) {
for (a = 0; a < ci->accesscount; a++) {
if (a > b)
break;
if (!ci->access[a].in_use) {
ci->access[a].in_use = 1;
ci->access[a].level = ci->access[b].level;
ci->access[a].nc = ci->access[b].nc;
ci->access[a].last_seen =
ci->access[b].last_seen;
ci->access[b].nc = NULL;
ci->access[b].in_use = 0;
break;
}
}
}
}
/* Clean the access list to make sure every thing is in use */
CleanAccess(ci);
/* Special case: is it a number/list? Only do search if it isn't. */
if (isdigit(*nick) && strspn(nick, "1234567890,-") == strlen(nick)) {
@@ -354,37 +331,7 @@ int do_access(User * u)
}
}
if (deleted) {
/* Reordering - DrStein */
for (b = 0; b < ci->accesscount; b++) {
if (ci->access[b].in_use) {
for (a = 0; a < ci->accesscount; a++) {
if (a > b)
break;
if (!ci->access[a].in_use) {
ci->access[a].in_use = 1;
ci->access[a].level = ci->access[b].level;
ci->access[a].nc = ci->access[b].nc;
ci->access[a].last_seen =
ci->access[b].last_seen;
ci->access[b].nc = NULL;
ci->access[b].in_use = 0;
break;
}
}
}
}
/* After reordering only the entries at the end could still be empty.
* We ll free the places no longer in use... */
for (i = ci->accesscount - 1; i >= 0; i--) {
if (ci->access[i].in_use == 1)
break;
ci->accesscount--;
}
ci->access =
srealloc(ci->access,sizeof(ChanAccess) * ci->accesscount);
CleanAccess(ci);
/* We don't know the nick if someone used numbers, so we trigger the event without
* nick param. We just do this once, even if someone enters a range. -Certus */
@@ -392,34 +339,15 @@ int do_access(User * u)
send_event(EVENT_ACCESS_DEL, 3, ci->name, u->nick, na->nick);
else
send_event(EVENT_ACCESS_DEL, 2, ci->name, u->nick);
}
} else if (stricmp(cmd, "LIST") == 0) {
int sent_header = 0;
int a, b;
if (ci->accesscount == 0) {
notice_lang(s_ChanServ, u, CHAN_ACCESS_LIST_EMPTY, chan);
return MOD_CONT;
}
for (b = 0; b < ci->accesscount; b++) {
if (ci->access[b].in_use) {
for (a = 0; a < ci->accesscount; a++) {
if (a > b)
break;
if (!ci->access[a].in_use) {
ci->access[a].in_use = 1;
ci->access[a].level = ci->access[b].level;
ci->access[a].nc = ci->access[b].nc;
ci->access[a].last_seen =
ci->access[b].last_seen;
ci->access[b].nc = NULL;
ci->access[b].in_use = 0;
break;
}
}
}
}
CleanAccess(ci);
if (nick && strspn(nick, "1234567890,-") == strlen(nick)) {
process_numlist(nick, NULL, access_list_callback, u, ci,
+3 -4
View File
@@ -765,17 +765,16 @@ int do_set_xop(User * u, ChannelInfo * ci, char *param)
} else if (CHECKLEV(CA_AUTOOP) || CHECKLEV(CA_OPDEOP)
|| CHECKLEV(CA_OPDEOPME)) {
access->level = ACCESS_AOP;
} else if (ircd->halfop) {
if (CHECKLEV(CA_AUTOHALFOP) || CHECKLEV(CA_HALFOP)
|| CHECKLEV(CA_HALFOPME)) {
} else if (ircd->halfop && (CHECKLEV(CA_AUTOHALFOP) || CHECKLEV(CA_HALFOP)
|| CHECKLEV(CA_HALFOPME))) {
access->level = ACCESS_HOP;
}
} else if (CHECKLEV(CA_AUTOVOICE) || CHECKLEV(CA_VOICE)
|| CHECKLEV(CA_VOICEME)) {
access->level = ACCESS_VOP;
} else {
access->in_use = 0;
access->nc = NULL;
CleanAccess(ci);
}
}
+3 -62
View File
@@ -303,13 +303,6 @@ int do_xop(User * u, char *xname, int xlev, int *xmsgs)
}
if (!change) {
/* All entries should be in use so we no longer need
* to go over the entire list..
for (i = 0; i < ci->accesscount; i++)
if (!ci->access[i].in_use)
break;
*/
if (i < CSAccessMax) {
ci->accesscount++;
ci->access =
@@ -415,40 +408,8 @@ int do_xop(User * u, char *xname, int xlev, int *xmsgs)
deleted = 1;
}
}
if (deleted) {
/* Reordering - DrStein */
for (b = 0; b < ci->accesscount; b++) {
if (ci->access[b].in_use) {
for (a = 0; a < ci->accesscount; a++) {
if (a > b)
break;
if (!ci->access[a].in_use) {
ci->access[a].in_use = 1;
ci->access[a].level = ci->access[b].level;
ci->access[a].nc = ci->access[b].nc;
ci->access[a].last_seen =
ci->access[b].last_seen;
ci->access[b].nc = NULL;
ci->access[b].in_use = 0;
break;
}
}
}
}
/* If the patch provided in bug #706 is applied, this should be placed
* before sending the events! */
/* After reordering only the entries at the end could still be empty.
* We ll free the places no longer in use... */
for (i = ci->accesscount - 1; i >= 0; i--) {
if (ci->access[i].in_use == 1)
break;
ci->accesscount--;
}
ci->access =
srealloc(ci->access,sizeof(ChanAccess) * ci->accesscount);
}
if (deleted)
CleanAccess(ci);
} else if (stricmp(cmd, "LIST") == 0) {
int sent_header = 0;
@@ -500,30 +461,10 @@ int do_xop(User * u, char *xname, int xlev, int *xmsgs)
if (ci->access[i].in_use && ci->access[i].level == xlev) {
ci->access[i].nc = NULL;
ci->access[i].in_use = 0;
j++;
}
}
for (b = 0; b < ci->accesscount; b++) {
if (ci->access[b].in_use) {
for (a = 0; a < ci->accesscount; a++) {
if (a > b)
break;
if (!ci->access[a].in_use) {
ci->access[a].in_use = 1;
ci->access[a].level = ci->access[b].level;
ci->access[a].nc = ci->access[b].nc;
ci->access[a].last_seen =
ci->access[b].last_seen;
ci->access[b].nc = NULL;
ci->access[b].in_use = 0;
break;
}
}
}
}
ci->accesscount = ci->accesscount - j;
CleanAccess(ci);
send_event(EVENT_ACCESS_CLEAR, 2, ci->name, u->nick);
+2 -1
View File
@@ -9,9 +9,10 @@ VERSION_MAJOR="1"
VERSION_MINOR="8"
VERSION_PATCH="2"
VERSION_EXTRA="-svn"
VERSION_BUILD="2601"
VERSION_BUILD="2667"
# $Log$ # Changes since 1.8.2 Release
#Revision 2667 - Cleaned up a lot of the channel access reordering code, properly change users with less than voice access on channels to XOP, and fix a potential crashbug after switching to XOP on IRCds that do not support halfop
#Revision 2601 - All usermodes are now recognized and properly set internally on Insp 1.2.
#Revision 2598 - More dynamic detection of channel modes on InspIRCd 1.2. Also fixes params being linked to the wrong mode.
#Revision 2571 - Fixed small typo in dutch translation.