mirror of
https://github.com/googleforgames/open-match.git
synced 2025-03-27 08:20:47 +00:00
Add comments to MatchMaking Function with Backfill example. It creates matches with Backfills first, then full matches with 1 vs 1 player match, and if number of players left is 1 create a match with new Backfill in it. Co-authored-by: Alexander Apalikov <alexander.apalikov@globant.com>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
// Copyright 2020 Google LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
// Package mmf provides a sample match function that uses the GRPC harness to set up 1v1 matches.
|
|
// This sample is a reference to demonstrate the usage of backfill and should only be used as
|
|
// a starting point for your match function. You will need to modify the
|
|
// matchmaking logic in this function based on your game's requirements.
|
|
package mmf
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
|
|
"google.golang.org/grpc"
|
|
"open-match.dev/open-match/pkg/pb"
|
|
)
|
|
|
|
func Start(queryServiceAddr string, serverPort int) {
|
|
// Connect to QueryService.
|
|
conn, err := grpc.Dial(queryServiceAddr, grpc.WithInsecure())
|
|
|
|
if err != nil {
|
|
log.Fatalf("Failed to connect to Open Match, got %s", err.Error())
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
mmfService := matchFunctionService{
|
|
queryServiceClient: pb.NewQueryServiceClient(conn),
|
|
}
|
|
|
|
// Create and host a new gRPC service on the configured port.
|
|
server := grpc.NewServer()
|
|
pb.RegisterMatchFunctionServer(server, &mmfService)
|
|
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", serverPort))
|
|
|
|
if err != nil {
|
|
log.Fatalf("TCP net listener initialization failed for port %v, got %s", serverPort, err.Error())
|
|
}
|
|
|
|
log.Printf("TCP net listener initialized for port %v", serverPort)
|
|
err = server.Serve(ln)
|
|
|
|
if err != nil {
|
|
log.Fatalf("gRPC serve failed, got %s", err.Error())
|
|
}
|
|
}
|