m_noinvite.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright (C) All Rights Reserved
  2. ** Written by Gottem <support@gottem.nl>
  3. ** Website: https://gitgud.malvager.net/Wazakindjes/unrealircd_mods
  4. ** License: https://gitgud.malvager.net/Wazakindjes/unrealircd_mods/raw/master/LICENSE
  5. */
  6. // One include for all cross-platform compatibility thangs
  7. #include "unrealircd.h"
  8. #define BACKPORT (UNREAL_VERSION_GENERATION == 4 && UNREAL_VERSION_MAJOR == 0 && UNREAL_VERSION_MINOR <= 15)
  9. #define UMODE_FLAG 'N' // No invite
  10. // Commands to override
  11. #define OVR_INVITE "INVITE"
  12. // Quality fowod declarations
  13. #if BACKPORT
  14. static int noinvite_override_invite(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[]);
  15. #else
  16. int noinvite_hook(aClient *sptr, aClient *target, aChannel *chptr, int *override);
  17. #endif
  18. // Muh globals
  19. static ModuleInfo *noinviteMI = NULL; // Store ModuleInfo so we can use it to check for errors in MOD_LOAD
  20. Umode *noinvite_umode = NULL; // Store umode handle
  21. long noinvite_extumode = 0L; // Store bitwise value latur
  22. #if BACKPORT
  23. Cmdoverride *noInvOVR; // Pointer to the override we're gonna add
  24. #else
  25. Hook *noinviteHook = NULL;
  26. #endif
  27. // Dat dere module header
  28. ModuleHeader MOD_HEADER(m_noinvite) = {
  29. "m_noinvite", // Module name
  30. "$Id: v1.03 2019/01/24 Gottem$", // Version
  31. "Adds umode +N to block invites", // Description
  32. "3.2-b8-1", // Modversion, not sure wat do
  33. NULL
  34. };
  35. // Initialisation routine (register hooks, commands and modes or create structs etc)
  36. MOD_INIT(m_noinvite) {
  37. noinviteMI = modinfo;
  38. #if !BACKPORT
  39. noinviteHook = HookAdd(modinfo->handle, HOOKTYPE_PRE_INVITE, 0, noinvite_hook);
  40. #endif
  41. // Add a global umode (i.e. propagate to all servers), allow anyone to set/remove it on themselves
  42. noinvite_umode = UmodeAdd(modinfo->handle, UMODE_FLAG, UMODE_GLOBAL, 0, NULL, &noinvite_extumode);
  43. return MOD_SUCCESS; // Let MOD_LOAD handle errors
  44. }
  45. // Actually load the module here (also command overrides as they may not exist in MOD_INIT yet)
  46. MOD_LOAD(m_noinvite) {
  47. #if BACKPORT
  48. noInvOVR = CmdoverrideAdd(noinviteMI->handle, OVR_INVITE, noinvite_override_invite); // Attempt to add command override
  49. if(ModuleGetError(noinviteMI->handle) != MODERR_NOERROR || !noinvite_umode || !noInvOVR)
  50. #else
  51. if(ModuleGetError(noinviteMI->handle) != MODERR_NOERROR || !noinvite_umode || !noinviteHook)
  52. #endif
  53. {
  54. // Display error string kek
  55. config_error("A critical error occurred when loading module %s: %s", MOD_HEADER(m_noinvite).name, ModuleGetErrorStr(noinviteMI->handle));
  56. return MOD_FAILED; // No good
  57. }
  58. return MOD_SUCCESS; // We good
  59. }
  60. // Called on unload/rehash obv
  61. MOD_UNLOAD(m_noinvite) {
  62. return MOD_SUCCESS; // We good
  63. }
  64. // Now for the actual override
  65. #if BACKPORT
  66. static int noinvite_override_invite(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[]) {
  67. aClient *acptr;
  68. if(BadPtr(parv[1]) || BadPtr(parv[2]))
  69. return CallCmdoverride(ovr, cptr, sptr, parc, parv); // Run original function yo
  70. if(!IsOper(sptr) && (acptr = find_person(parv[1], NULL)) && (acptr->umodes & noinvite_extumode)) {
  71. if(find_channel(parv[2], NULL)) {
  72. sendto_one(sptr, ":%s NOTICE %s :%s has blocked all invites", me.name, parv[2], parv[1]);
  73. return 0;
  74. }
  75. }
  76. return CallCmdoverride(ovr, cptr, sptr, parc, parv); // Run original function yo
  77. }
  78. #else
  79. int noinvite_hook(aClient *sptr, aClient *target, aChannel *chptr, int *override) {
  80. if(!IsULine(sptr) && !IsOper(sptr) && (target->umodes & noinvite_extumode)) {
  81. sendto_one(sptr, ":%s NOTICE %s :%s has blocked all invites", me.name, chptr->chname, target->name);
  82. return HOOK_DENY;
  83. }
  84. return HOOK_CONTINUE;
  85. }
  86. #endif