aozhiwei 7e674831d4 1
2023-08-12 16:01:36 +08:00

91 lines
1.9 KiB
Go

package main
import (
"time"
"fmt"
"sync"
"q5"
"f5"
"cs"
"mt"
)
type App struct {
f5.App_
msgMutex sync.Mutex
msgList q5.ListHead
workList q5.ListHead
}
var app = new (App)
func (this *App) Init() {
f5.App = &this.App_
f5.App.SetPkgName("imserver")
this.App_.Init(this.Update)
this.msgList.Init(nil)
this.workList.Init(nil)
f5.LoadMetaTable(mt.Table)
handlerMgr.Init()
wspListener.Init()
go this.goReportServerState()
}
func (this *App) UnInit() {
handlerMgr.UnInit()
wspListener.UnInit()
this.App_.UnInit()
}
func (this *App) Update() {
if this.workList.Empty() {
this.msgMutex.Lock()
defer this.msgMutex.Unlock()
if !this.msgList.Empty() {
this.msgList.ReplaceInit(&this.workList)
}
}
for !this.workList.Empty() {
next := this.workList.Next()
hdr, ok := next.GetData().(*f5.MsgHdr)
if ok {
handler := cs.GetNetMsgHandler(hdr.MsgId)
if handler != nil && handler.HandlerId== PLAYER_MGR_HANDLER_ID {
cs.DispatchMsg(handler, hdr, playerMgr)
}
}
next.Del()
}
}
func (this *App) goReportServerState() {
for {
params := q5.NewMxoObject()
params.SetXValue("node_id", q5.NewXInt32(1))
params.SetXValue("instance_id", q5.NewXInt32(1))
params.SetXValue("ip", q5.NewXString("192.168.100.39"))
params.SetXValue("port", q5.NewXInt32(8888))
params.SetXValue("online_num", q5.NewXInt32(1))
params.SetXValue("room_num", q5.NewXInt32(1))
params.SetXValue("channel", q5.NewXInt32(0))
params.SetXValue("alive_count", q5.NewXInt32(1))
params.SetXValue("servicing", q5.NewXInt32(1))
_, err := q5.HttpGet(
"http://192.168.100.45:7821/webapp/index.php?c=GS&a=report&",
params.AsXObject())
fmt.Println(err);
time.Sleep(time.Duration(1) * time.Second)
}
}
func (this *App) addNetMsg(hdr *f5.MsgHdr) {
{
this.msgMutex.Lock()
defer this.msgMutex.Unlock()
this.msgList.AddTail(&hdr.Entry);
}
this.NotifyLoopCond()
}