Frequently Asked Questions¶
This page addresses common questions about MafiaNet development and deployment.
General¶
What is MafiaNet?
MafiaNet is a cross-platform network engine for multiplayer games, forked from SLikeNet (which continued RakNet). It provides reliable UDP messaging, NAT traversal, and game-specific networking features.
What platforms are supported?
Windows (Visual Studio 2019+)
Linux (GCC 9+, Clang 10+)
macOS (Xcode 12+)
Is MafiaNet free to use?
Yes, MafiaNet uses a permissive license allowing both commercial and non-commercial use.
Networking¶
How do I choose between TCP and UDP?
Use UDP (RakPeerInterface) for:
Real-time game state updates
Low-latency requirements
Custom reliability needs
Use TCP (TCPInterface) for:
File downloads
Web API calls
Database connections
What’s the maximum packet size?
Default MTU is 1492 bytes. Larger messages are automatically fragmented and reassembled. For best performance, keep frequent messages under MTU.
How many connections can I handle?
Tested with 1000+ simultaneous connections. Actual limits depend on:
Server hardware
Message frequency
Game logic complexity
NAT Traversal¶
Why can’t players connect to each other?
Common causes:
Both behind symmetric NAT (use relay)
Firewall blocking ports
NAT punchthrough server not running
See NAT Traversal Architecture for solutions.
Do I need a dedicated server?
For NAT punchthrough, yes - a facilitator server on a public IP is required. The actual game traffic can be peer-to-peer after punchthrough succeeds.
What ports do I need to open?
Your game’s UDP port (configurable)
For servers: ensure port is forwarded in router
Performance¶
How do I reduce bandwidth?
Use appropriate reliability (UNRELIABLE for non-critical data)
Compress strings with StringCompressor
Use BitStream efficiently (WriteBits, not WriteBytes)
Reduce update frequency for non-critical data
Why am I getting high latency?
Check:
Message priority settings
Congestion control (may be throttling)
Message ordering channels
Server tick rate
See Congestion Control.
How do I handle packet loss?
Use
MafiaNet::Reliability::Reliable/ReliableOrderedfor critical dataUse
MafiaNet::Reliability::UnreliableSequencedfor real-time updatesMonitor statistics with GetStatistics()
Security¶
How do I prevent cheating?
Validate all client input server-side
Use TwoWayAuthentication for login
Use MessageFilter to restrict unauthorized actions
Never trust client-computed results
Is traffic encrypted?
Not by default. Enable with _RAKNET_SECURE_CONNECTIONS define or use
application-layer encryption.
Troubleshooting¶
Connection attempts always fail
Verify server is running and reachable
Check firewall settings
Confirm port numbers match
Enable PacketLogger for diagnostics
Memory usage keeps growing
Ensure packets are deallocated
Check for plugin memory leaks
Use custom memory management to track
See Also¶
Programming Tips - Best practices
Debugging Disconnects - Connection issues
Core Concepts - Core concepts