diff --git a/server/statserver/common/types.go b/server/statserver/common/types.go index 0f92f93b..b1b17022 100644 --- a/server/statserver/common/types.go +++ b/server/statserver/common/types.go @@ -9,4 +9,5 @@ type App interface { type SessionMgr interface { UpdateSession(accountId string, sessionId string) + GetOnlineNum() int64 } diff --git a/server/statserver/controller/stat.go b/server/statserver/controller/stat.go index f2397931..553b400f 100644 --- a/server/statserver/controller/stat.go +++ b/server/statserver/controller/stat.go @@ -27,9 +27,11 @@ func (this *Stat) caGetonlineNum(c *gin.Context) { rspObj := struct { ErrCode int32 `json:"errcode"` ErrMsg string `json:"errmsg"` + Num int32 `json:"num"` }{ ErrCode: 0, ErrMsg: "", + Num: int32(GetSessionMgr().GetOnlineNum()), } c.JSON(200, rspObj) } diff --git a/server/statserver/session/sessionmgr.go b/server/statserver/session/sessionmgr.go index bc84ef83..7271279e 100644 --- a/server/statserver/session/sessionmgr.go +++ b/server/statserver/session/sessionmgr.go @@ -115,3 +115,7 @@ func (this *sessionMgr) userOffline(session *userSession) { prop) atomic.AddInt64(&this.onlineNum, -1) } + +func (this *sessionMgr) GetOnlineNum() int64 { + return this.onlineNum +}