同步代码

This commit is contained in:
TsMask
2023-08-21 11:00:22 +08:00
parent 2735cc3009
commit 788f01674a
37 changed files with 2211 additions and 1 deletions

48
core/utils.go Normal file
View File

@@ -0,0 +1,48 @@
package core
import (
"errors"
"github.com/aceld/zinx/ziface"
"omc/omc"
"strings"
)
type NeBind struct {
NeType string
NeId string
}
func ConvertBindFlag(bindFlag string) (NeBind, error) {
var neBind NeBind
nb := strings.Split(bindFlag, "#")
if len(nb) != 2 {
return neBind, errors.New("ne bind flag invalid")
}
neBind.NeType = nb[0]
neBind.NeId = nb[1]
return neBind, nil
}
// APIDecode 消息解析
func APIDecode(request ziface.IRequest, checker []string) (*omc.MsgBody, error) {
// 消息处理
msgBody := omc.MsgBody{
RawData: request.GetData(),
Msg: make(map[string]string, 0),
}
if err := msgBody.Decode(); err != nil {
return nil, errors.New("inlaid message body")
}
for _, v := range checker {
if _, ok := msgBody.Msg[v]; !ok {
return nil, errors.New("missing parameter of message body")
}
}
uID, err := request.GetConnection().GetProperty("UID")
if err != nil {
request.GetConnection().Stop()
return nil, errors.New("server internal error")
}
msgBody.UID = uID.(string)
return &msgBody, nil
}