Director
#
Open Match Director Edgegap's tutorial (basic)The Director component of Open Match is the orchestrator of everything. This component requests game proposals and assigns a game server to them.
#
Prerequisites#
Create Your project- Go
- C# (HTTP)
Every Open Match service should be in its own project. Create a new folder named director for the OpenMatch director component.
In this folder, run the following command.
And create a file named main.go
where the core logic of the component will be.
Every Open Match service should be in its own project. Create a new folder named director for the OpenMatch director component.
In this folder, run the following command.
You will have to update director.csproj
If you don't use Dotnet version 6.0 preview 7 or greater you will generate a more complex project. You will be able to follow the tutorial. However the structure will be a bit more complex.
#
Create the main loop- Go
- C# (HTTP)
The first thing that we need for our Director is a loop that will match players every 5 seconds.
Now, in your main.go file, you can add the following code. This task will create the main loop.
You can try it by starting your app with go run ./main.go
. Every 5 seconds, you should see
The first thing that we need for our director is a loop that will match players every 5 seconds.
Let's update our main function. It should look like this.
Now, we will create a file Core.cs. This file will contain all the classes for our director component.
In Core.cs, let's create a class named Constant. In this class, we will store all the constants for our director.
In Core.cs, let's create a class named Director with a function Start.
Don't forget to change the variables gameServerPort, appName, appVersion, arbitriumAPI, apiToken with valid data. The values should come from Arbitrium. It should be an application that you own.
#
Get Profiles- Go
- C# (HTTP)
In order to obtain match proposals, we will need profiles. We will create a method that returns a list of profiles. We will need Open Match dependency for that.
Here is the code for profiles generation
You will have to change your dependencies. They should look like this
In order to obtain match proposals, we will need profiles. We will create a method that returns a list of profiles.
Now, we will create a file named Models.cs. This file will contain all the models.
Let's add a function to get all the profiles in our Director class.
#
Create a connection to Open Match Backend service- Go
- C# (HTTP)
We will retrieve the match proposals by communicating to Open Match Backend service via gRPC. We need to create the connection.
For that, we need gRPC dependency
Here is the code that creates the connection.
You will have to change your dependencies. They should look like this
This step is not necessary for C# (HTTP). We will communicate with the backend using HTTP calls.
#
Fetching match proposals- Go
- C# (HTTP)
The next step would be to create a function that will fetch the match proposals for a specific profile. We will make a call to Open Match Back End service.
Here is the piece of code for that.
You will have to change your dependencies. They should look like this
The next step would be to create a function that will fetch the match proposals for a specific profile. We will make a call to Open Match Back End service.
Here is the piece of code for that. Let's add it to our Director class
You will have to update Model.cs.
#
Assign game server to match proposalsWe need a function that will assign a game server to our match proposals. It is here that we will call Arbitrium API (CoDeMa).
Using Arbitrium deployment#
This section shows you how to integrate Arbitrium's deployment into your Director. If you use Arbitrium's session, you should go to the next section.
We assume that you already experimented with Arbitrium's deployment and know how they work. If you don't, we recommend you to see this section
- Go
- C# (HTTP)
You could make an HTTP request by following our API call definitions; however, we will use an auto-generated Go SDK. You can learn how to generate an SDK here. In your director project, you will have to create a swagger folder and put the generated SDK inside.
You will have to change your dependencies. They should look like this
You will have to update Model.cs.
Using Arbitrium session#
This section shows you how to integrate Arbitrium's session into your Director. If you use Arbitrium's deployment, you should go to the previous section.
We assume that you already experimented with Arbitrium's deployment and know how they work. If you don't, we recommend you to see this section
If your App Version (session kind) IS NOT in auto-deploy, you will need an instance running to link your session.
If your App Version (session kind) IS in auto-deploy, it will deploy a server automatically. It could end up in multiple instances running.
- Go
- C# (HTTP)
You could make an HTTP request by following our API call definitions; however, we will use an auto-generated Go SDK. You can learn how to generate an SDK here. In your director project, you will have to create a swagger folder and put the generated SDK inside.
You will have to change your dependencies. They should look like this
Coming soon
#
Putting everything together- Go
- C# (HTTP)
Now it's time to put all the pieces together. Our main function should look like this.
You will have to change your dependencies. They should look like this
It will be hard to test this service in a standalone context. We will see it in action when all the services (Front end, Director, and Match Function) will be ready.
Now it's time to put all the pieces together. Our MatchPlayers function should look like this.
It will be hard to test this service in a standalone context. We will see it in action when all the services (Front end, Director, and Match Function) will be ready.
#
Containerize your service- Go
- C# (HTTP)
Containerization is powerful. You can learn more about it on Edgegap's documentation or Docker. Our container, we will use golang:1.16 for its base image.
Create a file named Dockerfile and write this inside.
Containerization is powerful. You can learn more about it on Edgegap's documentation or Docker. Our container will use mcr.microsoft.com/dotnet/aspnet:6.0 for its base image.
Create a file named Dockerfile and write this inside.
You can now build your image using.
You can run it using this command, but without all the other services, it will not work.
#
ConclusionYou now have a basic Open Match Director service. This is not production-ready. However, you will learn the key function of Open Match Director. You also created a Docker image that can be used later.