协议消息注册优化
This commit is contained in:
parent
ef129ee8e0
commit
3cc3af2aff
@ -2,7 +2,7 @@
|
|||||||
"AppID": 0,
|
"AppID": 0,
|
||||||
"LogLevel": "debug",
|
"LogLevel": "debug",
|
||||||
"LogPath": "./log",
|
"LogPath": "./log",
|
||||||
"TCPAddr": ":3602",
|
"TCPAddr": ":3601",
|
||||||
"WSAddr": ":3567",
|
"WSAddr": ":3567",
|
||||||
"RPCAddr": ":50051",
|
"RPCAddr": ":50051",
|
||||||
"MySqlAddr": "127.0.0.1",
|
"MySqlAddr": "127.0.0.1",
|
||||||
|
|||||||
@ -98,6 +98,9 @@ func buildNewMsgHandlerAdapter(value interface{}) (func(*Player, *thrift.TStruct
|
|||||||
return nil, fmt.Errorf("second arg must be *thrift.TStruct or pointer type implementing thrift.TStruct")
|
return nil, fmt.Errorf("second arg must be *thrift.TStruct or pointer type implementing thrift.TStruct")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 注册具体的 thrift 消息类型到全局缓存
|
||||||
|
registerThriftType(msgArgType)
|
||||||
|
|
||||||
return func(player *Player, msg *thrift.TStruct) error {
|
return func(player *Player, msg *thrift.TStruct) error {
|
||||||
if msg == nil || *msg == nil {
|
if msg == nil || *msg == nil {
|
||||||
return fmt.Errorf("nil thrift message")
|
return fmt.Errorf("nil thrift message")
|
||||||
|
|||||||
@ -32,21 +32,24 @@ func buildProtoMessageTypeCache() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registerThriftType(msgType reflect.Type) {
|
||||||
|
if msgType == nil || msgType.Kind() != reflect.Ptr {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
elemType := msgType.Elem()
|
||||||
|
if elemType.Name() != "" {
|
||||||
|
thriftMessageTypeByName.Store(elemType.Name(), msgType)
|
||||||
|
}
|
||||||
|
thriftMessageTypeByName.Store(msgType.String(), msgType)
|
||||||
|
thriftMessageTypeByName.Store(elemType.String(), msgType)
|
||||||
|
if elemType.PkgPath() != "" && elemType.Name() != "" {
|
||||||
|
thriftMessageTypeByName.Store(elemType.PkgPath()+"."+elemType.Name(), msgType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func buildThriftMessageTypeCache() {
|
func buildThriftMessageTypeCache() {
|
||||||
msg.Processor.Range(func(_ uint16, msgType reflect.Type) {
|
msg.Processor.Range(func(_ uint16, msgType reflect.Type) {
|
||||||
if msgType == nil || msgType.Kind() != reflect.Ptr {
|
registerThriftType(msgType)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
elemType := msgType.Elem()
|
|
||||||
if elemType.Name() != "" {
|
|
||||||
thriftMessageTypeByName.Store(elemType.Name(), msgType)
|
|
||||||
}
|
|
||||||
thriftMessageTypeByName.Store(msgType.String(), msgType)
|
|
||||||
thriftMessageTypeByName.Store(elemType.String(), msgType)
|
|
||||||
if elemType.PkgPath() != "" && elemType.Name() != "" {
|
|
||||||
thriftMessageTypeByName.Store(elemType.PkgPath()+"."+elemType.Name(), msgType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package unit
|
package unit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go/importer"
|
||||||
"server/game"
|
"server/game"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -11,3 +13,19 @@ func TestPlayroomVisit(t *testing.T) {
|
|||||||
player.InitPlayerOnly()
|
player.InitPlayerOnly()
|
||||||
player.GetVisitorPlayer()
|
player.GetVisitorPlayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFlect(t *testing.T) {
|
||||||
|
pkgPath := "server/msg/meowmentnet"
|
||||||
|
pkg, err := importer.Default().Import(pkgPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to import package %s: %v\n", pkgPath, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, name := range pkg.Scope().Names() {
|
||||||
|
obj := pkg.Scope().Lookup(name)
|
||||||
|
if obj == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Printf("name %s, obj name %s\n", name, obj.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user