sajoin_chan.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright (C) All Rights Reserved
  2. ** Written by Gottem <support@gottem.nl>
  3. ** Website: https://gottem.nl/unreal
  4. ** License: https://gottem.nl/unreal/license
  5. */
  6. /*** <<<MODULE MANAGER START>>>
  7. module {
  8. documentation "https://gottem.nl/unreal/man/sajoin_chan";
  9. troubleshooting "In case of problems, check the FAQ at https://gottem.nl/unreal/halp or e-mail me at support@gottem.nl";
  10. min-unrealircd-version "5.*";
  11. //max-unrealircd-version "5.*";
  12. post-install-text {
  13. "The module is installed, now all you need to do is add a 'loadmodule' line to your config file:";
  14. "loadmodule \"third/sajoin_chan\";";
  15. "Then /rehash the IRCd.";
  16. "For usage information, refer to the module's documentation found at: https://gottem.nl/unreal/man/sajoin_chan";
  17. }
  18. }
  19. *** <<<MODULE MANAGER END>>>
  20. */
  21. // One include for all cross-platform compatibility thangs
  22. #include "unrealircd.h"
  23. // Commands to override
  24. #define OVR_SAJOIN "SAJOIN"
  25. #define CheckAPIError(apistr, apiobj) \
  26. do { \
  27. if(!(apiobj)) { \
  28. config_error("A critical error occurred on %s for %s: %s", (apistr), MOD_HEADER.name, ModuleGetErrorStr(modinfo->handle)); \
  29. return MOD_FAILED; \
  30. } \
  31. } while(0)
  32. // Quality fowod declarations
  33. CMD_OVERRIDE_FUNC(sajoin_chan_override);
  34. // Dat dere module header
  35. ModuleHeader MOD_HEADER = {
  36. "third/sajoin_chan", // Module name
  37. "2.0", // Version
  38. "Sajoin entire channels into another =]]", // Description
  39. "Gottem", // Author
  40. "unrealircd-5", // Modversion
  41. };
  42. // Initialisation routine (register hooks, commands and modes or create structs etc)
  43. MOD_INIT() {
  44. MARK_AS_GLOBAL_MODULE(modinfo);
  45. return MOD_SUCCESS;
  46. }
  47. // Actually load the module here (also command overrides as they may not exist in MOD_INIT yet)
  48. MOD_LOAD() {
  49. CheckAPIError("CommandOverrideAdd(SAJOIN)", CommandOverrideAdd(modinfo->handle, OVR_SAJOIN, sajoin_chan_override));
  50. return MOD_SUCCESS; // We good
  51. }
  52. // Called on unload/rehash obv
  53. MOD_UNLOAD() {
  54. return MOD_SUCCESS; // We good
  55. }
  56. // Now for the actual override
  57. CMD_OVERRIDE_FUNC(sajoin_chan_override) {
  58. // Gets args: CommandOverride *ovr, Client *client, MessageTag *recv_mtags, int parc, char *parv[]
  59. char *victimchan;
  60. char *targets;
  61. Channel *channel; // Pointer for victim channel
  62. Client *acptr; // Client pointer from the victim channel
  63. Member *member; // Channels work internally with "members" and "memberships" ;];]
  64. if(BadPtr(parv[1]) || BadPtr(parv[2]) || parv[1][0] != '#' || !MyUser(client) || !ValidatePermissionsForPath("sajoin", client, NULL, NULL, NULL)) {
  65. CallCommandOverride(ovr, client, recv_mtags, parc, parv); // Run original function yo
  66. return;
  67. }
  68. victimchan = parv[1];
  69. targets = parv[2];
  70. if(!(channel = find_channel(victimchan, NULL))) {
  71. sendnumeric(client, ERR_NOSUCHCHANNEL, victimchan);
  72. return;
  73. }
  74. for(member = channel->members; member; member = member->next) {
  75. acptr = member->client;
  76. if(IsULine(acptr)) // Let's skip these ;];]
  77. continue;
  78. char *newparv[4];
  79. newparv[0] = NULL;
  80. newparv[1] = acptr->name;
  81. newparv[2] = targets;
  82. newparv[3] = NULL;
  83. do_cmd(client, NULL, OVR_SAJOIN, 3, newparv);
  84. }
  85. return; // Stop processing yo
  86. }