-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from shoginyan/master
merged auth and secure, updated nex libraries.
- Loading branch information
Showing
42 changed files
with
894 additions
and
893 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,7 @@ go.work.sum | |
build | ||
log | ||
*.pem | ||
*.key | ||
*.key | ||
|
||
# macOS nonsense | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 := $(notdir $(CURDIR)) | ||
endif | ||
|
||
# * Final build string | ||
DATE_TIME := $(shell date --iso=seconds) | ||
BUILD_STRING := $(SERVER_BUILD), $(DATE_TIME) | ||
|
||
all: | ||
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/$(notdir $(CURDIR)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Wii U Chat replacement server | ||
Includes both the authentication and secure servers | ||
|
||
## 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/wiiu-chat | ||
$ cd wiiu-chat | ||
``` | ||
|
||
### 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/wiiu-chat | ||
``` | ||
|
||
The server is now built to `build/wiiu-chat` | ||
|
||
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/wiiu-chat` | ||
## Configuration | ||
All configuration options are handled via environment variables | ||
|
||
`.env` files are supported | ||
|
||
| Name | Description | Required | | ||
| ---- | ----------- | -------- | | ||
| `PN_WUC_POSTGRES_URI` | Fully qualified URI to your Postgres server (Example `postgres://username:password@localhost/wiiuchat?sslmode=disable`) | Yes | | ||
| `PN_WUC_AUTHENTICATION_SERVER_PORT` | Port for the authentication server | Yes | | ||
| `PN_WUC_SECURE_SERVER_HOST` | Host name for the secure server (should point to the same address as the authentication server) | Yes | | ||
| `PN_WUC_SECURE_SERVER_PORT` | Port for the secure server | Yes | | ||
| `PN_WUC_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes | | ||
| `PN_WUC_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes | | ||
| `PN_WUC_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) | | ||
| `PN_WUC_FRIENDS_GRPC_HOST` | Host name for your friends server gRPC service | Yes | | ||
| `PN_WUC_FRIENDS_GRPC_PORT` | Port for your friends server gRPC service | Yes | | ||
| `PN_WUC_FRIENDS_GRPC_API_KEY` | API key for your friends server gRPC service | No (Assumed to be an open gRPC API) | |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/wiiu-chat/globals" | ||
) | ||
|
||
var Postgres *sql.DB | ||
|
||
func ConnectPostgres() { | ||
var err error | ||
|
||
Postgres, err = sql.Open("postgres", os.Getenv("PN_WUC_POSTGRES_URI")) | ||
if err != nil { | ||
globals.Logger.Critical(err.Error()) | ||
} | ||
|
||
globals.Logger.Success("Connected to Postgres!") | ||
|
||
InitPostgres() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"github.com/PretendoNetwork/nex-go/v2/types" | ||
"github.com/PretendoNetwork/wiiu-chat/globals" | ||
) | ||
|
||
func EndCall(caller uint32) { | ||
filter := bson.D{ | ||
{"caller_pid", caller}, | ||
} | ||
|
||
_, err := callsCollection.DeleteOne(context.TODO(), filter) | ||
func EndCall(caller types.PID) { | ||
_, err := Postgres.Exec(`DELETE FROM ongoingcalls WHERE caller_pid = $1;`, caller) | ||
if err != nil { | ||
panic(err) | ||
globals.Logger.Critical(err.Error()) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"github.com/PretendoNetwork/nex-go/v2/types" | ||
"github.com/PretendoNetwork/wiiu-chat/globals" | ||
) | ||
|
||
func EndCallRinging(caller uint32) { | ||
filter := bson.D{ | ||
{"caller_pid", caller}, | ||
} | ||
|
||
update := bson.D{ | ||
{ | ||
"$set", bson.D{ | ||
{"ringing", false}, | ||
}, | ||
}, | ||
} | ||
|
||
_, err := callsCollection.UpdateOne(context.TODO(), filter, update) | ||
func EndCallRinging(caller types.PID) { | ||
_, err := Postgres.Exec(`UPDATE ongoingcalls SET (ringing = $1) WHERE caller_pid = $2;`, false, caller) | ||
if err != nil { | ||
panic(err) | ||
globals.Logger.Critical(err.Error()) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,16 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
"github.com/PretendoNetwork/nex-go/v2/types" | ||
"github.com/PretendoNetwork/wiiu-chat/globals" | ||
) | ||
|
||
func GetCallInfoByCaller(caller uint32) (uint32, uint32, bool) { // caller pid, target pid, ringing | ||
var result bson.M | ||
filter := bson.D{ | ||
{"caller_pid", caller}, | ||
} | ||
|
||
err := callsCollection.FindOne(context.TODO(), filter, options.FindOne()).Decode(&result) | ||
func GetCallInfoByCaller(caller types.PID) (caller_pid types.PID, target_pid types.PID, ringing types.Bool) { | ||
row := Postgres.QueryRow(`SELECT (caller_pid, target_pid, ringing) FROM ongoingcalls WHERE caller_pid = $1;`, caller) | ||
err := row.Scan(&caller_pid, &target_pid, &ringing) | ||
if err != nil { | ||
if err == mongo.ErrNoDocuments { | ||
return 0, 0, false | ||
} else { | ||
panic(err) | ||
} | ||
} else { | ||
return uint32(result["caller_pid"].(int64)), uint32(result["target_pid"].(int64)), result["ringing"].(bool) | ||
globals.Logger.Critical(err.Error()) | ||
return 0, 0, false | ||
} | ||
return caller_pid, target_pid, ringing | ||
} |
Oops, something went wrong.