1
This commit is contained in:
parent
ace0d1dd5e
commit
51f179c1de
61
app.go
61
app.go
@ -1,14 +1,23 @@
|
||||
package f5
|
||||
|
||||
import "flag"
|
||||
import "sync"
|
||||
import "time"
|
||||
import "q5"
|
||||
|
||||
type App_ struct {
|
||||
nodeId int32
|
||||
instanceId int32
|
||||
nodeId int
|
||||
instanceId int
|
||||
terminated bool
|
||||
flags map[int32]int32
|
||||
servicing bool
|
||||
contextHash map[int32]q5.XParams
|
||||
loopCond sync.Cond
|
||||
imTopNode *IMMsgNode
|
||||
imBotNode *IMMsgNode
|
||||
imWorkNode *IMMsgNode
|
||||
imMsgMutex sync.RWMutex
|
||||
chGoLoopTimerExit chan int
|
||||
}
|
||||
|
||||
func (this *App_) Init() {
|
||||
@ -18,9 +27,15 @@ func (this *App_) Init() {
|
||||
nil,
|
||||
1000 * 60,
|
||||
5000)
|
||||
flag.IntVar(&this.nodeId, "n", 0, "node id")
|
||||
flag.IntVar(&this.instanceId, "i", 0, "instance id")
|
||||
flag.Parse()
|
||||
this.chGoLoopTimerExit = make(chan int)
|
||||
go this.goLoopTimer()
|
||||
}
|
||||
|
||||
func (this *App_) UnInit() {
|
||||
this.chGoLoopTimerExit <- 1
|
||||
_Timer.UnInit()
|
||||
_Timer = nil
|
||||
}
|
||||
@ -28,6 +43,7 @@ func (this *App_) UnInit() {
|
||||
func (this *App_) Run() {
|
||||
for !this.terminated {
|
||||
_Timer.Update()
|
||||
this.loopCond.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +51,48 @@ func (this *App_) NewUuid() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *App_) GetInstanceId() uint32 {
|
||||
return uint32(this.instanceId)
|
||||
}
|
||||
|
||||
func (this *App_) GetNodeId() uint32 {
|
||||
return uint32(this.nodeId)
|
||||
}
|
||||
|
||||
func (this *App_) HasFlag(flag int32) bool {
|
||||
_, ok := this.flags[flag]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) {
|
||||
p := new(IMMsgNode)
|
||||
p.msgId = msgId
|
||||
p.params = params
|
||||
|
||||
{
|
||||
this.imMsgMutex.Lock()
|
||||
defer this.imMsgMutex.Unlock()
|
||||
if this.imBotNode != nil {
|
||||
this.imBotNode.next = p
|
||||
this.imBotNode = p
|
||||
} else {
|
||||
this.imTopNode = p
|
||||
this.imBotNode = p
|
||||
}
|
||||
}
|
||||
this.loopCond.Broadcast()
|
||||
}
|
||||
|
||||
func (this *App_) RegisterIMMsgHandle(msgId int16, handle func(int16,*q5.XParams)) {
|
||||
}
|
||||
|
||||
func (this *App_) goLoopTimer() {
|
||||
for {
|
||||
select {
|
||||
case <-this.chGoLoopTimerExit:
|
||||
return
|
||||
case <-time.After(time.Millisecond):
|
||||
this.loopCond.Broadcast()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
f5types.go
Normal file
13
f5types.go
Normal file
@ -0,0 +1,13 @@
|
||||
package f5
|
||||
|
||||
import "q5"
|
||||
|
||||
type MsgNode struct {
|
||||
|
||||
}
|
||||
|
||||
type IMMsgNode struct {
|
||||
msgId int16
|
||||
params *q5.XParams
|
||||
next *IMMsgNode
|
||||
}
|
28
metamgr.go
28
metamgr.go
@ -18,6 +18,7 @@ type MetaClass struct {
|
||||
WrapMeta interface{}
|
||||
PrimKey string
|
||||
SecKey string
|
||||
IsObject bool
|
||||
}
|
||||
|
||||
type MetaMgr struct {
|
||||
@ -50,7 +51,7 @@ func (this *MetaMgr) Load() {
|
||||
}
|
||||
|
||||
func (this *MetaMgr) loadRawMetaTable() {
|
||||
for key, val := range *this.metaClasses {
|
||||
for _, val := range *this.metaClasses {
|
||||
rawMeta, _ := this.loadJson(&val)
|
||||
values := rawMeta.Elem().FieldByName("Values")
|
||||
wrapMetaType := reflect.TypeOf(val.WrapMeta)
|
||||
@ -66,32 +67,32 @@ func (this *MetaMgr) loadRawMetaTable() {
|
||||
wrapMetaList = reflect.Append(wrapMetaList, wrapMeta)
|
||||
}
|
||||
|
||||
this.rawList[key] = rawMeta
|
||||
this.wrapList[key] = wrapMetaList.Interface()
|
||||
this.wrapIdHash[key] = map[int64]interface{}{}
|
||||
this.wrapNameHash[key] = map[string]interface{}{}
|
||||
this.rawList[val.Idx] = rawMeta
|
||||
this.wrapList[val.Idx] = wrapMetaList.Interface()
|
||||
this.wrapIdHash[val.Idx] = map[int64]interface{}{}
|
||||
this.wrapNameHash[val.Idx] = map[string]interface{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MetaMgr) bindPrimKey() {
|
||||
for key, val := range *this.metaClasses {
|
||||
wrapMetaList := reflect.ValueOf(this.wrapList[key])
|
||||
for _, val := range *this.metaClasses {
|
||||
wrapMetaList := reflect.ValueOf(this.wrapList[val.Idx])
|
||||
for i := 0; i < wrapMetaList.Len(); i++ {
|
||||
wrapMeta := wrapMetaList.Index(i)
|
||||
if val.PrimKey == "" {
|
||||
this.wrapIdHash[key][int64(i + 1)] = wrapMeta.Interface()
|
||||
this.wrapIdHash[val.Idx][int64(i + 1)] = wrapMeta.Interface()
|
||||
continue
|
||||
}
|
||||
primVal := wrapMeta.Elem().FieldByName(val.PrimKey)
|
||||
secVal := wrapMeta.Elem().FieldByName(val.SecKey)
|
||||
if fieldVal, ok := primVal.Interface().(*string); ok {
|
||||
this.wrapNameHash[key][*fieldVal] = wrapMeta
|
||||
this.wrapNameHash[val.Idx][*fieldVal] = wrapMeta
|
||||
} else if fieldVal, ok := primVal.Interface().(*int32); ok {
|
||||
if val.SecKey == "" {
|
||||
this.wrapIdHash[key][int64(*fieldVal)] = wrapMeta.Interface()
|
||||
this.wrapIdHash[val.Idx][int64(*fieldVal)] = wrapMeta.Interface()
|
||||
} else {
|
||||
if subFieldVal, ok := secVal.Interface().(*int32); ok {
|
||||
this.wrapIdHash[key][int64(*subFieldVal)] = wrapMeta.Interface()
|
||||
this.wrapIdHash[val.Idx][int64(*subFieldVal)] = wrapMeta.Interface()
|
||||
} else {
|
||||
|
||||
}
|
||||
@ -105,8 +106,13 @@ func (this *MetaMgr) bindPrimKey() {
|
||||
func (this *MetaMgr) loadJson(metaClass *MetaClass) (reflect.Value, error) {
|
||||
f, _ := os.Open(metaClass.FileName)
|
||||
data, _ := bufio.NewReader(f).ReadString(0)
|
||||
if metaClass.IsObject {
|
||||
data = "{\"values\":[" + data
|
||||
data += "]}"
|
||||
} else {
|
||||
data = "{\"values\":" + data
|
||||
data += "}"
|
||||
}
|
||||
|
||||
u := jsonpb.Unmarshaler{AllowUnknownFields: true}
|
||||
msgType := reflect.TypeOf(metaClass.RawMeta).Elem()
|
||||
|
79
sysutils.go
Normal file
79
sysutils.go
Normal file
@ -0,0 +1,79 @@
|
||||
package f5
|
||||
|
||||
import "os"
|
||||
import "strings"
|
||||
import "q5"
|
||||
|
||||
const (
|
||||
ONLINE_ENV = 0
|
||||
TEST_ENV
|
||||
DEV_ENV
|
||||
)
|
||||
|
||||
var serverEnv int32
|
||||
|
||||
func IsTestEnv() bool {
|
||||
return serverEnv == TEST_ENV
|
||||
}
|
||||
|
||||
func IsOnlineEnv() bool {
|
||||
return serverEnv == ONLINE_ENV
|
||||
}
|
||||
|
||||
func IsDevEnv() bool {
|
||||
return serverEnv == DEV_ENV
|
||||
}
|
||||
|
||||
func IsValidSessionId(accountId string, sessionId string, key string) bool {
|
||||
tmpStrings := strings.Split(sessionId, "_")
|
||||
if len(tmpStrings) < 4 {
|
||||
return false
|
||||
}
|
||||
sessionCreateTime := new(q5.XValue).SetString(tmpStrings[0]).GetString()
|
||||
registerTime := new(q5.XValue).SetString(tmpStrings[1]).GetString()
|
||||
md5Str := new(q5.XValue).SetString(tmpStrings[2]).GetString()
|
||||
return q5.Md5Str(accountId + registerTime + sessionCreateTime) == md5Str
|
||||
}
|
||||
|
||||
func ExtractRegisterTimeFromSessionId(sessionId string) int32 {
|
||||
tmpStrings := strings.Split(sessionId, "_")
|
||||
if len(tmpStrings) < 4 {
|
||||
return 0
|
||||
}
|
||||
return new(q5.XValue).SetString(tmpStrings[1]).GetInt32()
|
||||
}
|
||||
|
||||
func ExtractGameIdFromAccountId(accountId string) int32 {
|
||||
tmpStrings := strings.Split(accountId, "_")
|
||||
if len(tmpStrings) < 2 {
|
||||
return 0
|
||||
}
|
||||
return new(q5.XValue).SetString(tmpStrings[1]).GetInt32()
|
||||
}
|
||||
|
||||
func ExtractChannelFromAccountId(accountId string) int32 {
|
||||
tmpStrings := strings.Split(accountId, "_")
|
||||
if len(tmpStrings) < 2 {
|
||||
return 0
|
||||
}
|
||||
return new(q5.XValue).SetString(tmpStrings[0]).GetInt32()
|
||||
}
|
||||
|
||||
func ExtractOpenIdFromAccountId(accountId string) string {
|
||||
tmpStrings := strings.Split(accountId, "_")
|
||||
if len(tmpStrings) < 3 {
|
||||
return ""
|
||||
}
|
||||
return strings.Join(tmpStrings[2:], "_")
|
||||
}
|
||||
|
||||
func init() {
|
||||
switch os.Getenv("SERVER_ENV") {
|
||||
case "TEST":
|
||||
serverEnv = TEST_ENV
|
||||
case "DEBUG":
|
||||
serverEnv = DEV_ENV
|
||||
default:
|
||||
serverEnv = ONLINE_ENV
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user