|
| 1 | +/* |
| 2 | + Licence: GPLv3 or later |
| 3 | + Copyright Ⓒ 2022 Valerie Pond |
| 4 | +
|
| 5 | +
|
| 6 | +
|
| 7 | +*/ |
| 8 | +/*** <<<MODULE MANAGER START>>> |
| 9 | +module |
| 10 | +{ |
| 11 | + documentation "https://github.com/ValwareIRC/valware-unrealircd-mods/blob/main/kiwiirc-tags/README.md"; |
| 12 | + troubleshooting "In case of problems, documentation or e-mail me at [email protected]"; |
| 13 | + min-unrealircd-version "6.0.7"; |
| 14 | + max-unrealircd-version "6.*"; |
| 15 | + post-install-text { |
| 16 | + "The module is installed. Now all you need to do is add a loadmodule line:"; |
| 17 | + "loadmodule \"third/kiwiirc-tags\";"; |
| 18 | + "The module does not need any other configuration."; |
| 19 | + } |
| 20 | +} |
| 21 | +*** <<<MODULE MANAGER END>>> |
| 22 | +*/ |
| 23 | + |
| 24 | +#define MTAG_FILEUPLOAD "+kiwiirc.com/fileuploader" |
| 25 | +#define MTAG_CONFERENCE "+kiwiirc.com/conference" |
| 26 | +#define MTAG_TICTACTOE_OLD "+data" /* current */ |
| 27 | +#define MTAG_TICTACTOE "+kiwiirc.com/ttt" /* supported in near future */ |
| 28 | +#include "unrealircd.h" |
| 29 | + |
| 30 | +ModuleHeader MOD_HEADER = |
| 31 | +{ |
| 32 | + "third/kiwiirc-tags", |
| 33 | + "1.0", |
| 34 | + "Provides support for KiwiIRC's MessageTags", |
| 35 | + "Valware", |
| 36 | + "unrealircd-6", |
| 37 | +}; |
| 38 | +int kiwiirc_tag(Client *client, const char *name, const char *value); |
| 39 | +void mtag_add_kiwiirc_tag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature); |
| 40 | + |
| 41 | +MOD_INIT() |
| 42 | +{ |
| 43 | + MessageTagHandlerInfo mtag; |
| 44 | + |
| 45 | + MARK_AS_GLOBAL_MODULE(modinfo); |
| 46 | + |
| 47 | + memset(&mtag, 0, sizeof(mtag)); |
| 48 | + mtag.is_ok = kiwiirc_tag; |
| 49 | + mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED; |
| 50 | + mtag.name = MTAG_FILEUPLOAD; |
| 51 | + MessageTagHandlerAdd(modinfo->handle, &mtag); |
| 52 | + |
| 53 | + memset(&mtag, 0, sizeof(mtag)); |
| 54 | + mtag.is_ok = kiwiirc_tag; |
| 55 | + mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED; |
| 56 | + mtag.name = MTAG_CONFERENCE; |
| 57 | + MessageTagHandlerAdd(modinfo->handle, &mtag); |
| 58 | + |
| 59 | + memset(&mtag, 0, sizeof(mtag)); |
| 60 | + mtag.is_ok = kiwiirc_tag; |
| 61 | + mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED; |
| 62 | + mtag.name = MTAG_TICTACTOE_OLD; |
| 63 | + MessageTagHandlerAdd(modinfo->handle, &mtag); |
| 64 | + |
| 65 | + memset(&mtag, 0, sizeof(mtag)); |
| 66 | + mtag.is_ok = kiwiirc_tag; |
| 67 | + mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED; |
| 68 | + mtag.name = MTAG_TICTACTOE; |
| 69 | + MessageTagHandlerAdd(modinfo->handle, &mtag); |
| 70 | + |
| 71 | + HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_kiwiirc_tag); |
| 72 | + |
| 73 | + |
| 74 | + return MOD_SUCCESS; |
| 75 | +} |
| 76 | + |
| 77 | +MOD_LOAD() |
| 78 | +{ |
| 79 | + return MOD_SUCCESS; |
| 80 | +} |
| 81 | + |
| 82 | +MOD_UNLOAD() |
| 83 | +{ |
| 84 | + return MOD_SUCCESS; |
| 85 | +} |
| 86 | + |
| 87 | +int kiwiirc_tag(Client *client, const char *name, const char *value) |
| 88 | +{ |
| 89 | + if (!strlen(value)) |
| 90 | + { |
| 91 | + sendto_one(client, NULL, "FAIL * MESSAGE_TAG_TOO_SHORT %s :That message tag must contain a value.", name); |
| 92 | + return 0; |
| 93 | + } |
| 94 | + else if (strlen(value) > 3500) |
| 95 | + { |
| 96 | + sendnumericfmt(client, ERR_INPUTTOOLONG, "Input line was too long"); |
| 97 | + return 0; |
| 98 | + } |
| 99 | + return 1; |
| 100 | +} |
| 101 | + |
| 102 | +/** Only allow one at a time =] */ |
| 103 | +void mtag_add_kiwiirc_tag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature) |
| 104 | +{ |
| 105 | + MessageTag *m; |
| 106 | + |
| 107 | + if (IsUser(client)) |
| 108 | + { |
| 109 | + |
| 110 | + m = find_mtag(recv_mtags, MTAG_FILEUPLOAD); |
| 111 | + if (m) |
| 112 | + { |
| 113 | + m = duplicate_mtag(m); |
| 114 | + AddListItem(m, *mtag_list); |
| 115 | + return; |
| 116 | + } |
| 117 | + m = find_mtag(recv_mtags, MTAG_CONFERENCE); |
| 118 | + if (m) |
| 119 | + { |
| 120 | + m = duplicate_mtag(m); |
| 121 | + AddListItem(m, *mtag_list); |
| 122 | + return; |
| 123 | + } |
| 124 | + m = find_mtag(recv_mtags, MTAG_TICTACTOE_OLD); |
| 125 | + if (m) |
| 126 | + { |
| 127 | + m = duplicate_mtag(m); |
| 128 | + AddListItem(m, *mtag_list); |
| 129 | + return; |
| 130 | + } |
| 131 | + m = find_mtag(recv_mtags, MTAG_TICTACTOE); |
| 132 | + if (m) |
| 133 | + { |
| 134 | + m = duplicate_mtag(m); |
| 135 | + AddListItem(m, *mtag_list); |
| 136 | + return; |
| 137 | + } |
| 138 | + } |
| 139 | +} |
0 commit comments