nsetzer / mpgameserver

Python Multiplayer UDP Game Server
GNU Lesser General Public License v2.1
43 stars 6 forks source link

MpGameServer

A Python 3.8+ UDP Client and Server for building multiplayer games with a focus on security and ease of use.

MpGameServer abstracts all of the complexities with handling network connections and multithreading so that you can focus on building an event driven game server.

The network protocol is based on the work of Glenn Fiedler's Gaffer On Games

Client

Installation

MpGameServer has an optional installation of pygame.

pip install mpgameserver[pygame]

Features

Installation

You can install MpGameServer from PyPI

pip install mpgameserver

MpGameServer supports python 3.8+

How To Use

Read the Getting Started guide for how to use this package with PyGame.

Security

Datagrams are encrypted using AES-GCM. A unique key is generated for every connection using ECDH and ECDSA. The elliptic curve SECP256R1 is used. This provides Authentication (a client can verify it is communicating with the correct server), Integrity (the client and server can detect if a message has been modified) Confidentiality (unauthorized users are not able to decrypt the messages.)

Performance

The performance goal for this server is to handle 128 concurrent connections, each sending 32 datagrams per second, with 60 server ticks per second.

The primary bottleneck is the encryption or decryption of datagrams. The limit is about 40,000 datagrams per second (depending on hardware). In practice this translates to sending or receiving around 3000 datagrams per second, if any practical workload is performed on each datagram.

The second limitation is that the ack bits in the header only contains 32 bits. The implicit assumption is that there will not be more than 32 unacked datagrams in flight. This puts a limit of 32 datagrams per second, the default timeout. Sending more datagrams than this limit can result in datagrams that are received by the remote client, but are not acked on the sending side. A game or server running at 60 frames per second should take care to structure sending messages to avoid hitting this limit. Note that 32 datagrams per second is a transfer rate of about 45KB per second.

Road map