}
static void
-handle_command (LmConnection *connection,
+handle_command (loudgame_t *lg,
const char *peer,
- const char *command,
- loudgame_t *lg)
+ const char *command)
{
- char *error;
-
if (strcmp (command, "quit") == 0) {
loudgame_quit (lg, 0);
return;
}
- error = g_strdup_printf ("Unknown command: '%s'", command);
- loudgame_send (lg, peer, error);
- free (error);
+ loudgame_sendf (lg, "Unknown command: '%s'", command);
+}
+
+static void
+handle_say (loudgame_t *lg,
+ const char *peer,
+ const char *message)
+{
+ loudgame_broadcastf (lg, "%s: %s", peer, message);
+}
+
+static void
+handle_whisper (loudgame_t *lg,
+ const char *peer,
+ const char *body)
+{
+ const char *recipient, *space, *message;
+
+ space = strchr (body, ' ');
+ if (space == NULL) {
+ loudgame_sendf (lg, peer,
+ "Error: whisper should be of the form 'user message'");
+ return;
+ }
+
+ recipient = g_strndup (body, space - body);
+
+ message = space + 1;
+
+ loudgame_sendf (lg, recipient, "*%s*: %s", peer, message);
}
static LmHandlerResult
body_str = lm_message_node_get_value (body);
- if (body_str && body_str[0] == '%')
- handle_command (connection, peer, body_str + 1, lg);
- else if (lg->handle_message)
+ if (body_str) {
+ if (body_str[0] == '%')
+ handle_command (lg, peer, body_str + 1);
+ else if (strncmp (body_str, "say ", 4) == 0)
+ handle_say (lg, peer, body_str + 4);
+ else if (strncmp (body_str, "whisper ", 8) == 0)
+ handle_whisper (lg, peer, body_str + 8);
+ else if (lg->handle_message)
(lg->handle_message) (lg, peer, body_str);
+ }
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}