/zappy_server

Server made in pure C for one of my end of the year projects at Epitech

Primary LanguageC

zappy_server

A game server made in pure C for one of my end of the year projects at Epitech.

The rules of the game were that several AIs belonging to different teams connected to this server, sometimes hundreds at a time, and they fought for resources on a map. Their goal was to acquire enough to evolve repeatedly, winning the game when enough members of their team had reached their maximum level.

I've written 3312 lines of code for this project over the course of two months (2421 for the server itself and 891 for the unit tests) and I had to make sure it was extremely robust, stable and fast to handle several hundreds of connections at once; hence the great number of tests I've written. I've implemented all the networking, but also all of the game logic.

It also should not have any memory leaks (famous last words, though) and should completely comply to Epitech's strict coding style (most notably, 20 lines maximum per function and indentation levels cannot exceed a depth of 2). As such, I wanted to upload it to my personal GitHub out of pride.

Features

  • not a single dependency other than the C library
  • a custom, reusable argument parser
  • my own, thoroughly tested implementation of circular buffers
  • the ability to handle several hundreds of connections at the same time
  • extremely lightweight
  • designed to consume as little memory as possible
  • readable code that follows a strict coding style
  • no memory leaks
  • thorough tests for every part of the project
  • fun for the whole family (note : has not been tested on any family)

Compilation

The binary zappy_server can be generated by running the command make or make zappy_server.

Tests can be run with make tests_run, and coverage can be checked with a tool of your choice. gcovr shows a 51%.

Clients

The goal of the project was to create a server, an AI client and a graphical interface for clients that wished to use one (and also to help debugging). This was not a solo project, and my teammates worked on those last two (using python) while I wrote this server by myself.

Since I haven't worked on those parts of the project, I haven't uploaded them alongside the server, which also means it can't really be tested by anyone stumbling upon this repository. I could write a client... but I'm feeling lazy. Should you feel masochistic, the protocol is explained in the documentation, and making your own client is very much doable.

Usage

./zappy_server –help
USAGE: ./zappy_server -p port -x width -y height -n name1 name2 ... -c clientsNb -f freq
    port        is the port number
    width       is the width of the world
    height      is the height of the world
    nameX       is the name of the team X
    clientsNb   is the number of authorized clients per team
    freq        is the reciprocal of time unit for execution of actions