feat: Use redis as a cache to reduce database reads

pull/53/head
Helzoph 2 months ago
parent 8e20875453
commit 832b4b3908

125
cache/account.go vendored

@ -0,0 +1,125 @@
/*
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 cache
import (
"time"
)
func AddAccountSession(uuid []byte, token []byte) bool {
rdb.Do("SELECT", sessionDB)
err := rdb.Set(string(token), string(uuid), 7*24*time.Hour).Err()
return err == nil
}
func FetchUsernameBySessionToken(token []byte) (string, bool) {
rdb.Do("SELECT", sessionDB)
username, err := rdb.Get(string(token)).Result()
if err != nil {
return "", false
}
return username, true
}
func updateActivePlayers(uuid []byte) bool {
rdb.Do("SELECT", activePlayersDB)
err := rdb.Set(string(uuid), 1, 0).Err()
if err != nil {
return false
}
err = rdb.Expire(string(uuid), 5*time.Minute).Err()
return err == nil
}
func UpdateAccountLastActivity(uuid []byte) bool {
rdb.Do("SELECT", accountsDB)
err := rdb.HSet(string(uuid), "lastActivity", time.Now().Format("2006-01-02 15:04:05")).Err()
if err != nil {
return false
}
updateActivePlayers(uuid)
return err == nil
}
// FIXME: This is not atomic
func UpdateAccountStats(uuid []byte, battles, classicSessionsPlayed int) bool {
rdb.Do("SELECT", accountsDB)
err := rdb.HIncrBy(string(uuid), "battles", int64(battles)).Err()
if err != nil {
return false
}
err = rdb.HIncrBy(string(uuid), "classicSessionsPlayed", int64(classicSessionsPlayed)).Err()
return err == nil
}
func FetchTrainerIds(uuid []byte) (int, int, bool) {
rdb.Do("SELECT", accountsDB)
vals, err := rdb.HMGet(string(uuid), "trainerId", "secretId").Result()
if err == nil && len(vals) == 2 && vals[0] != nil && vals[1] != nil {
trainerId, ok1 := vals[0].(int)
secretId, ok2 := vals[1].(int)
if ok1 && ok2 {
return trainerId, secretId, true
}
}
return 0, 0, false
}
func UpdateTrainerIds(trainerId, secretId int, uuid []byte) bool {
rdb.Do("SELECT", accountsDB)
err := rdb.HMSet(string(uuid), map[string]interface{}{
"trainerId": trainerId,
"secretId": secretId,
}).Err()
return err == nil
}
func IsActiveSession(uuid []byte, sessionId string) (bool, bool) {
rdb.Do("SELECT", activeClientSessionsDB)
id, err := rdb.Get(string(uuid)).Result()
if err != nil {
return false, false
}
return id == sessionId, true
}
func UpdateActiveSession(uuid []byte, sessionId string) bool {
rdb.Do("SELECT", activeClientSessionsDB)
err := rdb.Set(string(uuid), sessionId, 0).Err()
return err == nil
}
func FetchUUIDFromToken(token []byte) ([]byte, bool) {
rdb.Do("SELECT", sessionDB)
uuid, err := rdb.Get(string(token)).Bytes()
if err != nil {
return nil, false
}
return uuid, true
}
func RemoveSessionFromToken(token []byte) bool {
rdb.Do("SELECT", sessionDB)
err := rdb.Del(string(token)).Err()
return err == nil
}

56
cache/cache.go vendored

@ -0,0 +1,56 @@
/*
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 cache
import (
"fmt"
"strconv"
"github.com/go-redis/redis"
)
const (
dailyRunCompletionsDB = 1
dailyRunsDB = 2
accountDailyRunsDB = 3
accountsDB = 4
sessionDB = 5
activeClientSessionsDB = 6
activePlayersDB = 7
)
var rdb *redis.Client
func InitRedis(address, password, database string) error {
db, err := strconv.Atoi(database)
if err != nil {
return fmt.Errorf("failed to convert database to int: %w", err)
}
rdb = redis.NewClient(&redis.Options{
Addr: address,
Password: password,
DB: db,
})
_, err = rdb.Ping().Result()
if err != nil {
return fmt.Errorf("failed to connect to redis: %w", err)
}
return nil
}

38
cache/daily.go vendored

@ -0,0 +1,38 @@
/*
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 cache
import (
"time"
)
func TryAddDailyRun(seed string) bool {
rdb.Do("SELECT", dailyRunsDB)
err := rdb.Set(time.Now().Format("2006-01-02"), seed, 24*time.Hour).Err()
return err == nil
}
func GetDailyRunSeed() (string, bool) {
rdb.Do("SELECT", dailyRunsDB)
cachedSeed, err := rdb.Get(time.Now().Format("2006-01-02")).Result()
if err != nil {
return "", false
}
return cachedSeed, true
}

62
cache/game.go vendored

@ -0,0 +1,62 @@
/*
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 cache
func FetchPlayerCount() (int, bool) {
rdb.Do("SELECT", activePlayersDB)
cachedPlayerCount, err := rdb.DBSize().Result()
if err != nil {
return 0, false
}
return int(cachedPlayerCount), true
}
// FIXME: This is not working
func FetchBattleCount() (int, bool) {
rdb.Do("SELECT", accountsDB)
cachedBattleCount, err := rdb.Get("battleCount").Int()
if err != nil {
return 0, false
}
return cachedBattleCount, true
}
func UpdateBattleCount(battleCount int) bool {
rdb.Do("SELECT", accountsDB)
err := rdb.Set("battleCount", battleCount, 0).Err()
return err == nil
}
// FIXME: This is not working
func FetchClassicSessionCount() (int, bool) {
rdb.Do("SELECT", accountsDB)
cachedClassicSessionCount, err := rdb.Get("classicSessionCount").Int()
if err != nil {
return 0, false
}
return cachedClassicSessionCount, true
}
func UpdateClassicSessionCount(classicSessionCount int) bool {
rdb.Do("SELECT", accountsDB)
err := rdb.Set("classicSessionCount", classicSessionCount, 0).Err()
return err == nil
}

38
cache/savedata.go vendored

@ -0,0 +1,38 @@
/*
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 cache
import (
"time"
)
func TryAddSeedCompletion(uuid []byte, seed string, mode int) bool {
rdb.Do("SELECT", dailyRunCompletionsDB)
err := rdb.HMSet(string(uuid), map[string]interface{}{
"mode": mode,
"seed": seed,
"timestamp": time.Now().Unix(),
}).Err()
return err == nil
}
func ReadSeedCompletion(uuid []byte, seed string) (bool, bool) {
rdb.Do("SELECT", dailyRunCompletionsDB)
completed, err := rdb.HExists(string(uuid), seed).Result()
return completed, err == nil
}

@ -24,6 +24,7 @@ import (
"slices"
_ "github.com/go-sql-driver/mysql"
"github.com/pagefaultgames/rogueserver/cache"
"github.com/pagefaultgames/rogueserver/defs"
)
@ -37,7 +38,18 @@ func AddAccountRecord(uuid []byte, username string, key, salt []byte) error {
}
func AddAccountSession(username string, token []byte) error {
_, err := handle.Exec("INSERT INTO sessions (uuid, token, expire) SELECT a.uuid, ?, DATE_ADD(UTC_TIMESTAMP(), INTERVAL 1 WEEK) FROM accounts a WHERE a.username = ?", token, username)
// _, err := handle.Exec("INSERT INTO sessions (uuid, token, expire) SELECT a.uuid, ?, DATE_ADD(UTC_TIMESTAMP(), INTERVAL 1 WEEK) FROM accounts a WHERE a.username = ?", token, username)
// if err != nil {
// return err
// }
var uuid []byte
err := handle.QueryRow("SELECT uuid FROM accounts WHERE username = ?", username).Scan(&uuid)
if err != nil {
return err
}
_, err = handle.Exec("INSERT INTO sessions (uuid, token, expire) VALUES (?, ?, DATE_ADD(UTC_TIMESTAMP(), INTERVAL 1 WEEK))", uuid, token)
if err != nil {
return err
}
@ -47,6 +59,8 @@ func AddAccountSession(username string, token []byte) error {
return err
}
cache.AddAccountSession(uuid, token)
return nil
}
@ -145,6 +159,10 @@ func FetchGoogleIdByUUID(uuid []byte) (string, error) {
}
func FetchUsernameBySessionToken(token []byte) (string, error) {
if username, ok := cache.FetchUsernameBySessionToken(token); ok {
return username, nil
}
var username string
err := handle.QueryRow("SELECT a.username FROM accounts a JOIN sessions s ON a.uuid = s.uuid WHERE s.token = ?", token).Scan(&username)
if err != nil {
@ -169,6 +187,8 @@ func UpdateAccountLastActivity(uuid []byte) error {
return err
}
cache.UpdateAccountLastActivity(uuid)
return nil
}
@ -246,6 +266,9 @@ func UpdateAccountStats(uuid []byte, stats defs.GameStats, voucherCounts map[str
return err
}
// TODO: Update cache battle count and classic session count
cache.UpdateAccountStats(uuid, int(statValues[1].(float64)), int(statValues[2].(float64)))
return nil
}
@ -269,11 +292,17 @@ func FetchAccountKeySaltFromUsername(username string) ([]byte, []byte, error) {
}
func FetchTrainerIds(uuid []byte) (trainerId, secretId int, err error) {
if trainerId, secretId, ok := cache.FetchTrainerIds(uuid); ok {
return trainerId, secretId, nil
}
err = handle.QueryRow("SELECT trainerId, secretId FROM accounts WHERE uuid = ?", uuid).Scan(&trainerId, &secretId)
if err != nil {
return 0, 0, err
}
cache.UpdateTrainerIds(trainerId, secretId, uuid)
return trainerId, secretId, nil
}
@ -283,10 +312,16 @@ func UpdateTrainerIds(trainerId, secretId int, uuid []byte) error {
return err
}
cache.UpdateTrainerIds(trainerId, secretId, uuid)
return nil
}
func IsActiveSession(uuid []byte, sessionId string) (bool, error) {
if result, ok := cache.IsActiveSession(uuid, sessionId); ok {
return result, nil
}
var id string
err := handle.QueryRow("SELECT clientSessionId FROM activeClientSessions WHERE uuid = ?", uuid).Scan(&id)
if err != nil {
@ -311,10 +346,16 @@ func UpdateActiveSession(uuid []byte, clientSessionId string) error {
return err
}
cache.UpdateActiveSession(uuid, clientSessionId)
return nil
}
func FetchUUIDFromToken(token []byte) ([]byte, error) {
if uuid, ok := cache.FetchUUIDFromToken(token); ok {
return uuid, nil
}
var uuid []byte
err := handle.QueryRow("SELECT uuid FROM sessions WHERE token = ?", token).Scan(&uuid)
if err != nil {
@ -330,6 +371,8 @@ func RemoveSessionFromToken(token []byte) error {
return err
}
cache.RemoveSessionFromToken(token)
return nil
}

@ -20,6 +20,7 @@ package db
import (
"math"
"github.com/pagefaultgames/rogueserver/cache"
"github.com/pagefaultgames/rogueserver/defs"
)
@ -30,10 +31,16 @@ func TryAddDailyRun(seed string) (string, error) {
return "", err
}
cache.TryAddDailyRun(actualSeed)
return actualSeed, nil
}
func GetDailyRunSeed() (string, error) {
if cachedSeed, ok := cache.GetDailyRunSeed(); ok {
return cachedSeed, nil
}
var seed string
err := handle.QueryRow("SELECT seed FROM dailyRuns WHERE date = UTC_DATE()").Scan(&seed)
if err != nil {

@ -25,12 +25,14 @@ import (
_ "github.com/go-sql-driver/mysql"
)
var handle *sql.DB
var (
handle *sql.DB
)
func Init(username, password, protocol, address, database string) error {
var err error
handle, err = sql.Open("mysql", username+":"+password+"@"+protocol+"("+address+")/"+database)
handle, err = sql.Open("mysql", username+":"+password+"@"+protocol+"("+address+":13306)/"+database)
if err != nil {
return fmt.Errorf("failed to open database connection: %s", err)
}

@ -17,7 +17,15 @@
package db
import (
"github.com/pagefaultgames/rogueserver/cache"
)
func FetchPlayerCount() (int, error) {
if cachedPlayerCount, ok := cache.FetchPlayerCount(); ok {
return cachedPlayerCount, nil
}
var playerCount int
err := handle.QueryRow("SELECT COUNT(*) FROM accounts WHERE lastActivity > DATE_SUB(UTC_TIMESTAMP(), INTERVAL 5 MINUTE)").Scan(&playerCount)
if err != nil {
@ -28,21 +36,33 @@ func FetchPlayerCount() (int, error) {
}
func FetchBattleCount() (int, error) {
if cachedBattleCount, ok := cache.FetchBattleCount(); ok {
return cachedBattleCount, nil
}
var battleCount int
err := handle.QueryRow("SELECT COALESCE(SUM(s.battles), 0) FROM accountStats s JOIN accounts a ON a.uuid = s.uuid WHERE a.banned = 0").Scan(&battleCount)
if err != nil {
return 0, err
}
cache.UpdateBattleCount(battleCount)
return battleCount, nil
}
func FetchClassicSessionCount() (int, error) {
if cachedClassicSessionCount, ok := cache.FetchClassicSessionCount(); ok {
return cachedClassicSessionCount, nil
}
var classicSessionCount int
err := handle.QueryRow("SELECT COALESCE(SUM(s.classicSessionsPlayed), 0) FROM accountStats s JOIN accounts a ON a.uuid = s.uuid WHERE a.banned = 0").Scan(&classicSessionCount)
if err != nil {
return 0, err
}
cache.UpdateClassicSessionCount(classicSessionCount)
return classicSessionCount, nil
}

@ -22,6 +22,7 @@ import (
"encoding/gob"
"github.com/klauspost/compress/zstd"
"github.com/pagefaultgames/rogueserver/cache"
"github.com/pagefaultgames/rogueserver/defs"
)
@ -39,10 +40,16 @@ func TryAddSeedCompletion(uuid []byte, seed string, mode int) (bool, error) {
return false, err
}
cache.TryAddSeedCompletion(uuid, seed, mode)
return true, nil
}
func ReadSeedCompleted(uuid []byte, seed string) (bool, error) {
if cachedCompleted, ok := cache.ReadSeedCompletion(uuid, seed); ok {
return cachedCompleted, nil
}
var count int
err := handle.QueryRow("SELECT COUNT(*) FROM dailyRunCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count)
if err != nil {

@ -12,3 +12,10 @@ services:
- "3306:3306"
volumes:
- ./.data/db:/var/lib/mysql
redis:
image: redis:7
container_name: pokerogue-redis-local
restart: unless-stopped
ports:
- "6379:6379"

@ -47,6 +47,14 @@ services:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock
redis:
image: redis:7
restart: unless-stopped
ports:
- "6379:6379"
networks:
- internal
volumes:
database:

@ -3,18 +3,25 @@ module github.com/pagefaultgames/rogueserver
go 1.22
require (
github.com/go-sql-driver/mysql v1.7.1
github.com/go-sql-driver/mysql v1.8.1
github.com/robfig/cron/v3 v3.0.1
golang.org/x/crypto v0.22.0
golang.org/x/crypto v0.26.0
)
require (
github.com/bwmarrin/discordgo v0.28.1
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/klauspost/compress v1.17.9
github.com/redis/go-redis v6.15.9+incompatible
)
require (
github.com/bwmarrin/discordgo v0.28.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/go-redis/redis v6.15.9+incompatible // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
golang.org/x/sys v0.19.0 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.27.10 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
)

103
go.sum

@ -1,22 +1,109 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis v6.15.9+incompatible h1:F+tnlesQSl3h9V8DdmtcYFdvkHLhbb7AgcLW6UJxnC4=
github.com/redis/go-redis v6.15.9+incompatible/go.mod h1:ic6dLmR0d9rkHSzaa0Ab3QVRZcjopJ9hSSPCrecj/+s=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -28,6 +28,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/pagefaultgames/rogueserver/api"
"github.com/pagefaultgames/rogueserver/api/account"
"github.com/pagefaultgames/rogueserver/cache"
"github.com/pagefaultgames/rogueserver/db"
)
@ -46,6 +47,10 @@ func main() {
dbaddr := getEnv("dbaddr", "localhost")
dbname := getEnv("dbname", "pokeroguedb")
redisaddr := getEnv("redisaddr", "localhost:6379")
redispass := getEnv("redispass", "")
redisdb := getEnv("redisdb", "0")
discordclientid := getEnv("discordclientid", "")
discordsecretid := getEnv("discordsecretid", "")
@ -80,6 +85,12 @@ func main() {
log.Fatalf("failed to initialize database: %s", err)
}
// get redis connection
err = cache.InitRedis(redisaddr, redispass, redisdb)
if err != nil {
log.Fatalf("failed to initialize redis: %s", err)
}
// create listener
listener, err := createListener(proto, addr)
if err != nil {

Loading…
Cancel
Save