Skip to content

Commit

Permalink
Merge pull request #6 from DaniElectra/rebase
Browse files Browse the repository at this point in the history
Use common matchmaking protocols
  • Loading branch information
jonbarrow authored Oct 5, 2023
2 parents 70a61fa + 0dff046 commit 9e5aedf
Show file tree
Hide file tree
Showing 67 changed files with 651 additions and 1,800 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
*.out

# custom
build
.env
*.key
go.work
go.work.sum

# config file
secure.config

# built server
mario-kart-7-secure
build

# logs
log
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# TODO - Assumes a UNIX-like OS

RED := $(shell tput setaf 1)
BLUE := $(shell tput setaf 4)
CYAN := $(shell tput setaf 14)
ORANGE := $(shell tput setaf 202)
YELLOW := $(shell tput setaf 214)
RESET := $(shell tput sgr0)

ifeq ($(shell which go),)
# TODO - Read contents from .git folder instead?
$(error "$(RED)go command not found. Install go to continue $(BLUE)https://go.dev/doc/install$(RESET)")
endif

ifneq ($(wildcard .git),)
# * .git folder exists, build server build string from repo info
ifeq ($(shell which git),)
# TODO - Read contents from .git folder instead?
$(error "$(RED)git command not found. Install git to continue $(ORANGE)https://git-scm.com/downloads$(RESET)")
endif
$(info "$(CYAN)Building server build string from repository info$(RESET)")
# * Build server build string from repo info
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
REMOTE_ORIGIN := $(shell git config --get remote.origin.url)

# * Handle multiple origin URL formats
HTTPS_PREFIX_CHECK := $(shell echo $(REMOTE_ORIGIN) | head -c 8)
HTTP_PREFIX_CHECK := $(shell echo $(REMOTE_ORIGIN) | head -c 7)
GIT@_PREFIX_CHECK := $(shell echo $(REMOTE_ORIGIN) | head -c 4)

ifeq ($(HTTPS_PREFIX_CHECK), https://)
REMOTE_PATH := $(shell echo $(REMOTE_ORIGIN) | cut -d/ -f4-)
else ifeq ($(HTTP_PREFIX_CHECK), http://)
REMOTE_PATH := $(shell echo $(REMOTE_ORIGIN) | cut -d/ -f4-)
else ifeq ($(GIT@_PREFIX_CHECK), git@)
REMOTE_PATH := $(shell echo $(REMOTE_ORIGIN) | cut -d: -f2-)
else
REMOTE_PATH := $(shell echo $(REMOTE_ORIGIN) | cut -d/ -f2-)
endif

HASH := $(shell git rev-parse --short HEAD)
SERVER_BUILD := $(BRANCH):$(REMOTE_PATH)@$(HASH)

else
# * .git folder not present, assume downloaded from zip file and just use folder name
$(info "$(CYAN)git repository not found. Building server build string from folder name$(RESET)")
SERVER_BUILD := mario-kart-7
endif

# * Final build string
DATE_TIME := $(shell date --iso=seconds)
BUILD_STRING := $(SERVER_BUILD), $(DATE_TIME)

default:
ifeq ($(wildcard .env),)
$(warning "$(YELLOW).env file not found, environment variables may not be populated correctly$(RESET)")
endif
go get -u
go mod tidy
go build -ldflags "-X 'main.serverBuildString=$(BUILD_STRING)'" -o ./build/mario-kart-7
59 changes: 55 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
# Mario Kart 7 - Secure
### Pretendo Mario Kart 7 secure server
# Mario Kart 7 (3DS) replacement server
Includes both the authentication and secure servers

## About
This server handles all of MK7's online functionality (incomplete).
## Compiling

### Setup
Install [Go](https://go.dev/doc/install) and [git](https://git-scm.com/downloads), then clone and enter the repository

```bash
$ git clone https://github.com/PretendoNetwork/mario-kart-7
$ cd mario-kart-7
```

### Compiling using `go`
To compile using Go, `go get` the required modules and then `go build` to your desired location. You may also want to tidy the go modules, though this is optional

```bash
$ go get -u
$ go mod tidy
$ go build -o build/mario-kart-7
```

The server is now built to `build/mario-kart-7`

When compiling with only Go, the authentication servers build string is not automatically set. This should not cause any issues with gameplay, but it means that the server build will not be visible in any packet dumps or logs a title may produce

To compile the servers with the authentication server build string, add `-ldflags "-X 'main.serverBuildString=BUILD_STRING_HERE'"` to the build command, or use `make` to compile the server

### Compiling using `make`
Compiling using `make` will read the local `.git` directory to create a dynamic authentication server build string, based on your repositories remote origin and current commit

Install `make` either through your systems package manager or the [official download](https://www.gnu.org/software/make/). We provide a `default` rule which compiles [using `go`](#compiling-using-go)

To build using `go`

```bash
$ make
```

The server is now built to `build/mario-kart-7`

## Configuration
All configuration options are handled via environment variables

`.env` files are supported

| Name | Description | Required |
|-------------------------------------|------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `PN_MK7_POSTGRES_URI` | Fully qualified URI to your Postgres server (Example `postgres://username:password@localhost/mk7?sslmode=disable`) | Yes |
| `PN_MK7_KERBEROS_PASSWORD` | Password used as part of the internal server data in Kerberos tickets | No (Default password `password` will be used) |
| `PN_MK7_AUTHENTICATION_SERVER_PORT` | Port for the authentication server | Yes |
| `PN_MK7_SECURE_SERVER_HOST` | Host name for the secure server (should point to the same address as the authentication server) | Yes |
| `PN_MK7_SECURE_SERVER_PORT` | Port for the secure server | Yes |
| `PN_MK7_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes |
| `PN_MK7_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes |
| `PN_MK7_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) |
14 changes: 0 additions & 14 deletions database/add_new_user.go

This file was deleted.

14 changes: 0 additions & 14 deletions database/add_player_session.go

This file was deleted.

49 changes: 0 additions & 49 deletions database/add_player_to_room.go

This file was deleted.

26 changes: 0 additions & 26 deletions database/community_exists.go

This file was deleted.

5 changes: 0 additions & 5 deletions database/connect_all.go

This file was deleted.

53 changes: 0 additions & 53 deletions database/connect_mongo.go

This file was deleted.

25 changes: 25 additions & 0 deletions database/connect_postgres.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package database

import (
"database/sql"
"os"

_ "github.com/lib/pq"

"github.com/PretendoNetwork/mario-kart-7/globals"
)

var Postgres *sql.DB

func ConnectPostgres() {
var err error

Postgres, err = sql.Open("postgres", os.Getenv("PN_MK7_POSTGRES_URI"))
if err != nil {
globals.Logger.Critical(err.Error())
}

globals.Logger.Success("Connected to Postgres!")

initPostgres()
}
14 changes: 0 additions & 14 deletions database/delete_player_session.go

This file was deleted.

15 changes: 0 additions & 15 deletions database/destroy_room.go

This file was deleted.

24 changes: 0 additions & 24 deletions database/does_session_exist.go

This file was deleted.

Loading

0 comments on commit 9e5aedf

Please sign in to comment.