Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- m_listrestrict.c_orig 2018-11-03 17:34:57.072296369 -0000
- +++ m_listrestrict.c 2018-11-03 17:35:45.264898467 -0000
- @@ -18,6 +18,14 @@
- restrictExcept *next;
- };
- +typedef struct t_fakechans fakeChannel;
- +struct t_fakechans {
- + char *name;
- + int users;
- + char *topic;
- + fakeChannel *next;
- +};
- +
- // Quality fowod declarations
- static int listrestrict_override(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[]);
- int listrestrict_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs);
- @@ -28,15 +36,18 @@
- static ModuleInfo *lrestrictMI = NULL; // Store ModuleInfo so we can use it to check for errors in MOD_LOAD
- Cmdoverride *lrestrictOVR; // Pointer to the override we're gonna add
- restrictExcept *exceptList = NULL; // Stores exceptions yo
- +fakeChannel *fakeChanList = NULL;
- // Deez defaults
- int muhDelay = 0; // Default to off yo
- unsigned short needAuth = 0; // Must be identified w/ NickServ
- +unsigned short fakeChans = 0;
- +unsigned short authIsEnough = 0;
- // Dat dere module header
- ModuleHeader MOD_HEADER(m_listrestrict) = {
- "m_listrestrict", // Module name
- - "$Id: v1.02 2017/09/02 Gottem$", // Version
- + "$Id: v1.03 2018/11/03 Gottem/k4be$", // Version
- "Impose certain restrictions on /LIST usage", // Description
- "3.2-b8-1", // Modversion, not sure wat do
- NULL
- @@ -102,6 +113,7 @@
- ** Also, parv[0] seems to always be NULL, so better not rely on it fam
- */
- restrictExcept *exEntry; // For iteration yo
- + fakeChannel *fakeChansEntry;
- unsigned short except_connect = 0; // We gottem exception?
- unsigned short except_auth = 0; // Ditt0
- @@ -131,9 +143,17 @@
- }
- }
- }
- +
- + if(fakeChans){ // we are sending our fake list here, regardless of the notices below
- + sendto_one(sptr, rpl_str(RPL_LISTSTART), me.name, sptr->name);
- + for(fakeChansEntry = fakeChanList; fakeChansEntry; fakeChansEntry = fakeChansEntry->next){
- + sendto_one(cptr, rpl_str(RPL_LIST), me.name, cptr->name, fakeChansEntry->name, fakeChansEntry->users, "[nrt]", fakeChansEntry->topic);
- + }
- + sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, sptr->name);
- + }
- // Sanity check + delay check =]
- - if(!except_connect && muhDelay > 0 && sptr->local && TStime() - sptr->local->firsttime < muhDelay) {
- + if(!(authIsEnough && IsLoggedIn(sptr)) && !except_connect && muhDelay > 0 && sptr->local && TStime() - sptr->local->firsttime < muhDelay) {
- sendnotice(sptr, "You have to be connected for at least %d seconds before being able to /%s", muhDelay, OVR_LIST);
- return 0;
- }
- @@ -151,6 +171,8 @@
- ConfigEntry *cep, *cep2; // For looping through our bl0cc, nested
- int errors = 0; // Error count
- int i; // iter8or m8
- + unsigned short authIsEnoughSet = 0;
- + unsigned short needAuthSet = 0;
- // Since we'll add a new top-level block to unrealircd.conf, need to filter on CONFIG_MAIN lmao
- if(type != CONFIG_MAIN)
- @@ -199,6 +221,32 @@
- config_error("%s:%i: %s::%s must be either 0 or 1 fam", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname);
- errors++; // Increment err0r count fam
- }
- + if(atoi(cep->ce_vardata) == 1) needAuthSet = 1;
- + if(authIsEnoughSet == 1 && needAuthSet == 1){
- + config_error("%s:%i: %s has needauth and authisenough options both enabled. Please disable one.", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF);
- + errors++;
- + }
- + continue;
- + }
- +
- + if(!strcmp(cep->ce_varname, "authisenough")) {
- + if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
- + config_error("%s:%i: %s::%s must be either 0 or 1 fam", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname);
- + errors++; // Increment err0r count fam
- + }
- + if(atoi(cep->ce_vardata) == 1) authIsEnoughSet = 1;
- + if(authIsEnoughSet == 1 && needAuthSet == 1){
- + config_error("%s:%i: %s has needauth and authisenough options both enabled. Please disable one.", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF);
- + errors++;
- + }
- + continue;
- + }
- +
- + if(!strcmp(cep->ce_varname, "fakechans")) {
- + if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
- + config_error("%s:%i: %s::%s must be either 0 or 1 fam", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname);
- + errors++; // Increment err0r count fam
- + }
- continue;
- }
- @@ -227,6 +275,52 @@
- continue;
- }
- + // Here comes another nested block =]
- + if(!strcmp(cep->ce_varname, "fakechannel")) {
- + int have_name = 0;
- + // Loop 'em again
- + for(cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) {
- + if(!cep2->ce_varname || !cep2->ce_vardata) {
- + config_error("%s:%i: blank/incomplete %s::fakechannel entry", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
- + errors++; // Increment err0r count fam
- + continue; // Next iteration imo tbh
- + }
- +
- + if(strcmp(cep2->ce_varname, "name") && strcmp(cep2->ce_varname, "users") && strcmp(cep2->ce_varname, "topic")) {
- + config_error("%s:%i: invalid %s::fakechannel entry (must be one of: name, users, topic)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
- + errors++; // Increment err0r count fam
- + continue; // Next iteration imo tbh
- + }
- +
- + if(!strcmp(cep2->ce_varname, "name")){
- + have_name = 1;
- + if(cep2->ce_vardata[0] != '#'){
- + config_error("%s:%i: invalid %s::fakechannel::name (channel name must start with a #)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
- + errors++;
- + continue;
- + }
- + if(strchr(cep2->ce_vardata, ',') || strchr(cep2->ce_vardata, ' ')){
- + config_error("%s:%i: invalid %s::fakechannel::name (contains space or comma)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
- + errors++;
- + continue;
- + }
- + }
- + if(!strcmp(cep->ce_varname, "users")) {
- + if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
- + config_error("%s:%i: %s::%s must be either 0 or 1 fam", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname);
- + errors++; // Increment err0r count fam
- + }
- + continue;
- + }
- + }
- + if(have_name == 0){
- + config_error("%s:%i: invalid %s::fakechannel (must contain a channel name)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
- + errors++;
- + continue;
- + }
- + continue;
- + }
- +
- // Anything else is unknown to us =]
- config_warn("%s:%i: unknown item %s::%s", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname); // So display just a warning
- }
- @@ -240,6 +334,8 @@
- ConfigEntry *cep, *cep2; // For looping through our bl0cc, nested
- restrictExcept *last = NULL; // Initialise to NULL so the loop requires minimal l0gic
- restrictExcept **exEntry = &exceptList; // Hecks so the ->next chain stays intact
- + fakeChannel **fakeChanEntry = &fakeChanList;
- + fakeChannel *fakeChanLast = NULL;
- // Since we'll add a new top-level block to unrealircd.conf, need to filter on CONFIG_MAIN lmao
- if(type != CONFIG_MAIN)
- @@ -268,6 +364,16 @@
- needAuth = atoi(cep->ce_vardata);
- continue;
- }
- +
- + if(cep->ce_vardata && !strcmp(cep->ce_varname, "authisenough")) {
- + authIsEnough = atoi(cep->ce_vardata);
- + continue;
- + }
- +
- + if(cep->ce_vardata && !strcmp(cep->ce_varname, "fakechans")) {
- + fakeChans = atoi(cep->ce_vardata);
- + continue;
- + }
- if(!strcmp(cep->ce_varname, "exceptions")) {
- // Loop 'em
- @@ -305,6 +411,56 @@
- }
- continue;
- }
- +
- + if(!strcmp(cep->ce_varname, "fakechannel")) {
- + // Loop 'em
- +
- + // Allocate mem0ry for the current entry
- + *fakeChanEntry = malloc(sizeof(fakeChannel));
- + (*fakeChanEntry)->next = NULL;
- + (*fakeChanEntry)->users = 2; // let this be default
- + // Premium linked list fam
- + if(fakeChanLast)
- + fakeChanLast->next = *fakeChanEntry;
- +
- + fakeChanLast = *fakeChanEntry;
- + fakeChanEntry = &(*fakeChanEntry)->next;
- +
- + for(cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) { // loop through parameters of a single fakechan
- +
- + if(!cep2->ce_varname || !cep2->ce_vardata) // Sanity checks imo
- + continue; // Next iteration imo tbh
- +
- + if(!strcmp(cep2->ce_varname, "name")){
- + size_t namelen = sizeof(char) * (strlen(cep2->ce_vardata) + 1);
- + fakeChanLast->name = malloc(namelen);
- + strncpy(fakeChanLast->name, cep2->ce_vardata, namelen);
- + continue;
- + }
- +
- + if(!strcmp(cep2->ce_varname, "users")){
- + int users = atoi(cep2->ce_vardata);
- + if(users < 0) users = 2; //something funny happened
- + fakeChanLast->users = users;
- + continue;
- + }
- +
- + if(!strcmp(cep2->ce_varname, "topic")){
- + size_t topiclen = sizeof(char) * (strlen(cep2->ce_vardata) + 1);
- + fakeChanLast->topic = malloc(topiclen);
- + strncpy(fakeChanLast->topic, cep2->ce_vardata, topiclen);
- + continue;
- + }
- + }
- + if(!fakeChanLast->name){ // should not happen!!!!
- + //???
- + }
- + if(!fakeChanLast->topic){ // empty topic is allowed
- + fakeChanLast->topic = malloc(sizeof(char)*1);
- + fakeChanLast->topic[0] = 0;
- + }
- + continue;
- + }
- }
- return 1; // We good
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement