[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

Keith Packard commit at keithp.com
Fri May 30 16:15:16 PDT 2003


Committed by: keithp

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

Modified Files:
	dispatch.5c games.5c protocol rr.5c send.5c server.5c timer.5c 
Log Message:
implement gameinfo and userinfo

Index: dispatch.5c
===================================================================
RCS file: /local/src/CVS/rrserver/dispatch.5c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- dispatch.5c	30 May 2003 21:39:11 -0000	1.10
+++ dispatch.5c	30 May 2003 22:15:14 -0000	1.11
@@ -109,11 +109,69 @@
 	    }
 
 	    void	gameinfo (string game) {
+		assert_user ();
 		&Game	g = Games::find (game);
+
+		int	    turn = 17 - dim (g.targets);
 		
+		int	    remain = 0;
+		if (g.state == GameState.Bidding)
+		{
+		    remain = g.expire_time - time();
+		    if (remain < 0) remain = 0;
+		}
+		
+		int	    bid = 0;
+		union switch (Games::lowest_bidder (&g)) {
+		case none: break;
+		case client c: bid = c.bid.number; break;
+		}
+
+		string	    active = "";
+		switch (g.state) {
+		case GameState.Showing:
+		case GameState.Solved:
+		    active = g.active.client.user.username;
+		    break;
+		}
+
+		respond ("GAMEINFO %d %C %S %G %d %d %s\n",
+			 turn, 
+			 g.target.color,
+			 g.target.shape,
+			 g.state,
+			 remain,
+			 bid,
+			 active);
 	    }
 
 	    void	userinfo (string username) {
+		assert_user ();
+		ClientRef	cr = Clients::find (username);
+		union switch (cr) {
+		case none:
+		    raise error (Error.NOUSER);
+		case client c:
+		    string  game = "";
+		    bool    playing = false;
+		    int	    score = 0;
+		    int	    bid = 0;
+
+		    union switch (c.game) {
+		    case none:	break;
+		    case game g:
+			game = g.name;
+			playing = c.playing;
+			if (playing)
+			{
+			    score = c.score;
+			    if (c.bid != Bid.none)
+				bid = c.bid.number;
+			}
+		    }
+		    respond ("USERINFO %s %b %d %d\n",
+			     game, playing, score, bid);
+		}
 	    }
 	    
 	    void	new(string game) {

Index: games.5c
===================================================================
RCS file: /local/src/CVS/rrserver/games.5c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- games.5c	30 May 2003 21:39:11 -0000	1.10
+++ games.5c	30 May 2003 22:15:14 -0000	1.11
@@ -124,7 +124,7 @@
 	    return all;
 	}
 	
-	ClientRef lowest_bidder (&Game g) {
+	public ClientRef lowest_bidder (&Game g) {
 	    Bid		min = Bid.none;
 	    ClientRef	min_client = ClientRef.none;
 	    void lower_bid (&Client c) {
@@ -182,7 +182,9 @@
 		    set_state (&g, GameState.Showing);
 		}
 
-		Timer::start (60, 10, lock, unlock, validate, notify, expire);
+		g.expire_time = Timer::start (g.expire_interval, 10, 
+					      lock, unlock, 
+					      validate, notify, expire);
 		break;
 	    case GameState.Showing:
 		set_active (&g);
@@ -256,19 +258,19 @@
 		return;
 	    }
 
-	    Target  t = g.targets[0];
+	    g.target = g.targets[0];
 	    g.targets = (Target[dim(g.targets)-1]) { [i] = g.targets[i+1] };
 	    g.history = (ObjectLoc[*]) {};
-	    g.time = Time.none;
+	    g.expire_time = 0;
 	    g.state = GameState.New;
-	    Boards::set_target (&g.board, t.color, t.shape);
+	    Boards::set_target (&g.board, g.target.color, g.target.shape);
 
 	    void reset_client (&Client c) {
 		c.bid = Bid.none;
 		c.abandon = false;
 	    }
 	    iterate_client (&g, reset_client, true, false);
-	    game_send (&g, "NOTICE TURN %C %S\n", t.color, t.shape);
+	    game_send (&g, "NOTICE TURN %C %S\n", g.target.color, g.target.shape);
 	}
 
 	public void next_turn (&Game g) {
@@ -329,6 +331,7 @@
 	    &Game g = insert ();
 	    g.name = name;
 	    g.clients = ((&Client)[*]) {};
+	    g.expire_interval = 60;
 	    init (&g);
 	    Clients::server_send ("NOTICE NEW %s\n", g.name);
 	    return &g;

Index: protocol
===================================================================
RCS file: /local/src/CVS/rrserver/protocol,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- protocol	30 May 2003 21:39:11 -0000	1.19
+++ protocol	30 May 2003 22:15:14 -0000	1.20
@@ -120,7 +120,7 @@
 
 	<score> is a number from 0 to 17 indicating this players score
 
-	<bid> is either "none" indicating no bid or a number indicating
+	<bid> is either "0" indicating no bid or a number indicating
 	the users minimum bid.
 	
 1.7. Creating a new game
@@ -438,6 +438,12 @@
 	ERROR NOGAME
 
 	A game name was provided that does not exist.
+
+3.1. No such user
+
+	ERROR NOUSER
+
+	A user name was provided that does not exist.
 
 3.1. Not in game
 

Index: rr.5c
===================================================================
RCS file: /local/src/CVS/rrserver/rr.5c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- rr.5c	30 May 2003 21:05:09 -0000	1.4
+++ rr.5c	30 May 2003 22:15:14 -0000	1.5
@@ -200,6 +200,7 @@
 
     public typedef enum {
 	NOGAME,
+	NOUSER,
 	NOTINGAME,
 	NOTBIDDING,
 	NOTLOWER,

Index: send.5c
===================================================================
RCS file: /local/src/CVS/rrserver/send.5c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- send.5c	30 May 2003 21:05:09 -0000	1.4
+++ send.5c	30 May 2003 22:15:14 -0000	1.5
@@ -101,6 +101,7 @@
 	    void put_error (Error e) {
 		switch (e) {
 		case Error.NOGAME:	File::fprintf (f, "NOGAME"); break;
+		case Error.NOUSER:	File::fprintf (f, "NOUSER"); break;
 		case Error.NOTINGAME:	File::fprintf (f, "NOTINGAME"); break;
 		case Error.NOTBIDDING:	File::fprintf (f, "NOTBIDDING"); break;
 		case Error.NOTLOWER:	File::fprintf (f, "NOTLOWER"); break;
@@ -123,6 +124,10 @@
 	    void put_number (int n) {
 		File::fprintf (f, "%d", n);
 	    }
+
+	    void put_bool (bool b) {
+		File::fprintf (f, "%s", b ? "true" : "false");
+	    }
 	    
 	    /*
 	     * A private namespace to walk the format string 
@@ -203,6 +208,7 @@
 		    switch (fmt::c()) {
 		    case 's':	put_string (a); break;
 		    case 'd':	put_number (a); break;
+		    case 'b':	put_bool (a); break;
 		    case 'C':	put_color (a); break;
 		    case 'D':	put_direction (a); break;
 		    case 'S':	put_shape (a); break;

Index: server.5c
===================================================================
RCS file: /local/src/CVS/rrserver/server.5c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- server.5c	30 May 2003 21:39:11 -0000	1.7
+++ server.5c	30 May 2003 22:15:14 -0000	1.8
@@ -97,8 +97,10 @@
 	GameState	state;
 	(&Client)[*]	clients;
 	Target[*]	targets;
+	Target		target;
 	Board		board;
-	Time		time;
+	int		expire_interval;
+	int		expire_time;
 	ClientRef	active;
 	ObjectLoc[*]    history;
 	int		timer_serial;

Index: timer.5c
===================================================================
RCS file: /local/src/CVS/rrserver/timer.5c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- timer.5c	30 May 2003 06:47:40 -0000	1.1
+++ timer.5c	30 May 2003 22:15:14 -0000	1.2
@@ -23,7 +23,7 @@
  */
 
 public namespace Timer {
-    public void start (int expire_delta, int notify_delta,
+    public int start (int expire_delta, int notify_delta,
 		       bool() lock, bool () unlock,
 		       bool() validate,
 		       void(int number) notify,
@@ -61,5 +61,6 @@
 	}
 
 	fork timer();
+	return expire_time;
     }
 }




More information about the Commit mailing list