```
feat(build): 更新构建脚本添加资源打包和proto编译 更新build.bat脚本,添加proto文件编译和资源打包功能,调整资源打包顺序。 BREAKING CHANGE: 构建流程发生变化,需要重新生成proto文件和打包资源。 --- refactor(xmlres): 使用gres替换gfile读取资源文件 将xmlres模块中文件读取方式从gfile.GetBytes改为gres.GetContent, 使
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"blazing/common/rpc"
|
||||
"blazing/common/socket"
|
||||
|
||||
"blazing/cool"
|
||||
"blazing/logic/controller"
|
||||
|
||||
blservice "blazing/modules/blazing/service"
|
||||
@@ -23,14 +22,12 @@ const (
|
||||
maxPortRetryCount = 5
|
||||
)
|
||||
|
||||
var candidatePorts = cool.Config.GamePort
|
||||
|
||||
// determinePort 确定服务器使用的端口
|
||||
func determinePort() (int, error) {
|
||||
func determinePort(ports []uint32) (int, error) {
|
||||
// 尝试从指定端口列表中找可用端口,最多尝试maxPortRetryCount轮
|
||||
for i := 0; i < maxPortRetryCount; i++ {
|
||||
// 遍历指定的端口列表
|
||||
for _, port := range candidatePorts {
|
||||
for _, port := range ports {
|
||||
if isPortAvailable(port) {
|
||||
return int(port), nil
|
||||
}
|
||||
@@ -43,7 +40,7 @@ func determinePort() (int, error) {
|
||||
}
|
||||
|
||||
// isPortAvailable 检查端口是否可用
|
||||
func isPortAvailable(port uint64) bool {
|
||||
func isPortAvailable(port uint32) bool {
|
||||
address := fmt.Sprintf(":%d", port)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
@@ -57,7 +54,8 @@ func isPortAvailable(port uint64) bool {
|
||||
// 如果id是0,那就是login server
|
||||
func Start(serverID uint16) {
|
||||
// 确定端口
|
||||
port, err := determinePort()
|
||||
r := blservice.NewLoginServiceService().GetServerID(serverID)
|
||||
port, err := determinePort(r.CanPort)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to determine port: %v", err)
|
||||
}
|
||||
@@ -68,10 +66,10 @@ func Start(serverID uint16) {
|
||||
// go func() {
|
||||
rpcClient := rpc.StartClient(serverID, uint16(port), server)
|
||||
|
||||
controller.Maincontroller.RPCClient = *rpcClient //将RPC赋值Start
|
||||
controller.Maincontroller.Port = uint16(port) //赋值服务器ID
|
||||
controller.Maincontroller.RPCClient = *rpcClient //将RPC赋值Start
|
||||
controller.Maincontroller.Port = uint16(port) //赋值服务器ID
|
||||
controller.Init(true)
|
||||
xmlres.Initfile()
|
||||
blservice.NewLoginServiceService().SetServerID(serverID, gconv.Uint16(port))
|
||||
server.Boot()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user