/* ============= IF_AddFilter Adds a filter of a certain type, can pass a userid or ip address. FIXME: pass client_t struct?. ============= */ qfilter_t *IF_AddFilter (int type, int uid, char *ip, char *reason) { qfilter_t *newfilter = NULL; ipfilter_t filter; client_t *cl; char *address = NULL; char newreason[IF_MAXREASONLEN]; int removed, i; qbool fromfile = false; // clear to trim all reasons to suitable length Q_bzero (newreason, sizeof(newreason)); if (type & IF_BAN) { if (!IF_StringToFilter (ip, &filter)) return NULL; // error message supplied by function } else if (type & IF_MUTE) { if (uid && !ip) { for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) if (cl->userid == uid) break; if (i == MAX_CLIENTS) { Com_Printf ("IPFilter: user does not exist.\n"); return NULL; } if (cl->isrelay) address = NET_BaseAdrToString (cl->realip); else address = NET_BaseAdrToString (cl->netchan.remote_address); } else address = ip; if (!IF_StringToFilter (address, &filter)) { Com_Printf ("IPFilter: couldn't translate address \"%s\".\n", address); return NULL; } } if (IF_CheckIfFilterExists (&filter, type)) { Com_Printf ("IPFilter: error: address masked or already defined in filter list.\n"); return NULL; } if (filtercount == MAX_IP_FILTERS) { Com_Printf ("IPFilter: error: too many filters.\n"); return NULL; } // Removes any addresses that are masked by our new address removed = IF_RemovedMaskedFilters (&filter, type); if (removed) Com_Printf ("IPFilter: removed %d previous addresses masked by new filter.\n", removed); if (reason) { if (reason[strlen(reason)-1] == '\r' || reason[strlen(reason)-1] == '\n') { // newline from file fromfile = true; strncpy (newreason, reason, strlen(reason)-1); } else strncpy (newreason, reason, sizeof(newreason)-1); } newfilter = (qfilter_t *)Z_Malloc (sizeof(qfilter_t)); // EVIL EVIL EVIL newfilter->next = ipfilters2; ipfilters2 = newfilter; newfilter->compare = filter.compare; newfilter->mask = filter.mask; newfilter->flags = type; newfilter->expireTime = 0; // will have to be added with expireban cmd if (reason != NULL) newfilter->reason = Z_CopyString (newreason); else newfilter->reason = NULL; filtercount++; if (!fromfile) // don't trigger autosave if it is read from file. IF_SaveFilters (); return newfilter; }