[Commit] rrserver dispatch.5c,1.24,1.25 games.5c,1.21,1.22 protocol,1.27,1.28 server.5c,1.12,1.13

Keith Packard commit at keithp.com
Thu Jun 12 11:59:18 PDT 2003


Committed by: keithp

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

Modified Files:
	dispatch.5c games.5c protocol server.5c 
Log Message:
add version command, change HELO protocol

Index: dispatch.5c
===================================================================
RCS file: /local/src/CVS/rrserver/dispatch.5c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- dispatch.5c	10 Jun 2003 07:07:57 -0000	1.24
+++ dispatch.5c	12 Jun 2003 17:59:16 -0000	1.25
@@ -79,6 +79,25 @@
 		void(string[])  f;
 	    } Cmd;
 
+	    string random_user () {
+		const string	consonant = "bcdfghjklmnpqrstvwxz";
+		const string	vowel = "aeiou";
+		
+		string randc (string a)
+		{
+		    int i = PRNG::randint (String::length (a));
+		    return String::substr (a, i, 1);
+		}
+		string randthree ()
+		{
+		    return (randc (consonant) + 
+			    randc (vowel) + 
+			    randc (consonant));
+		}
+
+		return randthree () + randthree ();
+	    }
+	    
 	    Cmd[] commands = {
 		{	
 		    command = "HELO", 
@@ -87,11 +106,22 @@
 		    "Sets the session username.  Must be used before\n"+
 		    "any other command (aside from QUIT)\n",
 		    f = void func (string[] w) {
-			string username = w[0];
+			string username;
+			if (dim (w) == 0) {
+			    do
+				username = random_user ();
+			    while (Clients::find (username) != ClientRef.none);
+			} else
+			    username = w[0];
 			if (Clients::find (username) != ClientRef.none)
 			    raise rr_error (Error.INVALIDNAME);
 			c.user.username = username;
-			respond ("HELO %s\n", server_id);
+			Sockets::sockaddr s = Sockets::getsockname (c.f);
+			respond ("HELO %s %s %s %d\n",
+				 server_id,
+				 username,
+				 Sockets::addr_to_string (s.addr),
+				 s.port);
 			Clients::server_send ("NOTICE USER %s\n", username);
 		    }
 		},
@@ -560,6 +590,18 @@
 			    for (int i = 0; i < dim(commands); i++)
 				print_help (&commands[i], false);
 			}
+		    }
+		},
+		{
+		    command = "VERSION",
+		    usage = "VERSION <client-version>",
+		    describe =
+		    "Negotiate protocol version.\n",
+		    f = void func (string[] w) {
+			int version = min (string_to_integer (w[0],
+							      server_version));
+			c.version = version;
+			respond ("VERSION %d\n", version);
 		    }
 		}
 	    };

Index: games.5c
===================================================================
RCS file: /local/src/CVS/rrserver/games.5c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- games.5c	10 Jun 2003 07:07:57 -0000	1.21
+++ games.5c	12 Jun 2003 17:59:16 -0000	1.22
@@ -236,6 +236,8 @@
 		case client c:
 		    game_send (&g, "NOTICE ACTIVE %s %d\n",
 			       c.user.username, c.bid.bid.number);
+		    Clients::client_send (&c, "NOTICE ACTIVATE %d\n",
+					  c.bid.bid.number);
 		    break;
 		}
 	    }

Index: protocol
===================================================================
RCS file: /local/src/CVS/rrserver/protocol,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- protocol	7 Jun 2003 19:09:02 -0000	1.27
+++ protocol	12 Jun 2003 17:59:16 -0000	1.28
@@ -40,11 +40,14 @@
     use must be done through some external mechanism.  Once connected,
     the client must identify itself:
     
-    HELO <username>
+    HELO [<username>]
     
     ->
     
-    HELO <servername>
+    HELO <servername> <username> <server-addr> <server-port>
+
+    If the client doesn't supply <username>, the server will compute
+    one and return it.
 
 1.2. Global commands
 
@@ -90,6 +93,20 @@
 
 	QUIT
 
+    1.2.6. Version
+
+	VERSION <client-version-number>
+
+	->
+
+	VERSION <server-version-number>
+
+	Negotiates version number between client and server.  The server
+	will respond with a version no higher than the client version
+	number, but it may be lower.  Version numbers are integers.
+
+	This document describes protocol version 1.
+
 1.3. Game management commands
 
     1.3.1. Listing players in a game
@@ -417,7 +434,8 @@
 	
 	    NOTICE GAMESTATE <state>
 
-	    Game state has changed to <state>
+	    Game state has changed to <state>.  <state> is one
+	    of "NEW", "BID", "SHOW" or "DONE".
 
 	2.2.1.2. Next turn (game)
 
@@ -459,7 +477,7 @@
 	
 	2.2.2.3. Timer (game)
 	
-	    NOTICE TIME <seconds>
+	    NOTICE TIMER <seconds>
     
 	    Timer ticks are sent every 10 seconds after the first
 	    bid has been made
@@ -517,6 +535,20 @@
 
 	    The indicated user has demonstrated a solution and
 	    received a point.
+
+2.3. User notices
+
+     These notices are sent to a single user
+
+     2.3.1. Solving notices
+
+	Notices sent during the solving phase of a turn
+	    	
+	2.3.1.1. Notify active player (user)
+
+	    NOTICE ACTIVATE <bid>
+
+	    Sent to the player which has just become active
 
 3. Errors
 

Index: server.5c
===================================================================
RCS file: /local/src/CVS/rrserver/server.5c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- server.5c	10 Jun 2003 07:07:57 -0000	1.12
+++ server.5c	12 Jun 2003 17:59:16 -0000	1.13
@@ -33,10 +33,12 @@
 
     mutex   server_mutex = Mutex::new ();
 
-    string	server_id = "RicochetServer";
+    string	server_id = Sockets::gethostname();
 
     public void set_server_id (string id) { server_id = id; }
 
+    const int server_version = 1;
+
     public bool lock () {
 	Mutex::acquire (server_mutex);
 #	printf ("lock %v\n", Thread::current());
@@ -80,6 +82,7 @@
 	GameRef	    game;
 	int	    score;
 	int	    games;
+	int	    version;
 	Bid	    bid;
 	bool	    playing;
 	bool	    abandon;




More information about the Commit mailing list