an erlang game server based on ranch, google protocol buffer and riak.
for more about ranch, google protocol buffer, and riak, please refer to
ranch,
google protocol buffer,
riak.
This framework cludes:
- a cluster of connector based on ranch for managing tcp front end session,
- a game application to handle various game logic.
Every player has a connector process, a game logic process( i.e. the role.erl gen_server ), and a riak client connection.
The Message format between server and client is as follows:
message length + message num + message body
the detailed description are as follows:
- message length: 2 bytes of big endian about the message length and parsed by erlang automatically with {packet,2} option, maybe later {packet,4} is more approriate.
- message num: 2 bytes of big endian number to indicate message name.Numbers are generated using proto_mapper.cc file under src/proto directory.
- message body: Binaries with google protocol buff encoding.
compile src/proto/proto_mapper.cc into one executable file using proto buff libs, for example, under my mbp environment, use this following command:
clang++ -o proto_mapper -I/usr/local/include proto_mapper.cc /usr/local/lib/libprotobuf.a /usr/local/lib/libprotoc.a
Code compilation and server initialization is controlled using ctl.py file. First, execute ./ctl.py build to generate erlang tools; second, execute ./ctl.py proto to generate google protocol buff files; Finally ./ctl.py build to build all *.erl files to *.beams.
Prepare riak database before start game server and execute ./ctl.py startto start the server. for more on how to start riak, please visit:riak. Currently, a connector is started on node 'server1_connector1@127.0.0.1', a game server is started on node 'server1_game1@127.0.0.1', configurations are supported later.