mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
优化协议代理代码生成
This commit is contained in:
+10
-12
@@ -6,7 +6,7 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
appConfig "hk4e/common/config"
|
||||
"hk4e/common/config"
|
||||
"hk4e/common/mq"
|
||||
"hk4e/gate/client_proto"
|
||||
"hk4e/gate/kcp"
|
||||
@@ -45,14 +45,13 @@ var MESSAGE_QUEUE *mq.MessageQueue
|
||||
var SELF *model.Player
|
||||
|
||||
type GameManager struct {
|
||||
dao *dao.Dao
|
||||
snowflake *alg.SnowflakeWorker
|
||||
clientCmdProtoMap *client_proto.ClientCmdProtoMap
|
||||
clientCmdProtoMapRefValue reflect.Value
|
||||
gsId uint32
|
||||
gsAppid string
|
||||
mainGsAppid string
|
||||
ai *model.Player // 本服的Ai玩家对象
|
||||
dao *dao.Dao
|
||||
snowflake *alg.SnowflakeWorker
|
||||
clientCmdProtoMap *client_proto.ClientCmdProtoMap
|
||||
gsId uint32
|
||||
gsAppid string
|
||||
mainGsAppid string
|
||||
ai *model.Player // 本服的Ai玩家对象
|
||||
}
|
||||
|
||||
func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppid string, mainGsAppid string) (r *GameManager) {
|
||||
@@ -60,9 +59,8 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
|
||||
r.dao = dao
|
||||
MESSAGE_QUEUE = messageQueue
|
||||
r.snowflake = alg.NewSnowflakeWorker(int64(gsId))
|
||||
if appConfig.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
if config.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
r.clientCmdProtoMap = client_proto.NewClientCmdProtoMap()
|
||||
r.clientCmdProtoMapRefValue = reflect.ValueOf(r.clientCmdProtoMap)
|
||||
// 反射调用的方法在启动时测试是否正常防止中途panic
|
||||
r.GetClientProtoObjByName("PingReq")
|
||||
}
|
||||
@@ -394,7 +392,7 @@ func (g *GameManager) DisconnectPlayer(userId uint32, reason uint32) {
|
||||
}
|
||||
|
||||
func (g *GameManager) GetClientProtoObjByName(protoObjName string) pb.Message {
|
||||
fn := g.clientCmdProtoMapRefValue.MethodByName("GetClientProtoObjByName")
|
||||
fn := g.clientCmdProtoMap.RefValue.MethodByName("GetClientProtoObjByName")
|
||||
ret := fn.Call([]reflect.Value{reflect.ValueOf(protoObjName)})
|
||||
obj := ret[0].Interface()
|
||||
if obj == nil {
|
||||
|
||||
Reference in New Issue
Block a user