From 6548d9d1bbb400f41c9a711bed87ec202c07caee Mon Sep 17 00:00:00 2001 From: Niall Weedon Date: Thu, 11 Nov 2021 17:05:58 +0000 Subject: [PATCH 1/2] chore: Restructure repository for multiplay-samples Move sample game server to `simple-game-server-go`. --- ...d-release.yml => simple-game-server-go.yml} | 10 ++++++++-- .gitignore | 18 ------------------ README.md | 16 +++------------- simple-game-server-go/.gitignore | 18 ++++++++++++++++++ .../.golangci.yml | 0 .../.goreleaser.yml | 1 + .../.unity}/server-config/server.json | 0 simple-game-server-go/README.md | 14 ++++++++++++++ go.mod => simple-game-server-go/go.mod | 2 +- go.sum => simple-game-server-go/go.sum | 0 main.go => simple-game-server-go/main.go | 2 +- .../main_test.go | 0 .../pkg}/game/bind.go | 0 .../pkg}/game/bind_test.go | 0 .../pkg}/game/config.go | 0 .../pkg}/game/config_test.go | 0 .../pkg}/game/game.go | 2 +- .../pkg}/game/game_loop.go | 6 +++--- .../pkg}/proto/a2s/a2s.go | 2 +- .../pkg}/proto/a2s/encoder.go | 0 .../pkg}/proto/a2s/errors.go | 0 .../pkg}/proto/query.go | 0 .../pkg}/proto/sqp/encoder.go | 0 .../pkg}/proto/sqp/errors.go | 0 .../pkg}/proto/sqp/server_info.go | 2 +- .../pkg}/proto/sqp/sqp.go | 2 +- .../pkg}/proto/sqp/sqp_test.go | 2 +- 27 files changed, 54 insertions(+), 43 deletions(-) rename .github/workflows/{build-and-release.yml => simple-game-server-go.yml} (74%) create mode 100644 simple-game-server-go/.gitignore rename .golangci.yml => simple-game-server-go/.golangci.yml (100%) rename .goreleaser.yml => simple-game-server-go/.goreleaser.yml (94%) rename {.unity => simple-game-server-go/.unity}/server-config/server.json (100%) create mode 100644 simple-game-server-go/README.md rename go.mod => simple-game-server-go/go.mod (80%) rename go.sum => simple-game-server-go/go.sum (100%) rename main.go => simple-game-server-go/main.go (95%) rename main_test.go => simple-game-server-go/main_test.go (100%) rename {pkg => simple-game-server-go/pkg}/game/bind.go (100%) rename {pkg => simple-game-server-go/pkg}/game/bind_test.go (100%) rename {pkg => simple-game-server-go/pkg}/game/config.go (100%) rename {pkg => simple-game-server-go/pkg}/game/config_test.go (100%) rename {pkg => simple-game-server-go/pkg}/game/game.go (97%) rename {pkg => simple-game-server-go/pkg}/game/game_loop.go (94%) rename {pkg => simple-game-server-go/pkg}/proto/a2s/a2s.go (95%) rename {pkg => simple-game-server-go/pkg}/proto/a2s/encoder.go (100%) rename {pkg => simple-game-server-go/pkg}/proto/a2s/errors.go (100%) rename {pkg => simple-game-server-go/pkg}/proto/query.go (100%) rename {pkg => simple-game-server-go/pkg}/proto/sqp/encoder.go (100%) rename {pkg => simple-game-server-go/pkg}/proto/sqp/errors.go (100%) rename {pkg => simple-game-server-go/pkg}/proto/sqp/server_info.go (92%) rename {pkg => simple-game-server-go/pkg}/proto/sqp/sqp.go (97%) rename {pkg => simple-game-server-go/pkg}/proto/sqp/sqp_test.go (91%) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/simple-game-server-go.yml similarity index 74% rename from .github/workflows/build-and-release.yml rename to .github/workflows/simple-game-server-go.yml index d3d0653..ee04c38 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/simple-game-server-go.yml @@ -1,4 +1,4 @@ -name: build-and-release +name: simple-game-server-go on: pull_request: push: @@ -7,6 +7,9 @@ permissions: jobs: goreleaser: runs-on: ubuntu-latest + defaults: + run: + working-directory: './simple-game-server-go' steps: - name: Checkout uses: actions/checkout@v2 @@ -20,6 +23,7 @@ jobs: uses: golangci/golangci-lint-action@v2 with: version: v1.39.0 + working-directory: './simple-game-server-go' - name: Build uses: goreleaser/goreleaser-action@v2 if: startsWith(github.ref, 'refs/tags/') == false @@ -27,16 +31,18 @@ jobs: distribution: goreleaser version: latest args: build --rm-dist --snapshot + workdir: './simple-game-server-go' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Test run: 'go test -timeout=5m -race -v ./...' - name: Release uses: goreleaser/goreleaser-action@v2 - if: startsWith(github.ref, 'refs/tags/') + if: ${{ startsWith(github.ref, 'refs/tags/') && endsWith(github.ref, '-simple-game-server-go') }} with: distribution: goreleaser version: latest args: release --rm-dist + workdir: './simple-game-server-go' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 69e8faa..4befed3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1,2 @@ -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib .DS_Store .idea - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories -vendor/ - -# Build output -dist/ diff --git a/README.md b/README.md index f3565fb..84658e9 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,7 @@ -# mp-game-server-sample-go +# multiplay-examples -This repository represents a sample game server capable of running on the [Unity Multiplay platform](https://unity.com/products/multiplay). -The [prebuilt releases](https://github.com/Unity-Technologies/mp-game-server-sample-go/releases) are ready for you to upload to Multiplay to try out the service without writing a single line of code! - -The capabilities of this sample are as follows: - -- Handling of [Multiplay allocation lifecycle](https://docs.unity.com/multiplay/Content/shared/allocation-flow.htm) - - Achieved by watching for file events on the provided configuration file - - When allocated, the sample starts a TCP server on the configured `Port` which listens for client connections - - When de-allocated, this TCP server is stopped -- Dynamic server query results - - Data such as number of players, map name, etc. are handled appropriately - - `sqp` and `a2s` query protocols over the configured UDP `QueryPort` +This repository represents a set of examples for using the [Unity Multiplay platform](https://unity.com/products/multiplay). +Visit one of the sub-directories to see more information on each sample. --- _Disclaimer: The repo owners will not (cannot) accept pull requests, GitHub review requests, or any other GitHub-hosted issue management requests._ diff --git a/simple-game-server-go/.gitignore b/simple-game-server-go/.gitignore new file mode 100644 index 0000000..cee241a --- /dev/null +++ b/simple-game-server-go/.gitignore @@ -0,0 +1,18 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories +vendor/ + +# Build output +dist/ diff --git a/.golangci.yml b/simple-game-server-go/.golangci.yml similarity index 100% rename from .golangci.yml rename to simple-game-server-go/.golangci.yml diff --git a/.goreleaser.yml b/simple-game-server-go/.goreleaser.yml similarity index 94% rename from .goreleaser.yml rename to simple-game-server-go/.goreleaser.yml index 142e898..4dc32b9 100644 --- a/.goreleaser.yml +++ b/simple-game-server-go/.goreleaser.yml @@ -1,3 +1,4 @@ +project_name: simple-game-server-go before: hooks: - go mod tidy diff --git a/.unity/server-config/server.json b/simple-game-server-go/.unity/server-config/server.json similarity index 100% rename from .unity/server-config/server.json rename to simple-game-server-go/.unity/server-config/server.json diff --git a/simple-game-server-go/README.md b/simple-game-server-go/README.md new file mode 100644 index 0000000..b8c7a30 --- /dev/null +++ b/simple-game-server-go/README.md @@ -0,0 +1,14 @@ +# simple-game-server-go + +This repository represents a simple game server capable of running on the [Unity Multiplay platform](https://unity.com/products/multiplay). +The [prebuilt releases](https://github.com/Unity-Technologies/multiplay-examples/releases) are ready for you to upload to Multiplay to try out the service without writing a single line of code! + +The capabilities of this sample are as follows: + +- Handling of [Multiplay allocation lifecycle](https://docs.unity.com/multiplay/Content/shared/allocation-flow.htm) + - Achieved by watching for file events on the provided configuration file + - When allocated, the sample starts a TCP server on the configured `-port` flag which listens for client connections + - When de-allocated, this TCP server is stopped +- Dynamic server query results + - Data such as number of players, map name, etc. are handled appropriately + - `sqp` and `a2s` query protocols over the configured UDP `-queryport` flag diff --git a/go.mod b/simple-game-server-go/go.mod similarity index 80% rename from go.mod rename to simple-game-server-go/go.mod index d2cd571..3dec2b3 100644 --- a/go.mod +++ b/simple-game-server-go/go.mod @@ -1,4 +1,4 @@ -module github.com/Unity-Technologies/mp-game-server-sample-go +module github.com/Unity-Technologies/multiplay-examples/simple-game-server-go go 1.17 diff --git a/go.sum b/simple-game-server-go/go.sum similarity index 100% rename from go.sum rename to simple-game-server-go/go.sum diff --git a/main.go b/simple-game-server-go/main.go similarity index 95% rename from main.go rename to simple-game-server-go/main.go index 3bf9d25..694194d 100644 --- a/main.go +++ b/simple-game-server-go/main.go @@ -6,7 +6,7 @@ import ( "os/signal" "path/filepath" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/game" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/game" "github.com/sirupsen/logrus" ) diff --git a/main_test.go b/simple-game-server-go/main_test.go similarity index 100% rename from main_test.go rename to simple-game-server-go/main_test.go diff --git a/pkg/game/bind.go b/simple-game-server-go/pkg/game/bind.go similarity index 100% rename from pkg/game/bind.go rename to simple-game-server-go/pkg/game/bind.go diff --git a/pkg/game/bind_test.go b/simple-game-server-go/pkg/game/bind_test.go similarity index 100% rename from pkg/game/bind_test.go rename to simple-game-server-go/pkg/game/bind_test.go diff --git a/pkg/game/config.go b/simple-game-server-go/pkg/game/config.go similarity index 100% rename from pkg/game/config.go rename to simple-game-server-go/pkg/game/config.go diff --git a/pkg/game/config_test.go b/simple-game-server-go/pkg/game/config_test.go similarity index 100% rename from pkg/game/config_test.go rename to simple-game-server-go/pkg/game/config_test.go diff --git a/pkg/game/game.go b/simple-game-server-go/pkg/game/game.go similarity index 97% rename from pkg/game/game.go rename to simple-game-server-go/pkg/game/game.go index 104411f..2decb45 100644 --- a/pkg/game/game.go +++ b/simple-game-server-go/pkg/game/game.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/proto" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/proto" "github.com/sirupsen/logrus" ) diff --git a/pkg/game/game_loop.go b/simple-game-server-go/pkg/game/game_loop.go similarity index 94% rename from pkg/game/game_loop.go rename to simple-game-server-go/pkg/game/game_loop.go index c0b60c1..5b5cd3c 100644 --- a/pkg/game/game_loop.go +++ b/simple-game-server-go/pkg/game/game_loop.go @@ -8,9 +8,9 @@ import ( "syscall" "time" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/proto" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/proto/a2s" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/proto/sqp" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/proto" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/proto/a2s" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/proto/sqp" ) type ( diff --git a/pkg/proto/a2s/a2s.go b/simple-game-server-go/pkg/proto/a2s/a2s.go similarity index 95% rename from pkg/proto/a2s/a2s.go rename to simple-game-server-go/pkg/proto/a2s/a2s.go index 0cab78f..d0087c4 100644 --- a/pkg/proto/a2s/a2s.go +++ b/simple-game-server-go/pkg/proto/a2s/a2s.go @@ -5,7 +5,7 @@ import ( "runtime" "sync/atomic" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/proto" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/proto" ) type ( diff --git a/pkg/proto/a2s/encoder.go b/simple-game-server-go/pkg/proto/a2s/encoder.go similarity index 100% rename from pkg/proto/a2s/encoder.go rename to simple-game-server-go/pkg/proto/a2s/encoder.go diff --git a/pkg/proto/a2s/errors.go b/simple-game-server-go/pkg/proto/a2s/errors.go similarity index 100% rename from pkg/proto/a2s/errors.go rename to simple-game-server-go/pkg/proto/a2s/errors.go diff --git a/pkg/proto/query.go b/simple-game-server-go/pkg/proto/query.go similarity index 100% rename from pkg/proto/query.go rename to simple-game-server-go/pkg/proto/query.go diff --git a/pkg/proto/sqp/encoder.go b/simple-game-server-go/pkg/proto/sqp/encoder.go similarity index 100% rename from pkg/proto/sqp/encoder.go rename to simple-game-server-go/pkg/proto/sqp/encoder.go diff --git a/pkg/proto/sqp/errors.go b/simple-game-server-go/pkg/proto/sqp/errors.go similarity index 100% rename from pkg/proto/sqp/errors.go rename to simple-game-server-go/pkg/proto/sqp/errors.go diff --git a/pkg/proto/sqp/server_info.go b/simple-game-server-go/pkg/proto/sqp/server_info.go similarity index 92% rename from pkg/proto/sqp/server_info.go rename to simple-game-server-go/pkg/proto/sqp/server_info.go index 0002dfa..94951c3 100644 --- a/pkg/proto/sqp/server_info.go +++ b/simple-game-server-go/pkg/proto/sqp/server_info.go @@ -3,7 +3,7 @@ package sqp import ( "sync/atomic" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/proto" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/proto" ) type ( diff --git a/pkg/proto/sqp/sqp.go b/simple-game-server-go/pkg/proto/sqp/sqp.go similarity index 97% rename from pkg/proto/sqp/sqp.go rename to simple-game-server-go/pkg/proto/sqp/sqp.go index 833d232..a6cd91f 100644 --- a/pkg/proto/sqp/sqp.go +++ b/simple-game-server-go/pkg/proto/sqp/sqp.go @@ -6,7 +6,7 @@ import ( "encoding/binary" "sync" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/proto" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/proto" ) type ( diff --git a/pkg/proto/sqp/sqp_test.go b/simple-game-server-go/pkg/proto/sqp/sqp_test.go similarity index 91% rename from pkg/proto/sqp/sqp_test.go rename to simple-game-server-go/pkg/proto/sqp/sqp_test.go index d3c9201..b5de2d4 100644 --- a/pkg/proto/sqp/sqp_test.go +++ b/simple-game-server-go/pkg/proto/sqp/sqp_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/Unity-Technologies/mp-game-server-sample-go/pkg/proto" + "github.com/Unity-Technologies/multiplay-examples/simple-game-server-go/pkg/proto" "github.com/stretchr/testify/require" ) From 1e6db09aec782777d5d53610ac5a98605142e0d7 Mon Sep 17 00:00:00 2001 From: Niall Weedon Date: Fri, 12 Nov 2021 09:48:55 +0000 Subject: [PATCH 2/2] chore: Resolve README nitpicks --- README.md | 4 ++-- simple-game-server-go/README.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 84658e9..1644438 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# multiplay-examples +# Multiplay Examples -This repository represents a set of examples for using the [Unity Multiplay platform](https://unity.com/products/multiplay). +[Unity Multiplay](https://unity.com/products/multiplay) is a platform for hosting and scaling dedicated game servers. This repository contains a set of examples for interacting with the services and APIs that Multiplay provides. Visit one of the sub-directories to see more information on each sample. --- diff --git a/simple-game-server-go/README.md b/simple-game-server-go/README.md index b8c7a30..7df0b9c 100644 --- a/simple-game-server-go/README.md +++ b/simple-game-server-go/README.md @@ -1,11 +1,11 @@ -# simple-game-server-go +# Simple Game Server (Go) +A very simple game server designed to demonstrate and test running a game server on the [Unity Multiplay platform](https://unity.com/products/multiplay). -This repository represents a simple game server capable of running on the [Unity Multiplay platform](https://unity.com/products/multiplay). The [prebuilt releases](https://github.com/Unity-Technologies/multiplay-examples/releases) are ready for you to upload to Multiplay to try out the service without writing a single line of code! The capabilities of this sample are as follows: -- Handling of [Multiplay allocation lifecycle](https://docs.unity.com/multiplay/Content/shared/allocation-flow.htm) +- Handling of the [Multiplay allocation lifecycle](https://docs.unity.com/multiplay/Content/shared/allocation-flow.htm) - Achieved by watching for file events on the provided configuration file - When allocated, the sample starts a TCP server on the configured `-port` flag which listens for client connections - When de-allocated, this TCP server is stopped