summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c189
1 files changed, 94 insertions, 95 deletions
diff --git a/degesch.c b/degesch.c
index e01da85..abe8236 100644
--- a/degesch.c
+++ b/degesch.c
@@ -3862,100 +3862,7 @@ irc_is_highlight (struct server *s, const char *message)
return result;
}
-// --- Input handling ----------------------------------------------------------
-
-static void
-irc_handle_join (struct server *s, const struct irc_message *msg)
-{
- if (!msg->prefix || msg->params.len < 1)
- return;
-
- const char *channel_name = msg->params.vector[0];
- if (!irc_is_channel (s, channel_name))
- return;
-
- struct channel *channel = str_map_find (&s->irc_channels, channel_name);
- struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel_name);
- hard_assert ((channel && buffer) ||
- (channel && !buffer) || (!channel && !buffer));
-
- // We've joined a new channel
- if (!channel && irc_is_this_us (s, msg->prefix))
- {
- buffer = buffer_new ();
- buffer->type = BUFFER_CHANNEL;
- buffer->name = xstrdup_printf ("%s.%s", s->name, channel_name);
- buffer->server = s;
- buffer->channel = channel =
- irc_make_channel (s, xstrdup (channel_name));
- str_map_set (&s->irc_buffer_map, channel->name, buffer);
-
- buffer_add (s->ctx, buffer);
- buffer_activate (s->ctx, buffer);
-
- // Request the channel mode as we don't get it automatically
- irc_send (s, "MODE %s", channel_name);
- }
-
- // This is weird, ignoring
- if (!channel)
- return;
-
- // Add the user to the channel
- char *nickname = irc_cut_nickname (msg->prefix);
- irc_channel_link_user (channel, irc_get_or_make_user (s, nickname), "");
- free (nickname);
-
- // Finally log the message
- if (buffer)
- {
- buffer_send (s->ctx, buffer, BUFFER_LINE_JOIN, 0,
- .who = irc_to_utf8 (s->ctx, msg->prefix),
- .object = irc_to_utf8 (s->ctx, channel_name));
- }
-}
-
-static void
-irc_handle_kick (struct server *s, const struct irc_message *msg)
-{
- if (!msg->prefix || msg->params.len < 2)
- return;
-
- const char *channel_name = msg->params.vector[0];
- const char *target = msg->params.vector[1];
- if (!irc_is_channel (s, channel_name)
- || irc_is_channel (s, target))
- return;
-
- const char *message = "";
- if (msg->params.len > 2)
- message = msg->params.vector[2];
-
- struct user *user = str_map_find (&s->irc_users, target);
- struct channel *channel = str_map_find (&s->irc_channels, channel_name);
- struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel_name);
- hard_assert ((channel && buffer) ||
- (channel && !buffer) || (!channel && !buffer));
-
- // It would be is weird for this to be false
- if (user && channel)
- {
- if (irc_is_this_us (s, target))
- irc_left_channel (channel);
- else
- irc_remove_user_from_channel (user, channel);
- }
-
- if (buffer)
- {
- buffer_send (s->ctx, buffer, BUFFER_LINE_KICK, 0,
- .who = irc_to_utf8 (s->ctx, msg->prefix),
- .object = irc_to_utf8 (s->ctx, target),
- .reason = irc_to_utf8 (s->ctx, message));
- }
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// --- Mode processor ----------------------------------------------------------
struct mode_processor
{
@@ -4006,6 +3913,7 @@ mode_char_cmp (const void *a, const void *b)
return *(const char *) a - *(const char *) b;
}
+/// Add/remove the current mode character to/from the given ordered list
static void
mode_processor_toggle (struct mode_processor *self, struct str *modes)
{
@@ -4126,7 +4034,98 @@ irc_handle_mode_user (struct server *s, char **params)
mode_processor_run (&p, params, mode_processor_apply_user);
}
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// --- Input handling ----------------------------------------------------------
+
+static void
+irc_handle_join (struct server *s, const struct irc_message *msg)
+{
+ if (!msg->prefix || msg->params.len < 1)
+ return;
+
+ const char *channel_name = msg->params.vector[0];
+ if (!irc_is_channel (s, channel_name))
+ return;
+
+ struct channel *channel = str_map_find (&s->irc_channels, channel_name);
+ struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel_name);
+ hard_assert ((channel && buffer) ||
+ (channel && !buffer) || (!channel && !buffer));
+
+ // We've joined a new channel
+ if (!channel && irc_is_this_us (s, msg->prefix))
+ {
+ buffer = buffer_new ();
+ buffer->type = BUFFER_CHANNEL;
+ buffer->name = xstrdup_printf ("%s.%s", s->name, channel_name);
+ buffer->server = s;
+ buffer->channel = channel =
+ irc_make_channel (s, xstrdup (channel_name));
+ str_map_set (&s->irc_buffer_map, channel->name, buffer);
+
+ buffer_add (s->ctx, buffer);
+ buffer_activate (s->ctx, buffer);
+
+ // Request the channel mode as we don't get it automatically
+ irc_send (s, "MODE %s", channel_name);
+ }
+
+ // This is weird, ignoring
+ if (!channel)
+ return;
+
+ // Add the user to the channel
+ char *nickname = irc_cut_nickname (msg->prefix);
+ irc_channel_link_user (channel, irc_get_or_make_user (s, nickname), "");
+ free (nickname);
+
+ // Finally log the message
+ if (buffer)
+ {
+ buffer_send (s->ctx, buffer, BUFFER_LINE_JOIN, 0,
+ .who = irc_to_utf8 (s->ctx, msg->prefix),
+ .object = irc_to_utf8 (s->ctx, channel_name));
+ }
+}
+
+static void
+irc_handle_kick (struct server *s, const struct irc_message *msg)
+{
+ if (!msg->prefix || msg->params.len < 2)
+ return;
+
+ const char *channel_name = msg->params.vector[0];
+ const char *target = msg->params.vector[1];
+ if (!irc_is_channel (s, channel_name)
+ || irc_is_channel (s, target))
+ return;
+
+ const char *message = "";
+ if (msg->params.len > 2)
+ message = msg->params.vector[2];
+
+ struct user *user = str_map_find (&s->irc_users, target);
+ struct channel *channel = str_map_find (&s->irc_channels, channel_name);
+ struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel_name);
+ hard_assert ((channel && buffer) ||
+ (channel && !buffer) || (!channel && !buffer));
+
+ // It would be is weird for this to be false
+ if (user && channel)
+ {
+ if (irc_is_this_us (s, target))
+ irc_left_channel (channel);
+ else
+ irc_remove_user_from_channel (user, channel);
+ }
+
+ if (buffer)
+ {
+ buffer_send (s->ctx, buffer, BUFFER_LINE_KICK, 0,
+ .who = irc_to_utf8 (s->ctx, msg->prefix),
+ .object = irc_to_utf8 (s->ctx, target),
+ .reason = irc_to_utf8 (s->ctx, message));
+ }
+}
static void
irc_handle_mode (struct server *s, const struct irc_message *msg)