+ assert (num_args == 1);
+
+ ttt_client_set_name (client, args[0]);
+
+ error = ttt_server_register_client (client->server, client);
+ if (error)
+ return error;
+ client->registered = TRUE;
+
+ xasprintf (&response, "HELO %s %s %s\r\n",
+ client->name,
+ ttt_server_get_host (client->server),
+ ttt_server_get_port (client->server));
+ ttt_client_send (client, response);
+
+ xasprintf (¬ice, "NOTICE USER %s\r\n",
+ client->name);
+ ttt_server_broadcast (client->server, notice);
+
+ free (notice);
+ free (response);
+
+ return TTT_ERROR_NONE;
+}
+
+static ttt_error_t
+_ttt_client_execute_who (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ char *response;
+
+ assert (num_args == 0);
+
+ if (!client->registered)
+ return TTT_ERROR_NO_NAME_SET;
+
+ response = xstrdup (ttt_server_who (client->server));
+ ttt_client_send (client, response);
+
+ free (response);
+
+ return TTT_ERROR_NONE;
+}
+
+static ttt_error_t
+_ttt_client_execute_message (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ char *response;
+ char *notice;
+
+ assert (num_args == 1);
+
+ if (!client->registered)
+ return TTT_ERROR_NO_NAME_SET;
+
+ xasprintf(&response, "MESSAGE\r\n");
+ ttt_client_send (client, response);
+
+ xasprintf(¬ice, "NOTICE MESSAGE %s \"%s\"\r\n",
+ client->name,
+ args[0]);
+ ttt_server_broadcast (client->server, notice);
+
+ free (notice);
+ free (response);
+
+ return TTT_ERROR_NONE;
+}
+
+static ttt_error_t
+_ttt_client_execute_help (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ char *response;
+
+ /* XXX: NYI */
+
+ xasprintf(&response, "HELP - NYI\r\n");
+ ttt_client_send (client, response);
+
+ free (response);
+ return TTT_ERROR_NONE;
+}
+
+static ttt_error_t
+_ttt_client_execute_version (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ char *response;
+
+ assert (num_args == 1);
+
+ /* XXX: Argument is being ignored.
+ This is not completely implemented. */
+
+ xasprintf (&response, "VERSION 1\r\n");
+ ttt_client_send (client, response);
+
+ free (response);
+ return TTT_ERROR_NONE;
+}
+
+static ttt_error_t
+_ttt_client_execute_quit (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ char *notice;
+
+ assert (num_args == 0);
+
+ if (!client->registered)
+ return TTT_ERROR_QUIT_REQUESTED;
+
+ xasprintf (¬ice, "NOTICE QUIT %s\r\n",
+ client->name);
+ ttt_server_broadcast (client->server, notice);
+
+ free (notice);
+
+ return TTT_ERROR_QUIT_REQUESTED;
+}
+
+static void
+_free_request (ttt_client_t *client);
+
+static void
+_ttt_client_init (ttt_client_t *client,
+ ttt_server_t *server,
+ int socket)
+{
+ FILE *file;
+
+ pthread_mutex_init (&client->mutex, NULL);