m_auditorium.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // Quality fowod declarations
  9. int auditorium_chmode_isok(aClient *sptr, aChannel *chptr, char mode, char *para, int checkt, int what);
  10. int auditorium_hook_visibleinchan(aClient *target, aChannel *chptr);
  11. char *auditorium_hook_prechanmsg(aClient *sptr, aChannel *chptr, char *text, int notice);
  12. #define CHMODE_FLAG 'u' // Good ol' +u ;];]
  13. #define IsAudit(x) ((x) && (x)->mode.extmode & auditorium_extcmode)
  14. // Muh globals
  15. static ModuleInfo *auditoriumMI = NULL; // Store ModuleInfo so we can use it to check for errors in MOD_LOAD
  16. Cmode_t auditorium_extcmode = 0L; // Store bitwise value latur
  17. // Dat dere module header
  18. ModuleHeader MOD_HEADER(m_auditorium) = {
  19. "m_auditorium", // Module name
  20. "$Id: v1.02 2017/07/30 Gottem$", // Version
  21. "Channel mode +u to show channel events/messages to/from people with +o/+a/+q only", // Description
  22. "3.2-b8-1", // Modversion, not sure wat do
  23. NULL
  24. };
  25. // Initialisation routine (register hooks, commands and modes or create structs etc)
  26. MOD_INIT(m_auditorium) {
  27. auditoriumMI = modinfo;
  28. // Request the mode flag
  29. CmodeInfo cmodereq;
  30. memset(&cmodereq, 0, sizeof(cmodereq));
  31. cmodereq.flag = CHMODE_FLAG; // Flag yo
  32. cmodereq.paracount = 0; // No params required chico
  33. cmodereq.is_ok = auditorium_chmode_isok; // Custom verification function
  34. CmodeAdd(modinfo->handle, cmodereq, &auditorium_extcmode); // Now finally add the mode lol
  35. HookAdd(modinfo->handle, HOOKTYPE_VISIBLE_IN_CHANNEL, 0, auditorium_hook_visibleinchan);
  36. HookAddPChar(modinfo->handle, HOOKTYPE_PRE_CHANMSG, 999, auditorium_hook_prechanmsg); // Low prio hook to make sure we go after everything else (like anticaps etc)
  37. return MOD_SUCCESS; // Let MOD_LOAD handle errors
  38. }
  39. // Actually load the module here (also command overrides as they may not exist in MOD_INIT yet)
  40. MOD_LOAD(m_auditorium) {
  41. // Did the module throw an error during initialisation?
  42. if(ModuleGetError(auditoriumMI->handle) != MODERR_NOERROR || !auditorium_extcmode) {
  43. // Display error string kek
  44. config_error("A critical error occurred when loading module %s: %s", MOD_HEADER(m_auditorium).name, ModuleGetErrorStr(auditoriumMI->handle));
  45. return MOD_FAILED; // No good
  46. }
  47. return MOD_SUCCESS; // We good
  48. }
  49. // Called on unload/rehash obv
  50. MOD_UNLOAD(m_auditorium) {
  51. return MOD_SUCCESS; // We good
  52. }
  53. int is_chanowner_prot(aClient *sptr, aChannel *chptr) {
  54. Membership *lp; // For checkin' em list access level =]
  55. if(IsServer(sptr) || IsMe(sptr)) // Allow servers always lel
  56. return 1;
  57. if(chptr) { // Sanity cheqq
  58. if((lp = find_membership_link(sptr->user->channel, chptr))) {
  59. #ifdef PREFIX_AQ
  60. if(lp->flags & (CHFL_CHANOWNER|CHFL_CHANPROT))
  61. #else
  62. if(lp->flags & CHFL_CHANOP)
  63. #endif
  64. return 1;
  65. }
  66. }
  67. return 0; // No valid channel/membership or doesn't have enough axx lol
  68. }
  69. int auditorium_chmode_isok(aClient *sptr, aChannel *chptr, char mode, char *para, int checkt, int what) {
  70. /* Args:
  71. ** sptr: Client who issues the MODE change
  72. ** chptr: Channel to which the MODE change applies
  73. ** mode: The mode character for completeness
  74. ** para: Parameter to the channel mode (will be NULL for paramless modes)
  75. ** checkt: Check type, one of EXCHK_*. Explained later.
  76. ** what: Used to differentiate between adding and removing the mode, one of MODE_ADD or MODE_DEL
  77. */
  78. /* Access types:
  79. ** EXCHK_ACCESS: Verify if the user may (un)set the mode, do NOT send error messages for this (just check access)
  80. ** EXCHK_ACCESS_ERR: Similar to above, but you SHOULD send an error message here
  81. ** EXCHK_PARAM: Check the sanity of the parameter(s)
  82. */
  83. /* Return values:
  84. ** EX_ALLOW: Allow it
  85. ** EX_DENY: Deny for most people (only IRC opers w/ override may use it)
  86. ** EX_ALWAYS_DENY: Even prevent IRC opers from overriding shit
  87. */
  88. if((checkt == EXCHK_ACCESS) || (checkt == EXCHK_ACCESS_ERR)) { // Access check lol
  89. // Check if the user has +a or +q (OperOverride automajikally overrides this bit ;])
  90. if(!is_chanowner_prot(sptr, chptr)) {
  91. if(checkt == EXCHK_ACCESS_ERR)
  92. sendto_one(sptr, err_str(ERR_CHANOWNPRIVNEEDED), me.name, sptr->name, chptr->chname);
  93. return EX_DENY;
  94. }
  95. return EX_ALLOW;
  96. }
  97. return EX_ALLOW; // Falltrough, like when someone attempts +u 10 it'll simply do +u
  98. }
  99. int auditorium_hook_visibleinchan(aClient *target, aChannel *chptr) {
  100. if(IsAudit(chptr) && !is_chanownprotop(target, chptr)) // If channel has +u and the checked user (not you) doesn't have +o or higher...
  101. return HOOK_DENY; // ...don't show in /names etc
  102. return HOOK_CONTINUE;
  103. }
  104. char *auditorium_hook_prechanmsg(aClient *sptr, aChannel *chptr, char *text, int notice) {
  105. if(IsAudit(chptr) && !is_chanownprotop(sptr, chptr)) { // If channel has +u and you don't have +o or higher...
  106. // ..."relay" the message to +o etc only
  107. sendto_channelprefix_butone(NULL, &me, chptr, PREFIX_OP|PREFIX_ADMIN|PREFIX_OWNER, ":%s %s @%s :%s", sptr->name, (notice ? "NOTICE" : "PRIVMSG"), chptr->chname, text);
  108. return NULL; // Then fuck off =]
  109. }
  110. return text;
  111. }