1
This commit is contained in:
parent
6f783f4197
commit
55f4219e3b
@ -13,6 +13,12 @@ import (
|
||||
. "main/global"
|
||||
)
|
||||
|
||||
type SocketCloseEventHandle struct {
|
||||
entry q5.ListHead
|
||||
cb func()
|
||||
deleted bool
|
||||
}
|
||||
|
||||
type pendingLoginRequest struct {
|
||||
hdr *f5.MsgHdr
|
||||
msg *cs.CMLogin
|
||||
@ -25,12 +31,15 @@ type playerMgr struct {
|
||||
accountIdHash map[string]*player
|
||||
socketHash map[f5.WspCliConn]*player
|
||||
pendingLoginHash map[string]*pendingLoginRequest
|
||||
socketCloseEventHash map[f5.WspCliConn]*q5.ListHead
|
||||
currReqId int64
|
||||
}
|
||||
|
||||
func (this *playerMgr) init() {
|
||||
this.accountIdHash = make(map[string]*player)
|
||||
this.socketHash = make(map[f5.WspCliConn]*player)
|
||||
this.pendingLoginHash = make(map[string]*pendingLoginRequest)
|
||||
this.socketCloseEventHash = make(map[f5.WspCliConn]*q5.ListHead)
|
||||
|
||||
f5.GetTimer().SetInterval(
|
||||
1000,
|
||||
@ -118,13 +127,18 @@ func (this *playerMgr) CMLogin(hdr *f5.MsgHdr, msg *cs.CMLogin) {
|
||||
}
|
||||
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
|
||||
rspObj := &common.LoginRsp{}
|
||||
f5.GetHttpCliMgr().SendJsStyleJsonRspRequest(
|
||||
var evHandle **SocketCloseEventHandle;
|
||||
handle := f5.GetHttpCliMgr().SendJsStyleJsonRspRequest(
|
||||
url,
|
||||
params,
|
||||
&rspObj,
|
||||
func(rsp f5.HttpCliResponse) {
|
||||
this.RemoveSocketCloseEvent(*evHandle)
|
||||
this.apiAuthCb(hdr, msg, reqId, rsp, rspObj)
|
||||
})
|
||||
*evHandle = this.AddSocketCloseEvent(hdr.GetSocket(), func() {
|
||||
handle.Cancel()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *playerMgr) apiAuthCb(hdr *f5.MsgHdr, msg *cs.CMLogin, reqId int64,
|
||||
@ -280,6 +294,18 @@ func (this *playerMgr) CMReconnect(hdr *f5.MsgHdr, msg *cs.CMReconnect) {
|
||||
}
|
||||
|
||||
func (this *playerMgr) OnSocketClose(conn f5.WspCliConn) {
|
||||
{
|
||||
l, ok := this.socketCloseEventHash[conn]
|
||||
if ok {
|
||||
for !l.Empty() {
|
||||
handle := l.FirstEntry().(*SocketCloseEventHandle)
|
||||
handle.cb()
|
||||
if !handle.deleted {
|
||||
this.RemoveSocketCloseEvent(handle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
hum := this.internalGetPlayerBySocket(conn)
|
||||
if hum == nil {
|
||||
return
|
||||
@ -287,3 +313,25 @@ func (this *playerMgr) OnSocketClose(conn f5.WspCliConn) {
|
||||
delete(this.socketHash, conn)
|
||||
hum.onOffline()
|
||||
}
|
||||
|
||||
func (this *playerMgr) AddSocketCloseEvent(conn f5.WspCliConn, cb func()) *SocketCloseEventHandle {
|
||||
evHandle := &SocketCloseEventHandle{}
|
||||
evHandle.entry.Init(evHandle)
|
||||
evHandle.cb = cb
|
||||
l, ok := this.socketCloseEventHash[conn]
|
||||
if !ok {
|
||||
l = q5.NewListHead()
|
||||
this.socketCloseEventHash[conn] = l
|
||||
}
|
||||
l.AddTail(&evHandle.entry)
|
||||
return evHandle
|
||||
}
|
||||
|
||||
func (this *playerMgr) RemoveSocketCloseEvent(evHandle *SocketCloseEventHandle) {
|
||||
if !evHandle.deleted {
|
||||
evHandle.entry.DelInit()
|
||||
evHandle.deleted = true
|
||||
} else {
|
||||
panic("RemoveSocketCloseEvent error")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user