diff --git a/common/cool/coolconfig/config.go b/common/cool/coolconfig/config.go index 6d7be6cd..b4729de0 100644 --- a/common/cool/coolconfig/config.go +++ b/common/cool/coolconfig/config.go @@ -9,7 +9,9 @@ type sConfig struct { File *file `json:"file,omitempty"` // 文件上传配置 Name string `json:"name"` // 项目名称 Port string `json:"port"` - PortBL uint16 `json:"port_bl"` + PortBL uint16 `json:"port_bl"` //这个是命令行输入的参数 + RPC uint16 //rpc端口 + GamePort []uint64 } // OSS相关配置 @@ -37,7 +39,9 @@ func newConfig() *sConfig { Name: GetCfgWithDefault(ctx, "server.name", g.NewVar("")).String(), Eps: GetCfgWithDefault(ctx, "blazing.eps", g.NewVar(false)).Bool(), Port: string(GetCfgWithDefault(ctx, "server.port", g.NewVar("8080")).String()), - //PortBL: string(GetCfgWithDefault(ctx, "blazing.port", g.NewVar("8080")).String()), + RPC: GetCfgWithDefault(ctx, "server.rpc", g.NewVar("8080")).Uint16(), + GamePort: GetCfgWithDefault(ctx, "server.game", g.NewVar("8080")).Uint64s(), + File: &file{ Mode: GetCfgWithDefault(ctx, "blazing.file.mode", g.NewVar("none")).String(), Domain: GetCfgWithDefault(ctx, "blazing.file.domain", g.NewVar("http://127.0.0.1:8300")).String(), diff --git a/common/rpc/rpc.go b/common/rpc/rpc.go index 7fa8b5e8..8271d663 100644 --- a/common/rpc/rpc.go +++ b/common/rpc/rpc.go @@ -10,9 +10,10 @@ import ( "net/http" "github.com/filecoin-project/go-jsonrpc" + "github.com/gogf/gf/v2/util/gconv" ) -const rpcport = ":40000" +var rpcport = gconv.String(cool.Config.RPC) var clientmap = make(map[uint16]*ClientHandler) //客户端map var clientidmap = make(map[uint16]uint16) //客户端map diff --git a/logic/server.go b/logic/server.go index 3973ad69..f6d150a6 100644 --- a/logic/server.go +++ b/logic/server.go @@ -12,9 +12,7 @@ import ( "fmt" "log" - "math/rand" "net" - "time" "github.com/gogf/gf/v2/util/gconv" ) @@ -26,28 +24,28 @@ const ( ) var defaultPort = gconv.Int(cool.Config.Port) //读入默认的端口 +var candidatePorts = []int{defaultPort} // determinePort 确定服务器使用的端口 func determinePort(serverid uint16) (int, error) { - rand.Seed(time.Now().UnixNano()) + // 服务器ID为0时使用默认端口 if serverid == 0 { return defaultPort, nil } + // 尝试从指定端口列表中找可用端口,最多尝试maxPortRetryCount轮 for i := 0; i < maxPortRetryCount; i++ { - port := generateRandomPort() - if isPortAvailable(port) { - return port, nil + // 遍历指定的端口列表 + for _, port := range candidatePorts { + if isPortAvailable(port) { + return port, nil + } + log.Printf("Port %d is not available, checking next...", port) } - log.Printf("Port %d is not available, retrying...", port) + log.Printf("All candidate ports are in use, retrying round %d...", i+1) } - return 0, fmt.Errorf("failed to find available port after %d attempts", maxPortRetryCount) -} - -// generateRandomPort 生成指定范围内的随机端口 -func generateRandomPort() int { - return minRandomPort + rand.Intn(maxRandomPort-minRandomPort) + return 0, fmt.Errorf("failed to find available port after %d rounds of checking", maxPortRetryCount) } // isPortAvailable 检查端口是否可用 diff --git a/logic/service/fight/node/Turn.go b/logic/service/fight/node/Turn.go index aa148660..35ad7ec7 100644 --- a/logic/service/fight/node/Turn.go +++ b/logic/service/fight/node/Turn.go @@ -10,7 +10,7 @@ func (e *EffectNode) Compare_Pre(fattack, sattack *action.SelectSkillAction) boo return false } func (e *EffectNode) Turn_Start(ctx input.Ctx) { - panic("not implemented") // TODO: Implement + //panic("not implemented") // TODO: Implement } func (e *EffectNode) Turn_End(ctx input.Ctx) { diff --git a/logic/service/fight/node/fight.go b/logic/service/fight/node/fight.go index 130269c2..4f16faf1 100644 --- a/logic/service/fight/node/fight.go +++ b/logic/service/fight/node/fight.go @@ -5,7 +5,8 @@ import "blazing/logic/service/fight/input" // 回合结束一次性effect清楚掉 func (e *EffectNode) Fight_Start(ctx input.Ctx) bool { - panic("not implemented") // TODO: Implement + //战斗开始应该注入魂印 + //panic("not implemented") // TODO: Implement } func (e *EffectNode) PreBattleEnd(ctx input.Ctx) bool { panic("not implemented") // TODO: Implement diff --git a/manifest/config/config.yaml b/manifest/config/config.yaml index 663421ab..4bce7efc 100644 --- a/manifest/config/config.yaml +++ b/manifest/config/config.yaml @@ -1,14 +1,17 @@ server: name: "blazing server" - address: ":8080" #前台服务器地址 - port: 12345 + address: ":59480" #前台服务器地址 + port: 53388 #后台服务器端口 + rpc: 56409 #rpc服务端口 + game: [55407,50876,52482] openapiPath: "/api.json" swaggerPath: "/swagger" - clientMaxBodySize: 104857600 # 100MB in bytes 100*1024*1024 - # 平滑重启特性 - graceful: true # 是否开启平滑重启特性,开启时将会在本地增加10000的本地TCP端口用于进程间通信。默认false - gracefulTimeout: 2 # 父进程在平滑重启后多少秒退出,默认2秒。若请求耗时大于该值,可能会导致请求中断 - gracefulShutdownTimeout: 5 # 关闭Server时如果存在正在执行的HTTP请求,Server等待多少秒才执行强行关闭 + clientMaxBodySize: + 104857600 # 100MB in bytes 100*1024*1024 + # 平滑重启特性 + graceful: true # 是否开启平滑重启特性,开启时将会在本地增加10000的本地TCP端口用于进程间通信。默认false + gracefulTimeout: 2 # 父进程在平滑重启后多少秒退出,默认2秒。若请求耗时大于该值,可能会导致请求中断 + gracefulShutdownTimeout: 5 # 关闭Server时如果存在正在执行的HTTP请求,Server等待多少秒才执行强行关闭 logger: level: "all" stdout: true @@ -16,10 +19,10 @@ logger: database: default: type: "pgsql" - host: "122.10.117.123" - port: "5432" + host: "125.208.20.223" + port: "55669" user: "bl" - pass: "WYrM5ZYFnX7Y8PRC" + pass: "4DD4z3T2Zh8rx8Yd" name: "bl" debug: true timezone: "Asia/Shanghai" @@ -50,9 +53,9 @@ database: # Redis 配置示例 redis: cool: - address: "122.10.117.123:6379" + address: "125.208.20.223:57095" db: 0 - pass: "redis_PPn5iT" + pass: "redis_wQ22jj" blazing: autoMigrate: true