[Commit]
rrserver clients.5c,1.3,1.4 dispatch.5c,1.9,1.10 games.5c,1.9,1.10
protocol,1.18,1.19 server.5c,1.6,1.7
Keith Packard
commit at keithp.com
Fri May 30 15:39:14 PDT 2003
- Previous message: [Commit]
rrserver dispatch.5c,1.8,1.9 games.5c,1.8,1.9 protocol,1.17,1.18
readreq.5c,1.4,1.5 rr.5c,1.3,1.4 send.5c,1.3,1.4 server.5c,1.5,1.6
- Next message: [Commit] rrserver dispatch.5c,1.10,1.11 games.5c,1.10,1.11
protocol,1.19,1.20 rr.5c,1.4,1.5 send.5c,1.4,1.5 server.5c,1.7,1.8
timer.5c,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: keithp
Update of /local/src/CVS/rrserver
In directory home.keithp.com:/tmp/cvs-serv12595
Modified Files:
clients.5c dispatch.5c games.5c protocol server.5c
Log Message:
Track number of games won, TURN moves to new game
Index: clients.5c
===================================================================
RCS file: /local/src/CVS/rrserver/clients.5c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- clients.5c 30 May 2003 20:26:07 -0000 1.3
+++ clients.5c 30 May 2003 21:39:11 -0000 1.4
@@ -83,9 +83,7 @@
f = f,
user = User.none,
game = GameRef.none,
- score = 0,
- bid = Bid.none,
- playing = false
+ games = 0
}));
return &clients[dim(clients)-1];
}
@@ -101,5 +99,36 @@
public void print (&Client c) {
printf ("%v\n", c);
}
+
+ public void print_client (&Client c, &Client o) {
+ union switch (o.user) {
+ case none:
+ break;
+ case username u:
+ client_send (&c, " %s", u);
+ break;
+ }
+ }
+
+ public void print_client_score (&Client c, &Client o) {
+ union switch (o.user) {
+ case none:
+ break;
+ case username u:
+ client_send (&c, " %s %d", u, o.score);
+ break;
+ }
+ }
+
+ public void print_client_games (&Client c, &Client o) {
+ union switch (o.user) {
+ case none:
+ break;
+ case username u:
+ client_send (&c, " %s %d", u, o.games);
+ break;
+ }
+ }
+
}
}
Index: dispatch.5c
===================================================================
RCS file: /local/src/CVS/rrserver/dispatch.5c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- dispatch.5c 30 May 2003 21:05:09 -0000 1.9
+++ dispatch.5c 30 May 2003 21:39:11 -0000 1.10
@@ -44,26 +44,6 @@
Clients::client_send (&c, fmt, args...);
}
- void print_client (&Client o) {
- union switch (o.user) {
- case none:
- break;
- case username u:
- respond (" %s", u);
- break;
- }
- }
-
- void print_client_score (&Client c) {
- union switch (c.user) {
- case none:
- break;
- case username u:
- respond (" %s %d", u, c.score);
- break;
- }
- }
-
void assert_user ()
{
if (c.user == User.none)
@@ -76,6 +56,18 @@
raise error (Error.NOTINGAME);
}
+ void print_client_score (&Client o) {
+ Clients::print_client_score (&c, &o);
+ }
+
+ void print_client_games (&Client o) {
+ Clients::print_client_games (&c, &o);
+ }
+
+ void print_client (&Client o) {
+ Clients::print_client (&c, &o);
+ }
+
void helo (string username) {
if (Clients::find (username) != ClientRef.none)
raise error (Error.INVALIDNAME);
@@ -87,7 +79,7 @@
void who () {
assert_user ();
respond ("WHO");
- Clients::iterate (print_client);
+ Clients::iterate (print_client_games);
respond ("\n");
}
@@ -112,10 +104,18 @@
assert_user ();
&Game g = Games::find (game);
respond ("WATCHERS");
- Games::iterate_client (&g, print_client_score, false, true);
+ Games::iterate_client (&g, print_client, false, true);
respond ("\n");
}
+ void gameinfo (string game) {
+ &Game g = Games::find (game);
+
+ }
+
+ void userinfo (string username) {
+ }
+
void new(string game) {
assert_user ();
&Game g = Games::new (game);
@@ -245,10 +245,10 @@
watchers (w.game);
break;
case GAMEINFO g:
-# gameinfo (g.game);
+ gameinfo (g.game);
break;
case USERINFO u:
-# userinfo (u.username);
+ userinfo (u.username);
break;
case NEW n:
new (n.game);
Index: games.5c
===================================================================
RCS file: /local/src/CVS/rrserver/games.5c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- games.5c 30 May 2003 21:05:09 -0000 1.9
+++ games.5c 30 May 2003 21:39:11 -0000 1.10
@@ -91,6 +91,19 @@
iterate_client (&g, message_client, true, true);
}
+ public void game_send_client_scores (&Game g, string fmt, poly args...) {
+ void message_client (&Client c) {
+ Clients::client_send (&c, fmt, args...);
+
+ void print_client_score (&Client o) {
+ Clients::print_client_score (&c, &o);
+ }
+ iterate_client (&g, print_client_score, true, false);
+ Clients::client_send (&c, "\n");
+ }
+ iterate_client (&g, message_client, true, true);
+ }
+
bool any_bids (&Game g) {
bool any = false;
void bid_set (&Client c) {
@@ -232,8 +245,17 @@
return &c;
}
+ void next_game (&Game g);
+
/* select the next target */
void next_target (&Game g) {
+
+ if (dim(g.targets) == 0)
+ {
+ next_game (&g);
+ return;
+ }
+
Target t = g.targets[0];
g.targets = (Target[dim(g.targets)-1]) { [i] = g.targets[i+1] };
g.history = (ObjectLoc[*]) {};
@@ -289,6 +311,14 @@
return t;
}
+ void init (&Game g) {
+ g.board = Boards::random_board ();
+ g.targets = random_targets ();
+ g.active = ClientRef.none;
+ g.timer_serial = 0;
+ next_target (&g);
+ }
+
public &Game new (string suggestion) {
string name;
for (int n = 0;
@@ -299,15 +329,26 @@
&Game g = insert ();
g.name = name;
g.clients = ((&Client)[*]) {};
- g.board = Boards::random_board ();
- g.targets = random_targets ();
- g.active = ClientRef.none;
- g.timer_serial = 0;
- next_target (&g);
+ init (&g);
Clients::server_send ("NOTICE NEW %s\n", g.name);
return &g;
}
+ void next_game (&Game g) {
+ ClientRef winner = ClientRef.none;
+ void find_winner (&Client c) {
+ if (c.score > 0 &&
+ (winner == ClientRef.none || c.score >
+ winner.client.score))
+ winner = (ClientRef.client) (&c);
+ }
+ iterate_client (&g, find_winner, true, false);
+ if (winner != ClientRef.none)
+ winner.client.games++;
+ game_send_client_scores (&g, "NOTICE GAMEOVER");
+ init (&g);
+ }
+
public ClientRef active_client (&Game g) {
return g.active;
}
Index: protocol
===================================================================
RCS file: /local/src/CVS/rrserver/protocol,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- protocol 30 May 2003 21:05:09 -0000 1.18
+++ protocol 30 May 2003 21:39:11 -0000 1.19
@@ -53,7 +53,9 @@
->
- WHO <username1> <username2> ...
+ WHO <username1> <games1> <username2> <games2> ...
+
+ lists connected users and the number of games they've won.
1.3. Listing available games
@@ -395,6 +397,10 @@
2.13. Next turn (game)
NOTICE TURN <color> <shape>
+
+2.14. Next game (game)
+
+ NOTICE GAME
2.14. Message (all)
Index: server.5c
===================================================================
RCS file: /local/src/CVS/rrserver/server.5c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- server.5c 30 May 2003 21:05:09 -0000 1.6
+++ server.5c 30 May 2003 21:39:11 -0000 1.7
@@ -76,6 +76,7 @@
User user;
GameRef game;
int score;
+ int games;
Bid bid;
bool playing;
bool abandon;
- Previous message: [Commit]
rrserver dispatch.5c,1.8,1.9 games.5c,1.8,1.9 protocol,1.17,1.18
readreq.5c,1.4,1.5 rr.5c,1.3,1.4 send.5c,1.3,1.4 server.5c,1.5,1.6
- Next message: [Commit] rrserver dispatch.5c,1.10,1.11 games.5c,1.10,1.11
protocol,1.19,1.20 rr.5c,1.4,1.5 send.5c,1.4,1.5 server.5c,1.7,1.8
timer.5c,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list