From f3d7dadce78258d5cb5f105df11f2435f630113f Mon Sep 17 00:00:00 2001 From: jeena Date: Fri, 11 Feb 2011 06:29:29 -0800 Subject: [PATCH] Rewritten the protocol Updated Protocol draft 2.0 (markdown) --- Protocol-draft-2.0.md | 125 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 107 insertions(+), 18 deletions(-) diff --git a/Protocol-draft-2.0.md b/Protocol-draft-2.0.md index 021b2a7..3d15936 100644 --- a/Protocol-draft-2.0.md +++ b/Protocol-draft-2.0.md @@ -1,22 +1,111 @@ The 2.0 specification is quite different from the old one. This one is based on a stable and mature protocol; HTTP. We will borrow certain elements from the protocol, with main focus on HTTP's POST style. Here is a link: http://www.jmarshall.com/easy/http/#http1.1c1 Below is a typical POST message in HTTP. - POST /path/script.cgi HTTP/1.0 - From: frog@jmarshall.com - User-Agent: HTTPTool/1.0 - Content-Type: application/x-www-form-urlencoded - Content-Length: 32 - - home=Cosby&favorite+flavor=flies +
POST /path/script.cgi HTTP/1.0
+From: frog@jmarshall.com
+User-Agent: HTTPTool/1.0
+Content-Type: application/x-www-form-urlencoded
+Content-Length: 32
 
-Our protocol looks like the following:
-    Token: 1001
-    Command: define
-    Content-Type: text
-    Content-Length: 40
-    
-    function helloWorld(x) {return x + 2 ;}
+home=Cosby&favorite+flavor=flies
-The following commands are to be supported: - define defines new javascript - run runs existing javascript - hello request a new token \ No newline at end of file +Our protocol is, unlike HTTP, asynchronous and statefull. After initializing a socket you send the hello server command: + +
Server-Command: hello
+User-Agent: Some Game v 0.2
+Accept: plaintext
+ +You will get an answer with your own client token: + +
Server-Command: token
+Content-Type: plaintext
+Content-Length: 45
+Server-Version: 1.0
+Accept: gzip,plaintext
+
+913AB7FD-F795-45E4-B31C-035FD81D0773
+ +Then you will define your game, that means, you send the source code of your game to the server: + +
Token: 913AB7FD-F795-45E4-B31C-035FD81D0773
+Server-Command: define
+Content-Type: text
+Content-Length: 666
+
+function userCommand(user, cmd, args) {
+	if(cmd == "moveUp") {
+		moveUp(user, args);
+	} else if(cmd == "moveDown") {
+		moveDown(user, args);
+	} else if(cmd == "chat") {
+		chat(user, args);
+	}
+}
+
+function moveUp(user, x) {
+	var key = "userpos_x_" + user.id;
+  var value = GGS.world.get(key);
+	value += x;
+	GGS.world.set(key, value);
+}
+
+function moveDown(user, x) {
+	var key = "userpos_x_" + user.id;
+  var value = GGS.world.get(key);
+	value -= x;
+	GGS.world.set(key, value);
+}
+
+function chat(user, text) {
+	var size = GGS.users.length;
+	for(var i = 0; i
+
+Now you can call commands in that game:
+
+
Token: 913AB7FD-F795-45E4-B31C-035FD81D0773
+Command: moveUp
+Content-Type: text
+Content-Length: 40
+
+5
+ +or: + +
Token: 913AB7FD-F795-45E4-B31C-035FD81D0773
+Command: chat
+Content-Type: text
+Content-Length: 90
+
+Hi guys,
+
+My name is Mimi and I'm new here. Would be great to here some of
+your stories.
+ +If you are not the first client who connects to the server in this game session, then you will have got a game token which will tell the server to which game you would like to connect (you get the game token from your friends or from the game lobby). + +
Server-Command: hello
+Game-Session-Token: 018FF079-B383-4523-93A2-6053E7EDC2BC
+User-Agent: Some Game v 0.2
+Accept: zip,plaintext
+ +Here you would again get an answer with your own Client token. + +If you are already connected to a game and would like to obtain the game token you send the command game-session-token: + +
Token: 913AB7FD-F795-45E4-B31C-035FD81D0773
+Server-Command: game-session-token
+User-Agent: Some Game v 0.2
+Accept: plaintext
+ +You will get as an answer just the game session token: + +
Server-Command: game-session-token
+Content-Type: plaintext
+Content-Length: 45
+Server-Version: 1.0
+Accept: gzip,plaintext
+
+018FF079-B383-4523-93A2-6053E7EDC2BC