]> git.cworth.org Git - ttt/commitdiff
* AUTHORS: Add Richard D. Worth
authorRichard Worth <richard@theworths.org>
Thu, 24 Nov 2005 16:42:21 +0000 (16:42 +0000)
committerRichard Worth <richard@theworths.org>
Thu, 24 Nov 2005 16:42:21 +0000 (16:42 +0000)
        * 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.

AUTHORS
ChangeLog
TODO
src/ttt-client.c
src/ttt-server.c
src/ttt-server.h

diff --git a/AUTHORS b/AUTHORS
index eb9c6f1f095ee93ab672006ae46d660c393cdd72..5be78c923cd0ef30fabab95e842e7c7f0c9aec79 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,2 +1,3 @@
 Carl Worth <cworth@cworth.org>
 Carl Worth <cworth@cworth.org>
+Richard D. Worth <richard@theworths.org>
 
 
index dc9d723180edd2541cb990da2d4fe2ee5f51b28f..a545b6451904a14880e8dab6627c6148527c6677 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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.
@@ -26,9 +35,9 @@
        * 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),
diff --git a/TODO b/TODO
index 98b90f5a92d6362756c9125ab7690609f2e7ff82..79d35fbc0a8a9a1eddca801ba9f077370975b2bd 100644 (file)
--- a/TODO
+++ b/TODO
@@ -49,4 +49,4 @@ S C
     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
+
index 1c23fcc3aced5d29ffa25ba19b4c3bebde00fa50..9c9b819f8c1a3dfeebcbe5c693e58811bca45c9b 100644 (file)
@@ -51,6 +51,11 @@ _ttt_client_execute_helo (ttt_client_t *client,
                          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,
@@ -64,6 +69,7 @@ typedef struct _ttt_command_description {
 
 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]))
@@ -97,6 +103,24 @@ _ttt_client_execute_helo (ttt_client_t *client,
     return TTT_ERROR_NONE;
 }
 
     return TTT_ERROR_NONE;
 }
 
+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,
index 450582b7667dae57fa374abc2d126dbfb76e4bf1..60276d39ccf691bed7b86e90822e02d3fb90abd7 100644 (file)
@@ -120,6 +120,7 @@ ttt_server_unregister_client (ttt_server_t *server, ttt_client_t *client)
     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)
 {
@@ -133,6 +134,27 @@ 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)
index 7cf3d9707ecc95aec9bbfa8e02dc8a20ea9d1137..fef70308dbb59b91df593de7b7fc39c2ba1d85e3 100644 (file)
@@ -59,6 +59,20 @@ ttt_server_unregister_client (ttt_server_t *server, ttt_client_t *client);
 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.
  *
  */