Switched to redis/postgres, major refactoring

- loginMetadata is passed to shards through redis now
- shards announce they're alive via redis.AnnounceShard() which just
  populates a hashset keyed 'shards'
- login servers grab the 'shards' hashset and randomly picks a shard to
  pass the player to (for now)
- ./service shard && ./service login
- Many new environment variables, check config/config.go for more info.
  or for a tl;dr just read the Dockerfile for the required ones
- Shard and login services now run in different processes ! (and
  containers?? wooaaah)
This commit is contained in:
2023-06-22 01:53:38 -05:00
parent 983588b6c9
commit d7445e0f0f
20 changed files with 489 additions and 192 deletions

View File

@@ -1,5 +1,21 @@
package config
import (
"os"
"time"
)
/*
Available environment variables:
REDIS_ADDR
REDIS_USER
REDIS_PASS
DB_ADDR
DB_USER
DB_PASS
ANNOUNCE_IP
*/
const (
AEQUIP_COUNT = 9
AINVEN_COUNT = 50
@@ -15,9 +31,49 @@ var (
LOGIN_PORT = 23000
SHARD_PORT = 23001
SHARD_IP = "127.0.0.1"
LOGIN_TIMEOUT = time.Second * 30
)
func getEnv(key string, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
func GetMaxHP(level int) int {
return (925 + 75*(level))
}
func GetRedisAddr() string {
return getEnv("REDIS_ADDR", "localhost:6379")
}
func GetRedisCredentials() func() (string, string) {
return func() (string, string) {
return getEnv("REDIS_USER", ""), getEnv("REDIS_PASS", "")
}
}
func GetDBName() string {
return getEnv("DB_NAME", "postgres")
}
func GetDBAddr() string {
return getEnv("DB_ADDR", "localhost:5432")
}
func GetDBUser() string {
return getEnv("DB_USER", "postgres")
}
func GetDBPass() string {
return getEnv("DB_PASS", "")
}
// needed for shard
func GetAnnounceIP() string {
return getEnv("ANNOUNCE_IP", "127.0.0.1")
}