Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mas-bandwidth/yojimbo
Browse files Browse the repository at this point in the history
  • Loading branch information
gafferongames committed Sep 18, 2024
2 parents d2cc0c0 + e342ac4 commit 1f5d2d7
Show file tree
Hide file tree
Showing 20 changed files with 467 additions and 66 deletions.
35 changes: 13 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@

It's designed around the networking requirements of competitive multiplayer games like first person shooters.

Generally speaking, if you have a custom game engine written in C++ and you want to network your game, yojimbo is a good choice.

![image](https://github.com/mas-bandwidth/yojimbo/assets/696656/098935f2-ba2b-4540-8d7f-474acc7f2cd8)

It has the following features:

* Cryptographically secure authentication via [connect tokens](https://github.com/networkprotocol/netcode/blob/master/STANDARD.md)
* Client/server connection management and timeouts
* Encrypted and signed packets sent over UDP
* Packet fragmentation and reassembly
* Reliable-ordered messages and data blocks
* Estimates of packet loss, latency and bandwidth usage
* Bitpacker and serialization system
* Unreliable-unordered messages for time sensitive data
* Reliable-ordered messages with aggressive resend until ack
* Data blocks larger than maximum packet size can be attached to reliable-ordered messages
* Estimates of latency, jitter, packet loss, bandwidth sent, received and acked per-connection

yojimbo is stable and production ready.

Expand All @@ -23,31 +30,15 @@ You can get the latest source code by cloning it from github:

git clone https://github.com/mas-bandwidth/yojimbo.git

Alternatively, you can download one of the latest [releases](https://github.com/mas-bandwidth/yojimbo/releases)
Alternatively, you can download the latest [release](https://github.com/mas-bandwidth/yojimbo/releases).

## Author

The author of this library is Glenn Fiedler.

Open source libraries by the same author include: [netcode](https://github.com/mas-bandwidth/netcode), [reliable](https://github.com/mas-bandwidth/reliable), and [serialize](https://github.com/mas-bandwidth/serialize)

## Sponsors
The author of this library is [Glenn Fiedler](https://www.linkedin.com/in/glenn-fiedler-11b735302/).

**yojimbo** was generously sponsored by:
Yojimbo is built on top of other open source libraries by the same author: [netcode](https://github.com/mas-bandwidth/netcode), [reliable](https://github.com/mas-bandwidth/reliable), and [serialize](https://github.com/mas-bandwidth/serialize)

* **Gold Sponsors**
* [Remedy Entertainment](http://www.remedygames.com/)
* [Cloud Imperium Games](https://cloudimperiumgames.com)

* **Silver Sponsors**
* [Moon Studios](http://www.oriblindforest.com/#!moon-3/)
* The Network Protocol Company

* **Bronze Sponsors**
* Kite & Lightning
* [Data Realms](http://datarealms.com)

And by individual supporters on Patreon. Thank you. You made this possible!
If you find this software useful, please consider [sponsoring it](https://github.com/sponsors/mas-bandwidth). Thanks!

## License

Expand Down
2 changes: 1 addition & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ OnlineGameScreen::OnlineGameScreen(const yojimbo::Address& serverAddress) :
m_client(yojimbo::GetDefaultAllocator(), yojimbo::Address("0.0.0.0"), m_connectionConfig, m_adapter, 0.0)
{
uint64_t clientId;
yojimbo::random_bytes((uint8_t*)&clientId, 8);
yojimbo_random_bytes((uint8_t*)&clientId, 8);
m_client.InsecureConnect(DEFAULT_PRIVATE_KEY, clientId, m_serverAddress);
}
```
Expand Down
2 changes: 1 addition & 1 deletion include/yojimbo_base_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace yojimbo
@param allocator The allocator for all memory used by the client.
@param config The base client/server configuration.
@param time The current time in seconds. See ClientInterface::AdvanceTime
@param allocator The adapter to the game program. Specifies allocators, message factory to use etc.
@param adapter The adapter to the game program. Specifies allocators, message factory to use etc.
*/

explicit BaseClient( class Allocator & allocator, const ClientServerConfig & config, class Adapter & adapter, double time );
Expand Down
2 changes: 1 addition & 1 deletion include/yojimbo_client_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace yojimbo

/**
Is the client connected to a server?
This is true once a client successfully finishes connection negotiatio, and connects to a server. It is false while connecting to a server.
This is true once a client successfully finishes connection negotiation, and connects to a server. It is false while connecting to a server.
@returns true if the client is connected to a server.
*/

Expand Down
7 changes: 4 additions & 3 deletions include/yojimbo_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#endif

#define YOJIMBO_MAJOR_VERSION 1
#define YOJIMBO_MINOR_VERSION 0
#define YOJIMBO_PATCH_VERSION 0
#define YOJIMBO_MINOR_VERSION 2
#define YOJIMBO_PATCH_VERSION 4

#if !defined(YOJIMBO_DEBUG) && !defined(YOJIMBO_RELEASE)
#if defined(NDEBUG)
Expand Down Expand Up @@ -170,8 +170,9 @@ namespace yojimbo

ConnectionConfig()
{
numChannels = 1;
numChannels = 2;
maxPacketSize = 8 * 1024;
channel[0].type = CHANNEL_TYPE_RELIABLE_ORDERED;
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/yojimbo_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace yojimbo
{
const int MaxClients = 64; ///< The maximum number of clients supported by this library. You can increase this if you want, but this library is designed around patterns that work best for [2,64] player games. If your game has less than 64 clients, reducing this will save memory.

const int MaxChannels = 64; ///< The maximum number of message channels supported by this library. If you need less than 64 channels per-packet, reducing this will save memory.
const int MaxChannels = 2; ///< The maximum number of message channels supported by this library. If you need less than 64 channels per-packet, reducing this will save memory. Minimum is 2.

const int KeyBytes = 32; ///< Size of encryption key for dedicated client/server in bytes. Must be equal to key size for libsodium encryption primitive. Do not change.

Expand Down
8 changes: 7 additions & 1 deletion include/yojimbo_network_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ namespace yojimbo

struct NetworkInfo
{
float RTT; ///< Round trip time estimate (milliseconds).
float RTT; ///< Round trip time estimate (milliseconds). Exponentially smoothed average tracking most recent RTT value.
float minRTT; ///< Minimum RTT seen over the last n samples (see rtt_history_size in reliable config). This is a more stable and accurate RTT value under typical Wi-Fi jitter.
float maxRTT; ///< Maximum RTT seen over the last n samples.
float averageRTT; ///< Average RTT seen over the last n samples.
float averageJitter; ///< Average jitter relative to min RTT over the last n samples.
float maxJitter; ///< Max jitter relative to min RTT seen over the last n samples.
float stddevJitter; ///< One standard deviation of jitter relative to average RTT over the last n samples.
float packetLoss; ///< Packet loss percent.
float sentBandwidth; ///< Sent bandwidth (kbps).
float receivedBandwidth; ///< Received bandwidth (kbps).
Expand Down
2 changes: 2 additions & 0 deletions include/yojimbo_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace yojimbo

uint64_t GetClientId( int clientIndex ) const;

const uint8_t * GetClientUserData( int clientIndex ) const;

netcode_address_t * GetClientAddress( int clientIndex ) const;

int GetNumConnectedClients() const;
Expand Down
7 changes: 7 additions & 0 deletions include/yojimbo_server_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ namespace yojimbo

virtual uint64_t GetClientId( int clientIndex ) const = 0;

/**
Get the user data of the client.
@param clientIndex the index of the client slot in [0,maxClients-1], where maxClients corresponds to the value passed into the last call to Server::Start.
@returns The user data of the client.
*/
const uint8_t * GetClientUserData( int clientIndex ) const;

/**
Get the address of the client
@param clientIndex the index of the client slot in [0,maxClients-1], where maxClients corresponds to the value passed into the last call to Server::Start.
Expand Down
28 changes: 28 additions & 0 deletions matcher/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM golang:1.20.13 AS matcher_build

# Matcher
WORKDIR /matcher

# Copy go.mod and go.sum files to the workspace separately and download dependecies.
# Doing this separately will cache these as its own separate layer
COPY ./go.mod .
COPY ./go.sum .
RUN go mod download

# Copy the source code as the last step
COPY . .

# Build the binary
RUN CGO_ENABLED=0 go build -o matcher.bin main.go

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Then we copy and run it from a slim image
FROM alpine:3.5
WORKDIR /matcher

COPY --from=matcher_build /matcher/matcher.bin .

EXPOSE 8081

ENTRYPOINT ["/matcher/matcher.bin"]
31 changes: 31 additions & 0 deletions matcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Yojimbo Matcher Sample

This is a sample matcher server written in go that will provide a connection token via the following endpoint:

```
GET /match/{protocolID}/{clientID}
```

# Building the Docker image:

To build the image run the following command from the `matcher` directory:

```sh
docker build --tag=matcher .
```

# Running the Docker container:

Run the container image mapping the port to your host machine:

```sh
docker run -d -p 8081:8081 --name matcher matcher
```

# Using the matcher:

To hit the container with a test request:

```sh
PROTOCOL_ID=123 && CLIENT_ID=42 && curl http://localhost:8081/match/${PROTOCOL_ID}/${CLIENT_ID}
```
11 changes: 11 additions & 0 deletions matcher/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/mas-bandwidth/matcher

go 1.20

require (
github.com/go-chi/chi/v5 v5.0.8
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.18.0
)

require golang.org/x/sys v0.16.0 // indirect
8 changes: 8 additions & 0 deletions matcher/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Loading

0 comments on commit 1f5d2d7

Please sign in to comment.