RPC Network Library for Multiplayer Games

Related tags

Game Game-NET
Overview

Game NET - A Simple RPC Network Library (C++11)

Write a simple server / client RPC system in just 10+20 lines of code.

Write a multiplayer game with client / server in 300+300 lines of code.

License : MIT

http://opensource.org/licenses/MIT

Summary

The library provides basic client / server network functionalities for games using RPCs. The major strength of the library is the template based RPC class. It allows to register and call RPCs effortless. It further includes a tutorial game server and game client (each around 300 lines of code ) for a very simple multiplayer shooting game as a proof of concept.

Network RPC Lib Features

  • Register RPCs in one line. The RPC class autodetects all paramters from the function pointer
  • RPC Data-type mismatch or wrong parameter count is printed as error to ease debugging (#define RPC_DEBUG)
  • Numbers are automatically sent as the smallest possible datatype (byte, short , .. )
  • Supports GLM datatypes for use in 3D Games
  • Supported Datatypes : (u)char,(u)short,(u)int,float,double,vector,map, GLM vec,mat and quat
  • Support for nested Datatypes like map [ string , vector ]
  • Reliable and unreliable calls possible
  • Hack-safe. Illegal packets (trying to create buffer overruns or such) are discarded.
  • Basic range compression (enet)
  • Function pointers of remote functions are not required
  • Based on ENet
  • Tested on Cygwin, Linux and Windows
  • C++11 based

Network RPC Lib Limitations

  • RPCs cannot be class member functions
  • No encryption
  • Only void functions supported. Non-void functions were tested but complicated everything.
  • Client to Client connections are not supported

Example Game Features

  • Lobby
  • Multiple Games
  • Handle spwaning/removing of game objects
  • Simple Shooting functionality
  • Intentionally textmode for simplicity

Benchmark

A first simple test on localhost (Core i7 Notebook) gave:

1 Call / Network Update:

  • 69.000 unreliable RPC calls/sec [client.call_ex(0,"hello_server", "Greetings")]
  • 74.000 reliable RPC calls/sec [client.call_ex(1,"hello_server", "Greetings")]

10 Calls grouped / Network Update

  • 144.000 unreliable RPC calls/sec [client.call_ex(0,"hello_server", "Greetings")]
  • 310.000 reliable RPC calls/sec [client.call_ex(1,"hello_server", "Greetings")]

20 Calls grouped / Network Update

  • 142.000 unreliable RPC calls/sec [client.call_ex(0,"hello_server", "Greetings")]
  • 364.000 reliable RPC calls/sec [client.call_ex(1,"hello_server", "Greetings")]

Note that this is not about the response time

Example Usage

Call Server Function:

Client Side:

NetClient client;

void set_pos(vec3 pos)
{
    // do something
    exit(0);
}

int main()
{
    rpc_register_remote(client.get_rpc(), login);
    rpc_register_local(client.get_rpc(), set_pos);
    client.connect("localhost", 12345);
    client.call("login", "myname", "pass");
    while(1) client.process();
    //client.disconnect();
}

Server Side:

NetServer server;

void login(uint clientid, string name, string password)
{
    // clientid is the first parameter for server functions
    server.call(clientid, "set_pos", vec3(1,2,3));    
}

int main()
{
    rpc_register_local(server.get_rpc(), login);
    rpc_register_remote(server.get_rpc(), set_pos);    
    server.start();
    core_sleep(10000) ; // wait client to do stuff
    server.stop();
}

Screenshot1 Screenshot2

RPC System, how its done: http://cpp.sh/9jc5

(C) by Sven Forstmann in 2015

You might also like...
C++ Library to connect games with Game Jolt

Game Jolt API C++ Library Game Jolt is a host for free independently developed computer games. As a gamer you are able to play every game on this site

C library for Wordle-like games

libwordle Open this project in 8bitworkshop. This is a C library for making Wordle-like games for 8-bit systems. Platforms supported: C64 (cc65) Wordl

Open-source, cross-platform, C++ game engine for creating 2D/3D games.

GamePlay v3.0.0 GamePlay is an open-source, cross-platform, C++ game framework/engine for creating 2D/3D mobile and desktop games. Website Wiki API De

3D games console based on RP2040 and iCE40 UP5k
3D games console based on RP2040 and iCE40 UP5k

PicoStation 3D This is an unfinished, untested project to develop a 3D games console based on an RP2040 microcontroller and an iCE40 UP5k FPGA. Quick

A set of libraries and tools to make MSX games using the C programming language.

ubox MSX lib This is a set of libraries and tools to make MSX games using the C programming language. There are three main components: ubox: thin wrap

TIC-80 is a fantasy computer for making, playing and sharing tiny games.
TIC-80 is a fantasy computer for making, playing and sharing tiny games.

TIC-80 is a fantasy computer for making, playing and sharing tiny games.

Enfusion Artifical Intelligence for DayZ and future Bohemia Interactive games.

Enfusion AI Project (eAI) This mod adds headless player units under the control of a script on the server. Although the script is very rudimentary now

Game engine behind Sea Dogs, Pirates of the Caribbean and Age of Pirates games.
Game engine behind Sea Dogs, Pirates of the Caribbean and Age of Pirates games.

Game engine behind Sea Dogs, Pirates of the Caribbean and Age of Pirates games.

Recast is state of the art navigation mesh construction toolset for games.
Owner
Spacerat
Spacerat
Dedicated Game Server Hosting and Scaling for Multiplayer Games on Kubernetes

Agones is a library for hosting, running and scaling dedicated game servers on Kubernetes. Agones, is derived from the Greek word agōn which roughly t

GoogleForGames 5k Jan 4, 2023
This is a list of different open-source video games and commercial video games open-source remakes.

This is a list of different open-source video games and commercial video games open-source remakes.

Ivan Bobev 173 Jan 2, 2023
Multiplayer Voxel Survival in C99, includes a badly written implementation of LISP

Imagine a mix between Minecraft, Quake ]I[ and Emacs. Apart from that there is no clear plan for this game, just a bunch of ideas that hopefully will turn out to be fun. Some of these are stored here in this repo, others have been talked about on Twitch during dev streams.

Ben 79 Nov 21, 2022
Multiplayer ludo game made in Unity

LUDO Multiplayer ludo game made in Unity This a multi-plaayer game. But due to lack of budget I am not able to make it online multi-player. So users h

Soumavo Dey 26 Sep 23, 2022
Advanced modding framework for multiplayer modifications

A suite of tools and libraries to accelerate multi-player modification development.

MafiaHub 28 Dec 14, 2022
Mod that adds multiplayer to Tales of Arise

Tales of Arise: Local Co-Op Mod Mod that adds multiplayer to Tales of Arise For progress, see Milestones. Installing Extract files to the game data fo

Eusthron 44 Nov 20, 2022
Multiplayer experience for Mafia: Definitive Edition

Mafia: Definitive Edition Multiplayer! Brought to you by @Segfault, @zaklaus, @DavoSK, and other contributors! Introduction This is a multiplayer mod

MafiaHub 31 Jan 3, 2023
A C math library targeted at games

Kazmath Kazmath is a simple 3D maths library written in C. It was initially coded for use in my book, Beginning OpenGL Game Programming - Second editi

Luke Benstead 506 Dec 31, 2022
A single-header C++ library for making simple 2D games

A single-header C++ library for making simple 2D games PLATFORM: Windows LANGUAGE: C++ ENVIRONMENT: Visual Studio Why? Learning C++ is often seen as d

Sumo Digital Academy 63 Dec 22, 2022
A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.

Jolt Physics Library A multi core friendly rigid body physics and collision detection library suitable for games and VR applications. A YouTube video

null 2.5k Dec 31, 2022