1
This commit is contained in:
parent
8a6f99576c
commit
a4f7d2747f
@ -24,14 +24,12 @@ type pendingLoginRequest struct {
|
||||
|
||||
type playerMgr struct {
|
||||
cs.MsgHandlerImpl
|
||||
accountIdHash map[string]*player
|
||||
socketHash map[f5.WspCliConn]*player
|
||||
pendingLoginHash map[string]*pendingLoginRequest
|
||||
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)
|
||||
|
||||
@ -79,19 +77,6 @@ func (this *playerMgr) CMLogin(hdr *f5.MsgHdr, msg *cs.CMLogin) {
|
||||
return
|
||||
}
|
||||
}
|
||||
{
|
||||
oldHum := this.internalGetPlayerByAccountId(msg.GetAccountId())
|
||||
if oldHum != nil {
|
||||
rspMsg := cs.SMLogin{}
|
||||
rspMsg.Errcode = proto.Int32(0)
|
||||
rspMsg.Errmsg = proto.String("")
|
||||
rspMsg.ServerInfo = proto.String(mt.Table.MatchCluster.GetServerInfo())
|
||||
oldHum.reBind(hdr.GetSocket())
|
||||
oldHum.SendMsg(&rspMsg)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
reqId := this.genSeqId()
|
||||
pendingReq := this.getPendingRequest(msg.GetAccountId())
|
||||
if pendingReq == nil {
|
||||
@ -176,7 +161,7 @@ func (this *playerMgr) apiAuthCb(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.HttpCli
|
||||
|
||||
hum := new(player)
|
||||
hum.init(pendingReq, rspObj.Info.Name, rspObj.Info.HeadId, rspObj.Info.HeroId, rspObj.Info.HeadFrame)
|
||||
this.accountIdHash[hum.GetAccountId()] = hum
|
||||
//this.accountIdHash[hum.GetAccountId()] = hum
|
||||
this.socketHash[pendingReq.hdr.GetSocket()] = hum
|
||||
|
||||
rspMsg.ServerInfo = proto.String(mt.Table.MatchCluster.GetServerInfo())
|
||||
@ -203,23 +188,6 @@ func (this *playerMgr) reportServerState(masterIp string, masterPort int32) {
|
||||
})
|
||||
}
|
||||
|
||||
func (this *playerMgr) GetPlayerByAccountId(accountId string) common.Player {
|
||||
hum := this.internalGetPlayerByAccountId(accountId)
|
||||
if hum != nil {
|
||||
return hum
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *playerMgr) internalGetPlayerByAccountId(accountId string) *player {
|
||||
player, ok := this.accountIdHash[accountId]
|
||||
if ok {
|
||||
return player
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *playerMgr) GetPlayerBySocket(socket f5.WspCliConn) common.Player {
|
||||
hum := this.internalGetPlayerBySocket(socket)
|
||||
if hum != nil {
|
||||
@ -268,6 +236,7 @@ func (this *playerMgr) SS_WSP_SocketDisconnect(hdr *f5.MsgHdr, msg *ss.SS_WSP_So
|
||||
}
|
||||
|
||||
func (this *playerMgr) CMReconnect(hdr *f5.MsgHdr, msg *cs.CMReconnect) {
|
||||
/*
|
||||
hum := this.internalGetPlayerByAccountId(msg.GetAccountId())
|
||||
rspMsg := &cs.SMReconnect{}
|
||||
if hum == nil {
|
||||
@ -283,7 +252,7 @@ func (this *playerMgr) CMReconnect(hdr *f5.MsgHdr, msg *cs.CMReconnect) {
|
||||
return
|
||||
}
|
||||
hum.reBind(hdr.GetSocket())
|
||||
GetWspListener().SendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
||||
GetWspListener().SendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)*/
|
||||
}
|
||||
|
||||
func (this *playerMgr) onSocketClose(conn f5.WspCliConn) {
|
||||
|
@ -2,83 +2,12 @@ package team
|
||||
|
||||
import (
|
||||
"cs"
|
||||
"f5"
|
||||
"github.com/golang/protobuf/proto"
|
||||
//"main/common"
|
||||
. "main/global"
|
||||
)
|
||||
|
||||
type team struct {
|
||||
cs.MsgHandlerImpl
|
||||
socket f5.WspCliConn
|
||||
accountId string
|
||||
sessionId string
|
||||
zoneId int32
|
||||
nodeId int32
|
||||
name string
|
||||
avatarUrl string
|
||||
heroId string
|
||||
headFrame string
|
||||
ping int32
|
||||
}
|
||||
|
||||
func (this *team) SendMsg(rspMsg proto.Message) {
|
||||
if this.socket.IsValid() {
|
||||
GetWspListener().SendProxyMsg(this.socket.Conn, this.socket.SocketHandle, rspMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *team) init(req *pendingLoginRequest, name string, avatarUrl string, heroId string,
|
||||
headFrame string){
|
||||
this.socket = req.hdr.GetSocket()
|
||||
this.accountId = req.msg.GetAccountId()
|
||||
this.sessionId = req.msg.GetSessionId()
|
||||
this.zoneId = req.msg.GetZoneId()
|
||||
this.nodeId = req.msg.GetNodeId()
|
||||
this.name = name
|
||||
this.avatarUrl = avatarUrl
|
||||
this.heroId = heroId
|
||||
this.headFrame = headFrame
|
||||
}
|
||||
|
||||
func (this *team) onOffline(){
|
||||
this.socket.Reset()
|
||||
}
|
||||
|
||||
func (this *team) reBind(socket f5.WspCliConn) {
|
||||
if this.socket.IsValid() {
|
||||
delete(_teamMgr.socketHash, this.socket)
|
||||
}
|
||||
this.socket = socket
|
||||
_teamMgr.socketHash[this.socket] = this
|
||||
}
|
||||
|
||||
func (this *team) GetAccountId() string {
|
||||
return this.accountId
|
||||
}
|
||||
|
||||
func (this *team) GetSessionId() string {
|
||||
return this.sessionId
|
||||
}
|
||||
|
||||
func (this *team) GetName() string {
|
||||
return this.name
|
||||
}
|
||||
|
||||
func (this *team) GetAvatarUrl() string {
|
||||
return this.avatarUrl
|
||||
}
|
||||
|
||||
func (this *team) GetHeroId() string {
|
||||
return this.heroId
|
||||
}
|
||||
|
||||
func (this *team) GetHeadFrame() string {
|
||||
return this.headFrame
|
||||
}
|
||||
|
||||
func (this *team) GetPing() int32 {
|
||||
return this.ping
|
||||
}
|
||||
|
||||
func (this *team) GetZoneId() int32 {
|
||||
@ -88,17 +17,3 @@ func (this *team) GetZoneId() int32 {
|
||||
func (this *team) GetNodeId() int32 {
|
||||
return this.nodeId
|
||||
}
|
||||
|
||||
func (this *team) IsOnline() bool {
|
||||
return this.socket.IsValid()
|
||||
}
|
||||
|
||||
func (this *team) internalSetPing(ping int32) {
|
||||
if ping < 30 {
|
||||
this.ping = 30
|
||||
} else if ping > 1000 {
|
||||
this.ping = 1000
|
||||
} else {
|
||||
this.ping = ping
|
||||
}
|
||||
}
|
||||
|
@ -2,283 +2,16 @@ package team
|
||||
|
||||
import (
|
||||
"cs"
|
||||
"encoding/json"
|
||||
"f5"
|
||||
"fmt"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"main/common"
|
||||
"main/constant"
|
||||
. "main/global"
|
||||
"mt"
|
||||
"net"
|
||||
"q5"
|
||||
"ss"
|
||||
)
|
||||
|
||||
type pendingLoginRequest struct {
|
||||
hdr *f5.MsgHdr
|
||||
msg *cs.CMLogin
|
||||
addTick int64
|
||||
reqId int64
|
||||
}
|
||||
|
||||
type teamMgr struct {
|
||||
cs.MsgHandlerImpl
|
||||
accountIdHash map[string]*team
|
||||
socketHash map[f5.WspCliConn]*team
|
||||
pendingLoginHash map[string]*pendingLoginRequest
|
||||
currReqId int64
|
||||
teamUuidHash map[string]*team
|
||||
}
|
||||
|
||||
func (this *teamMgr) Init() {
|
||||
this.accountIdHash = make(map[string]*team)
|
||||
this.socketHash = make(map[f5.WspCliConn]*team)
|
||||
this.pendingLoginHash = make(map[string]*pendingLoginRequest)
|
||||
|
||||
f5.GetTimer().SetInterval(
|
||||
1000,
|
||||
func(e int32, args *q5.Args) {
|
||||
if e == q5.TIMER_EXEC_EVENT {
|
||||
mt.Table.MasterCluster.Traverse(
|
||||
func(meta *mt.MasterCluster) bool {
|
||||
this.reportServerState(meta.GetIp(), meta.GetListenPort())
|
||||
return true
|
||||
})
|
||||
}
|
||||
})
|
||||
f5.GetApp().RegisterIMMsgHandle(
|
||||
constant.IM_WSP_CLOSE,
|
||||
func(args q5.Args) {
|
||||
conn := args[0].(net.Conn)
|
||||
deletedTeams := make(map[f5.WspCliConn]*team)
|
||||
for socket, hum := range this.socketHash {
|
||||
if conn == socket.Conn {
|
||||
deletedTeams[socket] = hum
|
||||
}
|
||||
}
|
||||
for socket, _ := range deletedTeams {
|
||||
this.onSocketClose(socket)
|
||||
}
|
||||
})
|
||||
this.teamUuidHash = make(map[string]*team)
|
||||
}
|
||||
|
||||
func (this *teamMgr) UnInit() {
|
||||
}
|
||||
|
||||
func (this *teamMgr) CMLogin(hdr *f5.MsgHdr, msg *cs.CMLogin) {
|
||||
{
|
||||
oldHum := this.internalGetTeamBySocket(hdr.GetSocket())
|
||||
if oldHum != nil {
|
||||
rspMsg := cs.SMLogin{}
|
||||
rspMsg.Errcode = proto.Int32(0)
|
||||
rspMsg.Errmsg = proto.String("")
|
||||
rspMsg.ServerInfo = proto.String(mt.Table.MatchCluster.GetServerInfo())
|
||||
oldHum.reBind(hdr.GetSocket())
|
||||
oldHum.SendMsg(&rspMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
{
|
||||
oldHum := this.internalGetTeamByAccountId(msg.GetAccountId())
|
||||
if oldHum != nil {
|
||||
rspMsg := cs.SMLogin{}
|
||||
rspMsg.Errcode = proto.Int32(0)
|
||||
rspMsg.Errmsg = proto.String("")
|
||||
rspMsg.ServerInfo = proto.String(mt.Table.MatchCluster.GetServerInfo())
|
||||
oldHum.reBind(hdr.GetSocket())
|
||||
oldHum.SendMsg(&rspMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
reqId := this.genSeqId()
|
||||
pendingReq := this.getPendingRequest(msg.GetAccountId())
|
||||
if pendingReq == nil {
|
||||
this.pendingLoginHash[msg.GetAccountId()] = &pendingLoginRequest{
|
||||
hdr: hdr,
|
||||
msg: msg,
|
||||
addTick: q5.GetTickCount(),
|
||||
reqId: *reqId,
|
||||
}
|
||||
} else {
|
||||
if pendingReq.msg.GetAccountId() == msg.GetAccountId() &&
|
||||
pendingReq.msg.GetSessionId() == msg.GetSessionId() {
|
||||
pendingReq.hdr = hdr
|
||||
pendingReq.msg = msg
|
||||
return
|
||||
} else {
|
||||
pendingReq.hdr = hdr
|
||||
pendingReq.msg = msg
|
||||
pendingReq.reqId = *reqId
|
||||
}
|
||||
}
|
||||
params := map[string]string{
|
||||
"c": "User",
|
||||
"a": "info",
|
||||
"account_id": msg.GetAccountId(),
|
||||
"session_id": msg.GetSessionId(),
|
||||
"target_id": msg.GetAccountId(),
|
||||
}
|
||||
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
|
||||
f5.GetHttpCliMgr().SendJsStyleRequest(
|
||||
url,
|
||||
params,
|
||||
func(rsp f5.HttpCliResponse) {
|
||||
this.apiAuthCb(hdr, msg, rsp, reqId)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *teamMgr) apiAuthCb(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.HttpCliResponse, reqId *int64) {
|
||||
pendingReq := this.getPendingRequest(msg.GetAccountId())
|
||||
if pendingReq == nil || pendingReq.reqId != *reqId {
|
||||
return
|
||||
}
|
||||
delete(this.pendingLoginHash, msg.GetAccountId())
|
||||
|
||||
rspMsg := cs.SMLogin{}
|
||||
if rsp.GetErr() != nil {
|
||||
rspMsg.Errcode = proto.Int32(2)
|
||||
rspMsg.Errmsg = proto.String("server internal error")
|
||||
GetWspListener().SendProxyMsg(pendingReq.hdr.Conn, pendingReq.hdr.SocketHandle, &rspMsg)
|
||||
return
|
||||
}
|
||||
rspObj := struct {
|
||||
Errcode int `json:"errcode"`
|
||||
Errmsg string `json:"errmsg"`
|
||||
Info struct {
|
||||
Activated string `json:"activated"`
|
||||
RenameCount string `json:"rename_count"`
|
||||
AccountID string `json:"account_id"`
|
||||
Name string `json:"name"`
|
||||
HeadId string `json:"head_id"`
|
||||
HeroId string `json:"hero_id"`
|
||||
HeadFrame string `json:"head_frame"`
|
||||
} `json:"info"`
|
||||
}{}
|
||||
{
|
||||
err := json.Unmarshal([]byte(rsp.GetRawData()), &rspObj)
|
||||
if err != nil {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("invalid session_id")
|
||||
GetWspListener().SendProxyMsg(pendingReq.hdr.Conn, pendingReq.hdr.SocketHandle, &rspMsg)
|
||||
f5.GetSysLog().Warning("game2006api parse error:%s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if rspObj.Errcode != 0 {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("invalid session_id")
|
||||
GetWspListener().SendProxyMsg(pendingReq.hdr.Conn, pendingReq.hdr.SocketHandle, &rspMsg)
|
||||
f5.GetSysLog().Warning("game2006api login auth errcode:%d", rspObj.Errcode)
|
||||
return
|
||||
}
|
||||
|
||||
hum := new(team)
|
||||
hum.init(pendingReq, rspObj.Info.Name, rspObj.Info.HeadId, rspObj.Info.HeroId, rspObj.Info.HeadFrame)
|
||||
this.accountIdHash[hum.GetAccountId()] = hum
|
||||
this.socketHash[pendingReq.hdr.GetSocket()] = hum
|
||||
|
||||
rspMsg.ServerInfo = proto.String(mt.Table.MatchCluster.GetServerInfo())
|
||||
GetWspListener().SendProxyMsg(hdr.Conn, hdr.SocketHandle, &rspMsg)
|
||||
}
|
||||
|
||||
func (this *teamMgr) reportServerState(masterIp string, masterPort int32) {
|
||||
params := map[string]string{
|
||||
"node_id": q5.ToString(f5.GetApp().GetNodeId()),
|
||||
"instance_id": q5.ToString(f5.GetApp().GetInstanceId()),
|
||||
"ip": mt.Table.MatchCluster.GetIp(),
|
||||
"port": q5.ToString(mt.Table.MatchCluster.GetListenPort()),
|
||||
"online_num": q5.ToString(0),
|
||||
"room_num": q5.ToString(0),
|
||||
"channel": q5.ToString(0),
|
||||
"alive_count": q5.ToString(0),
|
||||
"servicing": q5.ToString(1),
|
||||
}
|
||||
f5.GetHttpCliMgr().SendQuickChannelJsStyleRequest(
|
||||
fmt.Sprintf("http://%s:%d/webapp/index.php?c=GS&a=report&", masterIp, masterPort),
|
||||
params,
|
||||
func(rsp f5.HttpCliResponse) {
|
||||
//f5.GetSysLog().Info(rsp.GetRawData())
|
||||
})
|
||||
}
|
||||
|
||||
func (this *teamMgr) GetTeamByAccountId(accountId string) common.Team {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *teamMgr) internalGetTeamByAccountId(accountId string) *team {
|
||||
team, ok := this.accountIdHash[accountId]
|
||||
if ok {
|
||||
return team
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *teamMgr) GetTeamBySocket(socket f5.WspCliConn) common.Team {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *teamMgr) internalGetTeamBySocket(socket f5.WspCliConn) *team {
|
||||
team, ok := this.socketHash[socket]
|
||||
if ok {
|
||||
return team
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *teamMgr) ProcessCMMsg(handler *cs.CsNetMsgHandler, hdr *f5.MsgHdr) {
|
||||
switch handler.HandlerId {
|
||||
case constant.TEAM_MGR_HANDLER_ID:
|
||||
cs.DispatchMsg(handler, hdr, this)
|
||||
case constant.TEAM_HANDLER_ID:
|
||||
team := this.internalGetTeamBySocket(hdr.GetSocket())
|
||||
if team != nil {
|
||||
cs.DispatchMsg(handler, hdr, team)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *teamMgr) getPendingRequest(accountId string) *pendingLoginRequest {
|
||||
req, ok := this.pendingLoginHash[accountId]
|
||||
if ok {
|
||||
return req
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *teamMgr) genSeqId() *int64 {
|
||||
this.currReqId++
|
||||
reqId := this.currReqId
|
||||
return &reqId
|
||||
}
|
||||
|
||||
func (this *teamMgr) SS_WSP_SocketDisconnect(hdr *f5.MsgHdr, msg *ss.SS_WSP_SocketDisconnect) {
|
||||
this.onSocketClose(hdr.GetSocket())
|
||||
}
|
||||
|
||||
func (this *teamMgr) CMReconnect(hdr *f5.MsgHdr, msg *cs.CMReconnect) {
|
||||
hum := this.internalGetTeamByAccountId(msg.GetAccountId())
|
||||
rspMsg := &cs.SMReconnect{}
|
||||
if hum == nil {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("")
|
||||
GetWspListener().SendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
||||
return
|
||||
}
|
||||
if hum.GetSessionId() != msg.GetSessionId() {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("")
|
||||
GetWspListener().SendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
||||
return
|
||||
}
|
||||
hum.reBind(hdr.GetSocket())
|
||||
GetWspListener().SendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
||||
}
|
||||
|
||||
func (this *teamMgr) onSocketClose(conn f5.WspCliConn) {
|
||||
hum := this.internalGetTeamBySocket(conn)
|
||||
if hum == nil {
|
||||
return
|
||||
}
|
||||
delete(this.socketHash, conn)
|
||||
hum.onOffline()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user