aboutsummaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-06-14 07:51:00 -0400
committerTest_User <hax@andrewyu.org>2024-06-14 07:51:00 -0400
commit80bd818208729b24262141b9068c427f9d8a097a (patch)
tree949aa0fd89866fe5909b8b9f4204e5cf66b0c4b0 /protocols
parent60865e2f58cf75447745c718491488fd6e232992 (diff)
downloadhaxircd-80bd818208729b24262141b9068c427f9d8a097a.tar.gz
haxircd-80bd818208729b24262141b9068c427f9d8a097a.zip
PRIVMSG/NOTICE support, improve kill_user
Diffstat (limited to 'protocols')
-rw-r--r--protocols/inspircd2.c174
-rw-r--r--protocols/inspircd2.h7
2 files changed, 173 insertions, 8 deletions
diff --git a/protocols/inspircd2.c b/protocols/inspircd2.c
index c2fc6cd..da75e1b 100644
--- a/protocols/inspircd2.c
+++ b/protocols/inspircd2.c
@@ -141,6 +141,10 @@ int init_inspircd2_protocol(void) {
set_table_index(&inspircd2_protocol_commands, STRING("FJOIN"), &inspircd2_protocol_handle_fjoin);
set_table_index(&inspircd2_protocol_commands, STRING("PART"), &inspircd2_protocol_handle_part);
+ set_table_index(&inspircd2_protocol_commands, STRING("KICK"), &inspircd2_protocol_handle_kick);
+
+ set_table_index(&inspircd2_protocol_commands, STRING("PRIVMSG"), &inspircd2_protocol_handle_privmsg);
+ set_table_index(&inspircd2_protocol_commands, STRING("NOTICE"), &inspircd2_protocol_handle_notice);
set_table_index(&inspircd2_protocol_commands, STRING("DUMP"), &inspircd2_protocol_handle_dump);
@@ -665,6 +669,86 @@ void inspircd2_protocol_propagate_part_channel(struct string from, struct channe
inspircd2_protocol_propagate(from, self, STRING("\n"));
}
+// [:source] PRIVMSG <target> <message>
+void inspircd2_protocol_propagate_privmsg(struct string from, struct string source, struct string target, struct string msg) {
+ struct user_info *user = get_table_index(user_list, target);
+ struct server_info *server;
+ if (!user)
+ server = get_table_index(server_list, target);
+
+ if (user || server) {
+ struct server_info *target_server;
+ if (user) {
+ target_server = get_table_index(server_list, user->server);
+ } else {
+ target_server = server;
+ }
+
+ if (target_server->protocol != INSPIRCD2_PROTOCOL || STRING_EQ(target_server->sid, SID))
+ return;
+
+ struct server_info *adjacent = get_table_index(server_list, target_server->next);
+ networks[adjacent->net].send(adjacent->handle, STRING(":"));
+ networks[adjacent->net].send(adjacent->handle, source);
+ networks[adjacent->net].send(adjacent->handle, STRING(" PRIVMSG "));
+ networks[adjacent->net].send(adjacent->handle, target);
+ networks[adjacent->net].send(adjacent->handle, STRING(" :"));
+ networks[adjacent->net].send(adjacent->handle, msg);
+ networks[adjacent->net].send(adjacent->handle, STRING("\n"));
+ } else {
+ // TODO: Trim target list for channels as well
+ struct server_info *self = get_table_index(server_list, SID);
+
+ inspircd2_protocol_propagate(from, self, STRING(":"));
+ inspircd2_protocol_propagate(from, self, source);
+ inspircd2_protocol_propagate(from, self, STRING(" PRIVMSG "));
+ inspircd2_protocol_propagate(from, self, target);
+ inspircd2_protocol_propagate(from, self, STRING(" :"));
+ inspircd2_protocol_propagate(from, self, msg);
+ inspircd2_protocol_propagate(from, self, STRING("\n"));
+ }
+}
+
+// [:source] NOTICE <target> <message>
+void inspircd2_protocol_propagate_notice(struct string from, struct string source, struct string target, struct string msg) {
+ struct user_info *user = get_table_index(user_list, target);
+ struct server_info *server;
+ if (!user)
+ server = get_table_index(server_list, target);
+
+ if (user || server) {
+ struct server_info *target_server;
+ if (user) {
+ target_server = get_table_index(server_list, user->server);
+ } else {
+ target_server = server;
+ }
+
+ if (target_server->protocol != INSPIRCD2_PROTOCOL || STRING_EQ(target_server->sid, SID))
+ return;
+
+ struct server_info *adjacent = get_table_index(server_list, target_server->next);
+ networks[adjacent->net].send(adjacent->handle, STRING(":"));
+ networks[adjacent->net].send(adjacent->handle, source);
+ networks[adjacent->net].send(adjacent->handle, STRING(" NOTICE "));
+ networks[adjacent->net].send(adjacent->handle, target);
+ networks[adjacent->net].send(adjacent->handle, STRING(" :"));
+ networks[adjacent->net].send(adjacent->handle, msg);
+ networks[adjacent->net].send(adjacent->handle, STRING("\n"));
+ } else {
+ // TODO: Trim target list for channels as well
+ struct server_info *self = get_table_index(server_list, SID);
+
+ inspircd2_protocol_propagate(from, self, STRING(":"));
+ inspircd2_protocol_propagate(from, self, source);
+ inspircd2_protocol_propagate(from, self, STRING(" NOTICE "));
+ inspircd2_protocol_propagate(from, self, target);
+ inspircd2_protocol_propagate(from, self, STRING(" :"));
+ inspircd2_protocol_propagate(from, self, msg);
+ inspircd2_protocol_propagate(from, self, STRING("\n"));
+ }
+}
+
void inspircd2_protocol_do_unlink_inner(struct string from, struct server_info *target, struct string reason) {
target->distance = 1; // Reusing distance for `have passed`, since its set to 0 bc severed anyways
@@ -1159,24 +1243,28 @@ int inspircd2_protocol_handle_kill(struct string source, size_t argc, struct str
return 0;
}
+ int ignore;
if (STRING_EQ(user->server, SID)) {
if (config->ignore_local_kills) {
- inspircd2_protocol_introduce_user_to(net, handle, user);
+ ignore = 1;
} else {
if (argc > 1)
- kill_user(config->sid, source, user, argv[1]);
+ ignore = kill_user(config->sid, source, user, argv[1]);
else
- kill_user(config->sid, source, user, STRING(""));
+ ignore = kill_user(config->sid, source, user, STRING(""));
}
- } else if (config->ignore_remote_kills) {
- inspircd2_protocol_introduce_user_to(net, handle, user);
- } else {
+ } else if (!config->ignore_remote_kills) {
if (argc > 1)
- kill_user(config->sid, source, user, argv[1]);
+ ignore = kill_user(config->sid, source, user, argv[1]);
else
- kill_user(config->sid, source, user, STRING(""));
+ ignore = kill_user(config->sid, source, user, STRING(""));
+ } else {
+ ignore = 1;
}
+ if (ignore)
+ inspircd2_protocol_introduce_user_to(net, handle, user);
+
return 0;
}
@@ -1311,6 +1399,76 @@ int inspircd2_protocol_handle_part(struct string source, size_t argc, struct str
return 0;
}
+// [:source] KICK <channel> <user> [<reason>?]
+int inspircd2_protocol_handle_kick(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) {
+ if (argc < 2) {
+ WRITES(2, STRING("[InspIRCd v2] Invalid KICK recieved! (Missing parameters)\r\n"));
+ return -1;
+ }
+
+ struct channel_info *channel = get_table_index(channel_list, argv[0]);
+ if (!channel)
+ return 0;
+
+ struct user_info *user = get_table_index(user_list, argv[1]);
+ if (!user) {
+ char found = 0;
+ for (size_t i = 0; i < user_list.len; i++) {
+ user = user_list.array[i].ptr;
+ if (STRING_EQ(user->nick, argv[1])) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ return 0;
+ }
+
+ int rejoin;
+ if (argc > 2)
+ rejoin = kick_channel(config->sid, source, channel, user, argv[2]);
+ else
+ rejoin = kick_channel(config->sid, source, channel, user, STRING(""));
+
+ if (rejoin) {
+ networks[net].send(handle, STRING(":"));
+ networks[net].send(handle, SID);
+ networks[net].send(handle, STRING(" FJOIN "));
+ networks[net].send(handle, channel->name);
+ networks[net].send(handle, STRING(" "));
+ networks[net].send(handle, channel->channel_ts_str);
+ networks[net].send(handle, STRING(" + :,"));
+ networks[net].send(handle, user->uid);
+ networks[net].send(handle, STRING("\n"));
+ }
+
+ return 0;
+}
+
+// [:source] PRIVMSG <target> <message>
+int inspircd2_protocol_handle_privmsg(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) {
+ if (argc < 2) {
+ WRITES(2, STRING("[InspIRCd v2] Invalid PRIVMSG recieved! (Missing parameters)\r\n"));
+ return -1;
+ }
+
+ privmsg(config->sid, source, argv[0], argv[1]);
+
+ return 0;
+}
+
+// [:source] NOTICE <target> <message>
+int inspircd2_protocol_handle_notice(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) {
+ if (argc < 2) {
+ WRITES(2, STRING("[InspIRCd v2] Invalid NOTICE recieved! (Missing parameters)\r\n"));
+ return -1;
+ }
+
+ notice(config->sid, source, argv[0], argv[1]);
+
+ return 0;
+}
+
int inspircd2_protocol_handle_dump(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) {
for (size_t arg = 0; arg < argc; arg++) {
if (STRING_EQ(argv[arg], STRING("LATENCIES"))) {
diff --git a/protocols/inspircd2.h b/protocols/inspircd2.h
index 36a6b68..bf3da7d 100644
--- a/protocols/inspircd2.h
+++ b/protocols/inspircd2.h
@@ -53,6 +53,9 @@ void inspircd2_protocol_propagate_set_channel(struct string from, struct channel
void inspircd2_protocol_propagate_join_channel(struct string from, struct channel_info *channel, size_t user_count, struct user_info **users);
void inspircd2_protocol_propagate_part_channel(struct string from, struct channel_info *channel, struct user_info *user, struct string reason);
+void inspircd2_protocol_propagate_privmsg(struct string from, struct string source, struct string target, struct string msg);
+void inspircd2_protocol_propagate_notice(struct string from, struct string source, struct string target, struct string msg);
+
void inspircd2_protocol_do_unlink(struct string from, struct server_info *a, struct server_info *b);
void inspircd2_protocol_update_propagations_inner(struct server_info *source);
@@ -76,6 +79,10 @@ int inspircd2_protocol_handle_kill(struct string source, size_t argc, struct str
int inspircd2_protocol_handle_fjoin(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
int inspircd2_protocol_handle_part(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
+int inspircd2_protocol_handle_kick(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
+
+int inspircd2_protocol_handle_privmsg(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
+int inspircd2_protocol_handle_notice(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
int inspircd2_protocol_handle_dump(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);