Skip to content

sitano/slitherss

Repository files navigation

Readme

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.

anim

How to build

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.

Prerequisites

  • 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

Building

  1. git clone https://github.com/sitano/slitherss
  2. git submodule update --init
  3. cmake -DCMAKE_C_COMPILER=/usr/bin/cc -DCMAKE_CXX_COMPILER=/usr/bin/c++ -DCMAKE_BUILD_TYPE=Debug .
  4. 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.

How to play

  1. 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.
  2. 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;.

Valgrind

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

SystemTap

stap -v -d ./bin/slither_server -L 'process("*/slither_server").function("*")'

Vagrant

There is vagrant configuration with all dependencies required for development.

vagrant up
vagrant ssh

Code style

Use latest Google C++ Code Style guide with lines length 120.

TODO

  • force died snake disconnect
  • fix eating food
  • optimize snake intersection
  • snake observability tracking
  • make performance tests

OTHER

About

slither.io server in C++ emulating https://github.com/sitano/Slither.io-Protocol

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors