[Commit] librr/src rr_players.c, NONE, 1.1 Makefile.am, 1.6, 1.7 rr.h, 1.17, 1.18 rr_client.c, 1.11, 1.12 rrint.h, 1.8, 1.9

Carl Worth commit at keithp.com
Sat Jan 10 21:07:07 PST 2004


Committed by: cworth

Update of /local/src/CVS/librr/src
In directory home.keithp.com:/tmp/cvs-serv30959/src

Modified Files:
	Makefile.am rr.h rr_client.c rrint.h 
Added Files:
	rr_players.c 
Log Message:

        * src/rr_players.c (rr_players_create):
        (rr_players_destory):
        (rr_players_add):
        (rr_players_remove):
        (rr_players_find):
        (rr_players_set_score):
        (rr_players_get_score): A couple of structures and a few functions
        for managing a list of players and their scores.

        * src/rr_client.c (_rr_client_init):
        (_rr_client_fini):
        (rr_client_join):
        (rr_client_part): Save current game name in client->game.
        (rr_client_players): Fix this request which was totally
        broken. Now return an rr_players_t rather than a list of strings.


--- NEW FILE: rr_players.c ---
(This appears to be a binary file; contents omitted.)

Index: Makefile.am
===================================================================
RCS file: /local/src/CVS/librr/src/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Makefile.am	19 Jun 2003 11:39:15 -0000	1.6
+++ Makefile.am	11 Jan 2004 05:07:04 -0000	1.7
@@ -9,6 +9,7 @@
 	rr_client.c \
 	rr_history.c \
 	rr_notice.c \
+	rr_players.c \
 	rr_string.c \
 	rr_strbuf.c
 

Index: rr.h
===================================================================
RCS file: /local/src/CVS/librr/src/rr.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- rr.h	12 Jul 2003 01:50:09 -0000	1.17
+++ rr.h	11 Jan 2004 05:07:04 -0000	1.18
@@ -31,6 +31,18 @@
 typedef struct rr_board rr_board_t;
 typedef struct rr_client rr_client_t;
 
+typedef struct rr_player
+{
+    char *username;
+    int score;
+} rr_player_t;
+
+typedef struct rr_players
+{
+    rr_player_t *players;
+    int num_players;
+} rr_players_t;
+
 typedef enum {
     RR_STATUS_SUCCESS = 0,
     RR_STATUS_NO_MEMORY,
@@ -397,7 +409,7 @@
 rr_client_quit (rr_client_t *client);
 
 rr_status_t
-rr_client_players (rr_client_t *client, char ***players);
+rr_client_players (rr_client_t *client, rr_players_t **players);
 
 rr_status_t
 rr_client_watchers (rr_client_t *client, char ***watchers);
@@ -470,6 +482,29 @@
 void
 rr_notice_destroy (rr_notice_t *notice);
 
+/* rr_players.c */
+
+rr_players_t *
+rr_players_create (void);
+
+void
+rr_players_destory (rr_players_t *players);
+
+rr_status_t
+rr_players_add (rr_players_t *players, const char *username);
+
+rr_status_t
+rr_players_remove (rr_players_t *players, const char *username);
+
+rr_player_t *
+rr_players_find (rr_players_t *players, const char *username);
+
+void
+rr_players_set_score (rr_players_t *players, const char *username, int score);
+
+int
+rr_players_get_score (rr_players_t *players, const char *username);
+
 /* rr.c */
 
 const char *

Index: rr_client.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr_client.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- rr_client.c	3 Jul 2003 18:28:56 -0000	1.11
+++ rr_client.c	11 Jan 2004 05:07:04 -0000	1.12
@@ -125,6 +125,7 @@
     client->ptr = 0;
     client->end = 0;
     client->notice_queue = NULL;
+    client->game = NULL;
 
     status = _rr_client_connect (client, host, port);
     if (status)
@@ -168,6 +169,11 @@
 	free (notice);
     }
 
+    if (client->game) {
+	free (client->game);
+	client->game = NULL;
+    }
+
     return RR_STATUS_SUCCESS;
 }
 
@@ -468,9 +474,43 @@
 }
 
 rr_status_t
-rr_client_players (rr_client_t *client, char ***players)
+rr_client_players (rr_client_t *client, rr_players_t **players_ret)
 {
-    return _rr_client_cmd_request (client, RR_CMD_PLAYERS, NULL, players);
+    rr_status_t status;
+    rr_players_t *players;
+    char **players_str;
+    char **p;
+    int i;
+
+    *players_ret = NULL;
+
+    status = _rr_client_cmd_request (client, RR_CMD_PLAYERS, client->game, &players_str);
+    if (status)
+	return status;
+
+    players = rr_players_create ();
+    if (players == NULL)
+	return RR_STATUS_NO_MEMORY;
+
+    i = 0;
+    for (p = players_str; *p; p++)
+	i++;
+    players->num_players = (i-1) / 2;
+
+    players->players = malloc (players->num_players * sizeof (rr_player_t));
+    if (players->players == NULL) {
+	free (players);
+	return RR_STATUS_NO_MEMORY;
+    }
+
+    for (i = 0; i < players->num_players; i++) {
+	players->players[i].username = strdup (players_str[2*i]);
+	players->players[i].score = atoi (players_str[2*i+1]);
+    }
+
+    *players_ret = players;
+
+    return RR_STATUS_SUCCESS;
 }
 
 rr_status_t
@@ -494,7 +534,17 @@
 rr_status_t
 rr_client_join (rr_client_t *client, const char *game)
 {
-    return _rr_client_cmd_request (client, RR_CMD_JOIN, game, NULL);
+    rr_status_t status;
+
+    status = _rr_client_cmd_request (client, RR_CMD_JOIN, game, NULL);
+    if (status)
+	return status;
+
+    if (client->game)
+	free (client->game);
+    client->game = strdup (game);
+
+    return RR_STATUS_SUCCESS;
 }
 
 rr_status_t
@@ -539,7 +589,18 @@
 rr_status_t
 rr_client_part (rr_client_t *client)
 {
-    return _rr_client_cmd_request (client, RR_CMD_PART, NULL, NULL);
+    rr_status_t status;
+
+    status = _rr_client_cmd_request (client, RR_CMD_PART, NULL, NULL);
+    if (status)
+	return status;
+
+    if (client->game) {
+	free (client->game);
+	client->game = NULL;
+    }
+
+    return RR_STATUS_SUCCESS;
 }
 
 rr_status_t

Index: rrint.h
===================================================================
RCS file: /local/src/CVS/librr/src/rrint.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rrint.h	26 Jun 2003 01:18:34 -0000	1.8
+++ rrint.h	11 Jan 2004 05:07:04 -0000	1.9
@@ -123,6 +123,8 @@
     int ptr;
     int end;
     rr_notice_elt_t *notice_queue;
+
+    char *game;
 };
 
 typedef struct rr_strbuf {




More information about the Commit mailing list