Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.90 KB | None | 0 0
  1. +++ m_listrestrict.c    2018-11-03 20:57:30.761239908 -0000
  2. @@ -18,6 +18,14 @@
  3.     restrictExcept *next;
  4.  };
  5.  
  6. +typedef struct t_fakechans fakeChannel;
  7. +struct t_fakechans {
  8. +   char *name;
  9. +   int users;
  10. +   char *topic;
  11. +   fakeChannel *next;
  12. +};
  13. +
  14.  // Quality fowod declarations
  15.  static int listrestrict_override(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[]);
  16.  int listrestrict_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs);
  17. @@ -28,15 +36,18 @@
  18.  static ModuleInfo *lrestrictMI = NULL; // Store ModuleInfo so we can use it to check for errors in MOD_LOAD
  19.  Cmdoverride *lrestrictOVR; // Pointer to the override we're gonna add
  20.  restrictExcept *exceptList = NULL; // Stores exceptions yo
  21. +fakeChannel *fakeChanList = NULL;
  22.  
  23.  // Deez defaults
  24.  int muhDelay = 0; // Default to off yo
  25.  unsigned short needAuth = 0; // Must be identified w/ NickServ
  26. +unsigned short fakeChans = 0;
  27. +unsigned short authIsEnough = 0;
  28.  
  29.  // Dat dere module header
  30.  ModuleHeader MOD_HEADER(m_listrestrict) = {
  31.     "m_listrestrict", // Module name
  32. -   "$Id: v1.02 2017/09/02 Gottem$", // Version
  33. +   "$Id: v1.03 2018/11/03 Gottem/k4be$", // Version
  34.     "Impose certain restrictions on /LIST usage", // Description
  35.     "3.2-b8-1", // Modversion, not sure wat do
  36.     NULL
  37. @@ -102,6 +113,7 @@
  38.     ** Also, parv[0] seems to always be NULL, so better not rely on it fam
  39.     */
  40.     restrictExcept *exEntry; // For iteration yo
  41. +   fakeChannel *fakeChansEntry;
  42.     unsigned short except_connect = 0; // We gottem exception?
  43.     unsigned short except_auth = 0; // Ditt0
  44.  
  45. @@ -131,16 +143,29 @@
  46.             }
  47.         }
  48.     }
  49. +  
  50. +   if(authIsEnough && IsLoggedIn(sptr)) except_connect = 1; // do not check time when user already identified
  51.  
  52. -   // Sanity check + delay check =]
  53. -   if(!except_connect && muhDelay > 0 && sptr->local && TStime() - sptr->local->firsttime < muhDelay) {
  54. +   int delayF = !except_connect && muhDelay > 0 && (sptr->local && TStime() - sptr->local->firsttime < muhDelay); // Sanity check + delay check =]
  55. +   int authF = !except_auth && needAuth && !IsLoggedIn(sptr); // Need identified check ;];;]
  56. +
  57. +   if(fakeChans && (delayF || authF)) {
  58. +       sendto_one(sptr, rpl_str(RPL_LISTSTART), me.name, sptr->name);
  59. +       for(fakeChansEntry = fakeChanList; fakeChansEntry; fakeChansEntry = fakeChansEntry->next){
  60. +           sendto_one(cptr, rpl_str(RPL_LIST), me.name, cptr->name, fakeChansEntry->name, fakeChansEntry->users, "[+ntr]", fakeChansEntry->topic);
  61. +       }
  62. +       sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, sptr->name);
  63. +   }
  64. +
  65. +   if(delayF) {
  66.         sendnotice(sptr, "You have to be connected for at least %d seconds before being able to /%s", muhDelay, OVR_LIST);
  67. +       if(fakeChans) sendnotice(sptr, "Please ignore the fake /%s output above.", OVR_LIST);
  68.         return 0;
  69.     }
  70.  
  71. -   // Need identified check ;];;]
  72. -   if(!except_auth && needAuth && !IsLoggedIn(sptr)) {
  73. +   if(authF) {
  74.         sendnotice(sptr, "You have to be identified with services before being able to /%s", OVR_LIST);
  75. +       if(fakeChans) sendnotice(sptr, "Please ignore the fake /%s output above.", OVR_LIST);
  76.         return 0;
  77.     }
  78.  
  79. @@ -201,6 +226,22 @@
  80.             }
  81.             continue;
  82.         }
  83. +      
  84. +       if(!strcmp(cep->ce_varname, "authisenough")) {
  85. +           if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
  86. +               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);
  87. +               errors++; // Increment err0r count fam
  88. +           }
  89. +           continue;
  90. +       }
  91. +      
  92. +       if(!strcmp(cep->ce_varname, "fakechans")) {
  93. +           if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
  94. +               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);
  95. +               errors++; // Increment err0r count fam
  96. +           }
  97. +           continue;
  98. +       }
  99.  
  100.         // Here comes a nested block =]
  101.         if(!strcmp(cep->ce_varname, "exceptions")) {
  102. @@ -227,10 +268,56 @@
  103.             continue;
  104.         }
  105.  
  106. +       // Here comes another nested block =]
  107. +       if(!strcmp(cep->ce_varname, "fakechannel")) {
  108. +           int have_name = 0;
  109. +           // Loop 'em again
  110. +           for(cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) {
  111. +               if(!cep2->ce_varname || !cep2->ce_vardata) {
  112. +                   config_error("%s:%i: blank/incomplete %s::fakechannel entry", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  113. +                   errors++; // Increment err0r count fam
  114. +                   continue; // Next iteration imo tbh
  115. +               }
  116. +
  117. +               if(strcmp(cep2->ce_varname, "name") && strcmp(cep2->ce_varname, "users") && strcmp(cep2->ce_varname, "topic")) {
  118. +                   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
  119. +                   errors++; // Increment err0r count fam
  120. +                   continue; // Next iteration imo tbh
  121. +               }
  122. +
  123. +               if(!strcmp(cep2->ce_varname, "name")){
  124. +                   have_name = 1;
  125. +                   if(cep2->ce_vardata[0] != '#'){
  126. +                       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
  127. +                       errors++;
  128. +                       continue;
  129. +                   }
  130. +                   if(strchr(cep2->ce_vardata, ',') || strchr(cep2->ce_vardata, ' ')){
  131. +                       config_error("%s:%i: invalid %s::fakechannel::name (contains space or comma)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  132. +                       errors++;
  133. +                       continue;
  134. +                   }
  135. +               }
  136. +               if(!strcmp(cep->ce_varname, "users")) {
  137. +                   if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
  138. +                       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);
  139. +                       errors++; // Increment err0r count fam
  140. +                   }
  141. +                   continue;
  142. +               }
  143. +           }
  144. +           if(have_name == 0){
  145. +               config_error("%s:%i: invalid %s::fakechannel (must contain a channel name)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  146. +               errors++;
  147. +               continue;
  148. +           }
  149. +           continue;
  150. +       }
  151. +      
  152.         // Anything else is unknown to us =]
  153.         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
  154.     }
  155. -
  156. +  
  157.     *errs = errors;
  158.     return errors ? -1 : 1; // Returning 1 means "all good", -1 means we shat our panties
  159.  }
  160. @@ -240,6 +327,8 @@
  161.     ConfigEntry *cep, *cep2; // For looping through our bl0cc, nested
  162.     restrictExcept *last = NULL; // Initialise to NULL so the loop requires minimal l0gic
  163.     restrictExcept **exEntry = &exceptList; // Hecks so the ->next chain stays intact
  164. +   fakeChannel **fakeChanEntry = &fakeChanList;
  165. +   fakeChannel *fakeChanLast = NULL;
  166.  
  167.     // Since we'll add a new top-level block to unrealircd.conf, need to filter on CONFIG_MAIN lmao
  168.     if(type != CONFIG_MAIN)
  169. @@ -268,6 +357,16 @@
  170.             needAuth = atoi(cep->ce_vardata);
  171.             continue;
  172.         }
  173. +      
  174. +       if(cep->ce_vardata && !strcmp(cep->ce_varname, "authisenough")) {
  175. +           authIsEnough = atoi(cep->ce_vardata);
  176. +           continue;
  177. +       }
  178. +      
  179. +       if(cep->ce_vardata && !strcmp(cep->ce_varname, "fakechans")) {
  180. +           fakeChans = atoi(cep->ce_vardata);
  181. +           continue;
  182. +       }
  183.  
  184.         if(!strcmp(cep->ce_varname, "exceptions")) {
  185.             // Loop 'em
  186. @@ -305,6 +404,56 @@
  187.             }
  188.             continue;
  189.         }
  190. +      
  191. +       if(!strcmp(cep->ce_varname, "fakechannel")) {
  192. +           // Loop 'em
  193. +          
  194. +           // Allocate mem0ry for the current entry
  195. +           *fakeChanEntry = malloc(sizeof(fakeChannel));
  196. +           (*fakeChanEntry)->next = NULL;
  197. +           (*fakeChanEntry)->users = 2; // let this be default
  198. +           // Premium linked list fam
  199. +           if(fakeChanLast)
  200. +               fakeChanLast->next = *fakeChanEntry;
  201. +
  202. +           fakeChanLast = *fakeChanEntry;
  203. +           fakeChanEntry = &(*fakeChanEntry)->next;
  204. +              
  205. +           for(cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) { // loop through parameters of a single fakechan
  206. +              
  207. +               if(!cep2->ce_varname || !cep2->ce_vardata) // Sanity checks imo
  208. +                   continue; // Next iteration imo tbh
  209. +                  
  210. +               if(!strcmp(cep2->ce_varname, "name")){
  211. +                   size_t namelen = sizeof(char) * (strlen(cep2->ce_vardata) + 1);
  212. +                   fakeChanLast->name = malloc(namelen);
  213. +                   strncpy(fakeChanLast->name, cep2->ce_vardata, namelen);
  214. +                   continue;
  215. +               }
  216. +              
  217. +               if(!strcmp(cep2->ce_varname, "users")){
  218. +                   int users = atoi(cep2->ce_vardata);
  219. +                   if(users < 0) users = 2; //something funny happened
  220. +                   fakeChanLast->users = users;
  221. +                   continue;
  222. +               }
  223. +              
  224. +               if(!strcmp(cep2->ce_varname, "topic")){
  225. +                   size_t topiclen = sizeof(char) * (strlen(cep2->ce_vardata) + 1);
  226. +                   fakeChanLast->topic = malloc(topiclen);
  227. +                   strncpy(fakeChanLast->topic, cep2->ce_vardata, topiclen);
  228. +                   continue;
  229. +               }
  230. +           }
  231. +           if(!fakeChanLast->name){ // should not happen!!!!
  232. +               //???
  233. +           }
  234. +           if(!fakeChanLast->topic){ // empty topic is allowed
  235. +               fakeChanLast->topic = malloc(sizeof(char)*1);
  236. +               fakeChanLast->topic[0] = 0;
  237. +           }
  238. +           continue;
  239. +       }
  240.     }
  241.  
  242.     return 1; // We good
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement