mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-07-04 23:42:19 +02:00
Compare commits
No commits in common. "2704e64e38bdf52ebc54bc19f2b3a0c0f00579fa" and "fadd10602afbcc451f830cde7099e7fc23c56b17" have entirely different histories.
2704e64e38
...
fadd10602a
@ -1,10 +0,0 @@
|
|||||||
/.github/
|
|
||||||
|
|
||||||
Dockerfile*
|
|
||||||
docker-compose*.yml
|
|
||||||
|
|
||||||
/.data/
|
|
||||||
/secret.key
|
|
||||||
|
|
||||||
/rogueserver*
|
|
||||||
!/rogueserver.go
|
|
46
.github/workflows/ci.yml
vendored
46
.github/workflows/ci.yml
vendored
@ -1,46 +0,0 @@
|
|||||||
name: Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build (${{ matrix.os_name }})
|
|
||||||
env:
|
|
||||||
GO_VERSION: 1.22
|
|
||||||
GOOS: ${{ matrix.os_name }}
|
|
||||||
GOARCH: ${{ matrix.arch }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- os: ubuntu-latest
|
|
||||||
os_name: linux
|
|
||||||
arch: amd64
|
|
||||||
- os: windows-latest
|
|
||||||
os_name: windows
|
|
||||||
arch: amd64
|
|
||||||
# TODO macos needs universal binary!
|
|
||||||
# - os: macos-latest
|
|
||||||
# os_name: macos
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Set up Go ${{ env.GO_VERSION }}
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: ${{ env.GO_VERSION }}
|
|
||||||
- name: Install dependencies
|
|
||||||
run: go mod download
|
|
||||||
- name: Test
|
|
||||||
run: go test -v
|
|
||||||
- name: Build
|
|
||||||
run: go build -v
|
|
||||||
- name: Upload artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: rogueserver-${{ matrix.os_name }}-${{ matrix.arch }}-${{ github.sha }}
|
|
||||||
path: |
|
|
||||||
rogueserver*
|
|
||||||
!rogueserver.go
|
|
38
.github/workflows/ghcr.yml
vendored
38
.github/workflows/ghcr.yml
vendored
@ -1,38 +0,0 @@
|
|||||||
name: Publish to GHCR
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build and publish to GHCR
|
|
||||||
if: github.repository == 'pagefaultgames/rogueserver'
|
|
||||||
env:
|
|
||||||
GO_VERSION: 1.22
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Setup Docker BuildX
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Log into container registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.repository_owner }}
|
|
||||||
password: ${{ github.token }}
|
|
||||||
- name: Extract Docker metadata
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: ghcr.io/${{ github.repository }}
|
|
||||||
- name: Build Docker image
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
build-args: |
|
|
||||||
GO_VERSION=${{ env.GO_VERSION }}
|
|
||||||
VERSION=${{ github.ref_name }}-SNAPSHOT
|
|
||||||
COMMIT_SHA=${{ env.GITHUB_SHA_SHORT }}
|
|
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,16 +1,11 @@
|
|||||||
|
|
||||||
# no extension on linux, .exe on windows
|
# no extension on linux, .exe on windows
|
||||||
rogueserver*
|
rogueserver*
|
||||||
!/rogueserver/*
|
userdata/*
|
||||||
/userdata/*
|
|
||||||
secret.key
|
secret.key
|
||||||
|
|
||||||
# local testing
|
|
||||||
/.data/
|
|
||||||
|
|
||||||
# Jetbrains IDEs
|
# Jetbrains IDEs
|
||||||
/.idea/
|
/.idea/
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
.vscode/launch.json
|
|
||||||
|
29
Dockerfile
29
Dockerfile
@ -1,29 +0,0 @@
|
|||||||
ARG GO_VERSION=1.22
|
|
||||||
|
|
||||||
FROM golang:${GO_VERSION} AS builder
|
|
||||||
|
|
||||||
WORKDIR /src
|
|
||||||
|
|
||||||
COPY ./go.mod /src/
|
|
||||||
COPY ./go.sum /src/
|
|
||||||
|
|
||||||
RUN go mod download && go mod verify
|
|
||||||
|
|
||||||
COPY . /src/
|
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 \
|
|
||||||
go build -o rogueserver
|
|
||||||
|
|
||||||
RUN chmod +x /src/rogueserver
|
|
||||||
|
|
||||||
# ---------------------------------------------
|
|
||||||
|
|
||||||
FROM scratch
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY --from=builder /src/rogueserver .
|
|
||||||
|
|
||||||
EXPOSE 8001
|
|
||||||
|
|
||||||
ENTRYPOINT ["./rogueserver"]
|
|
@ -48,7 +48,6 @@ func Init(mux *http.ServeMux) {
|
|||||||
mux.HandleFunc("POST /savedata/update", handleSaveData)
|
mux.HandleFunc("POST /savedata/update", handleSaveData)
|
||||||
mux.HandleFunc("GET /savedata/delete", handleSaveData)
|
mux.HandleFunc("GET /savedata/delete", handleSaveData)
|
||||||
mux.HandleFunc("POST /savedata/clear", handleSaveData)
|
mux.HandleFunc("POST /savedata/clear", handleSaveData)
|
||||||
mux.HandleFunc("GET /savedata/newclear", handleNewClear)
|
|
||||||
|
|
||||||
// daily
|
// daily
|
||||||
mux.HandleFunc("GET /daily/seed", handleDailySeed)
|
mux.HandleFunc("GET /daily/seed", handleDailySeed)
|
||||||
@ -90,4 +89,4 @@ func uuidFromRequest(r *http.Request) ([]byte, error) {
|
|||||||
func httpError(w http.ResponseWriter, r *http.Request, err error, code int) {
|
func httpError(w http.ResponseWriter, r *http.Request, err error, code int) {
|
||||||
log.Printf("%s: %s\n", r.URL.Path, err)
|
log.Printf("%s: %s\n", r.URL.Path, err)
|
||||||
http.Error(w, err.Error(), code)
|
http.Error(w, err.Error(), code)
|
||||||
}
|
}
|
@ -61,26 +61,21 @@ func Init() error {
|
|||||||
secret = newSecret
|
secret = newSecret
|
||||||
}
|
}
|
||||||
|
|
||||||
seed, err := recordNewDaily()
|
err = recordNewDaily()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Daily Run Seed: %s", seed)
|
log.Printf("Daily Run Seed: %s", Seed())
|
||||||
|
|
||||||
_, err = scheduler.AddFunc("@daily", func() {
|
scheduler.AddFunc("@daily", func() {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
seed, err = recordNewDaily()
|
err := recordNewDaily()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error while recording new daily: %s", err)
|
log.Printf("error while recording new daily: %s", err)
|
||||||
} else {
|
|
||||||
log.Printf("Daily Run Seed: %s", seed)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduler.Start()
|
scheduler.Start()
|
||||||
|
|
||||||
@ -100,6 +95,11 @@ func deriveSeed(seedTime time.Time) []byte {
|
|||||||
return hashedSeed[:]
|
return hashedSeed[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordNewDaily() (string, error) {
|
func recordNewDaily() error {
|
||||||
return db.TryAddDailyRun(Seed())
|
err := db.TryAddDailyRun(Seed())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -296,15 +296,14 @@ func handleSaveData(w http.ResponseWriter, r *http.Request) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
var seed string
|
s, ok := save.(defs.SessionSaveData)
|
||||||
seed, err = db.GetDailyRunSeed()
|
if !ok {
|
||||||
if err != nil {
|
err = fmt.Errorf("save data is not type SessionSaveData")
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
break
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// doesn't return a save, but it works
|
// doesn't return a save, but it works
|
||||||
save, err = savedata.Clear(uuid, slot, seed, save.(defs.SessionSaveData))
|
save, err = savedata.Clear(uuid, slot, daily.Seed(), s)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
@ -325,47 +324,10 @@ func handleSaveData(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleNewClear(w http.ResponseWriter, r *http.Request) {
|
|
||||||
uuid, err := uuidFromRequest(r)
|
|
||||||
if err != nil {
|
|
||||||
httpError(w, r, err, http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var slot int
|
|
||||||
if r.URL.Query().Has("slot") {
|
|
||||||
slot, err = strconv.Atoi(r.URL.Query().Get("slot"))
|
|
||||||
if err != nil {
|
|
||||||
httpError(w, r, err, http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newClear, err := savedata.NewClear(uuid, slot)
|
|
||||||
if err != nil {
|
|
||||||
httpError(w, r, fmt.Errorf("failed to read new clear: %s", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.NewEncoder(w).Encode(newClear)
|
|
||||||
if err != nil {
|
|
||||||
httpError(w, r, fmt.Errorf("failed to encode response json: %s", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
}
|
|
||||||
|
|
||||||
// daily
|
// daily
|
||||||
|
|
||||||
func handleDailySeed(w http.ResponseWriter, r *http.Request) {
|
func handleDailySeed(w http.ResponseWriter, r *http.Request) {
|
||||||
seed, err := db.GetDailyRunSeed()
|
w.Write([]byte(daily.Seed()))
|
||||||
if err != nil {
|
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write([]byte(seed))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleDailyRankings(w http.ResponseWriter, r *http.Request) {
|
func handleDailyRankings(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -19,10 +19,9 @@ package savedata
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/pagefaultgames/rogueserver/db"
|
"github.com/pagefaultgames/rogueserver/db"
|
||||||
"github.com/pagefaultgames/rogueserver/defs"
|
"github.com/pagefaultgames/rogueserver/defs"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClearResponse struct {
|
type ClearResponse struct {
|
||||||
@ -57,7 +56,7 @@ func Clear(uuid []byte, slot int, seed string, save defs.SessionSaveData) (Clear
|
|||||||
}
|
}
|
||||||
|
|
||||||
if sessionCompleted {
|
if sessionCompleted {
|
||||||
response.Success, err = db.TryAddSeedCompletion(uuid, save.Seed, int(save.GameMode))
|
response.Success, err = db.TryAddDailyRunCompletion(uuid, save.Seed, int(save.GameMode))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to mark seed as completed: %s", err)
|
log.Printf("failed to mark seed as completed: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2024 Pagefault Games
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package savedata
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/pagefaultgames/rogueserver/db"
|
|
||||||
"github.com/pagefaultgames/rogueserver/defs"
|
|
||||||
)
|
|
||||||
|
|
||||||
// /savedata/newclear - return whether a session is a new clear for its seed
|
|
||||||
func NewClear(uuid []byte, slot int) (bool, error) {
|
|
||||||
if slot < 0 || slot >= defs.SessionSlotCount {
|
|
||||||
return false, fmt.Errorf("slot id %d out of range", slot)
|
|
||||||
}
|
|
||||||
|
|
||||||
session, err := db.ReadSessionSaveData(uuid, slot)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
completed, err := db.ReadSeedCompleted(uuid, session.Seed)
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("failed to read seed completed: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return !completed, nil
|
|
||||||
}
|
|
20
db/daily.go
20
db/daily.go
@ -23,25 +23,13 @@ import (
|
|||||||
"github.com/pagefaultgames/rogueserver/defs"
|
"github.com/pagefaultgames/rogueserver/defs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TryAddDailyRun(seed string) (string, error) {
|
func TryAddDailyRun(seed string) error {
|
||||||
var actualSeed string
|
_, err := handle.Exec("INSERT INTO dailyRuns (seed, date) VALUES (?, UTC_DATE()) ON DUPLICATE KEY UPDATE date = date", seed)
|
||||||
err := handle.QueryRow("INSERT INTO dailyRuns (seed, date) VALUES (?, UTC_DATE()) ON DUPLICATE KEY UPDATE date = date RETURNING seed", seed).Scan(&actualSeed)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return actualSeed, nil
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
func GetDailyRunSeed() (string, error) {
|
|
||||||
var seed string
|
|
||||||
err := handle.QueryRow("SELECT seed FROM dailyRuns WHERE date = UTC_DATE()").Scan(&seed)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return seed, nil
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddOrUpdateAccountDailyRun(uuid []byte, score int, wave int) error {
|
func AddOrUpdateAccountDailyRun(uuid []byte, score int, wave int) error {
|
||||||
|
41
db/db.go
41
db/db.go
@ -37,14 +37,14 @@ func Init(username, password, protocol, address, database string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open database connection: %s", err)
|
return fmt.Errorf("failed to open database connection: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conns := 1024
|
conns := 1024
|
||||||
if protocol != "unix" {
|
if protocol != "unix" {
|
||||||
conns = 256
|
conns = 256
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.SetMaxOpenConns(conns)
|
handle.SetMaxOpenConns(conns)
|
||||||
handle.SetMaxIdleConns(conns / 4)
|
handle.SetMaxIdleConns(conns/4)
|
||||||
|
|
||||||
handle.SetConnMaxIdleTime(time.Second * 10)
|
handle.SetConnMaxIdleTime(time.Second * 10)
|
||||||
|
|
||||||
@ -52,51 +52,14 @@ func Init(username, password, protocol, address, database string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// accounts
|
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS accounts (uuid BINARY(16) NOT NULL PRIMARY KEY, username VARCHAR(16) UNIQUE NOT NULL, hash BINARY(32) NOT NULL, salt BINARY(16) NOT NULL, registered TIMESTAMP NOT NULL, lastLoggedIn TIMESTAMP DEFAULT NULL, lastActivity TIMESTAMP DEFAULT NULL, banned TINYINT(1) NOT NULL DEFAULT 0, trainerId SMALLINT(5) UNSIGNED DEFAULT 0, secretId SMALLINT(5) UNSIGNED DEFAULT 0)")
|
|
||||||
|
|
||||||
// sessions
|
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS sessions (token BINARY(32) NOT NULL PRIMARY KEY, uuid BINARY(16) NOT NULL, active TINYINT(1) NOT NULL DEFAULT 0, expire TIMESTAMP DEFAULT NULL, CONSTRAINT sessions_ibfk_1 FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)")
|
|
||||||
tx.Exec("CREATE INDEX IF NOT EXISTS sessionsByUuid ON sessions (uuid)")
|
|
||||||
|
|
||||||
// stats
|
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS accountStats (uuid BINARY(16) NOT NULL PRIMARY KEY, playTime INT(11) NOT NULL DEFAULT 0, battles INT(11) NOT NULL DEFAULT 0, classicSessionsPlayed INT(11) NOT NULL DEFAULT 0, sessionsWon INT(11) NOT NULL DEFAULT 0, highestEndlessWave INT(11) NOT NULL DEFAULT 0, highestLevel INT(11) NOT NULL DEFAULT 0, pokemonSeen INT(11) NOT NULL DEFAULT 0, pokemonDefeated INT(11) NOT NULL DEFAULT 0, pokemonCaught INT(11) NOT NULL DEFAULT 0, pokemonHatched INT(11) NOT NULL DEFAULT 0, eggsPulled INT(11) NOT NULL DEFAULT 0, regularVouchers INT(11) NOT NULL DEFAULT 0, plusVouchers INT(11) NOT NULL DEFAULT 0, premiumVouchers INT(11) NOT NULL DEFAULT 0, goldenVouchers INT(11) NOT NULL DEFAULT 0, CONSTRAINT accountStats_ibfk_1 FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)")
|
|
||||||
|
|
||||||
// compensations
|
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS accountCompensations (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, uuid BINARY(16) NOT NULL, voucherType INT(11) NOT NULL, count INT(11) NOT NULL DEFAULT 1, claimed BIT(1) NOT NULL DEFAULT b'0', CONSTRAINT accountCompensations_ibfk_1 FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)")
|
|
||||||
tx.Exec("CREATE INDEX IF NOT EXISTS accountCompensationsByUuid ON accountCompensations (uuid)")
|
|
||||||
|
|
||||||
// daily runs
|
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS dailyRuns (date DATE NOT NULL PRIMARY KEY, seed CHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL)")
|
|
||||||
tx.Exec("CREATE INDEX IF NOT EXISTS dailyRunsByDateAndSeed ON dailyRuns (date, seed)")
|
|
||||||
|
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS dailyRunCompletions (uuid BINARY(16) NOT NULL, seed CHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, mode INT(11) NOT NULL DEFAULT 0, score INT(11) NOT NULL DEFAULT 0, timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (uuid, seed), CONSTRAINT dailyRunCompletions_ibfk_1 FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)")
|
|
||||||
tx.Exec("CREATE INDEX IF NOT EXISTS dailyRunCompletionsByUuidAndSeed ON dailyRunCompletions (uuid, seed)")
|
|
||||||
|
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS accountDailyRuns (uuid BINARY(16) NOT NULL, date DATE NOT NULL, score INT(11) NOT NULL DEFAULT 0, wave INT(11) NOT NULL DEFAULT 0, timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (uuid, date), CONSTRAINT accountDailyRuns_ibfk_1 FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT accountDailyRuns_ibfk_2 FOREIGN KEY (date) REFERENCES dailyRuns (date) ON DELETE NO ACTION ON UPDATE NO ACTION)")
|
|
||||||
tx.Exec("CREATE INDEX IF NOT EXISTS accountDailyRunsByDate ON accountDailyRuns (date)")
|
|
||||||
|
|
||||||
// save data
|
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS systemSaveData (uuid BINARY(16) PRIMARY KEY, data LONGBLOB, timestamp TIMESTAMP)")
|
tx.Exec("CREATE TABLE IF NOT EXISTS systemSaveData (uuid BINARY(16) PRIMARY KEY, data LONGBLOB, timestamp TIMESTAMP)")
|
||||||
tx.Exec("CREATE TABLE IF NOT EXISTS sessionSaveData (uuid BINARY(16), slot TINYINT, data LONGBLOB, timestamp TIMESTAMP, PRIMARY KEY (uuid, slot))")
|
tx.Exec("CREATE TABLE IF NOT EXISTS sessionSaveData (uuid BINARY(16), slot TINYINT, data LONGBLOB, timestamp TIMESTAMP, PRIMARY KEY (uuid, slot))")
|
||||||
|
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO temp code
|
// TODO temp code
|
||||||
_, err = os.Stat("userdata")
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) { // not found, do not migrate
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
log.Fatalf("failed to stat userdata directory: %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
entries, err := os.ReadDir("userdata")
|
entries, err := os.ReadDir("userdata")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/pagefaultgames/rogueserver/defs"
|
"github.com/pagefaultgames/rogueserver/defs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TryAddSeedCompletion(uuid []byte, seed string, mode int) (bool, error) {
|
func TryAddDailyRunCompletion(uuid []byte, seed string, mode int) (bool, error) {
|
||||||
var count int
|
var count int
|
||||||
err := handle.QueryRow("SELECT COUNT(*) FROM dailyRunCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count)
|
err := handle.QueryRow("SELECT COUNT(*) FROM dailyRunCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -41,16 +41,6 @@ func TryAddSeedCompletion(uuid []byte, seed string, mode int) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadSeedCompleted(uuid []byte, seed string) (bool, error) {
|
|
||||||
var count int
|
|
||||||
err := handle.QueryRow("SELECT COUNT(*) FROM dailyRunCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return count > 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadSystemSaveData(uuid []byte) (defs.SystemSaveData, error) {
|
func ReadSystemSaveData(uuid []byte) (defs.SystemSaveData, error) {
|
||||||
var system defs.SystemSaveData
|
var system defs.SystemSaveData
|
||||||
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
services:
|
|
||||||
db:
|
|
||||||
image: mariadb:11
|
|
||||||
container_name: pokerogue-db-local
|
|
||||||
restart: on-failure
|
|
||||||
environment:
|
|
||||||
MYSQL_ROOT_PASSWORD: admin
|
|
||||||
MYSQL_DATABASE: pokeroguedb
|
|
||||||
MYSQL_USER: pokerogue
|
|
||||||
MYSQL_PASSWORD: pokerogue
|
|
||||||
ports:
|
|
||||||
- "3306:3306"
|
|
||||||
volumes:
|
|
||||||
- ./.data/db:/var/lib/mysql
|
|
@ -1,27 +0,0 @@
|
|||||||
services:
|
|
||||||
server:
|
|
||||||
image: ghcr.io/pagefaultgames/pokerogue:latest
|
|
||||||
command: --debug --dbaddr db:3306 --dbuser pokerogue --dbpass pokerogue --dbname pokeroguedb
|
|
||||||
restart: unless-stopped
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
networks:
|
|
||||||
- internal
|
|
||||||
ports:
|
|
||||||
- "8001:8001"
|
|
||||||
db:
|
|
||||||
image: mariadb:11
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
MYSQL_ROOT_PASSWORD: admin
|
|
||||||
MYSQL_DATABASE: pokeroguedb
|
|
||||||
MYSQL_USER: pokerogue
|
|
||||||
MYSQL_PASSWORD: pokerogue
|
|
||||||
volumes:
|
|
||||||
- database:/var/lib/mysql
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
database:
|
|
||||||
|
|
||||||
networks:
|
|
||||||
internal:
|
|
@ -34,12 +34,10 @@ func main() {
|
|||||||
debug := flag.Bool("debug", false, "use debug mode")
|
debug := flag.Bool("debug", false, "use debug mode")
|
||||||
|
|
||||||
proto := flag.String("proto", "tcp", "protocol for api to use (tcp, unix)")
|
proto := flag.String("proto", "tcp", "protocol for api to use (tcp, unix)")
|
||||||
addr := flag.String("addr", "0.0.0.0:8001", "network address for api to listen on")
|
addr := flag.String("addr", "0.0.0.0", "network address for api to listen on")
|
||||||
tlscert := flag.String("tlscert", "", "tls certificate path")
|
|
||||||
tlskey := flag.String("tlskey", "", "tls key path")
|
|
||||||
|
|
||||||
dbuser := flag.String("dbuser", "pokerogue", "database username")
|
dbuser := flag.String("dbuser", "pokerogue", "database username")
|
||||||
dbpass := flag.String("dbpass", "pokerogue", "database password")
|
dbpass := flag.String("dbpass", "", "database password")
|
||||||
dbproto := flag.String("dbproto", "tcp", "protocol for database connection")
|
dbproto := flag.String("dbproto", "tcp", "protocol for database connection")
|
||||||
dbaddr := flag.String("dbaddr", "localhost", "database address")
|
dbaddr := flag.String("dbaddr", "localhost", "database address")
|
||||||
dbname := flag.String("dbname", "pokeroguedb", "database name")
|
dbname := flag.String("dbname", "pokeroguedb", "database name")
|
||||||
@ -68,15 +66,10 @@ func main() {
|
|||||||
api.Init(mux)
|
api.Init(mux)
|
||||||
|
|
||||||
// start web server
|
// start web server
|
||||||
handler := prodHandler(mux)
|
|
||||||
if *debug {
|
if *debug {
|
||||||
handler = debugHandler(mux)
|
err = http.Serve(listener, debugHandler(mux))
|
||||||
}
|
|
||||||
|
|
||||||
if *tlscert == "" {
|
|
||||||
err = http.Serve(listener, handler)
|
|
||||||
} else {
|
} else {
|
||||||
err = http.ServeTLS(listener, handler, *tlscert, *tlskey)
|
err = http.Serve(listener, mux)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to create http server or server errored: %s", err)
|
log.Fatalf("failed to create http server or server errored: %s", err)
|
||||||
@ -100,21 +93,6 @@ func createListener(proto, addr string) (net.Listener, error) {
|
|||||||
return listener, nil
|
return listener, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func prodHandler(router *http.ServeMux) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
|
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST")
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "https://pokerogue.net")
|
|
||||||
|
|
||||||
if r.Method == "OPTIONS" {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
router.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func debugHandler(router *http.ServeMux) http.Handler {
|
func debugHandler(router *http.ServeMux) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "*")
|
w.Header().Set("Access-Control-Allow-Headers", "*")
|
||||||
|
Loading…
Reference in New Issue
Block a user