GameServer is a project mainly written in JavaScript, it's free.
A experiment with making a generic game server in node, starting with an X and O game
My plan is to build a server layer which can act as a RESTFUL interface for any turn based, board game. It currently supports the following:
Each game file must create a game object (can be named anything you like) with the following defined:
@params
@params
@params
output:
note: This is quite a dangerous function, the user can pass anything in as options and this must be vetted by the game logic. It also must be parsed using the game logic. This may change, I have to think about it.
@params
output:
I decided to write a game to show the power of this server. When writing a game for this server, the most important part will be the game logic which sits behind the server. This game logic must do a lot, it must provide the above functions in this generic way, while also working out its individuals needs and quirks.
I made an XO game for example as it seemed easy to write a good XO game which would demonstrate the power.
Heres the commands above abstracted to the server level.
Lets set up a game between Alice and Bob
curl -d "player1=alice&player2=bob&type=xo" http://server:port/game
This will return a json object:
{"game_id":"a04fccfeb23e3f28140e8f96b8114de0da732691","status_code":1,"message":"Game Successfully added!"}
Perhaps we want to set up the board so that it we are midway through a game
curl -d 'game_id=a04fccfeb23e3f28140e8f96b8114de0da732691&board=[["1", "1", "-1"], ["0", "0", "-1"] , ["1", "0", "-1"]]' http://server:port/change
Responds with a json object
{"game_id":"a04fccfeb23e3f28140e8f96b8114de0da732691","status_code":1,"message":"Board change successful"}
This will be different depending on the game logic you are modelling but let me demonstrate how it works in my game.
curl -d 'game_id=a04fccfeb23e3f28140e8f96b8114de0da732691' http://richydelaney.com:8001/current
Responds with the default return json object along with some other valuable additions
{"game_id":"a04fccfeb23e3f28140e8f96b8114de0da732691","status_code":1,"message":"Retrieved state.","state":{"board":"[[\"X\",\"X\",\"-\"],[\"O\",\"O\",\"-\"],[\"X\",\"O\",\"-\"]]","turn":0,"status":"Running"}}
This is the area where most damage can be done and its the one I'm least happy with, as the server should support all game logic, it makes no sense for the server to do a check on the game so all checks on the JSON object needs to be done. Lets do a demo request:
curl -d 'game_id=a04fccfeb23e3f28140e8f96b8114de0da732691&options={"x":0, "y":2}' http://richydelaney.com:8001/move
Responds (on a valid move with)
{"game_id":"a04fccfeb23e3f28140e8f96b8114de0da732691","status_code":1,"message":"Valid Move"}