- 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);