+static ttt_error_t
+_ttt_client_execute_invite (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ const char *invitee_username;
+ ttt_client_t *invitee;
+ char *response;
+ char *notice;
+ ttt_error_t error;
+
+ assert (num_args == 1);
+
+ invitee_username = args[0];
+
+ if (!client->registered)
+ return TTT_ERROR_NO_NAME_SET;
+
+ error = ttt_server_get_client_from_username (client->server,
+ invitee_username,
+ &invitee);
+ if (error)
+ return error;
+
+ ttt_server_add_invite (client->server,
+ client,
+ invitee);
+
+ xasprintf (&response, "INVITE\r\n");
+ ttt_client_send (client, response);
+
+ xasprintf (¬ice, "NOTICE INVITE %s %s\r\n",
+ ttt_client_get_username(client),
+ ttt_client_get_username(invitee));
+ ttt_server_broadcast (client->server, notice);
+
+ free (notice);
+ free (response);
+
+ return TTT_ERROR_NONE;
+}
+
+static ttt_error_t
+_ttt_client_execute_accept (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ const char *actor_username;
+ ttt_client_t *actor;
+ char *response;
+ char *notice;
+ ttt_error_t error;
+
+ assert (num_args == 1);
+
+ actor_username = args[0];
+
+ if (!client->registered)
+ return TTT_ERROR_NO_NAME_SET;
+
+ error = ttt_server_get_client_from_username (client->server,
+ actor_username,
+ &actor);
+ if (error)
+ return error;
+
+ error = ttt_server_remove_invite (client->server,
+ actor,
+ client);
+ if (error)
+ return error;
+
+ xasprintf (&response, "ACCEPT\r\n");
+ ttt_client_send (client, response);
+
+ xasprintf (¬ice, "NOTICE ACCEPT %s %s\r\n",
+ ttt_client_get_username(client),
+ ttt_client_get_username(actor));
+ ttt_server_broadcast (client->server, notice);
+
+ /* XXX: Start a new game */
+
+ free (notice);
+ free (response);
+
+ return TTT_ERROR_NONE;
+}
+
+static ttt_error_t
+_ttt_client_execute_retract (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ const char *invitee_username;
+ ttt_client_t *invitee;
+ char *response;
+ char *notice;
+ ttt_error_t error;
+
+ assert (num_args == 1);
+
+ invitee_username = args[0];
+
+ if (!client->registered)
+ return TTT_ERROR_NO_NAME_SET;
+
+ error = ttt_server_get_client_from_username (client->server,
+ invitee_username,
+ &invitee);
+ if (error)
+ return error;
+
+ error = ttt_server_remove_invite (client->server,
+ client,
+ invitee);
+ if (error)
+ return error;
+
+ xasprintf (&response, "RETRACT\r\n");
+ ttt_client_send (client, response);
+
+ xasprintf (¬ice, "NOTICE RETRACT %s %s\r\n",
+ ttt_client_get_username(client),
+ ttt_client_get_username(invitee));
+ ttt_server_broadcast (client->server, notice);
+
+ free (notice);
+ free (response);
+
+ return TTT_ERROR_NONE;
+}
+
+static ttt_error_t
+_ttt_client_execute_decline (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ const char *actor_username;
+ ttt_client_t *actor;
+ char *response;
+ char *notice;
+ ttt_error_t error;
+
+ assert (num_args == 1);
+
+ actor_username = args[0];
+
+ if (!client->registered)
+ return TTT_ERROR_NO_NAME_SET;
+
+ error = ttt_server_get_client_from_username (client->server,
+ actor_username,
+ &actor);
+ if (error)
+ return error;
+
+ error = ttt_server_remove_invite (client->server,
+ actor,
+ client);
+ if (error)
+ return error;
+
+ xasprintf (&response, "DECLINE\r\n");
+ ttt_client_send (client, response);
+
+ xasprintf (¬ice, "NOTICE DECLINE %s %s\r\n",
+ ttt_client_get_username(client),
+ ttt_client_get_username(actor));
+ ttt_server_broadcast (client->server, notice);
+
+ free (notice);
+ free (response);
+
+ return TTT_ERROR_NONE;
+}
+