This commit is contained in:
aozhiwei 2024-03-11 16:39:08 +08:00
parent 257dde8f10
commit dd868a958f
3 changed files with 41 additions and 5 deletions

View File

@ -14,6 +14,7 @@ type Team interface {
GetTeamUuid() string GetTeamUuid() string
CanJoin(string) bool CanJoin(string) bool
Join(Player) bool Join(Player) bool
GetMemberByAccountId(string) Player
OnPlayerOffline(Player) OnPlayerOffline(Player)
OnPlayerOnline(Player) OnPlayerOnline(Player)
} }
@ -25,6 +26,7 @@ type TeamMgr interface {
} }
type Player interface { type Player interface {
GetSocket() f5.WspCliConn
GetAccountId() string GetAccountId() string
GetSessionId() string GetSessionId() string
GetName() string GetName() string

View File

@ -42,6 +42,23 @@ func (this *player) init(req *pendingLoginRequest, name string, avatarUrl string
this.headFrame = headFrame this.headFrame = headFrame
} }
func (this *player) againInit(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 *player) GetSocket() f5.WspCliConn {
return this.socket
}
func (this *player) onOffline(){ func (this *player) onOffline(){
this.socket.Reset() this.socket.Reset()
} }

View File

@ -193,17 +193,34 @@ func (this *playerMgr) apiAuthCb(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.HttpCli
GetWspListener().SendProxyMsg(pendingReq.hdr.Conn, pendingReq.hdr.SocketHandle, &rspMsg) GetWspListener().SendProxyMsg(pendingReq.hdr.Conn, pendingReq.hdr.SocketHandle, &rspMsg)
return return
} }
member := team.GetMemberByAccountId(msg.GetAccountId())
if !team.CanJoin(msg.GetAccountId()) { if !team.CanJoin(msg.GetAccountId()) {
rspMsg.Errcode = proto.Int32(103) rspMsg.Errcode = proto.Int32(103)
rspMsg.Errmsg = proto.String("join team error") rspMsg.Errmsg = proto.String("join team error")
GetWspListener().SendProxyMsg(pendingReq.hdr.Conn, pendingReq.hdr.SocketHandle, &rspMsg) GetWspListener().SendProxyMsg(pendingReq.hdr.Conn, pendingReq.hdr.SocketHandle, &rspMsg)
return return
} }
if member != nil {
hum := new(player) hum := member.(*player)
hum.init(pendingReq, rspObj.Info.Name, rspObj.Info.HeadId, rspObj.Info.HeroId, rspObj.Info.HeadFrame) if hum.socket.IsValid() {
this.socketHash[pendingReq.hdr.GetSocket()] = hum delete(this.socketHash, hum.socket)
team.Join(hum) }
hum.againInit(pendingReq,
rspObj.Info.Name,
rspObj.Info.HeadId,
rspObj.Info.HeroId,
rspObj.Info.HeadFrame)
this.socketHash[pendingReq.hdr.GetSocket()] = hum
} else {
hum := new(player)
hum.init(pendingReq,
rspObj.Info.Name,
rspObj.Info.HeadId,
rspObj.Info.HeroId,
rspObj.Info.HeadFrame)
this.socketHash[pendingReq.hdr.GetSocket()] = hum
team.Join(hum)
}
rspMsg.TeamUuid = proto.String(team.GetTeamUuid()) rspMsg.TeamUuid = proto.String(team.GetTeamUuid())
rspMsg.ServerInfo = proto.String(mt.Table.MatchCluster.GetServerInfo()) rspMsg.ServerInfo = proto.String(mt.Table.MatchCluster.GetServerInfo())