mirror of
https://github.com/googleforgames/open-match.git
synced 2025-04-08 10:27:22 +00:00
Compare commits
31 Commits
v0.2.0-alp
...
v0.2.0-alp
Author | SHA1 | Date | |
---|---|---|---|
4a8e018599 | |||
c1b5d44947 | |||
ae9db9fae8 | |||
104fbd19cd | |||
3b2571fced | |||
3fb17c5f22 | |||
3f42e3d986 | |||
0c74debbb3 | |||
1854ee0ba1 | |||
99d9d7e2b5 | |||
e286435e19 | |||
b17dccac3b | |||
b9bb0b1aeb | |||
a6f2edbbae | |||
55db5c5ba3 | |||
b4f696484f | |||
12935d2cab | |||
a0cff79878 | |||
7a3c5937f2 | |||
f430720d2f | |||
34010986f7 | |||
d8a8d16bfc | |||
243f53336c | |||
d188be60c8 | |||
f1541a8cee | |||
cd1c4c768e | |||
967b6cc695 | |||
906c0861c7 | |||
4e0bb5c07d | |||
b57dd3e668 | |||
b2897ca159 |
.gitignoreCHANGELOG.mdDockerfile.frontendapiDockerfile.mmf_goDockerfile.mmf_phpREADME.md
api/protobuf-spec
cloudbuild_mmf.yamlcloudbuild_mmf_go.yamlcloudbuild_mmf_php.yamlcloudbuild_mmf_py3.yamlcloudbuild_mmforc.yamlcloudbuild_mmlogicapi.yamlcmd
deployments/k8s
docs
examples
backendclient
functions
golang
php/mmlogic-simple
python3/mmlogic-simple
install/yaml
internal
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,6 +26,7 @@ populations
|
||||
|
||||
# Discarded code snippets
|
||||
build.sh
|
||||
*-fast.yaml
|
||||
|
||||
# Dotnet Core ignores
|
||||
*.swp
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Release history
|
||||
|
||||
##v0.2.0 RC1 (alpha)
|
||||
##v0.2.0 (alpha)
|
||||
This is a pretty large update. Custom MMFs or evaluators from 0.1.0 may need some tweaking to work with this version. Some Backend API function arguments have changed. Please join the [Slack channel](https://open-match.slack.com/) if you need help ([Signup link](https://join.slack.com/t/open-match/shared_invite/enQtNDM1NjcxNTY4MTgzLWQzMzE1MGY5YmYyYWY3ZjE2MjNjZTdmYmQ1ZTQzMmNiNGViYmQyN2M4ZmVkMDY2YzZlOTUwMTYwMzI1Y2I2MjU))!
|
||||
|
||||
v0.2.0 focused on adding additional functionality to Backend API calls and on **reducing the amount of boilerplate code required to make a custom Matchmaking Function**. For this, a new internal API for use by MMFs called the [Matchmaking Logic API (MMLogic API)](README.md#matchmaking-logic-mmlogic-api) has been added. Many of the core components and examples had to be updated to use the new Backend API arguments and the modules to support them, so we recommend you rebuild and redeploy all the components to use v0.2.0.
|
||||
@ -9,22 +9,24 @@
|
||||
- MMLogic API is now available. Deploy it to kubernetes using the [appropriate json file]() and check out the [gRPC API specification](api/protobuf-spec/mmlogic.proto) to see how to use it. To write a client against this API, you'll need to compile the protobuf files to your language of choice. There is an associated cloudbuild.yaml file and Dockerfile for it in the root directory.
|
||||
- When using the MMLogic API to filter players into pools, it will attempt to report back the number of players that matched the filters and how long the filters took to query state storage.
|
||||
- An [example MMF](examples/functions/python3/mmlogic-simple/harness.py) using it has been written in Python3. There is an associated cloudbuild.yaml file and Dockerfile for it in the root directory. By default the [example backend client](examples/backendclient/main.go) is now configured to use this MMF, so make sure you have it avaiable before you try to run the latest backend client.
|
||||
- An [example MMF](examples/functions/php/mmlogic-simple/harness.py) using it has been contributed by Ilya Hrankouski in PHP (thanks!). - The API specs have been split into separate files per API and the protobuf messages are in a separate file. Things were renamed slightly as a result, and you will need to update your API clients. The Frontend API hasn't had it's messages moved to the shared messages file yet, but this will happen in an upcoming version.
|
||||
- The [example golang MMF](examples/functions/golang/manual-simple/) has been updated to use the latest data schemas for MatchObjects, and renamed to `manual-simple` to denote that it is manually manipulating Redis, not using the MMLogic API.
|
||||
- The API specs have been split into separate files per API and the protobuf messages are in a separate file. Things were renamed slightly as a result, and you will need to update your API clients. The Frontend API hasn't had it's messages moved to the shared messages file yet, but this will happen in an upcoming version.
|
||||
- The message model for using the Backend API has changed slightly - for calls that make MatchObjects, the expectation is that you will provide a MatchObject with a few fields populated, and it will then be shuttled along through state storage to your MMF and back out again, with various processes 'filling in the blanks' of your MatchObject, which is then returned to your code calling the Backend API. Read the[gRPC API specification](api/protobuf-spec/backend.proto) for more information.
|
||||
- As part of this, compiled protobuf golang modules now live in the [internal/pb](internal/pb) directory. There's a handy [bash script](api/protoc-go.sh) for compiling them in your local golang environment if you need it.
|
||||
- As part of this, compiled protobuf golang modules now live in the [`internal/pb`](internal/pb) directory. There's a handy [bash script](api/protoc-go.sh) for compiling them from the `api/protobuf-spec` directory into this new `internal/pb` directory for development in your local golang environment if you need it.
|
||||
- As part of this Backend API message shift and the advent of the MMLogic API, 'player pools' and 'rosters' are now first-class data structures in MatchObjects for those who wish to use them. You can ignore them if you like, but if you want to use some of the MMLogic API calls to automate tasks for you - things like filtering a pool of players according attributes or adding all the players in your rosters to the ignorelist so other MMFs don't try to grab them - you'll need to put your data into the [protobuf messages](api/protobuf-spec/messages.proto) so Open Match knows how to read them. The sample backend client [test profile JSON](examples/backendclient/profiles/testprofile.json)has been updated to use this format if you want to see an example.
|
||||
- Rosters were formerly space-delimited lists of player IDs. They are now first-class repeated protobuf message fields in the [Roster message format](api/protobuf-spec/messages.proto). That means that in most languages, you can access the roster as a list of players using your native language data structures (more info can be found in the [guide for using protocol buffers in your langauge of choice](https://developers.google.com/protocol-buffers/docs/reference/overview)). If you don't care about the new fields or the new functionality, you can just leave all the other fields but the player ID unset.
|
||||
- Open Match is transitioning to using [protocol buffer messages](https://developers.google.com/protocol-buffers/) as its internal data format. There is now a Redis state storage [golang module](internal/statestorage/redis/redispb/) for marshaling and unmarshaling MatchObject messages to and from Redis. It isn't very clean code right now but will get worked on for the next couple releases.
|
||||
- Ignorelists now exist, and have a Redis state storage [golang module](internal/statestorage/redis/ignorelist/) for CRUD access. Currently three ignorelists are defined in the [config file](config/matchmaker_config.json) with their respective parameters. These are implemented as [Sorted Sets in Redis](https://redis.io/commands#sorted_set).
|
||||
- For those who only want to stand up Open Match and aren't interested in individually tweaking the required kubernetes resources, there are now [three YAML files](install/yaml) that can be used to install Redis, install Open Match, and (optionally) install Prometheus. You'll still need the `sed` [instructions from the Developer Guide](docs/development.md#running-open-match-in-a-development-environment) to substitute in the name of your Docker container registry.
|
||||
- A super-simple module has been created for doing instersections, unions, and differences of lists of player IDs. It lives in `internal/set/set.go`.
|
||||
|
||||
|
||||
### Roadmap
|
||||
- It has become clear from talking to multiple users that the software they write to talk to the Backend API needs a name. 'Backend API Client' is technically correct, but given how many APIs are in Open Match and the overwhelming use of 'Client' to refer to a Game Client in the industry, we're currently calling this a 'Director', as its primary purpose is to 'direct' which profiles are sent to the backend, and 'direct' the resulting MatchObjects to game servers. Further discussion / suggestions are welcome.
|
||||
- We'll be entering the design stage on longer-running MMFs before the end of the year. We'll get a proposal together and on the github repo as a request for comments, so please keep your eye out for that.
|
||||
- Match profiles providing multiple MMFs to run isn't planned anymore. Just send multiple copies of the profile with different MMFs specified via the backendapi.
|
||||
- Evaluators will be examined for removal in an upcoming version. There's a good change this logic should live in the Directory
|
||||
- Redis Sentinel will likely not be supported. Instead, replicated instances and HAProxy may be the HA solution of choice.
|
||||
- Redis Sentinel will likely not be supported. Instead, replicated instances and HAProxy may be the HA solution of choice. There's an [outstanding issue to investigate and implement](https://github.com/GoogleCloudPlatform/open-match/issues/41) if it fills our needs, feel free to contribute!
|
||||
|
||||
## v0.1.0 (alpha)
|
||||
Initial release.
|
@ -2,7 +2,6 @@
|
||||
FROM golang:1.10.3 as builder
|
||||
WORKDIR /go/src/github.com/GoogleCloudPlatform/open-match
|
||||
COPY cmd/frontendapi cmd/frontendapi
|
||||
COPY api/protobuf-spec/frontend.pb.go cmd/frontendapi/proto/
|
||||
COPY config config
|
||||
COPY internal internal
|
||||
WORKDIR /go/src/github.com/GoogleCloudPlatform/open-match/cmd/frontendapi
|
||||
|
@ -1,10 +1,9 @@
|
||||
# Golang application builder steps
|
||||
FROM golang:1.10.3 as builder
|
||||
# FROM golang:1.10.3 as builder
|
||||
FROM gcr.io/matchmaker-dev-201405/openmatch-devbase as builder
|
||||
WORKDIR /go/src/github.com/GoogleCloudPlatform/open-match
|
||||
COPY examples/functions/golang/simple examples/functions/golang/simple
|
||||
COPY config config
|
||||
COPY internal/statestorage internal/statestorage
|
||||
WORKDIR /go/src/github.com/GoogleCloudPlatform/open-match/examples/functions/golang/simple
|
||||
COPY examples/functions/golang/manual-simple examples/functions/golang/manual-simple
|
||||
WORKDIR /go/src/github.com/GoogleCloudPlatform/open-match/examples/functions/golang/manual-simple
|
||||
RUN go get -d -v
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o mmf .
|
||||
|
21
Dockerfile.mmf_php
Normal file
21
Dockerfile.mmf_php
Normal file
@ -0,0 +1,21 @@
|
||||
FROM php:7.2-cli
|
||||
|
||||
RUN apt-get update && apt-get install -y -q zip unzip zlib1g-dev && apt-get clean
|
||||
|
||||
RUN cd /usr/local/bin && curl -sS https://getcomposer.org/installer | php
|
||||
RUN cd /usr/local/bin && mv composer.phar composer
|
||||
|
||||
RUN pecl install grpc
|
||||
RUN echo "extension=grpc.so" > /usr/local/etc/php/conf.d/30-grpc.ini
|
||||
|
||||
RUN pecl install protobuf
|
||||
RUN echo "extension=protobuf.so" > /usr/local/etc/php/conf.d/30-protobuf.ini
|
||||
|
||||
WORKDIR /usr/src/open-match
|
||||
COPY examples/functions/php/mmlogic-simple examples/functions/php/mmlogic-simple
|
||||
COPY config config
|
||||
WORKDIR /usr/src/open-match/examples/functions/php/mmlogic-simple
|
||||
|
||||
RUN composer install
|
||||
|
||||
CMD [ "php", "./harness.php" ]
|
53
README.md
53
README.md
@ -1,20 +1,18 @@
|
||||
# Open Match
|
||||
|
||||
Open Match is an open source game matchmaker designed to allow game creators to re-use a common matchmaker framework. It’s designed to be flexible (run it anywhere Kubernetes runs), extensible (match logic can be customized to work for any game), and scalable.
|
||||
Open Match is an open source game matchmaking framework designed to allow game creators to re-use a common matchmaker framework. It’s designed to be flexible (run it anywhere Kubernetes runs), extensible (match logic can be customized to work for any game), and scalable.
|
||||
|
||||
Matchmaking is a complicated process, and when large player populations are involved, many popular matchmaking approaches touch on significant areas of computer science including graph theory and massively concurrent processing. Open Match is an effort to provide a foundation upon which these difficult problems can be addressed by the wider game development community. As Josh Menke — famous for working on matchmaking for many popular triple-A franchises — put it:
|
||||
|
||||
["Matchmaking, a lot of it actually really is just really good engineering. There's a lot of really hard networking and plumbing problems that need to be solved, depending on the size of your audience."](https://youtu.be/-pglxege-gU?t=830)
|
||||
|
||||
|
||||
This project attempts to solve the networking and plumbing problems, so game developers can focus on the logic to match players into great games.
|
||||
|
||||
## Disclaimer
|
||||
This software is currently alpha, and subject to change. **It is not yet ready to be used in production.**
|
||||
This software is currently alpha, and subject to change. Although Open Match has already been used to run [production workloads within Google](https://cloud.google.com/blog/topics/inside-google-cloud/no-tricks-just-treats-globally-scaling-the-halloween-multiplayer-doodle-with-open-match-on-google-cloud), but it's still early days on the way to our final goal. There's plenty left to write and we welcome contributions. **We strongly encourage you to engage with the community through the [Slack or Mailing lists](#get-involved) if you're considering using Open Match in production before the 1.0 release, as the documentation is likely to lag behind the latest version a bit while we focus on getting out of alpha/beta as soon as possible.**
|
||||
|
||||
## Version
|
||||
The current stable version in master is 0.1.0.
|
||||
The 0.2.0 RC1 is now available.
|
||||
[The current stable version in master is 0.2.0 (alpha)](https://github.com/GoogleCloudPlatform/open-match/releases/tag/020).
|
||||
|
||||
# Core Concepts
|
||||
|
||||
@ -28,10 +26,11 @@ Open Match is designed to support massively concurrent matchmaking, and to be sc
|
||||
* **Component** — One of the discrete processes in an Open Match deployment. Open Match is composed of multiple scalable microservices called 'components'.
|
||||
* **Roster** — A list of all the players in a match.
|
||||
* **Profile** — The json blob containing all the parameters used to select which players go into a roster.
|
||||
* **Match Object** — A protobuffer message format that contains the Profile and the results of the matchmaking function. Sent to the backend API from yoru game backend with an empty roster and then returned from your MMF with the matchmaking results filled in.
|
||||
* **Match Object** — A protobuffer message format that contains the Profile and the results of the matchmaking function. Sent to the backend API from your game backend with an empty roster and then returned from your MMF with the matchmaking results filled in.
|
||||
* **MMFOrc** — Matchmaker function orchestrator. This Open Match core component is in charge of kicking off custom matchmaking functions (MMFs) and evaluator processes.
|
||||
* **State Storage** — The storage software used by Open Match to hold all the matchmaking state. Open Match ships with [Redis](https://redis.io/) as the default state storage.
|
||||
* **Assignment** — Refers to assigning a player or group of players to a dedicated game server instance. Open Match offers a path to send dedicated game server connection details from your backend to your game clients after a match has been made.
|
||||
* **DGS** — Dedicated game server
|
||||
|
||||
## Requirements
|
||||
* [Kubernetes](https://kubernetes.io/) cluster — tested with version 1.9.
|
||||
@ -93,7 +92,7 @@ The MMLogic API provides a series of gRPC functions that act as a Matchmaking Fu
|
||||
|
||||
More details about the available gRPC calls can be found in the [API Specification](api/protobuf-spec/messages.proto).
|
||||
|
||||
**Note**: using the MMLogic API is **optional**. It tries to simplify the development of MMFs, but if you want to take care of these tasks on your own, you can make few or no calls to the MMLogic API as long as your MMF still completes all the required tasks. Read the [Matchmaking Functions section](https://github.com/GoogleCloudPlatform/open-match#matchmaking-functions-mmfs) for more details of what work an MMF must do.
|
||||
**Note**: using the MMLogic API is **optional**. It tries to simplify the development of MMFs, but if you want to take care of these tasks on your own, you can make few or no calls to the MMLogic API as long as your MMF still completes all the required tasks. Read the [Matchmaking Functions section](#matchmaking-functions-mmfs) for more details of what work an MMF must do.
|
||||
|
||||
### Evaluator
|
||||
|
||||
@ -107,16 +106,23 @@ Large-scale concurrent matchmaking functions is a complex topic, and users who w
|
||||
|
||||
Matchmaking Functions (MMFs) are run by the Matchmaker Function Orchestrator (MMFOrc) — once per profile it sees in state storage. The MMF is run as a Job in Kubernetes, and has full access to read and write from state storage. At a high level, the encouraged pattern is to write a MMF in whatever language you are comfortable in that can do the following things:
|
||||
|
||||
1. Be packaged in a (Linux) Docker container.
|
||||
1. Read/write from the Open Match state storage — Open Match ships with Redis as the default state storage.
|
||||
1. Read a profile you wrote to state storage using the Backend API.
|
||||
1. Select from the player data you wrote to state storage using the Frontend API.
|
||||
1. Run your custom logic to try to find a match.
|
||||
1. Write the match object it creates to state storage at a specified key.
|
||||
1. Remove the players it selected from consideration by other MMFs.
|
||||
1. (Optional, but recommended) Export stats for metrics collection.
|
||||
- [x] Be packaged in a (Linux) Docker container.
|
||||
- [x] Read/write from the Open Match state storage — Open Match ships with Redis as the default state storage.
|
||||
- [x] Read a profile you wrote to state storage using the Backend API.
|
||||
- [x] Select from the player data you wrote to state storage using the Frontend API.
|
||||
- [ ] Run your custom logic to try to find a match.
|
||||
- [x] Write the match object it creates to state storage at a specified key.
|
||||
- [x] Remove the players it selected from consideration by other MMFs.
|
||||
- [x] Notify the MMFOrc of completion.
|
||||
- [x] (Optional, but recommended) Export stats for metrics collection.
|
||||
|
||||
Example MMFs are provided in Golang and C#.
|
||||
**Open Match offers [matchmaking logic API](#matchmaking-logic-mmlogic-api) calls for handling the checked items, as long as you are able to format your input and output in the data schema Open Match expects (defined in the [protobuf messages](api/protobuf-spec/messages.proto)).** You can to do this work yourself if you don't want to or can't use the data schema Open Match is looking for. However, the data formats expected by Open Match are pretty generalized and will work with most common matchmaking scenarios and game types. If you have questions about how to fit your data into the formats specified, feel free to ask us in the [Slack or mailing group](#get-involved).
|
||||
|
||||
Example MMFs are provided in these languages:
|
||||
- [C#](examples/functions/csharp/simple) (doesn't use the MMLogic API)
|
||||
- [Python3](examples/functions/python3/mmlogic-simple) (MMLogic API enabled)
|
||||
- [PHP](examples/functions/php/mmlogic-simple) (MMLogic API enabled)
|
||||
- [golang](examples/functions/golang/manual-simple) (doesn't use the MMLogic API)
|
||||
|
||||
## Open Source Software integrations
|
||||
|
||||
@ -149,17 +155,17 @@ The following examples of how to call the APIs are provided in the repository. B
|
||||
|
||||
Documentation and usage guides on how to set up and customize Open Match.
|
||||
|
||||
## Precompiled container images
|
||||
### Precompiled container images
|
||||
|
||||
Once we reach a 1.0 release, we plan to produce publicly available (Linux) Docker container images of major releases in a public image registry. Until then, refer to the 'Compiling from source' section below.
|
||||
|
||||
## Compiling from source
|
||||
### Compiling from source
|
||||
|
||||
All components of Open Match produce (Linux) Docker container images as artifacts, and there are included `Dockerfile`s for each. [Google Cloud Platform Cloud Build](https://cloud.google.com/cloud-build/docs/) users will also find `cloudbuild_COMPONENT.yaml` files for each component in the repository root.
|
||||
|
||||
All the core components for Open Match are written in Golang and use the [Dockerfile multistage builder pattern](https://docs.docker.com/develop/develop-images/multistage-build/). This pattern uses intermediate Docker containers as a Golang build environment while producing lightweight, minimized container images as final build artifacts. When the project is ready for production, we will modify the `Dockerfile`s to uncomment the last build stage. Although this pattern is great for production container images, it removes most of the utilities required to troubleshoot issues during development.
|
||||
|
||||
## Configuration
|
||||
### Configuration
|
||||
|
||||
Currently, each component reads a local config file `matchmaker_config.json`, and all components assume they have the same configuration. To this end, there is a single centralized config file located in the `<REPO_ROOT>/config/` which is symlinked to each component's subdirectory for convenience when building locally. When `docker build`ing the component container images, the Dockerfile copies the centralized config file into the component directory.
|
||||
|
||||
@ -217,8 +223,9 @@ Apache 2.0
|
||||
|
||||
## State storage
|
||||
- [ ] All state storage operations should be isolated from core components into the `statestorage/` modules. This is necessary precursor work to enabling Open Match state storage to use software other than Redis.
|
||||
- [ ] The Redis deployment should have an example HA configuration using HAProxy
|
||||
- [ ] [The Redis deployment should have an example HA configuration](https://github.com/GoogleCloudPlatform/open-match/issues/41)
|
||||
- [ ] Redis watch should be unified to watch a hash and stream updates. The code for this is written and validated but not committed yet. We don't want to support two redis watcher code paths, so the backend watch of the match object should be switched to unify the way the frontend and backend watch keys. The backend part of this is in but the frontend part is in another branch and will be committed later.
|
||||
- [ ] Player/Group records generated when a client enters the matchmaking pool need to be removed after a certain amount of time with no activity. When using Redis, this will be implemented as a expiration on the player record.
|
||||
|
||||
## Instrumentation / Metrics / Analytics
|
||||
- [ ] Instrumentation of MMFs is in the planning stages. Since MMFs are by design meant to be completely customizable (to the point of allowing any process that can be packaged in a Docker container), metrics/stats will need to have an expected format and formalized outgoing pathway. Currently the thought is that it might be that the metrics should be written to a particular key in statestorage in a format compatible with opencensus, and will be collected, aggreggated, and exported to Prometheus using another process.
|
||||
@ -232,7 +239,6 @@ Apache 2.0
|
||||
- [ ] Autoscaling isn't turned on for the Frontend or Backend API Kubernetes deployments by default.
|
||||
- [ ] A [Helm](https://helm.sh/) chart to stand up Open Match will be provided in an upcoming version. For now just use the [installation YAMLs](./install/yaml).
|
||||
|
||||
- [ ] Player/Group records generated when a client enters the matchmaking pool need to be removed after a certain amount of time with no activity. When using Redis, this will be implemented as a expiration on the player record.
|
||||
## CI / CD / Build
|
||||
- [ ] We plan to host 'official' docker images for all release versions of the core components in publicly available docker registries soon.
|
||||
- [ ] CI/CD for this repo and the associated status tags are planned.
|
||||
@ -240,4 +246,7 @@ Apache 2.0
|
||||
- [ ] A full load-testing and e2e testing suite will be included in an upcoming version.
|
||||
|
||||
## Will not Implement
|
||||
- [X] Match profiles should be able to define multiple MMF container images to run, but this is not currently supported. This enables A/B testing and several other scenarios.
|
||||
- [X] Defining multiple images inside a profile for the purposes of experimentation adds another layer of complexity into profiles that can instead be handled outside of open match with custom match functions in collaboration with a director (thing that calls backend to schedule matchmaking)
|
||||
|
||||
### Special Thanks
|
||||
- Thanks to https://jbt.github.io/markdown-editor/ for help in marking this document down.
|
||||
|
@ -55,7 +55,7 @@ service MmLogic {
|
||||
// Player listing and filtering functions
|
||||
//
|
||||
// RetrievePlayerPool gets the list of players that match every Filter in the
|
||||
// PlayerPool, and then removes all players it finds in the ignore list. It
|
||||
// PlayerPool, .excluding players in any configured ignore lists. It
|
||||
// combines the results, and returns the resulting player pool.
|
||||
rpc GetPlayerPool(messages.PlayerPool) returns (stream messages.PlayerPool) {}
|
||||
|
||||
@ -63,8 +63,8 @@ service MmLogic {
|
||||
//
|
||||
// IlInput is an empty message reserved for future use.
|
||||
rpc GetAllIgnoredPlayers(messages.IlInput) returns (messages.Roster) {}
|
||||
// RetrieveIgnoreList retrieves players from the ignore list specified in the
|
||||
// config file under 'ignoreLists.proposedPlayers.key'.
|
||||
// ListIgnoredPlayers retrieves players from the ignore list specified in the
|
||||
// config file under 'ignoreLists.proposed.name'.
|
||||
rpc ListIgnoredPlayers(messages.IlInput) returns (messages.Roster) {}
|
||||
|
||||
// NYI
|
||||
|
@ -1,9 +0,0 @@
|
||||
steps:
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [
|
||||
'build',
|
||||
'--tag=gcr.io/$PROJECT_ID/openmatch-mmf:dev',
|
||||
'-f', 'Dockerfile.mmf',
|
||||
'.'
|
||||
]
|
||||
images: ['gcr.io/$PROJECT_ID/openmatch-mmf:dev']
|
11
cloudbuild_mmf_go.yaml
Normal file
11
cloudbuild_mmf_go.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
steps:
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [ 'pull', 'gcr.io/$PROJECT_ID/openmatch-devbase:latest' ]
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [
|
||||
'build',
|
||||
'--tag=gcr.io/$PROJECT_ID/openmatch-mmf:go',
|
||||
'-f', 'Dockerfile.mmf_go',
|
||||
'.'
|
||||
]
|
||||
images: ['gcr.io/$PROJECT_ID/openmatch-mmf:go']
|
9
cloudbuild_mmf_php.yaml
Normal file
9
cloudbuild_mmf_php.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
steps:
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [
|
||||
'build',
|
||||
'--tag=gcr.io/$PROJECT_ID/openmatch-mmf:php',
|
||||
'-f', 'Dockerfile.mmf_php',
|
||||
'.'
|
||||
]
|
||||
images: ['gcr.io/$PROJECT_ID/openmatch-mmf:php']
|
@ -1,11 +1,8 @@
|
||||
steps:
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [ 'pull', 'gcr.io/$PROJECT_ID/openmatch-mmf:py3' ]
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [
|
||||
'build',
|
||||
'--tag=gcr.io/$PROJECT_ID/openmatch-mmf:py3',
|
||||
'--cache-from=gcr.io/$PROJECT_ID/openmatch-mmf:py3',
|
||||
'-f', 'Dockerfile.mmf_py3',
|
||||
'.'
|
||||
]
|
||||
|
@ -1,11 +1,8 @@
|
||||
steps:
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [ 'pull', 'gcr.io/$PROJECT_ID/openmatch-mmforc:dev']
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [
|
||||
'build',
|
||||
'--tag=gcr.io/$PROJECT_ID/openmatch-mmforc:dev',
|
||||
'--cache-from=gcr.io/$PROJECT_ID/openmatch-mmforc:dev',
|
||||
'-f', 'Dockerfile.mmforc',
|
||||
'.'
|
||||
]
|
||||
|
@ -1,11 +1,8 @@
|
||||
steps:
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [ 'pull', 'gcr.io/$PROJECT_ID/openmatch-mmlogicapi:dev' ]
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: [
|
||||
'build',
|
||||
'--tag=gcr.io/$PROJECT_ID/openmatch-mmlogicapi:dev',
|
||||
'--cache-from=gcr.io/$PROJECT_ID/openmatch-mmlogicapi:dev',
|
||||
'-f', 'Dockerfile.mmlogicapi',
|
||||
'.'
|
||||
]
|
||||
|
@ -83,7 +83,7 @@ func New(cfg *viper.Viper, pool *redis.Pool) *BackendAPI {
|
||||
return &s
|
||||
}
|
||||
|
||||
// Open opens the api grpc service, starting it listening on the configured port.
|
||||
// Open starts the api grpc service listening on the configured port.
|
||||
func (s *BackendAPI) Open() error {
|
||||
ln, err := net.Listen("tcp", ":"+s.cfg.GetString("api.backend.port"))
|
||||
if err != nil {
|
||||
@ -346,8 +346,6 @@ func (s *backendAPI) DeleteMatch(ctx context.Context, mo *backend.MatchObject) (
|
||||
// defined in ../proto/backend.proto
|
||||
func (s *backendAPI) CreateAssignments(ctx context.Context, a *backend.Assignments) (*backend.Result, error) {
|
||||
|
||||
// TODO: make playerIDs a repeated protobuf message field and iterate over it
|
||||
//assignments := strings.Split(a.Roster.PlayerIds, " ")
|
||||
assignments := make([]string, 0)
|
||||
for _, roster := range a.Rosters {
|
||||
assignments = append(assignments, getPlayerIdsFromRoster(roster)...)
|
||||
|
@ -75,7 +75,7 @@ func New(cfg *viper.Viper, pool *redis.Pool) *FrontendAPI {
|
||||
return &s
|
||||
}
|
||||
|
||||
// Open opens the api grpc service, starting it listening on the configured port.
|
||||
// Open starts the api grpc service listening on the configured port.
|
||||
func (s *FrontendAPI) Open() error {
|
||||
ln, err := net.Listen("tcp", ":"+s.cfg.GetString("api.frontend.port"))
|
||||
if err != nil {
|
||||
|
@ -31,6 +31,8 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/metrics"
|
||||
mmlogic "github.com/GoogleCloudPlatform/open-match/internal/pb"
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/set"
|
||||
redishelpers "github.com/GoogleCloudPlatform/open-match/internal/statestorage/redis"
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/statestorage/redis/ignorelist"
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/statestorage/redis/redispb"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -80,7 +82,7 @@ func New(cfg *viper.Viper, pool *redis.Pool) *MmlogicAPI {
|
||||
return &s
|
||||
}
|
||||
|
||||
// Open opens the api grpc service, starting it listening on the configured port.
|
||||
// Open starts the api grpc service listening on the configured port.
|
||||
func (s *MmlogicAPI) Open() error {
|
||||
ln, err := net.Listen("tcp", ":"+s.cfg.GetString("api.mmlogic.port"))
|
||||
if err != nil {
|
||||
@ -219,20 +221,23 @@ func (s *mmlogicAPI) CreateProposal(c context.Context, prop *mmlogic.MatchObject
|
||||
return &mmlogic.Result{Success: false, Error: err.Error()}, err
|
||||
}
|
||||
}
|
||||
/*
|
||||
// add propkey to proposalsq
|
||||
_, err = redisConn.Do("SADD", proposalq, prop.Id)
|
||||
if err != nil {
|
||||
cpLog.WithFields(log.Fields{
|
||||
"error": err.Error(),
|
||||
"component": "statestorage",
|
||||
"key": proposalq,
|
||||
"proposal": prop.Id,
|
||||
}).Error("State storage error")
|
||||
stats.Record(fnCtx, MlGrpcErrors.M(1))
|
||||
return &mmlogic.Result{Success: false, Error: err.Error()}, err
|
||||
}
|
||||
*/
|
||||
|
||||
// Mark this MMF as finished by decrementing the concurrent MMFs.
|
||||
// This is used to trigger the evaluator early if all MMFs have finished
|
||||
// before its next scheduled run.
|
||||
cmLog := cpLog.WithFields(log.Fields{
|
||||
"component": "statestorage",
|
||||
"key": "concurrentMMFs",
|
||||
})
|
||||
cmLog.Info("marking MMF finished for evaluator")
|
||||
_, err = redishelpers.Decrement(fnCtx, s.pool, "concurrentMMFs")
|
||||
if err != nil {
|
||||
cmLog.WithFields(log.Fields{"error": err.Error()}).Error("State storage error")
|
||||
|
||||
// record error.
|
||||
stats.Record(fnCtx, MlGrpcErrors.M(1))
|
||||
return &mmlogic.Result{Success: false, Error: err.Error()}, err
|
||||
}
|
||||
|
||||
stats.Record(fnCtx, MlGrpcRequests.M(1))
|
||||
return &mmlogic.Result{Success: true, Error: ""}, err
|
||||
@ -271,13 +276,6 @@ func (s *mmlogicAPI) GetPlayerPool(pool *mmlogic.PlayerPool, stream mmlogic.MmLo
|
||||
|
||||
filterStart := time.Now()
|
||||
results, err := s.applyFilter(ctx, thisFilter)
|
||||
if results == nil && err == nil {
|
||||
// Filter applies to so many players that we can't filter on it.
|
||||
// Ignore this filter and attempt to process all the rest.
|
||||
thisFilter.Stats = &mmlogic.Stats{Elapsed: time.Since(filterStart).Seconds()}
|
||||
continue
|
||||
}
|
||||
|
||||
thisFilter.Stats = &mmlogic.Stats{Count: int64(len(results)), Elapsed: time.Since(filterStart).Seconds()}
|
||||
mlLog.WithFields(log.Fields{
|
||||
"count": int64(len(results)),
|
||||
@ -313,7 +311,7 @@ func (s *mmlogicAPI) GetPlayerPool(pool *mmlogic.PlayerPool, stream mmlogic.MmLo
|
||||
|
||||
}
|
||||
|
||||
// Make an array of only the player IDs; used to do unions and find the
|
||||
// Make an array of only the player IDs; used to do set.Unions and find the
|
||||
// logical AND
|
||||
m := make([]string, len(results))
|
||||
i := 0
|
||||
@ -331,7 +329,7 @@ func (s *mmlogicAPI) GetPlayerPool(pool *mmlogic.PlayerPool, stream mmlogic.MmLo
|
||||
|
||||
// Player must be in every filtered pool to be returned
|
||||
for field, thesePlayers := range filteredRosters {
|
||||
overlap = intersection(overlap, thesePlayers)
|
||||
overlap = set.Intersection(overlap, thesePlayers)
|
||||
|
||||
_ = field
|
||||
//mlLog.WithFields(log.Fields{"count": len(overlap), "field": field}).Debug("Amount of overlap")
|
||||
@ -344,7 +342,7 @@ func (s *mmlogicAPI) GetPlayerPool(pool *mmlogic.PlayerPool, stream mmlogic.MmLo
|
||||
}
|
||||
mlLog.WithFields(log.Fields{"count": len(overlap)}).Debug("Pool size before applying ignorelists")
|
||||
mlLog.WithFields(log.Fields{"count": len(il)}).Debug("Ignorelist size")
|
||||
playerList := difference(overlap, il) // removes ignorelist from the Roster
|
||||
playerList := set.Difference(overlap, il) // removes ignorelist from the Roster
|
||||
mlLog.WithFields(log.Fields{"count": len(playerList)}).Debug("Final Pool size")
|
||||
|
||||
// Reformat the playerList as a gRPC PlayerPool message. Send partial results as we go.
|
||||
@ -400,7 +398,9 @@ func (s *mmlogicAPI) GetPlayerPool(pool *mmlogic.PlayerPool, stream mmlogic.MmLo
|
||||
// If the provided field is not indexed or the provided range is too large, a nil result
|
||||
// is returned and this filter should be disregarded when applying filter overlaps.
|
||||
func (s *mmlogicAPI) applyFilter(c context.Context, filter *mmlogic.Filter) (map[string]int64, error) {
|
||||
|
||||
type pName string
|
||||
pool := make(map[string]int64)
|
||||
|
||||
// Default maximum value is positive infinity (i.e. highest possible number in redis)
|
||||
// https://redis.io/commands/zrangebyscore
|
||||
@ -438,8 +438,13 @@ func (s *mmlogicAPI) applyFilter(c context.Context, filter *mmlogic.Filter) (map
|
||||
} else if count > 500000 {
|
||||
// 500,000 results is an arbitrary number; OM doesn't encourage
|
||||
// patterns where MMFs look at this large of a pool.
|
||||
mlLog.Warn("filter applies to too many players, ignoring")
|
||||
return nil, nil
|
||||
err = errors.New("filter applies to too many players")
|
||||
mlLog.Error(err.Error())
|
||||
for i := 0; i < int(count); i++ {
|
||||
// Send back an empty pool, used by the calling function to calculate the number of results
|
||||
pool[strconv.Itoa(i)] = 0
|
||||
}
|
||||
return pool, err
|
||||
} else if count < 100000 {
|
||||
mlLog.Info("filter processed")
|
||||
} else {
|
||||
@ -451,7 +456,6 @@ func (s *mmlogicAPI) applyFilter(c context.Context, filter *mmlogic.Filter) (map
|
||||
// var init for player retrieval
|
||||
cmd = "ZRANGEBYSCORE"
|
||||
offset := 0
|
||||
pool := make(map[string]int64)
|
||||
|
||||
// Loop, retrieving players in chunks.
|
||||
for len(pool) == offset {
|
||||
@ -566,77 +570,12 @@ func (s *mmlogicAPI) allIgnoreLists(c context.Context, in *mmlogic.IlInput) (all
|
||||
}
|
||||
|
||||
// Join this ignorelist to the others we've retrieved
|
||||
allIgnored = union(allIgnored, thisIl)
|
||||
allIgnored = set.Union(allIgnored, thisIl)
|
||||
}
|
||||
|
||||
return allIgnored, err
|
||||
}
|
||||
|
||||
// Set data structure functions.
|
||||
// TODO: maybe move these into an internal module if they are useful elsewhere.
|
||||
func intersection(a []string, b []string) (out []string) {
|
||||
|
||||
hash := make(map[string]bool)
|
||||
|
||||
for _, v := range a {
|
||||
hash[v] = true
|
||||
}
|
||||
|
||||
for _, v := range b {
|
||||
if _, found := hash[v]; found {
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
|
||||
}
|
||||
|
||||
func union(a []string, b []string) (out []string) {
|
||||
|
||||
hash := make(map[string]bool)
|
||||
|
||||
// collect all values from input args
|
||||
for _, v := range a {
|
||||
hash[v] = true
|
||||
}
|
||||
|
||||
for _, v := range b {
|
||||
hash[v] = true
|
||||
}
|
||||
|
||||
// put values into string array
|
||||
for k := range hash {
|
||||
out = append(out, k)
|
||||
}
|
||||
|
||||
return out
|
||||
|
||||
}
|
||||
|
||||
func difference(a []string, b []string) (out []string) {
|
||||
|
||||
hash := make(map[string]bool)
|
||||
out = append([]string{}, a...)
|
||||
|
||||
for _, v := range b {
|
||||
hash[v] = true
|
||||
}
|
||||
|
||||
// Iterate through output, removing items found in b
|
||||
for i := 0; i < len(out); i++ {
|
||||
if _, found := hash[out[i]]; found {
|
||||
// Remove this element by moving the copying the last element of the
|
||||
// array to this index and then slicing off the last element.
|
||||
// https://stackoverflow.com/a/37335777/3113674
|
||||
out[i] = out[len(out)-1]
|
||||
out = out[:len(out)-1]
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// Functions for getting or setting player IDs to/from rosters
|
||||
// Probably should get moved to an internal module in a future version.
|
||||
func getPlayerIdsFromRoster(r *mmlogic.Roster) []string {
|
||||
|
@ -29,7 +29,6 @@
|
||||
"name":"om-backend",
|
||||
"image":"gcr.io/matchmaker-dev-201405/openmatch-backendapi:dev",
|
||||
"imagePullPolicy":"Always",
|
||||
"command": ["sleep", "30000"],
|
||||
"ports": [
|
||||
{
|
||||
"name": "grpc",
|
||||
|
@ -29,7 +29,6 @@
|
||||
"name":"om-mmforc",
|
||||
"image":"gcr.io/matchmaker-dev-201405/openmatch-mmforc:dev",
|
||||
"imagePullPolicy":"Always",
|
||||
"command": ["sleep", "30000"],
|
||||
"ports": [
|
||||
{
|
||||
"name": "metrics",
|
||||
|
@ -29,7 +29,6 @@
|
||||
"name":"om-mmlogic",
|
||||
"image":"gcr.io/matchmaker-dev-201405/openmatch-mmlogicapi:dev",
|
||||
"imagePullPolicy":"Always",
|
||||
"command": ["sleep", "30000"],
|
||||
"ports": [
|
||||
{
|
||||
"name": "grpc",
|
||||
@ -52,23 +51,3 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "om-mmlogicapi"
|
||||
},
|
||||
"spec": {
|
||||
"selector": {
|
||||
"app": "openmatch",
|
||||
"component": "mmlogic"
|
||||
},
|
||||
"ports": [
|
||||
{
|
||||
"protocol": "TCP",
|
||||
"port": 50503,
|
||||
"targetPort": "grpc"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
20
deployments/k8s/mmlogicapi_service.json
Normal file
20
deployments/k8s/mmlogicapi_service.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "om-mmlogicapi"
|
||||
},
|
||||
"spec": {
|
||||
"selector": {
|
||||
"app": "openmatch",
|
||||
"component": "mmlogic"
|
||||
},
|
||||
"ports": [
|
||||
{
|
||||
"protocol": "TCP",
|
||||
"port": 50503,
|
||||
"targetPort": "grpc"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -4,17 +4,58 @@ All components of Open Match produce (Linux) Docker container images as artifact
|
||||
|
||||
Note: Although Google Cloud Platform includes some free usage, you may incur charges following this guide if you use GCP products.
|
||||
|
||||
**This project has not completed a first-line security audit, and there are definitely going to be some service accounts that are too permissive. This should be fine for testing/development in a local environment, but absolutely should not be used as-is in a production environment.**
|
||||
## Security Disclaimer
|
||||
**This project has not completed a first-line security audit, and there are definitely going to be some service accounts that are too permissive. This should be fine for testing/development in a local environment, but absolutely should not be used as-is in a production environment without your team/organization evaluating it's permissions.**
|
||||
|
||||
## Before getting started
|
||||
**NOTE**: Before starting with this guide, you'll need to update all the URIs from the tutorial's gcr.io container image registry with the URI for your own image registry. If you are using the gcr.io registry on GCP, the default URI is `gcr.io/<PROJECT_NAME>`. Here's an example command in Linux to do the replacement for you this (replace YOUR_REGISTRY_URI with your URI, this should be run from the repository root directory):
|
||||
```
|
||||
# Linux
|
||||
egrep -lR 'gcr.io/matchmaker-dev-201405' . | xargs sed -i -e 's|gcr.io/matchmaker-dev-201405|YOUR_REGISTRY_URI|g'
|
||||
```
|
||||
```
|
||||
# Mac OS, you can delete the .backup files after if all looks good
|
||||
egrep -lR 'gcr.io/matchmaker-dev-201405' . | xargs sed -i'.backup' -e 's|gcr.io/matchmaker-dev-201405|YOUR_REGISTRY_URI|g'
|
||||
```
|
||||
|
||||
## Example of building using Google Cloud Builder
|
||||
|
||||
The [Quickstart for Docker](https://cloud.google.com/cloud-build/docs/quickstart-docker) guide explains how to set up a project, enable billing, enable Cloud Build, and install the Cloud SDK if you haven't do these things before. Once you get to 'Preparing source files' you are ready to continue with the steps below.
|
||||
|
||||
* Clone this repo to a local machine or Google Cloud Shell session, and cd into it.
|
||||
* Run the following one-line bash script to compile all the images for the first time, and push them to your gcr.io registry. You must enable the [Container Registry API](https://console.cloud.google.com/flows/enableapi?apiid=containerregistry.googleapis.com) first.
|
||||
```
|
||||
for dfile in $(ls Dockerfile.*); do gcloud builds submit --config cloudbuild_${dfile##*.}.yaml; done
|
||||
```
|
||||
* In Linux, you can run the following one-line bash script to compile all the images for the first time, and push them to your gcr.io registry. You must enable the [Container Registry API](https://console.cloud.google.com/flows/enableapi?apiid=containerregistry.googleapis.com) first.
|
||||
```
|
||||
# First, build the 'base' image. Some other images depend on this so it must complete first.
|
||||
gcloud build submit --config cloudbuild_base.yaml
|
||||
# Build all other images.
|
||||
for dfile in $(ls Dockerfile.* | grep -v base); do gcloud builds submit --config cloudbuild_${dfile##*.}.yaml & done
|
||||
```
|
||||
* Once the cloud builds have completed, you can verify that all the builds succeeded in the cloud console or by by checking the list of images in your **gcr.io** registry:
|
||||
```
|
||||
gcloud container images list
|
||||
```
|
||||
(your registry name will be different)
|
||||
```
|
||||
NAME
|
||||
gcr.io/matchmaker-dev-201405/openmatch-backendapi
|
||||
gcr.io/matchmaker-dev-201405/openmatch-devbase
|
||||
gcr.io/matchmaker-dev-201405/openmatch-evaluator
|
||||
gcr.io/matchmaker-dev-201405/openmatch-frontendapi
|
||||
gcr.io/matchmaker-dev-201405/openmatch-mmf
|
||||
gcr.io/matchmaker-dev-201405/openmatch-mmforc
|
||||
gcr.io/matchmaker-dev-201405/openmatch-mmlogicapi
|
||||
```
|
||||
* The default example MMF images all use the same name (`openmatch-mmf`), with different image tags designating the different examples. You can check that these exist by running this command (again, substituting your **gcr.io** registry):
|
||||
```
|
||||
gcloud container images list-tags gcr.io/matchmaker-dev-201405/openmatch-mmf
|
||||
```
|
||||
You should see tags for several of the example MMFs. By default, Open Match will try to use the `openmatch-mmf:py3` image in the examples below, so it is important that the image build was successful and a `py3` image tag exists in your **gcr.io** registry before you continue:
|
||||
```
|
||||
DIGEST TAGS TIMESTAMP
|
||||
5345475e026c php 2018-12-05T00:06:47
|
||||
e5c274c3509c go 2018-12-05T00:02:17
|
||||
1b3ec3176d0f py3 2018-12-05T00:02:07
|
||||
```
|
||||
|
||||
## Example of starting a GKE cluster
|
||||
|
||||
@ -32,76 +73,115 @@ gcloud compute zones list
|
||||
|
||||
## Configuration
|
||||
|
||||
Currently, each component reads a local config file `matchmaker_config.json` , and all components assume they have the same configuration. To this end, there is a single centralized config file located in the `<REPO_ROOT>/config/` which is symlinked to each component's subdirectory for convenience when building locally.
|
||||
|
||||
**NOTE** 'defaultImages' container images names in the config file will need to be updated with **your container registry URI**. Here's an example command in Linux to do this (just replace YOUR_REGISTRY_URI with the appropriate location in your environment, should be run from the config directory):
|
||||
```
|
||||
sed -i 's|gcr.io/matchmaker-dev-201405|YOUR_REGISTRY_URI|g' matchmaker_config.json
|
||||
```
|
||||
For MacOS the `-i` flag creates backup files when changing the original file in place. You can use the following command, and then delete the `*.backup` files afterwards if you don't need them anymore:
|
||||
```
|
||||
sed -i'.backup' -e 's|gcr.io/matchmaker-dev-201405|YOUR_REGISTRY_URI|g' matchmaker_config.json
|
||||
```
|
||||
If you are using the gcr.io registry on GCP, the default URI is `gcr.io/<PROJECT_NAME>`.
|
||||
|
||||
We plan to replace this with a Kubernetes-managed config with dynamic reloading when development time allows. Pull requests are welcome!
|
||||
Currently, each component reads a local config file `matchmaker_config.json`, and all components assume they have the same configuration (if you would like to help us design the replacement config solution, please join the [discussion](https://github.com/GoogleCloudPlatform/open-match/issues/42). To this end, there is a single centralized config file located in the `<REPO_ROOT>/config/` which is symlinked to each component's subdirectory for convenience when building locally.
|
||||
|
||||
## Running Open Match in a development environment
|
||||
|
||||
The rest of this guide assumes you have a cluster (example is using GKE, but works on any cluster with a little tweaking), and kubectl configured to administer that cluster, and you've built all the Docker container images described by `Dockerfiles` in the repository root directory and given them the docker tag 'dev'. It assumes you are in the `<REPO_ROOT>/deployments/k8s/` directory.
|
||||
|
||||
**NOTE** Kubernetes resources that use container images will need to be updated with **your container registry URI**. Here's an example command in Linux to do this (just replace YOUR_REGISTRY_URI with the appropriate location in your environment):
|
||||
```
|
||||
sed -i 's|gcr.io/matchmaker-dev-201405|YOUR_REGISTRY_URI|g' *deployment.json
|
||||
```
|
||||
For MacOS the `-i` flag creates backup files when changing the original file in place. You can use the following command, and then delete the `*.backup` files afterwards if you don't need them anymore:
|
||||
```
|
||||
sed -i'.backup' -e 's|gcr.io/matchmaker-dev-201405|YOUR_REGISTRY_URI|g' *deployment.json
|
||||
```
|
||||
If you are using the gcr.io registry on GCP, the default URI is `gcr.io/<PROJECT_NAME>`.
|
||||
|
||||
* Start a copy of redis and a service in front of it:
|
||||
```
|
||||
kubectl apply -f redis_deployment.json
|
||||
kubectl apply -f redis_service.json
|
||||
```
|
||||
* Run the **core components**: the frontend API, the backend API, and the matchmaker function orchestrator (MMFOrc).
|
||||
```
|
||||
kubectl apply -f redis_deployment.json
|
||||
kubectl apply -f redis_service.json
|
||||
```
|
||||
* Run the **core components**: the frontend API, the backend API, the matchmaker function orchestrator (MMFOrc), and the matchmaking logic API.
|
||||
**NOTE** In order to kick off jobs, the matchmaker function orchestrator needs a service account with permission to administer the cluster. This should be updated to have min required perms before launch, this is pretty permissive but acceptable for closed testing:
|
||||
```
|
||||
kubectl apply -f backendapi_deployment.json
|
||||
kubectl apply -f backendapi_service.json
|
||||
kubectl apply -f frontendapi_deployment.json
|
||||
kubectl apply -f frontendapi_service.json
|
||||
kubectl apply -f mmforc_deployment.json
|
||||
kubectl apply -f mmforc_serviceaccount.json
|
||||
```
|
||||
```
|
||||
kubectl apply -f backendapi_deployment.json
|
||||
kubectl apply -f backendapi_service.json
|
||||
kubectl apply -f frontendapi_deployment.json
|
||||
kubectl apply -f frontendapi_service.json
|
||||
kubectl apply -f mmforc_deployment.json
|
||||
kubectl apply -f mmforc_serviceaccount.json
|
||||
kubectl apply -f mmlogic_deployment.json
|
||||
kubectl apply -f mmlogic_service.json
|
||||
```
|
||||
* [optional, but recommended] Configure the OpenCensus metrics services:
|
||||
```
|
||||
kubectl apply -f metrics_services.json
|
||||
```
|
||||
```
|
||||
kubectl apply -f metrics_services.json
|
||||
```
|
||||
* [optional] Trying to apply the Kubernetes Prometheus Operator resource definition files without a cluster-admin rolebinding on GKE doesn't work without running the following command first. See https://github.com/coreos/prometheus-operator/issues/357
|
||||
```
|
||||
kubectl create clusterrolebinding projectowner-cluster-admin-binding --clusterrole=cluster-admin --user=<GCP_ACCOUNT>
|
||||
```
|
||||
```
|
||||
kubectl create clusterrolebinding projectowner-cluster-admin-binding --clusterrole=cluster-admin --user=<GCP_ACCOUNT>
|
||||
```
|
||||
* [optional, uses beta software] If using Prometheus as your metrics gathering backend, configure the [Prometheus Kubernetes Operator](https://github.com/coreos/prometheus-operator):
|
||||
|
||||
```
|
||||
kubectl apply -f prometheus_operator.json
|
||||
kubectl apply -f prometheus.json
|
||||
kubectl apply -f prometheus_service.json
|
||||
kubectl apply -f metrics_servicemonitor.json
|
||||
```
|
||||
|
||||
```
|
||||
kubectl apply -f prometheus_operator.json
|
||||
kubectl apply -f prometheus.json
|
||||
kubectl apply -f prometheus_service.json
|
||||
kubectl apply -f metrics_servicemonitor.json
|
||||
```
|
||||
You should now be able to see the core component pods running using a `kubectl get pods`, and the core component metrics in the Prometheus Web UI by running `kubectl proxy <PROMETHEUS_POD_NAME> 9090:9090` in your local shell, then opening http://localhost:9090/targets in your browser to see which services Prometheus is collecting from.
|
||||
|
||||
Here's an example output from `kubectl get all` if everything started correctly, and you included all the optional components (note: this could become out-of-date with upcoming versions; apologies if that happens):
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
pod/om-backendapi-84bc9d8fff-q89kr 1/1 Running 0 9m
|
||||
pod/om-frontendapi-55d5bb7946-c5ccb 1/1 Running 0 9m
|
||||
pod/om-mmforc-85bfd7f4f6-wmwhc 1/1 Running 0 9m
|
||||
pod/om-mmlogicapi-6488bc7fc6-g74dm 1/1 Running 0 9m
|
||||
pod/prometheus-operator-5c8774cdd8-7c5qm 1/1 Running 0 9m
|
||||
pod/prometheus-prometheus-0 2/2 Running 0 9m
|
||||
pod/redis-master-9b6b86c46-b7ggn 1/1 Running 0 9m
|
||||
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
service/kubernetes ClusterIP 10.59.240.1 <none> 443/TCP 19m
|
||||
service/om-backend-metrics ClusterIP 10.59.254.43 <none> 29555/TCP 9m
|
||||
service/om-backendapi ClusterIP 10.59.240.211 <none> 50505/TCP 9m
|
||||
service/om-frontend-metrics ClusterIP 10.59.246.228 <none> 19555/TCP 9m
|
||||
service/om-frontendapi ClusterIP 10.59.250.59 <none> 50504/TCP 9m
|
||||
service/om-mmforc-metrics ClusterIP 10.59.240.59 <none> 39555/TCP 9m
|
||||
service/om-mmlogicapi ClusterIP 10.59.248.3 <none> 50503/TCP 9m
|
||||
service/prometheus NodePort 10.59.252.212 <none> 9090:30900/TCP 9m
|
||||
service/prometheus-operated ClusterIP None <none> 9090/TCP 9m
|
||||
service/redis-sentinel ClusterIP 10.59.249.197 <none> 6379/TCP 9m
|
||||
|
||||
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
|
||||
deployment.extensions/om-backendapi 1 1 1 1 9m
|
||||
deployment.extensions/om-frontendapi 1 1 1 1 9m
|
||||
deployment.extensions/om-mmforc 1 1 1 1 9m
|
||||
deployment.extensions/om-mmlogicapi 1 1 1 1 9m
|
||||
deployment.extensions/prometheus-operator 1 1 1 1 9m
|
||||
deployment.extensions/redis-master 1 1 1 1 9m
|
||||
|
||||
NAME DESIRED CURRENT READY AGE
|
||||
replicaset.extensions/om-backendapi-84bc9d8fff 1 1 1 9m
|
||||
replicaset.extensions/om-frontendapi-55d5bb7946 1 1 1 9m
|
||||
replicaset.extensions/om-mmforc-85bfd7f4f6 1 1 1 9m
|
||||
replicaset.extensions/om-mmlogicapi-6488bc7fc6 1 1 1 9m
|
||||
replicaset.extensions/prometheus-operator-5c8774cdd8 1 1 1 9m
|
||||
replicaset.extensions/redis-master-9b6b86c46 1 1 1 9m
|
||||
|
||||
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
|
||||
deployment.apps/om-backendapi 1 1 1 1 9m
|
||||
deployment.apps/om-frontendapi 1 1 1 1 9m
|
||||
deployment.apps/om-mmforc 1 1 1 1 9m
|
||||
deployment.apps/om-mmlogicapi 1 1 1 1 9m
|
||||
deployment.apps/prometheus-operator 1 1 1 1 9m
|
||||
deployment.apps/redis-master 1 1 1 1 9m
|
||||
|
||||
NAME DESIRED CURRENT READY AGE
|
||||
replicaset.apps/om-backendapi-84bc9d8fff 1 1 1 9m
|
||||
replicaset.apps/om-frontendapi-55d5bb7946 1 1 1 9m
|
||||
replicaset.apps/om-mmforc-85bfd7f4f6 1 1 1 9m
|
||||
replicaset.apps/om-mmlogicapi-6488bc7fc6 1 1 1 9m
|
||||
replicaset.apps/prometheus-operator-5c8774cdd8 1 1 1 9m
|
||||
replicaset.apps/redis-master-9b6b86c46 1 1 1 9m
|
||||
|
||||
NAME DESIRED CURRENT AGE
|
||||
statefulset.apps/prometheus-prometheus 1 1 9m
|
||||
```
|
||||
|
||||
### End-to-End testing
|
||||
|
||||
**Note** The programs provided below are just bare-bones manual testing programs with no automation and no claim of code coverage. This sparseness of this part of the documentation is because we expect to discard all of these tools and write a fully automated end-to-end test suite and a collection of load testing tools, with extensive stats output and tracing capabilities before 1.0 release. Tracing has to be integrated first, which will be in an upcoming release.
|
||||
**Note**: The programs provided below are just bare-bones manual testing programs with no automation and no claim of code coverage. This sparseness of this part of the documentation is because we expect to discard all of these tools and write a fully automated end-to-end test suite and a collection of load testing tools, with extensive stats output and tracing capabilities before 1.0 release. Tracing has to be integrated first, which will be in an upcoming release.
|
||||
|
||||
In the end: *caveat emptor*. These tools all work and are quite small, and as such are fairly easy for developers to understand by looking at the code and logging output. They are provided as-is just as a reference point of how to begin experimenting with Open Match integrations.
|
||||
In the end: *caveat emptor*. These tools all work and are quite small, and as such are fairly easy for developers to understand by looking at the code and logging output. They are provided as-is just as a reference point of how to begin experimenting with Open Match integrations.
|
||||
|
||||
* `examples/frontendclient` is a fake client for the Frontend API. It pretends to be a real game client connecting to Open Match and requests a game, then dumps out the connection string it receives. Note that it doesn't actually test the return path by looking for arbitrary results from your matchmaking function; it pauses and tells you the name of a key to set a connection string in directly using a redis-cli client.
|
||||
* `examples/backendclient` is a fake client for the Backend API. It pretends to be a dedicated game server backend connecting to openmatch and sending in a match profile to fill. Once it receives a match object with a roster, it will also issue a call to assign the player IDs, and gives an example connection string. If it never seems to get a match, make sure you're adding players to the pool using the other two tools.
|
||||
* `test/cmd/client` is a (VERY) basic client load simulation tool. It does **not** test the Frontend API - in fact, it ignores it and writes players directly to state storage on its own. It doesn't do anything but loop endlessly, writing players into state storage so you can test your backend integration, and run your custom MMFs and Evaluators (which are only triggered when there are players in the pool).
|
||||
* `examples/frontendclient` is a fake client for the Frontend API. It pretends to be a real game client connecting to Open Match and requests a game, then dumps out the connection string it receives. Note that it doesn't actually test the return path by looking for arbitrary results from your matchmaking function; it pauses and tells you the name of a key to set a connection string in directly using a redis-cli client. **Note**: If you're using the rest of these test programs, you're probably using the Backend Client below. The default profiles that sends to the backend look for way more than one player, so if you want to see meaningful results from running this Frontend Client, you're going to need to generate a bunch of fake players using the client load simulation tool at the same time. Otherwise, expect to wait until it times out as your matchmaker never has enough players to make a successful match.
|
||||
* `examples/backendclient` is a fake client for the Backend API. It pretends to be a dedicated game server backend connecting to openmatch and sending in a match profile to fill. Once it receives a match object with a roster, it will also issue a call to assign the player IDs, and gives an example connection string. If it never seems to get a match, make sure you're adding players to the pool using the other two tools. Note: building this image requires that you first build the 'base' dev image (look for `cloudbuild_base.yaml` and `Dockerfile.base` in the root directory) and then update the first step to point to that image in your registry. This will be simplified in a future release. **Note**: If you run this by itself, expect it to wait about 30 seconds, then return a result of 'insufficient players' and exit - this is working as intended. Use the client load simulation tool below to add players to the pool or you'll never be able to make a successful match.
|
||||
* `test/cmd/client` is a (VERY) basic client load simulation tool. It does **not** test the Frontend API - in fact, it ignores it and writes players directly to state storage on its own. It doesn't do anything but loop endlessly, writing players into state storage so you can test your backend integration, and run your custom MMFs and Evaluators (which are only triggered when there are players in the pool).
|
||||
|
||||
### Resources
|
||||
|
||||
|
@ -33,7 +33,6 @@ import (
|
||||
"os"
|
||||
|
||||
backend "github.com/GoogleCloudPlatform/open-match/internal/pb"
|
||||
"github.com/gogo/protobuf/jsonpb"
|
||||
"github.com/tidwall/gjson"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
@ -72,10 +71,12 @@ func main() {
|
||||
|
||||
jsonProfile := buffer.String()
|
||||
pbProfile := &backend.MatchObject{}
|
||||
err = jsonpb.UnmarshalString(jsonProfile, pbProfile)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
/*
|
||||
err = jsonpb.UnmarshalString(jsonProfile, pbProfile)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
*/
|
||||
pbProfile.Properties = jsonProfile
|
||||
|
||||
log.Println("Requesting matches that fit profile:")
|
||||
@ -101,17 +102,9 @@ func main() {
|
||||
profileName = gjson.Get(jsonProfile, "name").String()
|
||||
}
|
||||
|
||||
/*
|
||||
// Test CreateMatch
|
||||
p := &backend.MatchObject{
|
||||
Id: profileName,
|
||||
// Make a stub debug hostname from the current time
|
||||
Properties: jsonProfile,
|
||||
}
|
||||
*/
|
||||
pbProfile.Id = profileName
|
||||
pbProfile.Properties = jsonProfile
|
||||
|
||||
//
|
||||
//log.Printf("Looking for matches for profile for the next 5 seconds:")
|
||||
log.Printf("Establishing HTTPv2 stream...")
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"imagename":"gcr.io/matchmaker-dev-201405/openmatch-mmf:py3",
|
||||
"name":"testprofilev1",
|
||||
"id":"testprofile",
|
||||
"properties":{
|
||||
|
@ -1,2 +0,0 @@
|
||||
// package backend should be a copy of the compiled gRPC protobuf file used by the backend API.
|
||||
package backend
|
355
examples/functions/golang/manual-simple/main.go
Normal file
355
examples/functions/golang/manual-simple/main.go
Normal file
@ -0,0 +1,355 @@
|
||||
/*
|
||||
Copyright 2018 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
|
||||
|
||||
https://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 main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/open-match/config"
|
||||
messages "github.com/GoogleCloudPlatform/open-match/internal/pb"
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/set"
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/statestorage/redis/ignorelist"
|
||||
"github.com/gogo/protobuf/jsonpb"
|
||||
"github.com/gomodule/redigo/redis"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
)
|
||||
|
||||
/*
|
||||
Here are the things a MMF needs to do:
|
||||
|
||||
*Read/write from the Open Match state storage — Open Match ships with Redis as
|
||||
the default state storage.
|
||||
*Be packaged in a (Linux) Docker container.
|
||||
*Read a profile you wrote to state storage using the Backend API.
|
||||
*Select from the player data you wrote to state storage using the Frontend API.
|
||||
*Run your custom logic to try to find a match.
|
||||
*Write the match object it creates to state storage at a specified key.
|
||||
*Remove the players it selected from consideration by other MMFs.
|
||||
*Notify the MMForc of completion.
|
||||
*(Optional & NYI, but recommended) Export stats for metrics collection.
|
||||
*/
|
||||
func main() {
|
||||
// Read config file.
|
||||
cfg := viper.New()
|
||||
cfg, err := config.Read()
|
||||
|
||||
// As per https://www.iana.org/assignments/uri-schemes/prov/redis
|
||||
// redis://user:secret@localhost:6379/0?foo=bar&qux=baz
|
||||
redisURL := "redis://" + os.Getenv("REDIS_SENTINEL_SERVICE_HOST") + ":" + os.Getenv("REDIS_SENTINEL_SERVICE_PORT")
|
||||
fmt.Println("Connecting to Redis at", redisURL)
|
||||
redisConn, err := redis.DialURL(redisURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer redisConn.Close()
|
||||
|
||||
// decrement the number of running MMFs once finished
|
||||
defer func() {
|
||||
fmt.Println("DECR moncurrentMMFs")
|
||||
_, err = redisConn.Do("DECR", "concurrentMMFs")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Environment vars set by the MMForc
|
||||
jobName := os.Getenv("PROFILE")
|
||||
timestamp := os.Getenv("MMF_TIMESTAMP")
|
||||
proposalKey := os.Getenv("MMF_PROPOSAL_ID")
|
||||
profileKey := os.Getenv("MMF_PROFILE_ID")
|
||||
errorKey := os.Getenv("MMF_ERROR_ID")
|
||||
rosterKey := os.Getenv("MMF_ROSTER_ID")
|
||||
_ = jobName
|
||||
_ = timestamp
|
||||
_ = proposalKey
|
||||
_ = profileKey
|
||||
_ = errorKey
|
||||
_ = rosterKey
|
||||
|
||||
fmt.Println("MMF request inserted at ", timestamp)
|
||||
fmt.Println("Looking for profile in key", profileKey)
|
||||
fmt.Println("Placing results in MatchObjectID", proposalKey)
|
||||
|
||||
// Retrieve profile from Redis.
|
||||
// NOTE: This can also be done with a call to the MMLogic API.
|
||||
profile, err := redis.StringMap(redisConn.Do("HGETALL", profileKey))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("=========Profile")
|
||||
p, err := json.MarshalIndent(profile, "", " ")
|
||||
fmt.Println(string(p))
|
||||
|
||||
// select players
|
||||
const numPlayers = 8
|
||||
// ZRANGE is 0-indexed
|
||||
pools := gjson.Get(profile["properties"], cfg.GetString("jsonkeys.pools"))
|
||||
fmt.Println("=========Pools")
|
||||
fmt.Printf("pool.String() = %+v\n", pools.String())
|
||||
|
||||
// Parse all the pools.
|
||||
// NOTE: When using pool definitions like these that are using the
|
||||
// PlayerPool protobuf message data schema, you can avoid all of this by
|
||||
// using the MMLogic API call to automatically parse the pools, run the
|
||||
// filters, and return the results in one gRPC call per pool.
|
||||
//
|
||||
// ex: poolRosters["defaultPool"]["mmr.rating"]=[]string{"abc", "def", "ghi"}
|
||||
poolRosters := make(map[string]map[string][]string)
|
||||
|
||||
// Loop through each pool.
|
||||
pools.ForEach(func(_, pool gjson.Result) bool {
|
||||
pName := gjson.Get(pool.String(), "name").String()
|
||||
pFilters := gjson.Get(pool.String(), "filters")
|
||||
poolRosters[pName] = make(map[string][]string)
|
||||
|
||||
// Loop through each filter for this pool
|
||||
pFilters.ForEach(func(_, filter gjson.Result) bool {
|
||||
// Note: This only works when running only one filter on each attribute!
|
||||
searchKey := gjson.Get(filter.String(), "attribute").String()
|
||||
min := int64(0)
|
||||
max := int64(time.Now().Unix())
|
||||
poolRosters[pName][searchKey] = make([]string, 0)
|
||||
|
||||
// Parse the min and max values.
|
||||
if minv := gjson.Get(filter.String(), "minv"); minv.Bool() {
|
||||
min = int64(minv.Int())
|
||||
}
|
||||
if maxv := gjson.Get(filter.String(), "maxv"); maxv.Bool() {
|
||||
max = int64(maxv.Int())
|
||||
}
|
||||
fmt.Printf("%v: %v: [%v-%v]\n", pName, searchKey, min, max)
|
||||
|
||||
// NOTE: This only pulls the first 50000 matches for a given index!
|
||||
// This is an example, and probably shouldn't be used outside of
|
||||
// testing without some performance tuning based on the size of
|
||||
// your indexes. In prodution, this could be run concurrently on
|
||||
// multiple parts of the index, and combined.
|
||||
// NOTE: It is recommended you also send back some stats about this
|
||||
// query along with your MMF, which can be useful when your backend
|
||||
// API client is deciding which profiles to send. This example does
|
||||
// not return stats, but when using the MMLogic API, this is done
|
||||
// for you.
|
||||
poolRosters[pName][searchKey], err = redis.Strings(
|
||||
redisConn.Do("ZRANGEBYSCORE", searchKey, min, max, "LIMIT", "0", "50000"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return true // keep iterating
|
||||
})
|
||||
|
||||
return true // keep iterating
|
||||
})
|
||||
|
||||
// Get ignored players.
|
||||
combinedIgnoreList := make([]string, 0)
|
||||
// Loop through all ignorelists configured in the config file.
|
||||
for il := range cfg.GetStringMap("ignoreLists") {
|
||||
ilCfg := cfg.Sub(fmt.Sprintf("ignoreLists.%v", il))
|
||||
thisIl, err := ignorelist.Retrieve(redisConn, ilCfg, il)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Join this ignorelist to the others we've retrieved
|
||||
combinedIgnoreList = set.Union(combinedIgnoreList, thisIl)
|
||||
}
|
||||
|
||||
// Cycle through all filters for each pool, and calculate the overlap
|
||||
// (players that match all filters)
|
||||
overlaps := make(map[string][]string)
|
||||
// Loop through pools
|
||||
for pName, p := range poolRosters {
|
||||
fmt.Println(pName)
|
||||
|
||||
// Var init
|
||||
overlaps[pName] = make([]string, 0)
|
||||
first := true // Flag used to initialize the overlap on the first iteration.
|
||||
|
||||
// Loop through rosters that matched each filter
|
||||
for fName, roster := range p {
|
||||
if first {
|
||||
first = false
|
||||
overlaps[pName] = roster
|
||||
}
|
||||
// Calculate overlap
|
||||
overlaps[pName] = set.Intersection(overlaps[pName], roster)
|
||||
|
||||
// Print out for visibility/debugging
|
||||
fmt.Printf(" filtering: %-20v | participants remaining: %-5v\n", fName, len(overlaps[pName]))
|
||||
}
|
||||
|
||||
// Remove players on ignorelists
|
||||
overlaps[pName] = set.Difference(overlaps[pName], combinedIgnoreList)
|
||||
fmt.Printf(" removing: %-21v | participants remaining: %-5v\n", "(ignorelists)", len(overlaps[pName]))
|
||||
}
|
||||
|
||||
// Loop through each roster in the profile and fill in players.
|
||||
rosters := gjson.Get(profile["properties"], cfg.GetString("jsonkeys.rosters"))
|
||||
fmt.Println("=========Rosters")
|
||||
fmt.Printf("rosters.String() = %+v\n", rosters.String())
|
||||
|
||||
// Parse all the rosters in the profile, adding players if we can.
|
||||
// NOTE: This is using roster definitions that follow the Roster protobuf
|
||||
// message data schema.
|
||||
profileRosters := make(map[string][]string)
|
||||
//proposedRosters := make([]string, 0)
|
||||
mo := &messages.MatchObject{}
|
||||
mo.Rosters = make([]*messages.Roster, 0)
|
||||
|
||||
// List of all player IDs on all proposed rosters, used to add players to
|
||||
// the ignore list.
|
||||
// NOTE: when using the MMLogic API, writing your final proposal to state
|
||||
// storage will automatically add players to the ignorelist, so you don't
|
||||
// need to track them separately and add them to the ignore list yourself.
|
||||
playerList := make([]string, 0)
|
||||
|
||||
rosters.ForEach(func(_, roster gjson.Result) bool {
|
||||
rName := gjson.Get(roster.String(), "name").String()
|
||||
fmt.Println(rName)
|
||||
rPlayers := gjson.Get(roster.String(), "players")
|
||||
profileRosters[rName] = make([]string, 0)
|
||||
pbRoster := messages.Roster{Name: rName, Players: []*messages.Player{}}
|
||||
|
||||
rPlayers.ForEach(func(_, player gjson.Result) bool {
|
||||
// TODO: This is where you would put your own custom matchmaking
|
||||
// logic. MMFs have full access to the state storage in Redis, so
|
||||
// you can choose some participants from the pool according to your
|
||||
// favored strategy. You have complete freedom to read the
|
||||
// participant's records from Redis and make decisions accordingly.
|
||||
//
|
||||
// This example just chooses the players in the order they were
|
||||
// returned from state storage.
|
||||
|
||||
//fmt.Printf(" %v\n", player.String()) //DEBUG
|
||||
proposedPlayer := player.String()
|
||||
// Get the name of the pool that the profile wanted this player pulled from.
|
||||
desiredPool := gjson.Get(player.String(), "pool").String()
|
||||
|
||||
if _, ok := overlaps[desiredPool]; ok {
|
||||
// There are players that match all the desired filters.
|
||||
if len(overlaps[desiredPool]) > 0 {
|
||||
// Propose the next player returned from state storage for this
|
||||
// slot in the match rosters.
|
||||
|
||||
// Functionally, a pop from the overlap array into the proposed slot.
|
||||
playerID := ""
|
||||
playerID, overlaps[desiredPool] = overlaps[desiredPool][0], overlaps[desiredPool][1:]
|
||||
|
||||
proposedPlayer, err = sjson.Set(proposedPlayer, "id", playerID)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
profileRosters[rName] = append(profileRosters[rName], proposedPlayer)
|
||||
fmt.Printf(" proposing: %v\n", proposedPlayer)
|
||||
|
||||
pbRoster.Players = append(pbRoster.Players, &messages.Player{Id: playerID, Pool: desiredPool})
|
||||
playerList = append(playerList, playerID)
|
||||
|
||||
} else {
|
||||
// Not enough players, exit.
|
||||
fmt.Println("Not enough players in the pool to fill all player slots in requested roster", rName)
|
||||
fmt.Printf("%+v\n", roster.String())
|
||||
fmt.Println("SET", errorKey, `{"error": "insufficient_players"}`)
|
||||
redisConn.Do("SET", errorKey, `{"error": "insufficient_players"}`)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
//proposedRoster, err := sjson.Set(roster.String(), "players", profileRosters[rName])
|
||||
mo.Rosters = append(mo.Rosters, &pbRoster)
|
||||
//fmt.Sprintf("[%v]", strings.Join(profileRosters[rName], ",")))
|
||||
//if err != nil {
|
||||
// panic(err)
|
||||
//}
|
||||
//proposedRosters = append(proposedRosters, proposedRoster)
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
// Write back the match object to state storage so the evaluator can look at it, and update the ignorelist.
|
||||
// NOTE: the MMLogic API CreateProposal automates most of this for you, as
|
||||
// long as you send it properly formatted data (i.e. data that fits the schema of
|
||||
// the protobuf messages)
|
||||
// Add proposed players to the ignorelist so other MMFs won't consider them.
|
||||
fmt.Printf("Adding %v players to ignorelist\n", len(playerList))
|
||||
err = ignorelist.Add(redisConn, "proposed", playerList)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to add proposed players to the ignorelist")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Write the match object that will be sent back to the DGS
|
||||
jmarshaler := jsonpb.Marshaler{}
|
||||
moJSON, err := jmarshaler.MarshalToString(mo)
|
||||
proposedRosters := gjson.Get(moJSON, "rosters")
|
||||
|
||||
fmt.Println("===========Proposal")
|
||||
// Set the properties field.
|
||||
// This is a filthy hack due to the way sjson escapes & quotes values it inserts.
|
||||
// Better in most cases than trying to marshal the JSON into giant multi-dimensional
|
||||
// interface maps only to dump it back out to a string after.
|
||||
// Note: this hack isn't necessary for most users, who just use this same
|
||||
// data directly from the protobuf message 'rosters' field, or write custom
|
||||
// rosters directly to the JSON properties when choosing players. This is here
|
||||
// for backwards compatibility with backends that haven't been updated to take
|
||||
// advantage of the new rosters field in the MatchObject protobuf message introduced
|
||||
// in 0.2.0.
|
||||
profile["properties"], err = sjson.Set(profile["properties"], cfg.GetString("jsonkeys.rosters"), proposedRosters.String())
|
||||
profile["properties"] = strings.Replace(profile["properties"], "\\", "", -1)
|
||||
profile["properties"] = strings.Replace(profile["properties"], "]\"", "]", -1)
|
||||
profile["properties"] = strings.Replace(profile["properties"], "\"[", "[", -1)
|
||||
if err != nil {
|
||||
fmt.Println("problem with sjson")
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Printf("Proposed ID: %v | Properties: %v", proposalKey, profile["properties"])
|
||||
|
||||
// Write the roster that will be sent to the evaluator. This needs to be written to the
|
||||
// "rosters" key of the match object, in the protobuf format for an array of
|
||||
// rosters protobuf messages. You can write this output by hand (not recommended)
|
||||
// or use the MMLogic API call CreateProposal will a filled out MatchObject protobuf message
|
||||
// and let it do the work for you.
|
||||
profile["rosters"] = proposedRosters.String()
|
||||
|
||||
fmt.Println("===========Redis")
|
||||
// Start writing proposed results to Redis.
|
||||
redisConn.Send("MULTI")
|
||||
for key, value := range profile {
|
||||
if key != "id" {
|
||||
fmt.Println("HSET", proposalKey, key, value)
|
||||
redisConn.Send("HSET", proposalKey, key, value)
|
||||
}
|
||||
}
|
||||
|
||||
//Finally, write the propsal key to trigger the evaluation of these results
|
||||
fmt.Println("SADD", cfg.GetString("queues.proposals.name"), proposalKey)
|
||||
redisConn.Send("SADD", cfg.GetString("queues.proposals.name"), proposalKey)
|
||||
_, err = redisConn.Do("EXEC")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
@ -1,244 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 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
|
||||
|
||||
https://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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/statestorage/redis/playerq"
|
||||
"github.com/gobs/pretty"
|
||||
"github.com/gomodule/redigo/redis"
|
||||
intersect "github.com/juliangruber/go-intersect"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
)
|
||||
|
||||
/*
|
||||
Here are the things a MMF needs to do:
|
||||
|
||||
*Read/write from the Open Match state storage — Open Match ships with Redis as the default state storage.
|
||||
*Be packaged in a (Linux) Docker container.
|
||||
*Read a profile you wrote to state storage using the Backend API.
|
||||
*Select from the player data you wrote to state storage using the Frontend API.
|
||||
*Run your custom logic to try to find a match.
|
||||
*Write the match object it creates to state storage at a specified key.
|
||||
*Remove the players it selected from consideration by other MMFs.
|
||||
*(Optional, but recommended) Export stats for metrics collection.
|
||||
*/
|
||||
func main() {
|
||||
// As per https://www.iana.org/assignments/uri-schemes/prov/redis
|
||||
// redis://user:secret@localhost:6379/0?foo=bar&qux=baz
|
||||
redisURL := "redis://" + os.Getenv("REDIS_SENTINEL_SERVICE_HOST") + ":" + os.Getenv("REDIS_SENTINEL_SERVICE_PORT")
|
||||
|
||||
//Single redis connection
|
||||
fmt.Println("Connecting to Redis at", redisURL)
|
||||
redisConn, err := redis.DialURL(redisURL)
|
||||
check(err, "QUIT")
|
||||
defer redisConn.Close()
|
||||
defer func() {
|
||||
// decrement the number of running MMFs since this one is finished
|
||||
fmt.Println("DECR concurrentMMFs")
|
||||
_, err = redisConn.Do("DECR", "concurrentMMFs")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// PROFILE is passed via the k8s downward API through an env set to jobName.
|
||||
jobName := os.Getenv("PROFILE")
|
||||
timestamp := os.Getenv("OM_TIMESTAMP")
|
||||
moID := os.Getenv("OM_PROPOSAL_ID")
|
||||
profileKey := os.Getenv("OM_PROFILE_ID")
|
||||
errorKey := os.Getenv("OM_SHORTCIRCUIT_MATCHOBJECT_ID")
|
||||
rosterKey := os.Getenv("OM_ROSTER_ID")
|
||||
|
||||
fmt.Println("MMF request inserted at ", timestamp)
|
||||
fmt.Println("Looking for profile in key", profileKey)
|
||||
fmt.Println("Placing results in MatchObjectID", moID)
|
||||
|
||||
profile, err := redis.String(redisConn.Do("GET", profileKey))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Got profile!")
|
||||
fmt.Println(profile)
|
||||
|
||||
// Redis key under which to store results
|
||||
resultsKey := "proposal." + jobName
|
||||
rosterKey := "roster." + jobName
|
||||
shortcutKey := moID + "." + profileKey
|
||||
|
||||
// select players
|
||||
const numPlayers = 8
|
||||
// ZRANGE is 0-indexed
|
||||
defaultPool := gjson.Get(profile, "properties.playerPool")
|
||||
fmt.Println("defaultPool")
|
||||
fmt.Printf("defaultPool.String() = %+v\n", defaultPool.String())
|
||||
|
||||
filters := make(map[string]map[string]int)
|
||||
defaultPool.ForEach(func(key, value gjson.Result) bool {
|
||||
// Make a map entry for this filter.
|
||||
searchKey := key.String()
|
||||
filters[searchKey] = map[string]int{"min": 0, "max": 9999999999}
|
||||
|
||||
// Parse the min and max values. JSON format is "min-max"
|
||||
r := strings.Split(value.String(), "-")
|
||||
filters[searchKey]["min"], err = strconv.Atoi(r[0])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
filters[searchKey]["max"], err = strconv.Atoi(r[1])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
return true // keep iterating
|
||||
})
|
||||
pretty.PrettyPrint(filters)
|
||||
|
||||
if len(filters) < 1 {
|
||||
fmt.Printf("No filters in the default pool for the profile, %v\n", len(filters))
|
||||
fmt.Println("SET", moID+"."+profileKey, `{"error": "insufficient_filters"}`)
|
||||
redisConn.Do("SET", moID+"."+profileKey, `{"error": "insufficient_filters"}`)
|
||||
return
|
||||
}
|
||||
|
||||
//init 2d array
|
||||
stuff := make([][]string, len(filters))
|
||||
for i := range stuff {
|
||||
stuff[i] = make([]string, 0)
|
||||
}
|
||||
|
||||
i := 0
|
||||
for key, value := range filters {
|
||||
// TODO: this needs a lot of time and effort on building sane values for how many IDs to pull at once.
|
||||
// TODO: this should also be run concurrently per index we're filtering on
|
||||
fmt.Printf("key = %+v\n", key)
|
||||
fmt.Printf("value = %+v\n", value)
|
||||
results, err := redis.Strings(redisConn.Do("ZRANGEBYSCORE", key, value["min"], value["max"], "LIMIT", "0", "10000"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Store off these results in the 2d array used to calculate intersections below.
|
||||
stuff[i] = append(stuff[i], results...)
|
||||
i++
|
||||
}
|
||||
|
||||
fmt.Println("overlap")
|
||||
overlap := stuff[0]
|
||||
for i := range stuff {
|
||||
if i > 0 {
|
||||
set := fmt.Sprint(intersect.Hash(overlap, stuff[i]))
|
||||
overlap = strings.Split(set[1:len(set)-1], " ")
|
||||
}
|
||||
}
|
||||
pretty.PrettyPrint(overlap)
|
||||
|
||||
// TODO: rigourous logic to put players in desired groups
|
||||
teamRosters := make(map[string][]string)
|
||||
rosterProfile := gjson.Get(profile, "properties.roster")
|
||||
fmt.Printf("rosterProfile.String() = %+v\n", rosterProfile.String())
|
||||
|
||||
// TODO: get this by parsing the JSON instead of cheating
|
||||
rosterSize := int(gjson.Get(profile, "properties.roster.blue").Int() + gjson.Get(profile, "properties.roster.red").Int())
|
||||
matchRoster := make([]string, 0)
|
||||
|
||||
if len(overlap) < rosterSize {
|
||||
fmt.Printf("Not enough players in the pool to fill %v player slots in requested roster", rosterSize)
|
||||
fmt.Printf("rosterProfile.String() = %+v\n", rosterProfile.String())
|
||||
fmt.Println("SET", moID+"."+profileKey, `{"error": "insufficient_players"}`)
|
||||
redisConn.Do("SET", moID+"."+profileKey, `{"error": "insufficient_players"}`)
|
||||
return
|
||||
}
|
||||
rosterProfile.ForEach(func(name, size gjson.Result) bool {
|
||||
teamKey := name.String()
|
||||
teamRosters[teamKey] = make([]string, size.Int())
|
||||
for i := 0; i < int(size.Int()); i++ {
|
||||
var playerID string
|
||||
// Functionally a Pop from the overlap array into playerID
|
||||
playerID, overlap = overlap[0], overlap[1:]
|
||||
teamRosters[teamKey][i] = playerID
|
||||
matchRoster = append(matchRoster, playerID)
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
pretty.PrettyPrint(teamRosters)
|
||||
pretty.PrettyPrint(matchRoster)
|
||||
|
||||
profile, err = sjson.Set(profile, "properties.roster", teamRosters)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Write the match object that will be sent back to the DGS
|
||||
fmt.Println("Proposing the following group ", resultsKey)
|
||||
fmt.Println("SET", resultsKey, profile)
|
||||
_, err = redisConn.Do("SET", resultsKey, profile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Write the roster that will be sent to the evaluator
|
||||
fmt.Println("Sending the following roster to the evaluator under key ", rosterKey)
|
||||
fmt.Println("SET", rosterKey, strings.Join(matchRoster, " "))
|
||||
_, err = redisConn.Do("SET", rosterKey, strings.Join(matchRoster, " "))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//TODO: make this auto-correcting if the player doesn't end up in a group.
|
||||
for _, playerID := range matchRoster {
|
||||
fmt.Printf("Attempting to remove player %v from indices\n", playerID)
|
||||
// TODO: make playerq module available to everything
|
||||
err := playerq.Deindex(redisConn, playerID)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Finally, write the propsal key to trigger the evaluation of these
|
||||
//results
|
||||
// TODO: read this from a config ala proposalq := cfg.GetString("queues.proposals.name")
|
||||
proposalq := "proposalq"
|
||||
fmt.Println("SADD", proposalq, jobName)
|
||||
_, err = redisConn.Do("SADD", proposalq, jobName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// DEBUG
|
||||
results, err := redis.Strings(redisConn.Do("SMEMBERS", proposalq))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pretty.PrettyPrint(results)
|
||||
}
|
||||
|
||||
func check(err error, action string) {
|
||||
if err != nil {
|
||||
if action == "QUIT" {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
12
examples/functions/php/mmlogic-simple/composer.json
Normal file
12
examples/functions/php/mmlogic-simple/composer.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"require": {
|
||||
"grpc/grpc": "v1.9.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Api\\": "proto/Api",
|
||||
"Messages\\": "proto/Messages",
|
||||
"GPBMetadata\\": "proto/GPBMetadata"
|
||||
}
|
||||
}
|
||||
}
|
131
examples/functions/php/mmlogic-simple/harness.php
Normal file
131
examples/functions/php/mmlogic-simple/harness.php
Normal file
@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
# Step 1 - Package this in a linux container image.
|
||||
|
||||
require dirname(__FILE__).'/vendor/autoload.php';
|
||||
|
||||
require 'mmf.php';
|
||||
|
||||
function dump_pb_message($msg) {
|
||||
print($msg->serializeToJsonString() . "\n");
|
||||
}
|
||||
|
||||
# Load config file
|
||||
$cfg = json_decode(file_get_contents('matchmaker_config.json'), true);
|
||||
|
||||
# Step 2 - Talk to Redis. This example uses the MM Logic API in OM to read/write to/from redis.
|
||||
# Establish grpc channel and make the API client stub
|
||||
$api_conn_info = sprintf('%s:%s', $cfg['api']['mmlogic']['hostname'], $cfg['api']['mmlogic']['port']);
|
||||
|
||||
$mmlogic_api = new Api\MmLogicClient($api_conn_info, [
|
||||
'credentials' => Grpc\ChannelCredentials::createInsecure(),
|
||||
]);
|
||||
|
||||
# Step 3 - Read the profile written to the Backend API.
|
||||
# Get profile from redis
|
||||
$match_object = new Messages\MatchObject([
|
||||
'id' => getenv('MMF_PROFILE_ID'
|
||||
)]);
|
||||
list($profile_pb, $status) = $mmlogic_api->GetProfile($match_object)->wait();
|
||||
dump_pb_message($profile_pb);
|
||||
|
||||
$profile_dict = json_decode($profile_pb->getProperties(), true);
|
||||
|
||||
# Step 4 - Select the player data from Redis that we want for our matchmaking logic.
|
||||
# Embedded in this profile are JSON representations of the filters for each player pool.
|
||||
# JsonFilterSet() is able to read those directly. No need to marhal that
|
||||
# JSON into the protobuf message format
|
||||
$player_pools = [];
|
||||
foreach ($profile_pb->getPools() as $empty_pool) {
|
||||
$empty_pool_name = $empty_pool->getName();
|
||||
|
||||
# Dict to hold value-sorted field dictionary for easy retreival of players by value
|
||||
$player_pools[$empty_pool_name] = [];
|
||||
printf("Retrieving pool '%s'\n", $empty_pool_name);
|
||||
|
||||
if (!$empty_pool->getStats()) {
|
||||
$empty_pool->setStats(new Messages\Stats());
|
||||
}
|
||||
|
||||
if ($cfg['debug']) {
|
||||
$start = microtime(true);
|
||||
}
|
||||
|
||||
# Pool filter results are streamed in chunks as they can be too large to send
|
||||
# in one grpc message. Loop to get them all.
|
||||
$call = $mmlogic_api->GetPlayerPool($empty_pool);
|
||||
foreach ($call->responses() as $partial_results) {
|
||||
if ($partial_results->getStats()) {
|
||||
$empty_pool->getStats()->setCount($partial_results->getStats()->getCount());
|
||||
$empty_pool->getStats()->setElapsed($partial_results->getStats()->getElapsed());
|
||||
}
|
||||
print ".\n";
|
||||
|
||||
$roster = $partial_results->getRoster();
|
||||
if ($roster) {
|
||||
foreach ($roster->getPlayers() as $player) {
|
||||
if (!array_key_exists($player->getId(), $player_pools[$empty_pool_name])) {
|
||||
$player_pools[$empty_pool_name][$player->getId()] = [];
|
||||
}
|
||||
foreach ($player->getAttributes() as $attr) {
|
||||
$player_pools[$empty_pool_name][$player->getId()][$attr->getName()] = $attr->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($cfg['debug']) {
|
||||
$end = microtime(true);
|
||||
printf("\n'%s': count %06d | elapsed %0.3f\n", $empty_pool_name, count($player_pools[$empty_pool_name]), $end - $start);
|
||||
}
|
||||
}
|
||||
|
||||
#################################################################
|
||||
# Step 5 - Run custom matchmaking logic to try to find a match
|
||||
# This is in the file mmf.py
|
||||
$results = make_matches($profile_dict, $player_pools);
|
||||
#################################################################
|
||||
|
||||
# DEBUG
|
||||
if ($cfg['debug']) {
|
||||
print("======= match_properties\n");
|
||||
var_export($results);
|
||||
}
|
||||
|
||||
# Generate a MatchObject message to write to state storage with the results in it.
|
||||
$mo = new Messages\MatchObject([
|
||||
'id' => getenv('MMF_PROPOSAL_ID'),
|
||||
'properties' => json_encode($results)
|
||||
]);
|
||||
$mo->setPools($profile_pb->getPools());
|
||||
|
||||
# Access the rosters in dict form within the properties json.
|
||||
# It is stored at the key specified in the config file.
|
||||
$rosters_dict = $results;
|
||||
foreach (explode('.', $cfg['jsonkeys']['rosters']) as $partial_key) {
|
||||
$rosters_dict = $rosters_dict[$partial_key] ?? [];
|
||||
}
|
||||
|
||||
# Unmarshal the rosters into the MatchObject
|
||||
foreach ($rosters_dict as $roster) {
|
||||
$r = new Messages\Roster();
|
||||
$r->mergeFromJsonString(json_encode($roster));
|
||||
$mo->getRosters() []= $r;
|
||||
}
|
||||
|
||||
#DEBUG: writing to error key prevents evalutor run
|
||||
if ($cfg['debug']) {
|
||||
print("======== MMF results:\n");
|
||||
dump_pb_message($mo);
|
||||
}
|
||||
|
||||
# Step 6 - Write the outcome of the matchmaking logic back to state storage.
|
||||
# Step 7 - Remove the selected players from consideration by other MMFs.
|
||||
# CreateProposal does both of these for you, and some other items as well.
|
||||
list($result, $status) = $mmlogic_api->CreateProposal($mo)->wait();
|
||||
printf("======== MMF write to state storage: %s\n", $result->getSuccess() ? 'true' : 'false');
|
||||
dump_pb_message($result);
|
||||
|
||||
# [OPTIONAL] Step 8 - Export stats about this run.
|
||||
# TODO
|
||||
|
||||
?>
|
1
examples/functions/php/mmlogic-simple/matchmaker_config.json
Symbolic link
1
examples/functions/php/mmlogic-simple/matchmaker_config.json
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../config/matchmaker_config.json
|
27
examples/functions/php/mmlogic-simple/mmf.php
Normal file
27
examples/functions/php/mmlogic-simple/mmf.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
function make_matches($profile_dict, $player_pools) {
|
||||
###########################################################################
|
||||
# This is the exciting part, and where most of your custom code would go! #
|
||||
###########################################################################
|
||||
|
||||
foreach ($profile_dict['properties']['rosters'] as &$roster) {
|
||||
foreach ($roster['players'] as &$player) {
|
||||
if (array_key_exists('pool', $player)) {
|
||||
$player['id'] = array_rand($player_pools[$player['pool']]);
|
||||
printf("Selected player %s from pool %s (strategy: RANDOM)\n",
|
||||
$player['id'],
|
||||
$player['pool']
|
||||
);
|
||||
} else {
|
||||
var_export($player);
|
||||
}
|
||||
}
|
||||
unset($player);
|
||||
}
|
||||
unset($roster);
|
||||
|
||||
return $profile_dict;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
// GENERATED CODE -- DO NOT EDIT!
|
||||
|
||||
namespace Api;
|
||||
|
||||
/**
|
||||
*/
|
||||
class BackendClient extends \Grpc\BaseStub {
|
||||
|
||||
/**
|
||||
* @param string $hostname hostname
|
||||
* @param array $opts channel options
|
||||
* @param \Grpc\Channel $channel (optional) re-use channel object
|
||||
*/
|
||||
public function __construct($hostname, $opts, $channel = null) {
|
||||
parent::__construct($hostname, $opts, $channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run MMF once. Return a matchobject that fits this profile.
|
||||
* INPUT: MatchObject message with these fields populated:
|
||||
* - id
|
||||
* - properties
|
||||
* - [optional] roster, any fields you fill are available to your MMF.
|
||||
* - [optional] pools, any fields you fill are available to your MMF.
|
||||
* OUTPUT: MatchObject message with these fields populated:
|
||||
* - id
|
||||
* - properties
|
||||
* - error. Empty if no error was encountered
|
||||
* - rosters, if you choose to fill them in your MMF. (Recommended)
|
||||
* - pools, if you used the MMLogicAPI in your MMF. (Recommended, and provides stats)
|
||||
* @param \Messages\MatchObject $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function CreateMatch(\Messages\MatchObject $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.Backend/CreateMatch',
|
||||
$argument,
|
||||
['\Messages\MatchObject', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Continually run MMF and stream matchobjects that fit this profile until
|
||||
* client closes the connection. Same inputs/outputs as CreateMatch.
|
||||
* @param \Messages\MatchObject $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function ListMatches(\Messages\MatchObject $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_serverStreamRequest('/api.Backend/ListMatches',
|
||||
$argument,
|
||||
['\Messages\MatchObject', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a matchobject from state storage manually. (Matchobjects in state
|
||||
* storage will also automatically expire after a while)
|
||||
* INPUT: MatchObject message with the 'id' field populated.
|
||||
* (All other fields are ignored.)
|
||||
* @param \Messages\MatchObject $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function DeleteMatch(\Messages\MatchObject $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.Backend/DeleteMatch',
|
||||
$argument,
|
||||
['\Messages\Result', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call fors communication of connection info to players.
|
||||
*
|
||||
* Write the connection info for the list of players in the
|
||||
* Assignments.messages.Rosters to state storage. The FrontendAPI is
|
||||
* responsible for sending anything sent here to the game clients.
|
||||
* Sending a player to this function kicks off a process that removes
|
||||
* the player from future matchmaking functions by adding them to the
|
||||
* 'deindexed' player list and then deleting their player ID from state storage
|
||||
* indexes.
|
||||
* INPUT: Assignments message with these fields populated:
|
||||
* - connection_info, anything you write to this string is sent to Frontend API
|
||||
* - rosters. You can send any number of rosters, containing any number of
|
||||
* player messages. All players from all rosters will be sent the connection_info.
|
||||
* The only field in the Player object that is used by CreateAssignments is
|
||||
* the id field. All others are silently ignored.
|
||||
* @param \Messages\Assignments $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function CreateAssignments(\Messages\Assignments $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.Backend/CreateAssignments',
|
||||
$argument,
|
||||
['\Messages\Result', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove DGS connection info from state storage for players.
|
||||
* INPUT: Roster message with the 'players' field populated.
|
||||
* The only field in the Player object that is used by
|
||||
* DeleteAssignments is the 'id' field. All others are silently ignored. If
|
||||
* you need to delete multiple rosters, make multiple calls.
|
||||
* @param \Messages\Roster $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function DeleteAssignments(\Messages\Roster $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.Backend/DeleteAssignments',
|
||||
$argument,
|
||||
['\Messages\Result', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// GENERATED CODE -- DO NOT EDIT!
|
||||
|
||||
// Original file comments:
|
||||
// TODO: In a future version, these messages will be moved/merged with those in om_messages.proto
|
||||
namespace Api;
|
||||
|
||||
/**
|
||||
*/
|
||||
class FrontendClient extends \Grpc\BaseStub {
|
||||
|
||||
/**
|
||||
* @param string $hostname hostname
|
||||
* @param array $opts channel options
|
||||
* @param \Grpc\Channel $channel (optional) re-use channel object
|
||||
*/
|
||||
public function __construct($hostname, $opts, $channel = null) {
|
||||
parent::__construct($hostname, $opts, $channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Api\Group $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function CreateRequest(\Api\Group $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.Frontend/CreateRequest',
|
||||
$argument,
|
||||
['\Messages\Result', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Api\Group $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function DeleteRequest(\Api\Group $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.Frontend/DeleteRequest',
|
||||
$argument,
|
||||
['\Messages\Result', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Api\PlayerId $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function GetAssignment(\Api\PlayerId $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.Frontend/GetAssignment',
|
||||
$argument,
|
||||
['\Messages\ConnectionInfo', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Api\PlayerId $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function DeleteAssignment(\Api\PlayerId $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.Frontend/DeleteAssignment',
|
||||
$argument,
|
||||
['\Messages\Result', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
}
|
102
examples/functions/php/mmlogic-simple/proto/Api/Group.php
Normal file
102
examples/functions/php/mmlogic-simple/proto/Api/Group.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/frontend.proto
|
||||
|
||||
namespace Api;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Data structure for a group of players to pass to the matchmaking function.
|
||||
* Obviously, the group can be a group of one!
|
||||
*
|
||||
* Generated from protobuf message <code>api.Group</code>
|
||||
*/
|
||||
class Group extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* By convention, string of space-delimited playerIDs
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
*/
|
||||
private $id = '';
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
*/
|
||||
private $properties = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $id
|
||||
* By convention, string of space-delimited playerIDs
|
||||
* @type string $properties
|
||||
* By convention, a JSON-encoded string
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Frontend::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, string of space-delimited playerIDs
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, string of space-delimited playerIDs
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->id = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperties($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->properties = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
// GENERATED CODE -- DO NOT EDIT!
|
||||
|
||||
namespace Api;
|
||||
|
||||
/**
|
||||
* The MMLogic API provides utility functions for common MMF functionality, such
|
||||
* as retreiving profiles and players from state storage, writing results to state storage,
|
||||
* and exposing metrics and statistics.
|
||||
*/
|
||||
class MmLogicClient extends \Grpc\BaseStub {
|
||||
|
||||
/**
|
||||
* @param string $hostname hostname
|
||||
* @param array $opts channel options
|
||||
* @param \Grpc\Channel $channel (optional) re-use channel object
|
||||
*/
|
||||
public function __construct($hostname, $opts, $channel = null) {
|
||||
parent::__construct($hostname, $opts, $channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send GetProfile a match object with the ID field populated, it will return a
|
||||
* 'filled' one.
|
||||
* Note: filters are assumed to have been checked for validity by the
|
||||
* backendapi when accepting a profile
|
||||
* @param \Messages\MatchObject $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function GetProfile(\Messages\MatchObject $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.MmLogic/GetProfile',
|
||||
$argument,
|
||||
['\Messages\MatchObject', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* CreateProposal is called by MMFs that wish to write their results to
|
||||
* a proposed MatchObject, that can be sent out the Backend API once it has
|
||||
* been approved (by default, by the evaluator process).
|
||||
* - adds all players in all Rosters to the proposed player ignore list
|
||||
* - writes the proposed match to the provided key
|
||||
* - adds that key to the list of proposals to be considered
|
||||
* INPUT:
|
||||
* * TO RETURN A MATCHOBJECT AFTER A SUCCESSFUL MMF RUN
|
||||
* To create a match MatchObject message with these fields populated:
|
||||
* - id, set to the value of the MMF_PROPOSAL_ID env var
|
||||
* - properties
|
||||
* - error. You must explicitly set this to an empty string if your MMF
|
||||
* - roster, with the playerIDs filled in the 'players' repeated field.
|
||||
* - [optional] pools, set to the output from the 'GetPlayerPools' call,
|
||||
* will populate the pools with stats about how many players the filters
|
||||
* matched and how long the filters took to run, which will be sent out
|
||||
* the backend api along with your match results.
|
||||
* was successful.
|
||||
* * TO RETURN AN ERROR
|
||||
* To report a failure or error, send a MatchObject message with these
|
||||
* these fields populated:
|
||||
* - id, set to the value of the MMF_ERROR_ID env var.
|
||||
* - error, set to a string value describing the error your MMF encountered.
|
||||
* - [optional] properties, anything you put here is returned to the
|
||||
* backend along with your error.
|
||||
* - [optional] rosters, anything you put here is returned to the
|
||||
* backend along with your error.
|
||||
* - [optional] pools, set to the output from the 'GetPlayerPools' call,
|
||||
* will populate the pools with stats about how many players the filters
|
||||
* matched and how long the filters took to run, which will be sent out
|
||||
* the backend api along with your match results.
|
||||
* OUTPUT: a Result message with a boolean success value and an error string
|
||||
* if an error was encountered
|
||||
* @param \Messages\MatchObject $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function CreateProposal(\Messages\MatchObject $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.MmLogic/CreateProposal',
|
||||
$argument,
|
||||
['\Messages\Result', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Player listing and filtering functions
|
||||
*
|
||||
* RetrievePlayerPool gets the list of players that match every Filter in the
|
||||
* PlayerPool, and then removes all players it finds in the ignore list. It
|
||||
* combines the results, and returns the resulting player pool.
|
||||
* @param \Messages\PlayerPool $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function GetPlayerPool(\Messages\PlayerPool $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_serverStreamRequest('/api.MmLogic/GetPlayerPool',
|
||||
$argument,
|
||||
['\Messages\PlayerPool', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore List functions
|
||||
*
|
||||
* IlInput is an empty message reserved for future use.
|
||||
* @param \Messages\IlInput $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function GetAllIgnoredPlayers(\Messages\IlInput $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.MmLogic/GetAllIgnoredPlayers',
|
||||
$argument,
|
||||
['\Messages\Roster', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* RetrieveIgnoreList retrieves players from the ignore list specified in the
|
||||
* config file under 'ignoreLists.proposedPlayers.key'.
|
||||
* @param \Messages\IlInput $argument input argument
|
||||
* @param array $metadata metadata
|
||||
* @param array $options call options
|
||||
*/
|
||||
public function ListIgnoredPlayers(\Messages\IlInput $argument,
|
||||
$metadata = [], $options = []) {
|
||||
return $this->_simpleRequest('/api.MmLogic/ListIgnoredPlayers',
|
||||
$argument,
|
||||
['\Messages\Roster', 'decode'],
|
||||
$metadata, $options);
|
||||
}
|
||||
|
||||
}
|
65
examples/functions/php/mmlogic-simple/proto/Api/PlayerId.php
Normal file
65
examples/functions/php/mmlogic-simple/proto/Api/PlayerId.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/frontend.proto
|
||||
|
||||
namespace Api;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Generated from protobuf message <code>api.PlayerId</code>
|
||||
*/
|
||||
class PlayerId extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
*/
|
||||
private $id = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $id
|
||||
* By convention, a UUID
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Frontend::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->id = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/backend.proto
|
||||
|
||||
namespace GPBMetadata\Api\ProtobufSpec;
|
||||
|
||||
class Backend
|
||||
{
|
||||
public static $is_initialized = false;
|
||||
|
||||
public static function initOnce() {
|
||||
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
|
||||
|
||||
if (static::$is_initialized == true) {
|
||||
return;
|
||||
}
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
$pool->internalAddGeneratedFile(hex2bin(
|
||||
"0aa8030a1f6170692f70726f746f6275662d737065632f6261636b656e64" .
|
||||
"2e70726f746f120361706932be020a074261636b656e64123d0a0b437265" .
|
||||
"6174654d6174636812152e6d657373616765732e4d617463684f626a6563" .
|
||||
"741a152e6d657373616765732e4d617463684f626a6563742200123f0a0b" .
|
||||
"4c6973744d61746368657312152e6d657373616765732e4d617463684f62" .
|
||||
"6a6563741a152e6d657373616765732e4d617463684f626a656374220030" .
|
||||
"0112380a0b44656c6574654d6174636812152e6d657373616765732e4d61" .
|
||||
"7463684f626a6563741a102e6d657373616765732e526573756c74220012" .
|
||||
"3e0a1143726561746541737369676e6d656e747312152e6d657373616765" .
|
||||
"732e41737369676e6d656e74731a102e6d657373616765732e526573756c" .
|
||||
"74220012390a1144656c65746541737369676e6d656e747312102e6d6573" .
|
||||
"73616765732e526f737465721a102e6d657373616765732e526573756c74" .
|
||||
"220042375a356769746875622e636f6d2f476f6f676c65436c6f7564506c" .
|
||||
"6174666f726d2f6f70656e2d6d617463682f696e7465726e616c2f706262" .
|
||||
"0670726f746f33"
|
||||
));
|
||||
|
||||
static::$is_initialized = true;
|
||||
}
|
||||
}
|
||||
|
38
examples/functions/php/mmlogic-simple/proto/GPBMetadata/Api/ProtobufSpec/Frontend.php
Normal file
38
examples/functions/php/mmlogic-simple/proto/GPBMetadata/Api/ProtobufSpec/Frontend.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/frontend.proto
|
||||
|
||||
namespace GPBMetadata\Api\ProtobufSpec;
|
||||
|
||||
class Frontend
|
||||
{
|
||||
public static $is_initialized = false;
|
||||
|
||||
public static function initOnce() {
|
||||
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
|
||||
|
||||
if (static::$is_initialized == true) {
|
||||
return;
|
||||
}
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
$pool->internalAddGeneratedFile(hex2bin(
|
||||
"0a8b030a206170692f70726f746f6275662d737065632f66726f6e74656e" .
|
||||
"642e70726f746f120361706922270a0547726f7570120a0a026964180120" .
|
||||
"01280912120a0a70726f7065727469657318022001280922160a08506c61" .
|
||||
"7965724964120a0a02696418012001280932df010a0846726f6e74656e64" .
|
||||
"122f0a0d43726561746552657175657374120a2e6170692e47726f75701a" .
|
||||
"102e6d657373616765732e526573756c742200122f0a0d44656c65746552" .
|
||||
"657175657374120a2e6170692e47726f75701a102e6d657373616765732e" .
|
||||
"526573756c742200123a0a0d47657441737369676e6d656e74120d2e6170" .
|
||||
"692e506c6179657249641a182e6d657373616765732e436f6e6e65637469" .
|
||||
"6f6e496e666f220012350a1044656c65746541737369676e6d656e74120d" .
|
||||
"2e6170692e506c6179657249641a102e6d657373616765732e526573756c" .
|
||||
"74220042375a356769746875622e636f6d2f476f6f676c65436c6f756450" .
|
||||
"6c6174666f726d2f6f70656e2d6d617463682f696e7465726e616c2f7062" .
|
||||
"620670726f746f33"
|
||||
));
|
||||
|
||||
static::$is_initialized = true;
|
||||
}
|
||||
}
|
||||
|
54
examples/functions/php/mmlogic-simple/proto/GPBMetadata/Api/ProtobufSpec/Messages.php
Normal file
54
examples/functions/php/mmlogic-simple/proto/GPBMetadata/Api/ProtobufSpec/Messages.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace GPBMetadata\Api\ProtobufSpec;
|
||||
|
||||
class Messages
|
||||
{
|
||||
public static $is_initialized = false;
|
||||
|
||||
public static function initOnce() {
|
||||
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
|
||||
|
||||
if (static::$is_initialized == true) {
|
||||
return;
|
||||
}
|
||||
$pool->internalAddGeneratedFile(hex2bin(
|
||||
"0a9a070a206170692f70726f746f6275662d737065632f6d657373616765" .
|
||||
"732e70726f746f12086d657373616765732284010a0b4d617463684f626a" .
|
||||
"656374120a0a02696418012001280912120a0a70726f7065727469657318" .
|
||||
"0220012809120d0a056572726f7218032001280912210a07726f73746572" .
|
||||
"7318042003280b32102e6d657373616765732e526f7374657212230a0570" .
|
||||
"6f6f6c7318052003280b32142e6d657373616765732e506c61796572506f" .
|
||||
"6f6c22390a06526f73746572120c0a046e616d6518012001280912210a07" .
|
||||
"706c617965727318022003280b32102e6d657373616765732e506c617965" .
|
||||
"7222650a0646696c746572120c0a046e616d6518012001280912110a0961" .
|
||||
"7474726962757465180220012809120c0a046d617876180320012803120c" .
|
||||
"0a046d696e76180420012803121e0a05737461747318052001280b320f2e" .
|
||||
"6d657373616765732e537461747322270a055374617473120d0a05636f75" .
|
||||
"6e74180120012803120f0a07656c6170736564180220012801227f0a0a50" .
|
||||
"6c61796572506f6f6c120c0a046e616d6518012001280912210a0766696c" .
|
||||
"7465727318022003280b32102e6d657373616765732e46696c7465721220" .
|
||||
"0a06726f7374657218032001280b32102e6d657373616765732e526f7374" .
|
||||
"6572121e0a05737461747318042001280b320f2e6d657373616765732e53" .
|
||||
"746174732290010a06506c61796572120a0a02696418012001280912120a" .
|
||||
"0a70726f70657274696573180220012809120c0a04706f6f6c1803200128" .
|
||||
"09122e0a0a6174747269627574657318042003280b321a2e6d6573736167" .
|
||||
"65732e506c617965722e4174747269627574651a280a0941747472696275" .
|
||||
"7465120c0a046e616d65180120012809120d0a0576616c75651802200128" .
|
||||
"0322280a06526573756c74120f0a0773756363657373180120012808120d" .
|
||||
"0a056572726f7218022001280922090a07496c496e707574222b0a0e436f" .
|
||||
"6e6e656374696f6e496e666f12190a11636f6e6e656374696f6e5f737472" .
|
||||
"696e6718012001280922630a0b41737369676e6d656e747312210a07726f" .
|
||||
"737465727318012003280b32102e6d657373616765732e526f7374657212" .
|
||||
"310a0f636f6e6e656374696f6e5f696e666f18022001280b32182e6d6573" .
|
||||
"73616765732e436f6e6e656374696f6e496e666f42375a35676974687562" .
|
||||
"2e636f6d2f476f6f676c65436c6f7564506c6174666f726d2f6f70656e2d" .
|
||||
"6d617463682f696e7465726e616c2f7062620670726f746f33"
|
||||
));
|
||||
|
||||
static::$is_initialized = true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/mmlogic.proto
|
||||
|
||||
namespace GPBMetadata\Api\ProtobufSpec;
|
||||
|
||||
class Mmlogic
|
||||
{
|
||||
public static $is_initialized = false;
|
||||
|
||||
public static function initOnce() {
|
||||
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
|
||||
|
||||
if (static::$is_initialized == true) {
|
||||
return;
|
||||
}
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
$pool->internalAddGeneratedFile(hex2bin(
|
||||
"0aab030a1f6170692f70726f746f6275662d737065632f6d6d6c6f676963" .
|
||||
"2e70726f746f120361706932c1020a074d6d4c6f676963123c0a0a476574" .
|
||||
"50726f66696c6512152e6d657373616765732e4d617463684f626a656374" .
|
||||
"1a152e6d657373616765732e4d617463684f626a6563742200123b0a0e43" .
|
||||
"726561746550726f706f73616c12152e6d657373616765732e4d61746368" .
|
||||
"4f626a6563741a102e6d657373616765732e526573756c742200123f0a0d" .
|
||||
"476574506c61796572506f6f6c12142e6d657373616765732e506c617965" .
|
||||
"72506f6f6c1a142e6d657373616765732e506c61796572506f6f6c220030" .
|
||||
"01123d0a14476574416c6c49676e6f726564506c617965727312112e6d65" .
|
||||
"7373616765732e496c496e7075741a102e6d657373616765732e526f7374" .
|
||||
"65722200123b0a124c69737449676e6f726564506c617965727312112e6d" .
|
||||
"657373616765732e496c496e7075741a102e6d657373616765732e526f73" .
|
||||
"746572220042375a356769746875622e636f6d2f476f6f676c65436c6f75" .
|
||||
"64506c6174666f726d2f6f70656e2d6d617463682f696e7465726e616c2f" .
|
||||
"7062620670726f746f33"
|
||||
));
|
||||
|
||||
static::$is_initialized = true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Generated from protobuf message <code>messages.Assignments</code>
|
||||
*/
|
||||
class Assignments extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* Generated from protobuf field <code>repeated .messages.Roster rosters = 1;</code>
|
||||
*/
|
||||
private $rosters;
|
||||
/**
|
||||
* Generated from protobuf field <code>.messages.ConnectionInfo connection_info = 2;</code>
|
||||
*/
|
||||
private $connection_info = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type \Messages\Roster[]|\Google\Protobuf\Internal\RepeatedField $rosters
|
||||
* @type \Messages\ConnectionInfo $connection_info
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>repeated .messages.Roster rosters = 1;</code>
|
||||
* @return \Google\Protobuf\Internal\RepeatedField
|
||||
*/
|
||||
public function getRosters()
|
||||
{
|
||||
return $this->rosters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>repeated .messages.Roster rosters = 1;</code>
|
||||
* @param \Messages\Roster[]|\Google\Protobuf\Internal\RepeatedField $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setRosters($var)
|
||||
{
|
||||
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Messages\Roster::class);
|
||||
$this->rosters = $arr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>.messages.ConnectionInfo connection_info = 2;</code>
|
||||
* @return \Messages\ConnectionInfo
|
||||
*/
|
||||
public function getConnectionInfo()
|
||||
{
|
||||
return $this->connection_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>.messages.ConnectionInfo connection_info = 2;</code>
|
||||
* @param \Messages\ConnectionInfo $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnectionInfo($var)
|
||||
{
|
||||
GPBUtil::checkMessage($var, \Messages\ConnectionInfo::class);
|
||||
$this->connection_info = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Simple message used to pass the connection string for the DGS to the player.
|
||||
* DEPRECATED: Likely to be integrated into another protobuf message in a future version.
|
||||
*
|
||||
* Generated from protobuf message <code>messages.ConnectionInfo</code>
|
||||
*/
|
||||
class ConnectionInfo extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* Passed by the matchmaker to game clients without modification.
|
||||
*
|
||||
* Generated from protobuf field <code>string connection_string = 1;</code>
|
||||
*/
|
||||
private $connection_string = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $connection_string
|
||||
* Passed by the matchmaker to game clients without modification.
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passed by the matchmaker to game clients without modification.
|
||||
*
|
||||
* Generated from protobuf field <code>string connection_string = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getConnectionString()
|
||||
{
|
||||
return $this->connection_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passed by the matchmaker to game clients without modification.
|
||||
*
|
||||
* Generated from protobuf field <code>string connection_string = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnectionString($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->connection_string = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
203
examples/functions/php/mmlogic-simple/proto/Messages/Filter.php
Normal file
203
examples/functions/php/mmlogic-simple/proto/Messages/Filter.php
Normal file
@ -0,0 +1,203 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* A 'hard' filter to apply to the player pool.
|
||||
*
|
||||
* Generated from protobuf message <code>messages.Filter</code>
|
||||
*/
|
||||
class Filter extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable name of this filter. Appears in logs and metrics.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
*/
|
||||
private $name = '';
|
||||
/**
|
||||
* Name of the player attribute this filter operates on.
|
||||
*
|
||||
* Generated from protobuf field <code>string attribute = 2;</code>
|
||||
*/
|
||||
private $attribute = '';
|
||||
/**
|
||||
* Maximum value. Defaults to positive infinity (any value above minv).
|
||||
*
|
||||
* Generated from protobuf field <code>int64 maxv = 3;</code>
|
||||
*/
|
||||
private $maxv = 0;
|
||||
/**
|
||||
* Minimum value. Defaults to 0.
|
||||
*
|
||||
* Generated from protobuf field <code>int64 minv = 4;</code>
|
||||
*/
|
||||
private $minv = 0;
|
||||
/**
|
||||
* Statistics for the last time the filter was applied.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Stats stats = 5;</code>
|
||||
*/
|
||||
private $stats = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $name
|
||||
* Arbitrary developer-chosen, human-readable name of this filter. Appears in logs and metrics.
|
||||
* @type string $attribute
|
||||
* Name of the player attribute this filter operates on.
|
||||
* @type int|string $maxv
|
||||
* Maximum value. Defaults to positive infinity (any value above minv).
|
||||
* @type int|string $minv
|
||||
* Minimum value. Defaults to 0.
|
||||
* @type \Messages\Stats $stats
|
||||
* Statistics for the last time the filter was applied.
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable name of this filter. Appears in logs and metrics.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable name of this filter. Appears in logs and metrics.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->name = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the player attribute this filter operates on.
|
||||
*
|
||||
* Generated from protobuf field <code>string attribute = 2;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getAttribute()
|
||||
{
|
||||
return $this->attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the player attribute this filter operates on.
|
||||
*
|
||||
* Generated from protobuf field <code>string attribute = 2;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttribute($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->attribute = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum value. Defaults to positive infinity (any value above minv).
|
||||
*
|
||||
* Generated from protobuf field <code>int64 maxv = 3;</code>
|
||||
* @return int|string
|
||||
*/
|
||||
public function getMaxv()
|
||||
{
|
||||
return $this->maxv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum value. Defaults to positive infinity (any value above minv).
|
||||
*
|
||||
* Generated from protobuf field <code>int64 maxv = 3;</code>
|
||||
* @param int|string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setMaxv($var)
|
||||
{
|
||||
GPBUtil::checkInt64($var);
|
||||
$this->maxv = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimum value. Defaults to 0.
|
||||
*
|
||||
* Generated from protobuf field <code>int64 minv = 4;</code>
|
||||
* @return int|string
|
||||
*/
|
||||
public function getMinv()
|
||||
{
|
||||
return $this->minv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimum value. Defaults to 0.
|
||||
*
|
||||
* Generated from protobuf field <code>int64 minv = 4;</code>
|
||||
* @param int|string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setMinv($var)
|
||||
{
|
||||
GPBUtil::checkInt64($var);
|
||||
$this->minv = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics for the last time the filter was applied.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Stats stats = 5;</code>
|
||||
* @return \Messages\Stats
|
||||
*/
|
||||
public function getStats()
|
||||
{
|
||||
return $this->stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics for the last time the filter was applied.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Stats stats = 5;</code>
|
||||
* @param \Messages\Stats $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setStats($var)
|
||||
{
|
||||
GPBUtil::checkMessage($var, \Messages\Stats::class);
|
||||
$this->stats = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* IlInput is an empty message reserved for future use.
|
||||
*
|
||||
* Generated from protobuf message <code>messages.IlInput</code>
|
||||
*/
|
||||
class IlInput extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,213 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Open Match's internal representation and wire protocol format for "MatchObjects".
|
||||
* In order to request a match using the Backend API, your backend code should generate
|
||||
* a new MatchObject with an ID and properties filled in (for more details about valid
|
||||
* values for these fields, see the documentation). Open Match then sends the Match
|
||||
* Object through to your matchmaking function, where you add players to 'rosters' and
|
||||
* store any schemaless data you wish in the 'properties' field. The MatchObject
|
||||
* is then sent, populated, out through the Backend API to your backend code.
|
||||
*
|
||||
* MatchObjects contain a number of fields, but many gRPC calls that take a
|
||||
* MatchObject as input only require a few of them to be filled in. Check the
|
||||
* gRPC function in question for more details.
|
||||
*
|
||||
* Generated from protobuf message <code>messages.MatchObject</code>
|
||||
*/
|
||||
class MatchObject extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
*/
|
||||
private $id = '';
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
*/
|
||||
private $properties = '';
|
||||
/**
|
||||
* Last error encountered.
|
||||
*
|
||||
* Generated from protobuf field <code>string error = 3;</code>
|
||||
*/
|
||||
private $error = '';
|
||||
/**
|
||||
* Rosters of players.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Roster rosters = 4;</code>
|
||||
*/
|
||||
private $rosters;
|
||||
/**
|
||||
* 'Hard' filters, and the players who match them.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.PlayerPool pools = 5;</code>
|
||||
*/
|
||||
private $pools;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $id
|
||||
* By convention, a UUID
|
||||
* @type string $properties
|
||||
* By convention, a JSON-encoded string
|
||||
* @type string $error
|
||||
* Last error encountered.
|
||||
* @type \Messages\Roster[]|\Google\Protobuf\Internal\RepeatedField $rosters
|
||||
* Rosters of players.
|
||||
* @type \Messages\PlayerPool[]|\Google\Protobuf\Internal\RepeatedField $pools
|
||||
* 'Hard' filters, and the players who match them.
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->id = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperties($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->properties = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Last error encountered.
|
||||
*
|
||||
* Generated from protobuf field <code>string error = 3;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Last error encountered.
|
||||
*
|
||||
* Generated from protobuf field <code>string error = 3;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setError($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->error = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rosters of players.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Roster rosters = 4;</code>
|
||||
* @return \Google\Protobuf\Internal\RepeatedField
|
||||
*/
|
||||
public function getRosters()
|
||||
{
|
||||
return $this->rosters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rosters of players.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Roster rosters = 4;</code>
|
||||
* @param \Messages\Roster[]|\Google\Protobuf\Internal\RepeatedField $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setRosters($var)
|
||||
{
|
||||
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Messages\Roster::class);
|
||||
$this->rosters = $arr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Hard' filters, and the players who match them.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.PlayerPool pools = 5;</code>
|
||||
* @return \Google\Protobuf\Internal\RepeatedField
|
||||
*/
|
||||
public function getPools()
|
||||
{
|
||||
return $this->pools;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Hard' filters, and the players who match them.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.PlayerPool pools = 5;</code>
|
||||
* @param \Messages\PlayerPool[]|\Google\Protobuf\Internal\RepeatedField $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setPools($var)
|
||||
{
|
||||
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Messages\PlayerPool::class);
|
||||
$this->pools = $arr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
169
examples/functions/php/mmlogic-simple/proto/Messages/Player.php
Normal file
169
examples/functions/php/mmlogic-simple/proto/Messages/Player.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Data structure to hold details about a player
|
||||
*
|
||||
* Generated from protobuf message <code>messages.Player</code>
|
||||
*/
|
||||
class Player extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
*/
|
||||
private $id = '';
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
*/
|
||||
private $properties = '';
|
||||
/**
|
||||
* Optionally used to specify the PlayerPool in which to find a player.
|
||||
*
|
||||
* Generated from protobuf field <code>string pool = 3;</code>
|
||||
*/
|
||||
private $pool = '';
|
||||
/**
|
||||
* Attributes of this player.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Player.Attribute attributes = 4;</code>
|
||||
*/
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $id
|
||||
* By convention, a UUID
|
||||
* @type string $properties
|
||||
* By convention, a JSON-encoded string
|
||||
* @type string $pool
|
||||
* Optionally used to specify the PlayerPool in which to find a player.
|
||||
* @type \Messages\Player\Attribute[]|\Google\Protobuf\Internal\RepeatedField $attributes
|
||||
* Attributes of this player.
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a UUID
|
||||
*
|
||||
* Generated from protobuf field <code>string id = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->id = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* By convention, a JSON-encoded string
|
||||
*
|
||||
* Generated from protobuf field <code>string properties = 2;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperties($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->properties = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally used to specify the PlayerPool in which to find a player.
|
||||
*
|
||||
* Generated from protobuf field <code>string pool = 3;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getPool()
|
||||
{
|
||||
return $this->pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally used to specify the PlayerPool in which to find a player.
|
||||
*
|
||||
* Generated from protobuf field <code>string pool = 3;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setPool($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->pool = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attributes of this player.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Player.Attribute attributes = 4;</code>
|
||||
* @return \Google\Protobuf\Internal\RepeatedField
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attributes of this player.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Player.Attribute attributes = 4;</code>
|
||||
* @param \Messages\Player\Attribute[]|\Google\Protobuf\Internal\RepeatedField $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttributes($var)
|
||||
{
|
||||
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Messages\Player\Attribute::class);
|
||||
$this->attributes = $arr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages\Player;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Generated from protobuf message <code>messages.Player.Attribute</code>
|
||||
*/
|
||||
class Attribute extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* Name should match a Filter.attribute field.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
*/
|
||||
private $name = '';
|
||||
/**
|
||||
* Generated from protobuf field <code>int64 value = 2;</code>
|
||||
*/
|
||||
private $value = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $name
|
||||
* Name should match a Filter.attribute field.
|
||||
* @type int|string $value
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Name should match a Filter.attribute field.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name should match a Filter.attribute field.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->name = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>int64 value = 2;</code>
|
||||
* @return int|string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>int64 value = 2;</code>
|
||||
* @param int|string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($var)
|
||||
{
|
||||
GPBUtil::checkInt64($var);
|
||||
$this->value = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Adding a class alias for backwards compatibility with the previous class name.
|
||||
class_alias(Attribute::class, \Messages\Player_Attribute::class);
|
||||
|
@ -0,0 +1,173 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* PlayerPools are defined by a set of 'hard' filters, and can be filled in
|
||||
* with the players that match those filters.
|
||||
* PlayerPools contain a number of fields, but many gRPC calls that take a
|
||||
* PlayerPool as input only require a few of them to be filled in. Check the
|
||||
* gRPC function in question for more details.
|
||||
*
|
||||
* Generated from protobuf message <code>messages.PlayerPool</code>
|
||||
*/
|
||||
class PlayerPool extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable string.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
*/
|
||||
private $name = '';
|
||||
/**
|
||||
* Filters are logical AND-ed (a player must match every filter).
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Filter filters = 2;</code>
|
||||
*/
|
||||
private $filters;
|
||||
/**
|
||||
* Roster of players that match all filters.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Roster roster = 3;</code>
|
||||
*/
|
||||
private $roster = null;
|
||||
/**
|
||||
* Statisticss for the last time this Pool was retrieved from state storage.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Stats stats = 4;</code>
|
||||
*/
|
||||
private $stats = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $name
|
||||
* Arbitrary developer-chosen, human-readable string.
|
||||
* @type \Messages\Filter[]|\Google\Protobuf\Internal\RepeatedField $filters
|
||||
* Filters are logical AND-ed (a player must match every filter).
|
||||
* @type \Messages\Roster $roster
|
||||
* Roster of players that match all filters.
|
||||
* @type \Messages\Stats $stats
|
||||
* Statisticss for the last time this Pool was retrieved from state storage.
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable string.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable string.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->name = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters are logical AND-ed (a player must match every filter).
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Filter filters = 2;</code>
|
||||
* @return \Google\Protobuf\Internal\RepeatedField
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters are logical AND-ed (a player must match every filter).
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Filter filters = 2;</code>
|
||||
* @param \Messages\Filter[]|\Google\Protobuf\Internal\RepeatedField $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilters($var)
|
||||
{
|
||||
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Messages\Filter::class);
|
||||
$this->filters = $arr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Roster of players that match all filters.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Roster roster = 3;</code>
|
||||
* @return \Messages\Roster
|
||||
*/
|
||||
public function getRoster()
|
||||
{
|
||||
return $this->roster;
|
||||
}
|
||||
|
||||
/**
|
||||
* Roster of players that match all filters.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Roster roster = 3;</code>
|
||||
* @param \Messages\Roster $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setRoster($var)
|
||||
{
|
||||
GPBUtil::checkMessage($var, \Messages\Roster::class);
|
||||
$this->roster = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statisticss for the last time this Pool was retrieved from state storage.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Stats stats = 4;</code>
|
||||
* @return \Messages\Stats
|
||||
*/
|
||||
public function getStats()
|
||||
{
|
||||
return $this->stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statisticss for the last time this Pool was retrieved from state storage.
|
||||
*
|
||||
* Generated from protobuf field <code>.messages.Stats stats = 4;</code>
|
||||
* @param \Messages\Stats $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setStats($var)
|
||||
{
|
||||
GPBUtil::checkMessage($var, \Messages\Stats::class);
|
||||
$this->stats = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
if (false) {
|
||||
/**
|
||||
* This class is deprecated. Use Messages\Player\Attribute instead.
|
||||
* @deprecated
|
||||
*/
|
||||
class Player_Attribute {}
|
||||
}
|
||||
class_exists(Player\Attribute::class);
|
||||
@trigger_error('Messages\Player_Attribute is deprecated and will be removed in the next major release. Use Messages\Player\Attribute instead', E_USER_DEPRECATED);
|
||||
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Simple message to return success/failure and error status.
|
||||
*
|
||||
* Generated from protobuf message <code>messages.Result</code>
|
||||
*/
|
||||
class Result extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* Generated from protobuf field <code>bool success = 1;</code>
|
||||
*/
|
||||
private $success = false;
|
||||
/**
|
||||
* Generated from protobuf field <code>string error = 2;</code>
|
||||
*/
|
||||
private $error = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type bool $success
|
||||
* @type string $error
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>bool success = 1;</code>
|
||||
* @return bool
|
||||
*/
|
||||
public function getSuccess()
|
||||
{
|
||||
return $this->success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>bool success = 1;</code>
|
||||
* @param bool $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setSuccess($var)
|
||||
{
|
||||
GPBUtil::checkBool($var);
|
||||
$this->success = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>string error = 2;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated from protobuf field <code>string error = 2;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setError($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->error = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
101
examples/functions/php/mmlogic-simple/proto/Messages/Roster.php
Normal file
101
examples/functions/php/mmlogic-simple/proto/Messages/Roster.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Data structure to hold a list of players in a match.
|
||||
*
|
||||
* Generated from protobuf message <code>messages.Roster</code>
|
||||
*/
|
||||
class Roster extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable string. By convention, set to team name.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
*/
|
||||
private $name = '';
|
||||
/**
|
||||
* Player profiles on this roster.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Player players = 2;</code>
|
||||
*/
|
||||
private $players;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type string $name
|
||||
* Arbitrary developer-chosen, human-readable string. By convention, set to team name.
|
||||
* @type \Messages\Player[]|\Google\Protobuf\Internal\RepeatedField $players
|
||||
* Player profiles on this roster.
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable string. By convention, set to team name.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Arbitrary developer-chosen, human-readable string. By convention, set to team name.
|
||||
*
|
||||
* Generated from protobuf field <code>string name = 1;</code>
|
||||
* @param string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($var)
|
||||
{
|
||||
GPBUtil::checkString($var, True);
|
||||
$this->name = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Player profiles on this roster.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Player players = 2;</code>
|
||||
* @return \Google\Protobuf\Internal\RepeatedField
|
||||
*/
|
||||
public function getPlayers()
|
||||
{
|
||||
return $this->players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Player profiles on this roster.
|
||||
*
|
||||
* Generated from protobuf field <code>repeated .messages.Player players = 2;</code>
|
||||
* @param \Messages\Player[]|\Google\Protobuf\Internal\RepeatedField $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setPlayers($var)
|
||||
{
|
||||
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Messages\Player::class);
|
||||
$this->players = $arr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
101
examples/functions/php/mmlogic-simple/proto/Messages/Stats.php
Normal file
101
examples/functions/php/mmlogic-simple/proto/Messages/Stats.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: api/protobuf-spec/messages.proto
|
||||
|
||||
namespace Messages;
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBUtil;
|
||||
|
||||
/**
|
||||
* Holds statistics
|
||||
*
|
||||
* Generated from protobuf message <code>messages.Stats</code>
|
||||
*/
|
||||
class Stats extends \Google\Protobuf\Internal\Message
|
||||
{
|
||||
/**
|
||||
* Number of results.
|
||||
*
|
||||
* Generated from protobuf field <code>int64 count = 1;</code>
|
||||
*/
|
||||
private $count = 0;
|
||||
/**
|
||||
* How long it took to get the results.
|
||||
*
|
||||
* Generated from protobuf field <code>double elapsed = 2;</code>
|
||||
*/
|
||||
private $elapsed = 0.0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data {
|
||||
* Optional. Data for populating the Message object.
|
||||
*
|
||||
* @type int|string $count
|
||||
* Number of results.
|
||||
* @type float $elapsed
|
||||
* How long it took to get the results.
|
||||
* }
|
||||
*/
|
||||
public function __construct($data = NULL) {
|
||||
\GPBMetadata\Api\ProtobufSpec\Messages::initOnce();
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of results.
|
||||
*
|
||||
* Generated from protobuf field <code>int64 count = 1;</code>
|
||||
* @return int|string
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of results.
|
||||
*
|
||||
* Generated from protobuf field <code>int64 count = 1;</code>
|
||||
* @param int|string $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setCount($var)
|
||||
{
|
||||
GPBUtil::checkInt64($var);
|
||||
$this->count = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it took to get the results.
|
||||
*
|
||||
* Generated from protobuf field <code>double elapsed = 2;</code>
|
||||
* @return float
|
||||
*/
|
||||
public function getElapsed()
|
||||
{
|
||||
return $this->elapsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it took to get the results.
|
||||
*
|
||||
* Generated from protobuf field <code>double elapsed = 2;</code>
|
||||
* @param float $var
|
||||
* @return $this
|
||||
*/
|
||||
public function setElapsed($var)
|
||||
{
|
||||
GPBUtil::checkDouble($var);
|
||||
$this->elapsed = $var;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ with grpc.insecure_channel(api_conn_info) as channel:
|
||||
for player in partial_results.roster.players:
|
||||
if not player.id in player_pools[empty_pool.name]:
|
||||
player_pools[empty_pool.name][player.id] = dict()
|
||||
for prop in player.properties:
|
||||
player_pools[empty_pool.name][player.id][prop.name] = prop.value
|
||||
for attr in player.attributes:
|
||||
player_pools[empty_pool.name][player.id][attr.name] = attr.value
|
||||
except Exception as err:
|
||||
print("Error encountered: %s" % err)
|
||||
if cfg['debug']:
|
||||
|
@ -1,66 +0,0 @@
|
||||
#! /usr/bin/env python3
|
||||
#Copyright 2018 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
|
||||
#
|
||||
# https://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.
|
||||
|
||||
import os
|
||||
import grpc
|
||||
|
||||
import customlogic
|
||||
|
||||
import mmlogic_pb2
|
||||
import mmlogic_pb2_grpc
|
||||
|
||||
#import simplejson as json
|
||||
import ujson as json
|
||||
import pprint as pp
|
||||
|
||||
cfg = ''
|
||||
|
||||
# Load config file
|
||||
with open("matchmaker_config.json") as f:
|
||||
cfg = json.loads(f.read())
|
||||
|
||||
api_conn_info = "%s:%d" % (cfg['api']['mmlogic']['hostname'], cfg['api']['mmlogic']['port'])
|
||||
|
||||
# Step 2 - Talk to Redis. This example uses the MM Logic API in OM to read/write to/from redis.
|
||||
with grpc.insecure_channel(api_conn_info) as channel:
|
||||
mmlogic_api = mmlogic_pb2_grpc.APIStub(channel)
|
||||
|
||||
# Step 3 - Read the profile written to the Backend API.
|
||||
profile_dict = json.loads(mmlogic_api.GetProfile(mmlogic_pb2.Profile(id=os.environ["MMF_PROFILE_ID"])))
|
||||
|
||||
# Step 4 - Select the player data from Redis that we want for our matchmaking logic.
|
||||
player_pools = dict() # holds pools returned by the associated filter
|
||||
for p in profile_dict['properties']['playerPools']:
|
||||
player_pools[p['id']] =mmlogic_api.GetPlayerPool(mmlogic_pb2.JsonFilterSet(id=p['id'],json=json.dumps(p)))
|
||||
|
||||
# Step 5 - Run custom matchmaking logic to try to find a match
|
||||
# This is in the file customlogic.py
|
||||
match_properties = json.dumps(customlogic.makeMatches(profile_dict, player_pools))
|
||||
|
||||
# Step 6 - Write the outcome of the matchmaking logic back to state storage.
|
||||
# Step 7 - Remove the selected players from consideration by other MMFs.
|
||||
# CreateProposal does both of these for you, and some other items as well.
|
||||
success = mmlogic_api.CreateProposal(mmlogic_pb2.MMFResults(
|
||||
id = os.environ["MMF_PROPOSAL_ID"],
|
||||
matchobject = mmlogic_pb2.MatchObject(
|
||||
properties = match_properties,
|
||||
),
|
||||
roster = mmlogic_pb2.Roster(
|
||||
id = os.environ["MMF_ROSTER_ID"],
|
||||
player = match_properties[cfg['jsonKeys']['roster']],
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
# [OPTIONAL] Step 8 - Export stats about this run.
|
@ -33,7 +33,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: om-backend
|
||||
image: gcr.io/unite-au-demo/openmatch-backendapi:dev
|
||||
image: gcr.io/matchmaker-dev-201405/openmatch-backendapi:dev
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- name: grpc
|
||||
@ -79,7 +79,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: om-frontendapi
|
||||
image: gcr.io/unite-au-demo/openmatch-frontendapi:dev
|
||||
image: gcr.io/matchmaker-dev-201405/openmatch-frontendapi:dev
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- name: grpc
|
||||
@ -125,7 +125,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: om-mmforc
|
||||
image: gcr.io/unite-au-demo/openmatch-mmforc:dev
|
||||
image: gcr.io/matchmaker-dev-201405/openmatch-mmforc:dev
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- name: metrics
|
||||
@ -139,3 +139,52 @@ spec:
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
---
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: om-mmlogicapi
|
||||
labels:
|
||||
app: openmatch
|
||||
component: mmlogic
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: openmatch
|
||||
component: mmlogic
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: openmatch
|
||||
component: mmlogic
|
||||
spec:
|
||||
containers:
|
||||
- name: om-mmlogic
|
||||
image: gcr.io/matchmaker-dev-201405/openmatch-mmlogicapi:dev
|
||||
imagePullPolicy: Always
|
||||
command:
|
||||
- sleep
|
||||
- '30000'
|
||||
ports:
|
||||
- name: grpc
|
||||
containerPort: 50503
|
||||
- name: metrics
|
||||
containerPort: 9555
|
||||
resources:
|
||||
requests:
|
||||
memory: 100Mi
|
||||
cpu: 100m
|
||||
---
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: om-mmlogicapi
|
||||
spec:
|
||||
selector:
|
||||
app: openmatch
|
||||
component: mmlogic
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 50503
|
||||
targetPort: grpc
|
||||
|
73
install/yaml/README.md
Normal file
73
install/yaml/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
# install/yaml
|
||||
This directory contains Kubernetes YAML resource definitions, which should be applied according to their filename order. Only Redis & Open Match are required, Prometheus is optional.
|
||||
```
|
||||
kubectl apply -f 01-redis.yaml
|
||||
kubectl apply -f 02-open-match.yaml
|
||||
```
|
||||
**Note**: Trying to apply the Kubernetes Prometheus Operator resource definition files without a cluster-admin rolebinding on GKE doesn't work without running the following command first. See https://github.com/coreos/prometheus-operator/issues/357
|
||||
```
|
||||
kubectl create clusterrolebinding projectowner-cluster-admin-binding --clusterrole=cluster-admin --user=<GCP_ACCOUNT>
|
||||
```
|
||||
```
|
||||
kubectl apply -f 03-prometheus.yaml
|
||||
```
|
||||
[There is a known dependency ordering issue when applying the Prometheus resource; just wait a couple moments and apply it again.](https://github.com/GoogleCloudPlatform/open-match/issues/46)
|
||||
|
||||
[Accurate as of v0.2.0] Output from `kubectl get all` if everything succeeded should look something like this:
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
pod/om-backendapi-84bc9d8fff-q89kr 1/1 Running 0 9m
|
||||
pod/om-frontendapi-55d5bb7946-c5ccb 1/1 Running 0 9m
|
||||
pod/om-mmforc-85bfd7f4f6-wmwhc 1/1 Running 0 9m
|
||||
pod/om-mmlogicapi-6488bc7fc6-g74dm 1/1 Running 0 9m
|
||||
pod/prometheus-operator-5c8774cdd8-7c5qm 1/1 Running 0 9m
|
||||
pod/prometheus-prometheus-0 2/2 Running 0 9m
|
||||
pod/redis-master-9b6b86c46-b7ggn 1/1 Running 0 9m
|
||||
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
service/kubernetes ClusterIP 10.59.240.1 <none> 443/TCP 19m
|
||||
service/om-backend-metrics ClusterIP 10.59.254.43 <none> 29555/TCP 9m
|
||||
service/om-backendapi ClusterIP 10.59.240.211 <none> 50505/TCP 9m
|
||||
service/om-frontend-metrics ClusterIP 10.59.246.228 <none> 19555/TCP 9m
|
||||
service/om-frontendapi ClusterIP 10.59.250.59 <none> 50504/TCP 9m
|
||||
service/om-mmforc-metrics ClusterIP 10.59.240.59 <none> 39555/TCP 9m
|
||||
service/om-mmlogicapi ClusterIP 10.59.248.3 <none> 50503/TCP 9m
|
||||
service/prometheus NodePort 10.59.252.212 <none> 9090:30900/TCP 9m
|
||||
service/prometheus-operated ClusterIP None <none> 9090/TCP 9m
|
||||
service/redis-sentinel ClusterIP 10.59.249.197 <none> 6379/TCP 9m
|
||||
|
||||
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
|
||||
deployment.extensions/om-backendapi 1 1 1 1 9m
|
||||
deployment.extensions/om-frontendapi 1 1 1 1 9m
|
||||
deployment.extensions/om-mmforc 1 1 1 1 9m
|
||||
deployment.extensions/om-mmlogicapi 1 1 1 1 9m
|
||||
deployment.extensions/prometheus-operator 1 1 1 1 9m
|
||||
deployment.extensions/redis-master 1 1 1 1 9m
|
||||
|
||||
NAME DESIRED CURRENT READY AGE
|
||||
replicaset.extensions/om-backendapi-84bc9d8fff 1 1 1 9m
|
||||
replicaset.extensions/om-frontendapi-55d5bb7946 1 1 1 9m
|
||||
replicaset.extensions/om-mmforc-85bfd7f4f6 1 1 1 9m
|
||||
replicaset.extensions/om-mmlogicapi-6488bc7fc6 1 1 1 9m
|
||||
replicaset.extensions/prometheus-operator-5c8774cdd8 1 1 1 9m
|
||||
replicaset.extensions/redis-master-9b6b86c46 1 1 1 9m
|
||||
|
||||
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
|
||||
deployment.apps/om-backendapi 1 1 1 1 9m
|
||||
deployment.apps/om-frontendapi 1 1 1 1 9m
|
||||
deployment.apps/om-mmforc 1 1 1 1 9m
|
||||
deployment.apps/om-mmlogicapi 1 1 1 1 9m
|
||||
deployment.apps/prometheus-operator 1 1 1 1 9m
|
||||
deployment.apps/redis-master 1 1 1 1 9m
|
||||
|
||||
NAME DESIRED CURRENT READY AGE
|
||||
replicaset.apps/om-backendapi-84bc9d8fff 1 1 1 9m
|
||||
replicaset.apps/om-frontendapi-55d5bb7946 1 1 1 9m
|
||||
replicaset.apps/om-mmforc-85bfd7f4f6 1 1 1 9m
|
||||
replicaset.apps/om-mmlogicapi-6488bc7fc6 1 1 1 9m
|
||||
replicaset.apps/prometheus-operator-5c8774cdd8 1 1 1 9m
|
||||
replicaset.apps/redis-master-9b6b86c46 1 1 1 9m
|
||||
|
||||
NAME DESIRED CURRENT AGE
|
||||
statefulset.apps/prometheus-prometheus 1 1 9m
|
||||
```
|
88
internal/set/set.go
Normal file
88
internal/set/set.go
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
package apisrv provides an implementation of the gRPC server defined in ../../../api/protobuf-spec/mmlogic.proto.
|
||||
Most of the documentation for what these calls should do is in that file!
|
||||
|
||||
Copyright 2018 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
|
||||
|
||||
https://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 set
|
||||
|
||||
// Intersection returns the interection of two sets.
|
||||
func Intersection(a []string, b []string) (out []string) {
|
||||
|
||||
hash := make(map[string]bool)
|
||||
|
||||
for _, v := range a {
|
||||
hash[v] = true
|
||||
}
|
||||
|
||||
for _, v := range b {
|
||||
if _, found := hash[v]; found {
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
|
||||
}
|
||||
|
||||
// Union returns the union of two sets.
|
||||
func Union(a []string, b []string) (out []string) {
|
||||
|
||||
hash := make(map[string]bool)
|
||||
|
||||
// collect all values from input args
|
||||
for _, v := range a {
|
||||
hash[v] = true
|
||||
}
|
||||
|
||||
for _, v := range b {
|
||||
hash[v] = true
|
||||
}
|
||||
|
||||
// put values into string array
|
||||
for k := range hash {
|
||||
out = append(out, k)
|
||||
}
|
||||
|
||||
return out
|
||||
|
||||
}
|
||||
|
||||
// Difference returns the items in the first argument that are not in the
|
||||
// second (set 'a' - set 'b')
|
||||
func Difference(a []string, b []string) (out []string) {
|
||||
|
||||
hash := make(map[string]bool)
|
||||
out = append([]string{}, a...)
|
||||
|
||||
for _, v := range b {
|
||||
hash[v] = true
|
||||
}
|
||||
|
||||
// Iterate through output, removing items found in b
|
||||
for i := 0; i < len(out); i++ {
|
||||
if _, found := hash[out[i]]; found {
|
||||
// Remove this element by moving the copying the last element of the
|
||||
// array to this index and then slicing off the last element.
|
||||
// https://stackoverflow.com/a/37335777/3113674
|
||||
out[i] = out[len(out)-1]
|
||||
out = out[:len(out)-1]
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
@ -1,4 +1,22 @@
|
||||
package apisrv
|
||||
/*
|
||||
package set provides implementation of basic set operationg in golang.
|
||||
|
||||
Copyright 2018 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
|
||||
|
||||
https://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 set
|
||||
|
||||
import (
|
||||
"flag"
|
||||
@ -31,15 +49,15 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestStringOperations(t *testing.T) {
|
||||
t.Run("Difference: valid slices", testStringOperation(difference, a1[:], a2[:], d[:]))
|
||||
t.Run("Difference: remove nil", testStringOperation(difference, a1[:], nil, a1[:]))
|
||||
t.Run("Difference: remove from nil", testStringOperation(difference, nil, a2[:], nil))
|
||||
t.Run("Union: valid slices", testStringOperation(union, a1[:], a2[:], u[:]))
|
||||
t.Run("Union: nil first", testStringOperation(union, nil, a2[:], a2[:]))
|
||||
t.Run("Union: nil second", testStringOperation(union, a1[:], nil, a1[:]))
|
||||
t.Run("Intersection: valid slices", testStringOperation(intersection, a1[:], a2[:], i[:]))
|
||||
t.Run("Intersection: nil first", testStringOperation(intersection, a1[:], nil, nil))
|
||||
t.Run("Intersection: nil second", testStringOperation(intersection, nil, a2[:], nil))
|
||||
t.Run("Difference: valid slices", testStringOperation(Difference, a1[:], a2[:], d[:]))
|
||||
t.Run("Difference: remove nil", testStringOperation(Difference, a1[:], nil, a1[:]))
|
||||
t.Run("Difference: remove from nil", testStringOperation(Difference, nil, a2[:], nil))
|
||||
t.Run("Union: valid slices", testStringOperation(Union, a1[:], a2[:], u[:]))
|
||||
t.Run("Union: nil first", testStringOperation(Union, nil, a2[:], a2[:]))
|
||||
t.Run("Union: nil second", testStringOperation(Union, a1[:], nil, a1[:]))
|
||||
t.Run("Intersection: valid slices", testStringOperation(Intersection, a1[:], a2[:], i[:]))
|
||||
t.Run("Intersection: nil first", testStringOperation(Intersection, a1[:], nil, nil))
|
||||
t.Run("Intersection: nil second", testStringOperation(Intersection, nil, a2[:], nil))
|
||||
}
|
||||
|
||||
func testStringOperation(thisFunc stringOperation, in1 []string, in2 []string, outputExpected []string) func(*testing.T) {
|
@ -124,25 +124,25 @@ func Delete(redisConn redis.Conn, playerID string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Deindex a BLARG without deleting there JSON object representation from
|
||||
// state storage. Unindexing is done in two stages: first the BLARG is added to an ignore list, which 'atomically' removes them from consideration. A Goroutine is then kicked off to 'lazily' remove them from any field indicies that contain them.
|
||||
func Deindex(redisConn redis.Conn, BLARGID string) (err error) {
|
||||
// Deindex a player without deleting there JSON object representation from
|
||||
// state storage. Unindexing is done in two stages: first the player is added to an ignore list, which 'atomically' removes them from consideration. A Goroutine is then kicked off to 'lazily' remove them from any field indicies that contain them.
|
||||
func Deindex(redisConn redis.Conn, playerID string) (err error) {
|
||||
|
||||
//TODO: remove deindexing from delete and call this instead
|
||||
|
||||
results, err := Retrieve(redisConn, BLARGID)
|
||||
results, err := Retrieve(redisConn, playerID)
|
||||
if err != nil {
|
||||
log.Println("couldn't retreive player properties for ", BLARGID)
|
||||
log.Println("couldn't retreive player properties for ", playerID)
|
||||
}
|
||||
|
||||
redisConn.Send("MULTI")
|
||||
|
||||
// Remove BLARGID from indices
|
||||
// Remove playerID from indices
|
||||
for iName := range results {
|
||||
log.WithFields(log.Fields{
|
||||
"field": iName,
|
||||
"key": BLARGID}).Debug("Un-indexing field")
|
||||
redisConn.Send("ZREM", iName, BLARGID)
|
||||
"key": playerID}).Debug("Un-indexing field")
|
||||
redisConn.Send("ZREM", iName, playerID)
|
||||
}
|
||||
_, err = redisConn.Do("EXEC")
|
||||
check(err, "")
|
||||
|
@ -328,7 +328,7 @@ func Count(ctx context.Context, pool *redis.Pool, key string) (int, error) {
|
||||
}
|
||||
|
||||
// Increment increments a redis value at key.
|
||||
func Increment(ctx context.Context, pool *redis.Pool, key string) (string, error) {
|
||||
func Increment(ctx context.Context, pool *redis.Pool, key string) (interface{}, error) {
|
||||
|
||||
// Add the key as a field to all logs for the execution of this function.
|
||||
rhLog = rhLog.WithFields(log.Fields{"key": key})
|
||||
@ -349,11 +349,11 @@ func Increment(ctx context.Context, pool *redis.Pool, key string) (string, error
|
||||
}
|
||||
|
||||
// Run redis query and return
|
||||
return redis.String(redisConn.Do("INCR", key))
|
||||
return redisConn.Do("INCR", key)
|
||||
}
|
||||
|
||||
// Decrement decrements a redis value at key.
|
||||
func Decrement(ctx context.Context, pool *redis.Pool, key string) (string, error) {
|
||||
func Decrement(ctx context.Context, pool *redis.Pool, key string) (interface{}, error) {
|
||||
|
||||
// Add the key as a field to all logs for the execution of this function.
|
||||
rhLog = rhLog.WithFields(log.Fields{"key": key})
|
||||
@ -374,7 +374,7 @@ func Decrement(ctx context.Context, pool *redis.Pool, key string) (string, error
|
||||
}
|
||||
|
||||
// Run redis query and return
|
||||
return redis.String(redisConn.Do("DECR", key))
|
||||
return redisConn.Do("DECR", key)
|
||||
}
|
||||
|
||||
// JSONStringToMap converts a JSON blob (which is how we store many things in
|
||||
|
Reference in New Issue
Block a user