Skip to content

Instantly share code, notes, and snippets.

@jeena
Last active December 17, 2015 19:19
Show Gist options
  • Save jeena/5659404 to your computer and use it in GitHub Desktop.
Save jeena/5659404 to your computer and use it in GitHub Desktop.
You make a connection to the server via your socket and then send
this (without Token because you don't have one yet):
-----------------------------
Server-Command: hello
Content-Length: 0
-----------------------------
A new table will begenerated for you and you get a token in the
data section:
-----------------------------
Client-Command: hello
Client-Encoding: text
Content-Size: 79
GGS-Version: 1.0
Accept: text
bad9b034-7eef-417d-a209-6406722d0cd1,true,55149782-2ab8-4b01-bfa0-e733e0ea7f65
-----------------------------
The data part is a comma separated list with user-token, should define
the source code, table-token. You use the user-token every time you
talk to the server. You can give the table-taken to a friend so he
will be placed on the same table as you.
You send a define Server-Command with the JS-source-code of the game
to the server:
-----------------------------
Token: bad9b034-7eef-417d-a209-6406722d0cd1
Server-Command: define
Content-Length: 108
function playerCommand(player_id, command, args) {
GGS.sendCommandToAll("echo", command + " - " + args);
}
-----------------------------
The server will set up everything for you and when it is done you will get
this response back:
-----------------------------
Client-Command: defined
Client-Encoding: text
Content-Size: 2
GGS-Version: 1.0
Accept: text
ok
-----------------------------
From this time on you can send game-commands to the server which will be
delivered to the JSVM where your game which you defined runs. every game
command will call the function playerCommand(player_id, command, args)
which you defined. In the example we defined just a echo function which
delivers everything which comes in to all players. So we could send
something like that:
-----------------------------
Token: bad9b034-7eef-417d-a209-6406722d0cd1
Game-Command: something
Content-Length: 9
test 123
-----------------------------
this will call:
playerCommand("bad9b034-7eef-417d-a209-6406722d0cd1", "something". "test 123")
which will run:
GGS.sendCommandToAll("echo", "something - test 123")
which will result in a message to each user on that table which will look
like this:
-----------------------------
Client-Command: echo
Client-Encoding: text
Content-Size: 20
GGS-Version: 1.0
Accept: text
something - test 123
-----------------------------
Now if you want another player to sit on the same table you need to do a little
bit less. Basically you will do a hello with a table token which will make you
seated on the same table as the person you got your token from.
-----------------------------
Server-Command: hello
Content-Length: 36
55149782-2ab8-4b01-bfa0-e733e0ea7f65
-----------------------------
The server will answer you with your own player token but the same table-token:
-----------------------------
Client-Command: hello
Client-Encoding: text
Content-Size: 79
GGS-Version: 1.0
Accept: text
d8796dee-f129-4bfe-bdc8-808f94146691,false,55149782-2ab8-4b01-bfa0-e733e0ea7f65
-----------------------------
You see that it also returns "false" to indicate that the game is already set
up by some other player so you don't need to define it anymore (do not need
to send the source code.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment