1
This commit is contained in:
parent
121f61ffd1
commit
e35c14933d
@ -1,5 +0,0 @@
|
||||
package ca
|
||||
|
||||
type RouterGroup struct {
|
||||
StatRouter
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package ca
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"main/api/ca"
|
||||
)
|
||||
|
||||
type StatRouter struct{}
|
||||
|
||||
func (this *StatRouter) InitStatRouter() {
|
||||
f5.GetApp().RegisterCaHandle("Stat", "updateSession", ca.ApiGroupApp.UpdateSession)
|
||||
f5.GetApp().RegisterCaHandle("Ops", "getOnlineNum", ca.ApiGroupApp.GetOnlineNum)
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"main/constant"
|
||||
"main/global"
|
||||
)
|
||||
|
||||
var _routerMgr = new(routerMgr)
|
||||
|
||||
func init() {
|
||||
global.RegModule(constant.ROUTER_MGR_MODULE_IDX, _routerMgr)
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"main/router/ca"
|
||||
)
|
||||
|
||||
type routerMgr struct {
|
||||
ca ca.RouterGroup
|
||||
}
|
||||
|
||||
func (this *routerMgr) Init() {
|
||||
/*
|
||||
f5.GetApp().GetGinEngine().Use(middleware.Cors())
|
||||
*/
|
||||
this.ca.InitGameLogRouter()
|
||||
f5.GetSysLog().Info("routerMgr.init")
|
||||
|
||||
}
|
||||
|
||||
func (this *routerMgr) UnInit() {
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"main/constant"
|
||||
"main/global"
|
||||
)
|
||||
|
||||
var _sessionMgr = new (sessionMgr)
|
||||
|
||||
func init() {
|
||||
global.RegModule(constant.SESSION_MGR_MODULE_IDX, _sessionMgr)
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"q5"
|
||||
"f5"
|
||||
"time"
|
||||
"sync"
|
||||
"main/mt"
|
||||
)
|
||||
|
||||
type userSession struct {
|
||||
accountId string
|
||||
sessionId string
|
||||
lastUpdateTime int64
|
||||
timerWp *q5.XTimerWp
|
||||
onlineNum int64
|
||||
}
|
||||
|
||||
type sessionMgr struct {
|
||||
idHash sync.Map
|
||||
lock sync.Mutex
|
||||
timer *q5.XTimer
|
||||
}
|
||||
|
||||
func (this *sessionMgr) Init() {
|
||||
this.timer = new(q5.XTimer)
|
||||
this.timer.Init(
|
||||
func (context interface{}) int64 {
|
||||
return f5.GetApp().GetRealSeconds()
|
||||
},
|
||||
this,
|
||||
60,
|
||||
10000)
|
||||
go this.updateTimer()
|
||||
}
|
||||
|
||||
func (this *sessionMgr) UnInit() {
|
||||
}
|
||||
|
||||
func (this *sessionMgr) UpdateSession(accountId string, sessionId string) {
|
||||
session := this.getSession(accountId)
|
||||
if session != nil {
|
||||
session.lastUpdateTime = f5.GetApp().GetRealSeconds()
|
||||
return
|
||||
}
|
||||
defer this.lock.Unlock()
|
||||
this.lock.Lock()
|
||||
session = this.getSession(accountId)
|
||||
if session != nil {
|
||||
session.lastUpdateTime = f5.GetApp().GetRealSeconds()
|
||||
} else {
|
||||
session = new(userSession)
|
||||
session.accountId = accountId
|
||||
session.sessionId = sessionId
|
||||
session.lastUpdateTime = f5.GetApp().GetRealSeconds()
|
||||
this.idHash.Store(accountId, session)
|
||||
this.userOnline(session)
|
||||
session.timerWp = this.timer.SetTimeoutWp(
|
||||
mt.Table.Config.GetSessionExpireTime(),
|
||||
func (e int32, args *q5.Args) {
|
||||
if e == q5.TIMER_EXEC_EVENT {
|
||||
nowTime := f5.GetApp().GetRealSeconds()
|
||||
if nowTime - session.lastUpdateTime >= mt.Table.Config.GetSessionExpireTime() {
|
||||
this.idHash.Delete(session.accountId)
|
||||
this.timer.DeleteRunningTimer()
|
||||
this.userOffline(session)
|
||||
} else {
|
||||
this.timer.ModifyTimer(session.timerWp, 10)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (this *sessionMgr) getSession(accountId string) *userSession {
|
||||
if p, ok := this.idHash.Load(accountId); ok {
|
||||
return p.(*userSession)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *sessionMgr) updateTimer() {
|
||||
for true {
|
||||
this.lock.Lock()
|
||||
this.timer.Update()
|
||||
this.lock.Unlock()
|
||||
time.Sleep(1 * time.Second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (this *sessionMgr) userOnline(session *userSession) {
|
||||
prop := map[string]string{}
|
||||
prop["gameid"] = q5.ToString(constant.GAME_ID)
|
||||
f5.GetTgLog().AddTrackLog(
|
||||
constant.GAME_ID,
|
||||
session.accountId,
|
||||
"", //distance_id
|
||||
"", //ip
|
||||
"user_online",
|
||||
prop)
|
||||
atomic.AddInt64(&this.onlineNum, 1)
|
||||
}
|
||||
|
||||
func (this *sessionMgr) userOffline(session *userSession) {
|
||||
prop := map[string]string{}
|
||||
prop["gameid"] = q5.ToString(constant.GAME_ID)
|
||||
f5.GetTgLog().AddTrackLog(
|
||||
constant.GAME_ID,
|
||||
session.accountId,
|
||||
"", //distance_id
|
||||
"", //ip
|
||||
"user_offline",
|
||||
prop)
|
||||
atomic.AddInt64(&this.onlineNum, -1)
|
||||
}
|
||||
|
||||
func (this *sessionMgr) GetOnlineNum() int64 {
|
||||
return this.onlineNum
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user