Match Function
#
Open Match Match Function Edgegap's tutorial (basic)The Match Function is the core of the decision. It's this service that creates game proposals. It makes its decisions from profile's configuration. In this service, you can code any logic that will generate your match proposals
#
Prerequisites#
Create Your project- Go
- C# (HTTP)
Every Open Match service should be in its own project. Create a new folder named match-function for the OpenMatch match-function 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 match-function for the OpenMatch match-function component.
In this folder, run the following command.
If you don't use Dotnet version 6.0 preview 7 or greater you will generate an more complex project. You will be able to follow the tutorial. However the structure will be a bit more complex. You will have to work in Startup.cs file
#
Implement Match Function base structure- Go
- C# (HTTP)
The first thing that we need for our Match Function is a gRPC server that will listen for a call from Open Match Core.
We will need two libraries for this step. You can install them with
Now, in your main.go file, you can add the following code. This will create the gPRC server.
You can try it by starting your app with go run ./main.go
. You should see
The first thing that we need for our Match Function is a HTTP API that will listen for a call from Open Match Core.
We need to change the configuration. You should change the configuration in Properties/launchSettings.json to the following.
Then, we will update Program.cs. We will add a logger and add a middleware to catch unhandled exceptions.
Now, we will create a file named Core.cs. This file will contain all the classes that have logic inside.
In Core.cs, let's create a class named Constant. In this class, we will store all the constants for our match function.
In Core.cs, let's create a class named MatchFunction with a function Handle. In this function, we will match the players together.
You can try it by starting your app with dotnet run
. You should see
#
Create the Match FunctionThe strength of Open Match comes from the customization of Match Function and Director services. We will now create the Match Function. This one aims to fetch Open Match tickets based on profiles. Match Function can be very complicated, but we will keep it simple and implement a basic Match Function in this tutorial.
The Match Function will fetch all the tickets that match the profile received in the request. The tickets will be categorized by pool name (Profiles contain pools). Then, we will go through each pool and create game proposals from the tickets in the pool. When the proposals are all created, we will send them back to Open Match Core
- Go
- C# (HTTP)
We will use gRPC to query the core and send back the proposals.
Below is the code for the Match Function. It should be placed in the main.go file under the main
function.
You will have to change your dependencies. They should look like this
Also, you will have to update the main function to create the Open Match Query service connection and make the basicMatchFunction
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, we will create a file named Models.cs. This file will contain all the models used for HTTP calls.
Let's update our class MatchFunction. We will add the logic that communicate with Open Match core. The class should look like this.
#
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 Match Function service that can be called by Open Match Core using gRPC protocol. This is not production-ready. However, you should be able to grasp the basics of Open Match Match Function. You also created a Docker image that can be used later.