87 lines
1.8 KiB
Go
87 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
"fmt"
|
|
"sync"
|
|
|
|
"q5"
|
|
"f5"
|
|
"cs"
|
|
)
|
|
|
|
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)
|
|
WSPListener.Init()
|
|
go this.goReportServerState();
|
|
}
|
|
|
|
func (this *App_) 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().(*q5.MsgHdr)
|
|
if ok {
|
|
handlerId := cs.GetMsgHandlerId(hdr.MsgId)
|
|
if handlerId == PLAYER_MGR_HANDLER_ID {
|
|
cs.DispatchMsg(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 *q5.MsgHdr) {
|
|
{
|
|
this.msgMutex.Lock()
|
|
defer this.msgMutex.Unlock()
|
|
this.msgList.AddTail(&hdr.Entry);
|
|
}
|
|
this.NotifyLoopCond()
|
|
}
|