Skip to content

MafiaNet is a cross-platform network engine written in C++ and specifially designed for games.

License

Notifications You must be signed in to change notification settings

MafiaHub/MafiaNet

 
 

Repository files navigation

MafiaHub

MafiaNet

A modern, cross-platform networking engine for multiplayer games

Build & Test Discord License C++17 CMake

Quick StartFeaturesDocumentationCommunity


About

MafiaNet is an actively maintained networking library built for game developers who need reliable, high-performance multiplayer networking. Built on the foundation of RakNet and SLikeNet, MafiaNet delivers battle-tested networking capabilities with modern C++ standards and security practices.

Supported Platforms: Windows, Linux, macOS (primary) | iOS, Android (limited)

Quick Start

Requirements

  • CMake 3.21+
  • C++17 compatible compiler
  • OpenSSL 1.0.0+
  • Internet connection (first build fetches dependencies automatically)

Building

Linux / macOS:

git clone https://github.com/MafiaHub/MafiaNet.git
cd MafiaNet
mkdir build && cd build
cmake ..
cmake --build . -j$(nproc)  # Linux
cmake --build . -j$(sysctl -n hw.ncpu)  # macOS

Windows (Visual Studio):

git clone https://github.com/MafiaHub/MafiaNet.git
cd MafiaNet

# Generate Visual Studio 2022 solution
cmake -G "Visual Studio 17 2022" -A x64 -B build

# Build from command line, or open build/MafiaNet.sln in Visual Studio
cmake --build build --config Release

Build Options

Option Default Description
MAFIANET_BUILD_SHARED ON Build shared library (.dll/.so/.dylib)
MAFIANET_BUILD_STATIC ON Build static library (.lib/.a)
MAFIANET_BUILD_SAMPLES OFF Build 80 sample applications and extensions
MAFIANET_BUILD_TESTS OFF Build test suite

To build with samples:

cmake -DMAFIANET_BUILD_SAMPLES=ON ..

Basic Usage

#include "mafianet/peerinterface.h"
#include "mafianet/MessageIdentifiers.h"

// Create a peer
MafiaNet::RakPeerInterface* peer = MafiaNet::RakPeerInterface::GetInstance();

// Start as server
MafiaNet::SocketDescriptor sd(60000, 0);
peer->Startup(32, &sd, 1);
peer->SetMaximumIncomingConnections(32);

// Or connect as client
peer->Connect("127.0.0.1", 60000, nullptr, 0);

// Process incoming packets
MafiaNet::Packet* packet;
while ((packet = peer->Receive()) != nullptr) {
    switch (packet->data[0]) {
        case ID_NEW_INCOMING_CONNECTION:
            printf("Client connected\n");
            break;
        case ID_CONNECTION_REQUEST_ACCEPTED:
            printf("Connected to server\n");
            break;
    }
    peer->DeallocatePacket(packet);
}

// Cleanup
MafiaNet::RakPeerInterface::DestroyInstance(peer);

Features

Core Networking

  • Reliable UDP with automatic retransmission
  • Packet ordering and sequencing
  • Automatic packet splitting for large messages
  • IPv4 and IPv6 dual-stack support
  • SSL/TLS encryption via OpenSSL
  • Connection statistics and monitoring

Multiplayer Systems

  • Peer-to-peer and client-server architectures
  • NAT punchthrough and traversal
  • Host migration
  • Room and lobby management
  • Object replication (ReplicaManager3)
  • Remote procedure calls (RPC4)

Development Tools

  • Packet logger with multiple outputs
  • Network simulator (latency, packet loss)
  • Bandwidth monitoring and limiting
  • Message filtering
  • Comprehensive debug statistics

Extensions

  • RakVoice - Voice chat with Opus codec and RNNoise
  • Autopatcher - Delta patching for game updates
  • FileListTransfer - Reliable file transfer
  • Database - MySQL, PostgreSQL, SQLite integration
  • UPnP - Automatic port forwarding

Plugins

MafiaNet provides a modular plugin system for extending functionality:

Plugin Description
ReplicaManager3 Automatic object replication and state synchronization
RPC4 Remote procedure calls with parameter serialization
FullyConnectedMesh2 P2P mesh networking with host migration
NatPunchthrough NAT traversal for peer-to-peer connections
FileListTransfer Reliable file transfer with progress callbacks
DirectoryDeltaTransfer Incremental directory synchronization
Autopatcher Delta patching system for game updates
RakVoice Voice chat with Opus codec and noise suppression
ReadyEvent Player ready state synchronization
TeamManager Team assignment and balancing
Router2 Message routing through intermediate peers
MessageFilter Security filtering for incoming messages
PacketLogger Network traffic logging and debugging
TwoWayAuthentication Mutual authentication between peers
CloudComputing Distributed data storage and retrieval
Lobby2 Matchmaking and lobby system

See the Plugin Documentation for detailed usage.

Documentation

Full documentation is available at mafianet.mafiahub.dev

Documentation includes:

Building Documentation Locally

# Install dependencies
brew install doxygen        # macOS
sudo apt install doxygen    # Ubuntu/Debian
pip install -r docs/requirements.txt

# Build and serve
cd docs
./build.sh serve            # http://localhost:8000

Project Structure

MafiaNet/
├── Source/
│   ├── include/mafianet/   # Public API headers
│   ├── src/                # Implementation files
│   └── *.h                 # Thin wrapper headers for compatibility
├── Samples/                # 80 example applications
│   ├── ChatExample/        # Simple chat application
│   ├── Ping/               # Basic UDP communication
│   ├── ReplicaManager3/    # Object replication demo
│   ├── NATCompleteClient/  # NAT traversal client
│   ├── NATCompleteServer/  # NAT traversal server
│   ├── RakVoice/           # Voice chat examples
│   ├── FileListTransfer/   # File transfer demo
│   └── Tests/              # Comprehensive test suite
├── DependentExtensions/    # Optional integrations
│   ├── Autopatcher/        # Delta patching system
│   ├── Lobby2/             # Matchmaking and lobbies
│   ├── RakVoice.cpp/h      # Voice communication
│   ├── MySQLInterface/     # MySQL connectivity
│   ├── PostgreSQLInterface/# PostgreSQL connectivity
│   ├── SQLite3Plugin/      # SQLite integration
│   └── RPC3/               # Legacy RPC system
├── docs/                   # Sphinx documentation source
└── cmake/                  # CMake modules and helpers

Dependencies

MafiaNet automatically fetches required dependencies via CMake FetchContent:

Dependency Version Used For
OpenSSL 1.0.0+ Encryption (required, system-installed)
bzip2 - Compression (Autopatcher)
miniupnpc - UPnP port forwarding
Opus 1.5.2 Voice codec (RakVoice)
RNNoise - Noise suppression (RakVoice)

Running Tests

Build with samples enabled, then run the test suite:

cmake -DMAFIANET_BUILD_SAMPLES=ON ..
cmake --build .
./Samples/Tests/Tests

# Run a specific test
./Samples/Tests/Tests EightPeerTest

Available tests include: EightPeerTest, MaximumConnectTest, PeerConnectDisconnectTest, ManyClientsOneServerBlockingTest, ReliableOrderedConvertedTest, SecurityFunctionsTest, SystemAddressAndGuidTest, and more.

Changelog

Version 0.3.0 (Latest)

  • RakVoice: Migrated from Speex to Opus codec with RNNoise noise suppression
  • Added support for 8000, 16000, 24000, 48000 Hz sample rates
  • Voice activity detection using Opus DTX

Version 0.2.0

  • Rebranded from SLikeNet to MafiaNet
  • Updated to C++17 standard
  • Modernized CMake build system
  • Added Sphinx documentation with Breathe integration
  • Removed pre-generated Visual Studio solution files

See CHANGELOG for full history.

Background

MafiaNet continues the legacy of two foundational networking libraries:

  • RakNet (2001-2014) - Industry-standard game networking library by Jenkins Software, used in countless multiplayer games. Acquired and open-sourced by Oculus VR.
  • SLikeNet (2016-2019) - Community continuation by SLikeSoft that modernized RakNet with bug fixes, security patches, and C++11 support.

With SLikeNet no longer maintained, MafiaNet carries the torch forward—providing an actively developed, modern networking solution for the game development community.

Community

License

MafiaNet is released under the MIT License.


Built with passion by the MafiaHub community

About

MafiaNet is a cross-platform network engine written in C++ and specifially designed for games.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 94.8%
  • C 4.0%
  • Other 1.2%