char **args,
int num_args);
+static ttt_error_t
+_ttt_client_execute_invite (ttt_client_t *client,
+ char **args,
+ int num_args);
+
+static ttt_error_t
+_ttt_client_execute_accept (ttt_client_t *client,
+ char **args,
+ int num_args);
+
typedef struct _ttt_command_description {
const char *command;
int args_min;
{"HELP", 0, 1, _ttt_client_execute_help,
"HELP <command> ", "Display help for a command."},
+ {"INVITE", 1, 1, _ttt_client_execute_invite,
+ "INVITE <username> ", "Invite a player to play a game."},
+
+ {"ACCEPT", 1, 1, _ttt_client_execute_accept,
+ "ACCEPT <username> ", "Accept a game invitation."},
+
{"MESSAGE", 1, 1, _ttt_client_execute_message,
"MESSAGE <message> ", "Send a message to everyone."},
static ttt_error_t
_ttt_client_execute_help (ttt_client_t *client,
- char **args,
- int num_args)
+ char **args,
+ int num_args)
{
char *response;
char *command;
return TTT_ERROR_QUIT_REQUESTED;
}
+static ttt_error_t
+_ttt_client_execute_invite (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ const char *username;
+ char *response;
+ char *notice;
+ ttt_error_t error;
+
+ assert (num_args == 1);
+
+ username = args[0];
+
+ if (!client->registered)
+ return TTT_ERROR_NO_NAME_SET;
+
+ error = ttt_server_verify_username (client->server, username);
+ if (error)
+ return error;
+
+ xasprintf (&response, "INVITE\r\n");
+ ttt_client_send (client, response);
+
+ xasprintf (¬ice, "NOTICE INVITE %s %s\r\n",
+ client->username,
+ username);
+ 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 *username;
+ char *response;
+ char *notice;
+ ttt_error_t error;
+
+ assert (num_args == 1);
+
+ username = args[0];
+
+ if (!client->registered)
+ return TTT_ERROR_NO_NAME_SET;
+
+ error = ttt_server_verify_username (client->server, username);
+ if (error)
+ return error;
+
+ xasprintf (&response, "ACCEPT\r\n");
+ ttt_client_send (client, response);
+
+ xasprintf (¬ice, "NOTICE ACCEPT %s %s\r\n",
+ client->username,
+ username);
+ ttt_server_broadcast (client->server, notice);
+
+ /* XXX: Start a new game */
+
+ free (notice);
+ free (response);
+
+ return TTT_ERROR_NONE;
+}
+
static void
_free_request (ttt_client_t *client);