* TODO: Add newline before EOF
* src/ttt-client.c: (_ttt_client_execute_who):
* src/ttt-server.h:
* src/ttt-server.c: (ttt_server_who): Implement WHO.
Carl Worth <cworth@cworth.org>
Carl Worth <cworth@cworth.org>
+Richard D. Worth <richard@theworths.org>
+2005-11-24 Richard D. Worth <richard@theworths.org>
+
+ * AUTHORS: Add Richard D. Worth
+ * TODO: Add newline before EOF
+
+ * src/ttt-client.c: (_ttt_client_execute_who):
+ * src/ttt-server.h:
+ * src/ttt-server.c: (ttt_server_who): Implement WHO.
+
2005-11-24 Carl Worth <cworth@cworth.org>
* PROTOCOL: Document QUIT.
2005-11-24 Carl Worth <cworth@cworth.org>
* PROTOCOL: Document QUIT.
* TODO: Note that HELO and ERROR INVALIDNAME are implemented in
the server.
* TODO: Note that HELO and ERROR INVALIDNAME are implemented in
the server.
-2005-11-23 Richard Worth <richard@theworths.org>
+2005-11-23 Richard D. Worth <richard@theworths.org>
- * PROTOCOL: Removed unused servername
+ * PROTOCOL: Remove unused servername
* src/ttt-client.h: * src/ttt-client.c:
(_ttt_client_execute_helo), (_ttt_client_init),
* src/ttt-client.h: * src/ttt-client.c:
(_ttt_client_execute_helo), (_ttt_client_init),
3.6.1.2. ERROR NOTPLAYING
3.6.2. Moving errors
3.6.2.1. ERROR NOTYOURTURN
3.6.1.2. ERROR NOTPLAYING
3.6.2. Moving errors
3.6.2.1. ERROR NOTYOURTURN
-
\ No newline at end of file
char **args,
int num_args);
char **args,
int num_args);
+static ttt_error_t
+_ttt_client_execute_who (ttt_client_t *client,
+ char **args,
+ int num_args);
+
static ttt_error_t
_ttt_client_execute_quit (ttt_client_t *client,
char **args,
static ttt_error_t
_ttt_client_execute_quit (ttt_client_t *client,
char **args,
ttt_command_description_t command_descriptions[] = {
{"HELO", 1, _ttt_client_execute_helo},
ttt_command_description_t command_descriptions[] = {
{"HELO", 1, _ttt_client_execute_helo},
+ {"WHO", 0, _ttt_client_execute_who},
{"QUIT", 0, _ttt_client_execute_quit}
};
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
{"QUIT", 0, _ttt_client_execute_quit}
};
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
+static ttt_error_t
+_ttt_client_execute_who (ttt_client_t *client,
+ char **args,
+ int num_args)
+{
+ const char *response;
+
+ assert (num_args == 0);
+
+ response = ttt_server_who (client->server);
+
+ 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,
static ttt_error_t
_ttt_client_execute_quit (ttt_client_t *client,
char **args,
pthread_mutex_unlock (&server->mutex);
}
pthread_mutex_unlock (&server->mutex);
}
+/* Exported: See ttt-server.h for documentation. */
void
ttt_server_broadcast (ttt_server_t *server, const char *message)
{
void
ttt_server_broadcast (ttt_server_t *server, const char *message)
{
pthread_mutex_unlock (&server->mutex);
}
pthread_mutex_unlock (&server->mutex);
}
+/* Exported: See ttt-server.h for documentation. */
+const char*
+ttt_server_who (ttt_server_t *server)
+{
+ int i;
+ char *response;
+
+ pthread_mutex_lock (&server->mutex);
+
+ xasprintf (&response, "WHO");
+
+ for (i = 0; i < server->num_clients; i++)
+ xasprintf (&response, "%s %s", response, ttt_client_get_name(server->clients[i]));
+
+ xasprintf (&response, "%s\n", response);
+
+ pthread_mutex_unlock (&server->mutex);
+
+ return response;
+}
+
/* Exported: See ttt-server.h for documentation. */
const char*
ttt_server_get_host (ttt_server_t *server)
/* Exported: See ttt-server.h for documentation. */
const char*
ttt_server_get_host (ttt_server_t *server)
void
ttt_server_broadcast (ttt_server_t *server, const char *message);
void
ttt_server_broadcast (ttt_server_t *server, const char *message);
+
+/* Returns the WHO response. The return string is allocated in this
+ * function and will need to be free'd by the caller.
+ *
+ * Locking: The server mutex will be acquired and held throughout the
+ * execution of this function. Each client mutex may also be acquired
+ * and held by functions called during the execution of this function.
+ *
+ * Errors: If an error such as an IO error occurs, this function will
+ * not return.
+ */
+const char*
+ttt_server_who (ttt_server_t *server);
+
/* Gets the server hostname.
*
*/
/* Gets the server hostname.
*
*/