slither.io server in C++ emulating native protocol.
Note: this was mostly an experiment and fun reversing slither.io game. Thus, some code or parts of it may not met real world high quality standards, and that was not a goal of this work.
Note: why c++? I just wanted to play with a language I've touched 10 years ago last time.
Note: there are a lot of strange decisions inside of slither.io, like i.e. 8ms simulation tick - I will ignore that.
This software was developed with Ubuntu and can be easily build under any unix native environment. It is possible to run it on Windows as well, because main websockets library is cross-platform, but environment setup under Windows is out of the scope of this article.
- Boost:
sudo apt-get install libboost-dev libboost-system-dev libboost-thread-dev libboost-program-options-dev - Zlib:
sudo apt-get install zlib1g-dev - CMake env:
sudo apt-get install cmake gcc g++ cppcheck valgrind git
git clone https://github.com/sitano/slitherssgit submodule update --initcmake -DCMAKE_C_COMPILER=/usr/bin/cc -DCMAKE_CXX_COMPILER=/usr/bin/c++ -DCMAKE_BUILD_TYPE=Debug .make -j
Note: Make sure boost lib was built using the same compiler or at least compatible ABI.
Clang users:
- 3.5, 3.6 will require -stdlib=libc++ and libc++-dev package and it will not compile old boost at chriskohlhoff/asio#76
- 3.8 and latest env of ubuntu 16.04 will do fine, but native repo boost program options library have been compiled with latest gcc with incomptible abi. rebuild boost with clang if you want.
- Run the server using something like
./bin/slither_server --bots 50 --avg_len 50. Built-in bots are supported and you can choose average snakes length on the start. - Force your client to connect to opened server port (127.0.0.1:8080) using
either debug tool, pressing 'c',
or inject force command right into the console of running web site in a browser:
window.bso = { ip: "127.0.0.1", po: 8080 }; window.forcing = true; window.want_play = true;.
CPU
valgrind --tool=callgrind ./bin/slither_server --bots=500 --min_len=50
Memory
valgrind --track-origins=yes -v ./bin/slither_server
VGDB
$ valgrind --vgdb=yes --vgdb-error=0 ./bin/slither_server --bots 5000
gdb: target remote | vgdb
stap -v -d ./bin/slither_server -L 'process("*/slither_server").function("*")'
There is vagrant configuration with all dependencies required for development.
vagrant up
vagrant ssh
Use latest Google C++ Code Style guide with lines length 120.
- force died snake disconnect
- fix eating food
- optimize snake intersection
- snake observability tracking
- make performance tests
- inject googletest / boost testing
- inject benchmark framework ( https://github.com/google/benchmark, https://github.com/DigitalInBlue/Celero, https://github.com/nickbruun/hayai)
- fixed point math test
- intersections math test