mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2025-12-19 18:32:23 +08:00
上外网前准备
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -33,3 +33,6 @@ node/api/*.pb.go
|
||||
|
||||
# Local game data config table file
|
||||
gdconf/game_data_config/csv/*.csv
|
||||
|
||||
# Deploy
|
||||
docker/docker-compose.yaml
|
||||
|
||||
1
Makefile
1
Makefile
@@ -39,6 +39,7 @@ docker_clean:
|
||||
# 复制配置模板等文件
|
||||
.PHONY: docker_config
|
||||
docker_config:
|
||||
mkdir -p ./docker && cp -rf ./docker-compose.yaml ./docker/
|
||||
mkdir -p ./docker/node/bin && cp -rf ./cmd/node/* ./docker/node/bin/
|
||||
mkdir -p ./docker/dispatch/bin && cp -rf ./cmd/dispatch/* ./docker/dispatch/bin/
|
||||
mkdir -p ./docker/gate/bin && cp -rf ./cmd/gate/* ./docker/gate/bin/
|
||||
|
||||
@@ -50,6 +50,7 @@ make docker_build # 构建镜像
|
||||
|
||||
```shell
|
||||
make gen_csv # 生成配置表
|
||||
cd docker
|
||||
# 启动前请先确保各服务器的配置文件正确(如docker/node/bin/application.toml)
|
||||
docker-compose up -d # 启动服务器
|
||||
```
|
||||
|
||||
@@ -9,5 +9,9 @@ max_size = 10485760
|
||||
[database]
|
||||
url = "mongodb://mongo:27017"
|
||||
|
||||
[redis]
|
||||
addr = "redis:6379"
|
||||
password = ""
|
||||
|
||||
[mq]
|
||||
nats_url = "nats://nats:4222"
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
func (d *Dao) GetNextAccountId() (uint64, error) {
|
||||
func (d *Dao) _GetNextAccountId() (uint64, error) {
|
||||
db := d.db.Collection("account_id_counter")
|
||||
find := db.FindOne(context.TODO(), bson.D{{"_id", "default"}})
|
||||
item := new(model.AccountIDCounter)
|
||||
@@ -50,7 +50,7 @@ func (d *Dao) GetNextAccountId() (uint64, error) {
|
||||
return item.AccountID, nil
|
||||
}
|
||||
|
||||
func (d *Dao) GetNextYuanShenUid() (uint64, error) {
|
||||
func (d *Dao) _GetNextYuanShenUid() (uint64, error) {
|
||||
db := d.db.Collection("player_id_counter")
|
||||
find := db.FindOne(context.TODO(), bson.D{{"_id", "default"}})
|
||||
item := new(model.PlayerIDCounter)
|
||||
46
dispatch/dao/account_redis.go
Normal file
46
dispatch/dao/account_redis.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const RedisPlayerKeyPrefix = "HK4E"
|
||||
|
||||
const (
|
||||
AccountIdRedisKey = "AccountId"
|
||||
AccountIdBegin uint64 = 1
|
||||
YuanShenUidRedisKey = "YuanShenUid"
|
||||
YuanShenUidBegin uint64 = 100000001
|
||||
)
|
||||
|
||||
func (d *Dao) GetNextAccountId() (uint64, error) {
|
||||
return d.redisInc(RedisPlayerKeyPrefix + ":" + AccountIdRedisKey)
|
||||
}
|
||||
|
||||
func (d *Dao) GetNextYuanShenUid() (uint64, error) {
|
||||
return d.redisInc(RedisPlayerKeyPrefix + ":" + YuanShenUidRedisKey)
|
||||
}
|
||||
|
||||
func (d *Dao) redisInc(keyName string) (uint64, error) {
|
||||
exist, err := d.redis.Exists(context.TODO(), keyName).Result()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if exist == 0 {
|
||||
var value uint64 = 0
|
||||
if keyName == AccountIdRedisKey {
|
||||
value = AccountIdBegin
|
||||
} else if keyName == YuanShenUidRedisKey {
|
||||
value = YuanShenUidBegin
|
||||
}
|
||||
err := d.redis.Set(context.TODO(), keyName, value, 0).Err()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
id, err := d.redis.Incr(context.TODO(), keyName).Result()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(id), nil
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"hk4e/common/config"
|
||||
"hk4e/pkg/logger"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
type Dao struct {
|
||||
mongo *mongo.Client
|
||||
db *mongo.Database
|
||||
redis *redis.Client
|
||||
}
|
||||
|
||||
func NewDao() (r *Dao) {
|
||||
@@ -31,6 +33,18 @@ func NewDao() (r *Dao) {
|
||||
}
|
||||
r.mongo = client
|
||||
r.db = client.Database("dispatch_hk4e")
|
||||
r.redis = redis.NewClient(&redis.Options{
|
||||
Addr: config.CONF.Redis.Addr,
|
||||
Password: config.CONF.Redis.Password,
|
||||
DB: 0,
|
||||
PoolSize: 10,
|
||||
MinIdleConns: 1,
|
||||
})
|
||||
err = r.redis.Ping(context.TODO()).Err()
|
||||
if err != nil {
|
||||
logger.Error("redis ping error: %v", err)
|
||||
return nil
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -39,4 +53,8 @@ func (d *Dao) CloseDao() {
|
||||
if err != nil {
|
||||
logger.Error("mongo close error: %v", err)
|
||||
}
|
||||
err = d.redis.Close()
|
||||
if err != nil {
|
||||
logger.Error("redis close error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ services:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./docker/node/bin/application.toml:/node/application.toml
|
||||
- ./node/bin/application.toml:/node/application.toml
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
@@ -30,9 +30,9 @@ services:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./docker/dispatch/bin/application.toml:/dispatch/application.toml
|
||||
- ./docker/dispatch/bin/key:/dispatch/key
|
||||
- ./docker/dispatch/bin/static:/dispatch/static
|
||||
- ./dispatch/bin/application.toml:/dispatch/application.toml
|
||||
- ./dispatch/bin/key:/dispatch/key
|
||||
- ./dispatch/bin/static:/dispatch/static
|
||||
depends_on:
|
||||
- node_services
|
||||
deploy:
|
||||
@@ -54,8 +54,8 @@ services:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./docker/gate/bin/application.toml:/gate/application.toml
|
||||
- ./docker/gate/bin/key:/gate/key
|
||||
- ./gate/bin/application.toml:/gate/application.toml
|
||||
- ./gate/bin/key:/gate/key
|
||||
depends_on:
|
||||
- dispatch_services
|
||||
deploy:
|
||||
@@ -74,7 +74,7 @@ services:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./docker/fight/bin/application.toml:/fight/application.toml
|
||||
- ./fight/bin/application.toml:/fight/application.toml
|
||||
depends_on:
|
||||
- gate_services
|
||||
deploy:
|
||||
@@ -93,7 +93,7 @@ services:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./docker/pathfinding/bin/application.toml:/pathfinding/application.toml
|
||||
- ./pathfinding/bin/application.toml:/pathfinding/application.toml
|
||||
depends_on:
|
||||
- fight_services
|
||||
deploy:
|
||||
@@ -112,8 +112,8 @@ services:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./docker/gs/bin/application.toml:/gs/application.toml
|
||||
- ./gdconf/game_data_config:/gs/game_data_config
|
||||
- ./gs/bin/application.toml:/gs/application.toml
|
||||
- ../gdconf/game_data_config:/gs/game_data_config
|
||||
depends_on:
|
||||
- pathfinding_services
|
||||
deploy:
|
||||
@@ -134,7 +134,7 @@ services:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./docker/gm/bin/application.toml:/gm/application.toml
|
||||
- ./gm/bin/application.toml:/gm/application.toml
|
||||
depends_on:
|
||||
- gs_services
|
||||
deploy:
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/pkg/logger"
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
// 游戏数据配置表
|
||||
|
||||
var CONF *GameDataConfig = nil
|
||||
var CONF_RELOAD *GameDataConfig = nil
|
||||
|
||||
type GameDataConfig struct {
|
||||
// 配置表路径前缀
|
||||
@@ -44,8 +46,22 @@ type GameDataConfig struct {
|
||||
|
||||
func InitGameDataConfig() {
|
||||
CONF = new(GameDataConfig)
|
||||
startTime := time.Now().Unix()
|
||||
CONF.loadAll()
|
||||
logger.Info("load all game data config finish")
|
||||
endTime := time.Now().Unix()
|
||||
logger.Info("load all game data config finish, cost: %v(s)", endTime-startTime)
|
||||
}
|
||||
|
||||
func ReloadGameDataConfig() {
|
||||
CONF_RELOAD = new(GameDataConfig)
|
||||
startTime := time.Now().Unix()
|
||||
CONF_RELOAD.loadAll()
|
||||
endTime := time.Now().Unix()
|
||||
logger.Info("reload all game data config finish, cost: %v(s)", endTime-startTime)
|
||||
}
|
||||
|
||||
func ReplaceGameDataConfig() {
|
||||
CONF = CONF_RELOAD
|
||||
}
|
||||
|
||||
func (g *GameDataConfig) loadAll() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"hk4e/common/mq"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/gs/model"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/pkg/object"
|
||||
@@ -17,6 +18,8 @@ const (
|
||||
RunUserCopyAndSave // 执行一次在线玩家内存数据复制到数据库写入协程
|
||||
ExitRunUserCopyAndSave
|
||||
UserOfflineSaveToDbFinish
|
||||
ReloadGameDataConfig
|
||||
ReloadGameDataConfigFinish
|
||||
)
|
||||
|
||||
type LocalEvent struct {
|
||||
@@ -134,5 +137,19 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) {
|
||||
logger.Info("user change gs notify to gate, uid: %v, gate appid: %v, gs appid: %v, host uid: %v",
|
||||
playerOfflineInfo.Player.PlayerID, playerOfflineInfo.Player.GateAppId, gsAppId, playerOfflineInfo.ChangeGsInfo.JoinHostUserId)
|
||||
}
|
||||
case ReloadGameDataConfig:
|
||||
go func() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logger.Error("reload game data config error: %v", err)
|
||||
}
|
||||
}()
|
||||
gdconf.ReloadGameDataConfig()
|
||||
LOCAL_EVENT_MANAGER.localEventChan <- &LocalEvent{
|
||||
EventId: ReloadGameDataConfigFinish,
|
||||
}
|
||||
}()
|
||||
case ReloadGameDataConfigFinish:
|
||||
gdconf.ReplaceGameDataConfig()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user