mirror of
https://github.com/CPunch/gopenfusion.git
synced 2025-10-13 04:40:10 +00:00
moved config/ -> internal/config
This commit is contained in:
85
internal/config/config.go
Normal file
85
internal/config/config.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
Available environment variables:
|
||||
REDIS_ADDR
|
||||
REDIS_USER
|
||||
REDIS_PASS
|
||||
DB_ADDR
|
||||
DB_USER
|
||||
DB_PASS
|
||||
ANNOUNCE_IP
|
||||
TDATA_PATH
|
||||
*/
|
||||
|
||||
const (
|
||||
AEQUIP_COUNT = 9
|
||||
AINVEN_COUNT = 50
|
||||
ABANK_COUNT = 119
|
||||
|
||||
NANO_COUNT = 37
|
||||
)
|
||||
|
||||
var (
|
||||
SPAWN_X = 632032
|
||||
SPAWN_Y = 187177
|
||||
SPAWN_Z = -5500
|
||||
|
||||
LOGIN_PORT = 23000
|
||||
SHARD_PORT = 23001
|
||||
|
||||
LOGIN_TIMEOUT = time.Second * 30
|
||||
VIEW_DISTANCE = 25600
|
||||
)
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
func GetTDataPath() string {
|
||||
return getEnv("TDATA_PATH", "./tdata")
|
||||
}
|
@@ -4,7 +4,7 @@ import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnet/protocol"
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/internal/config"
|
||||
"github.com/blockloop/scan"
|
||||
)
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/internal/config"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/internal/config"
|
||||
)
|
||||
|
||||
type LoginMetadata struct {
|
||||
|
@@ -7,7 +7,7 @@ package redis
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/internal/config"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
Reference in New Issue
Block a user