572 lines
15 KiB
Go
572 lines
15 KiB
Go
package player
|
|
|
|
import (
|
|
"cs"
|
|
"q5"
|
|
"f5"
|
|
"github.com/golang/protobuf/proto"
|
|
"main/common"
|
|
. "main/global"
|
|
"fmt"
|
|
"encoding/json"
|
|
"main/mt"
|
|
)
|
|
|
|
type hero struct {
|
|
heroUniId string
|
|
heroId int32
|
|
quality int32
|
|
specSkill int32
|
|
wealth int32
|
|
validLeftTime int32
|
|
currentTimes int32
|
|
totalTimes int32
|
|
skinId int32
|
|
}
|
|
|
|
type player struct {
|
|
cs.MsgHandlerImpl
|
|
socket f5.WspCliConn
|
|
accountId string
|
|
sessionId string
|
|
zoneId int32
|
|
nodeId int32
|
|
name string
|
|
avatarUrl string
|
|
headFrame string
|
|
state int32
|
|
isReady int32
|
|
permission int32
|
|
admissionItemNum int32
|
|
circuitScore int32
|
|
totalLucky int64
|
|
hero hero
|
|
team common.Team
|
|
battling bool
|
|
sortIdx int32
|
|
}
|
|
|
|
func (this *player) SendMsg(rspMsg proto.Message) {
|
|
if this.socket.IsValid() {
|
|
GetWspListener().SendProxyMsg(this.socket.Conn, this.socket.SocketHandle, rspMsg)
|
|
}
|
|
}
|
|
|
|
func (this *player) parseUserInfo(userInfo *common.UserInfo){
|
|
this.name = userInfo.Name
|
|
this.avatarUrl = userInfo.HeadId
|
|
this.headFrame = userInfo.HeadFrame
|
|
q5.DuckToSimple(userInfo.TotalLucky, &this.totalLucky)
|
|
q5.DuckToSimple(userInfo.AdmissionItemNum, &this.admissionItemNum)
|
|
q5.DuckToSimple(userInfo.CircuitScore, &this.circuitScore)
|
|
}
|
|
|
|
func (this *player) parseHeroInfo(heroInfo *common.HeroInfo){
|
|
this.hero.heroUniId = heroInfo.HeroUniId
|
|
this.hero.heroId = q5.ToInt32(heroInfo.HeroId)
|
|
this.hero.quality = q5.ToInt32(heroInfo.Quality)
|
|
this.hero.specSkill = q5.ToInt32(heroInfo.SpecSkill)
|
|
q5.DuckToSimple(heroInfo.Wealth, &this.hero.wealth)
|
|
q5.DuckToSimple(heroInfo.ValidLefttime, &this.hero.validLeftTime)
|
|
q5.DuckToSimple(heroInfo.CurrentTimes, &this.hero.currentTimes)
|
|
q5.DuckToSimple(heroInfo.TotalTimes, &this.hero.totalTimes)
|
|
q5.DuckToSimple(heroInfo.SkinId, &this.hero.skinId)
|
|
}
|
|
|
|
func (this *player) init(req *pendingLoginRequest, rsp *common.LoginRsp){
|
|
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.parseUserInfo(&rsp.Info.UserInfo)
|
|
this.parseHeroInfo(&rsp.Info.HeroInfo)
|
|
}
|
|
|
|
func (this *player) againInit(req *pendingLoginRequest, rsp *common.LoginRsp){
|
|
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.parseUserInfo(&rsp.Info.UserInfo)
|
|
this.parseHeroInfo(&rsp.Info.HeroInfo)
|
|
}
|
|
|
|
func (this *player) GetSocket() f5.WspCliConn {
|
|
return this.socket
|
|
}
|
|
|
|
func (this *player) onOffline(){
|
|
this.socket.Reset()
|
|
this.GetTeam().Leave(this)
|
|
}
|
|
|
|
func (this *player) reBind(socket f5.WspCliConn, sessionId string) {
|
|
if this.socket.IsValid() {
|
|
delete(_playerMgr.socketHash, this.socket)
|
|
}
|
|
this.socket = socket
|
|
this.sessionId = sessionId
|
|
_playerMgr.socketHash[this.socket] = this
|
|
}
|
|
|
|
func (this *player) GetAccountId() string {
|
|
return this.accountId
|
|
}
|
|
|
|
func (this *player) GetSessionId() string {
|
|
return this.sessionId
|
|
}
|
|
|
|
func (this *player) GetName() string {
|
|
return this.name
|
|
}
|
|
|
|
func (this *player) GetAvatarUrl() string {
|
|
return this.avatarUrl
|
|
}
|
|
|
|
func (this *player) GetHeadFrame() string {
|
|
return this.headFrame
|
|
}
|
|
|
|
func (this *player) GetZoneId() int32 {
|
|
return this.zoneId
|
|
}
|
|
|
|
func (this *player) GetNodeId() int32 {
|
|
return this.nodeId
|
|
}
|
|
|
|
func (this *player) IsOnline() bool {
|
|
return this.socket.IsValid()
|
|
}
|
|
|
|
func (this *player) IsReady() bool {
|
|
return this.isReady != 0
|
|
}
|
|
|
|
func (this *player) GetSpecSkill() int32 {
|
|
return this.hero.specSkill
|
|
}
|
|
|
|
func (this *player) GetHeroUniid() string {
|
|
return this.hero.heroUniId
|
|
}
|
|
|
|
func (this *player) GetPermission() int32 {
|
|
return this.permission
|
|
}
|
|
|
|
func (this *player) SetPermission(permission int32) {
|
|
this.permission = permission
|
|
}
|
|
|
|
func (this *player) GetTeam() common.Team {
|
|
return this.team
|
|
}
|
|
|
|
func (this *player) SetTeam(team common.Team) {
|
|
this.team = team
|
|
}
|
|
|
|
func (this *player) GetSortIdx() int32 {
|
|
return this.sortIdx
|
|
}
|
|
|
|
func (this *player) SetSortIdx(sortIdx int32) {
|
|
this.sortIdx = sortIdx
|
|
}
|
|
|
|
func (this *player) GenNextCopy() common.Player {
|
|
nextCopy := newPlayer()
|
|
//nextCopy.socket
|
|
nextCopy.accountId = this.accountId
|
|
nextCopy.sessionId = this.sessionId
|
|
nextCopy.zoneId = this.zoneId
|
|
nextCopy.nodeId = this.nodeId
|
|
nextCopy.name = this.name
|
|
nextCopy.avatarUrl = this.avatarUrl
|
|
nextCopy.headFrame = this.headFrame
|
|
nextCopy.state = 0
|
|
nextCopy.isReady = 0
|
|
nextCopy.permission = 0
|
|
nextCopy.hero = this.hero
|
|
nextCopy.team = nil
|
|
nextCopy.sortIdx = 0
|
|
return nextCopy
|
|
}
|
|
|
|
func (this *player) FillMFTeamMember(member_pb *cs.MFTeamMember) {
|
|
member_pb.AccountId = proto.String(this.accountId)
|
|
member_pb.Name = proto.String(this.name)
|
|
member_pb.Id = proto.Int32(this.sortIdx)
|
|
if this.GetTeam().IsLeader(this) {
|
|
member_pb.IsLeader = proto.Int32(1)
|
|
} else {
|
|
member_pb.IsLeader = proto.Int32(0)
|
|
}
|
|
member_pb.SpecSkill = proto.Int32(this.hero.specSkill)
|
|
{
|
|
member_pb.Hero = &cs.MFHero{}
|
|
member_pb.Hero.HeroId = proto.Int32(this.hero.heroId)
|
|
member_pb.Hero.Quality = proto.Int32(this.hero.quality)
|
|
member_pb.Hero.CurrentTimes = proto.Int32(this.hero.currentTimes)
|
|
member_pb.Hero.TotalTimes = proto.Int32(this.hero.totalTimes)
|
|
member_pb.Hero.SkinId = proto.Int32(this.hero.skinId)
|
|
}
|
|
member_pb.State = proto.Int32(this.state)
|
|
if this.IsOnline() {
|
|
member_pb.Online = proto.Int32(1)
|
|
} else {
|
|
member_pb.Online = proto.Int32(0)
|
|
}
|
|
member_pb.Permission = proto.Int32(this.permission)
|
|
member_pb.IsReady = proto.Int32(this.isReady)
|
|
member_pb.Wealth = proto.Int32(this.hero.wealth)
|
|
member_pb.TotalLucky = proto.Int64(this.totalLucky)
|
|
member_pb.ValidLefttime = proto.Int32(this.hero.validLeftTime)
|
|
member_pb.AdmissionItemNum = proto.Int32(this.admissionItemNum)
|
|
member_pb.CircuitScore = proto.Int32(this.circuitScore)
|
|
}
|
|
|
|
func (this *player) CMLeaveTeam(hdr *f5.MsgHdr, msg *cs.CMLeaveTeam) {
|
|
rspMsg := &cs.SMLeaveTeam{}
|
|
team := this.GetTeam()
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
} else {
|
|
this.GetTeam().Leave(this)
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
if team.GetMemberNum() > 0 {
|
|
team.SendUpdateNotify()
|
|
}
|
|
}
|
|
|
|
func (this *player) CMDisbandTeam(hdr *f5.MsgHdr, msg *cs.CMDisbandTeam) {
|
|
rspMsg := &cs.SMDisbandTeam{}
|
|
team := this.GetTeam()
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
} else {
|
|
this.GetTeam().Disband()
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
team.SendUpdateNotify()
|
|
}
|
|
|
|
func (this *player) CMKickOut(hdr *f5.MsgHdr, msg *cs.CMKickOut) {
|
|
rspMsg := &cs.SMKickOut{}
|
|
team := this.GetTeam()
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
} else {
|
|
this.GetTeam().KickOut(this, msg.GetTargetId())
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
team.SendUpdateNotify()
|
|
}
|
|
|
|
func (this *player) CMHandoverLeader(hdr *f5.MsgHdr, msg *cs.CMHandoverLeader) {
|
|
rspMsg := &cs.SMHandoverLeader{}
|
|
team := this.GetTeam()
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
} else {
|
|
this.GetTeam().HandoverLeader(this, msg.GetTargetId())
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
team.SendUpdateNotify()
|
|
}
|
|
|
|
func (this *player) CMStartGame(hdr *f5.MsgHdr, msg *cs.CMStartGame) {
|
|
rspMsg := &cs.SMStartGame{}
|
|
if !this.GetTeam().IsLock() {
|
|
if this.GetTeam().CanStartGame(this) {
|
|
if GetHistoryMgr().CanStart(this.GetAccountId(),
|
|
this.GetTeam().GetMapId(),
|
|
this.GetTeam().GetModeId()) {
|
|
this.GetTeam().StartGame()
|
|
}
|
|
}
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
|
|
func (this *player) CMCancel(hdr *f5.MsgHdr, msg *cs.CMCancel) {
|
|
rspMsg := &cs.SMCancel{}
|
|
if this.GetTeam().Started() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
} else {
|
|
this.GetTeam().CancelMatch()
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
this.GetTeam().SendUpdateNotify()
|
|
this.GetTeam().SendStateNotify()
|
|
}
|
|
|
|
func (this *player) CMSetReady(hdr *f5.MsgHdr, msg *cs.CMSetReady) {
|
|
rspMsg := &cs.SMSetReady{}
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
} else {
|
|
if msg.GetIsReady() != 0 {
|
|
this.isReady = 1
|
|
} else {
|
|
this.isReady = 0
|
|
}
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
this.GetTeam().SendUpdateNotify()
|
|
}
|
|
|
|
func (this *player) CMSetSpecSkill(hdr *f5.MsgHdr, msg *cs.CMSetSpecSkill) {
|
|
rspMsg := &cs.SMSetSpecSkill{}
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
return
|
|
} else {
|
|
this.updateChoose(
|
|
msg.GetSkillId(),
|
|
this.hero.heroUniId,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode == 0 {
|
|
this.SendMsg(rspMsg)
|
|
if this.GetTeam() != nil {
|
|
this.GetTeam().SendUpdateNotify()
|
|
}
|
|
} else {
|
|
rspMsg.Errcode = proto.Int32(2)
|
|
rspMsg.Errmsg = proto.String("server internal error")
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func (this *player) CMChooseHero(hdr *f5.MsgHdr, msg *cs.CMChooseHero) {
|
|
rspMsg := &cs.SMChooseHero{}
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
} else {
|
|
this.updateChoose(
|
|
this.hero.specSkill,
|
|
msg.GetHeroUniid(),
|
|
func (errCode int32, errMsg string) {
|
|
if errCode == 0 {
|
|
this.SendMsg(rspMsg)
|
|
if this.GetTeam() != nil {
|
|
this.GetTeam().SendUpdateNotify()
|
|
}
|
|
} else {
|
|
rspMsg.Errcode = proto.Int32(2)
|
|
rspMsg.Errmsg = proto.String("server internal error")
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func (this *player) CMChooseMap(hdr *f5.MsgHdr, msg *cs.CMChooseMap) {
|
|
rspMsg := &cs.SMChooseMap{}
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
this.SendMsg(rspMsg)
|
|
} else {
|
|
this.updateMap(
|
|
msg.GetModeId(),
|
|
msg.GetMapId(),
|
|
func (errCode int32, errMsg string) {
|
|
if errCode == 0 {
|
|
this.SendMsg(rspMsg)
|
|
if this.GetTeam() != nil {
|
|
this.GetTeam().SendUpdateNotify()
|
|
}
|
|
} else {
|
|
rspMsg.Errcode = proto.Int32(errCode)
|
|
rspMsg.Errmsg = proto.String(errMsg)
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func (this *player) CMRefreshUser(hdr *f5.MsgHdr, msg *cs.CMRefreshUser) {
|
|
rspMsg := new(cs.SMRefreshUser)
|
|
params := map[string]string{
|
|
"c": "User",
|
|
"a": "getBattleUser",
|
|
"account_id": this.GetAccountId(),
|
|
"session_id": this.GetSessionId(),
|
|
}
|
|
rspObj := common.UserRsp{}
|
|
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
|
|
f5.GetHttpCliMgr().SendJsStyleJsonRspRequest(
|
|
url,
|
|
params,
|
|
&rspObj,
|
|
func(rsp f5.HttpCliResponse) {
|
|
this.SendMsg(rspMsg)
|
|
if rsp.GetErr() == nil && rsp.JsonParseOk() {
|
|
this.parseUserInfo(&rspObj.Info.UserInfo)
|
|
this.parseHeroInfo(&rspObj.Info.HeroInfo)
|
|
if this.GetTeam() != nil {
|
|
this.GetTeam().SendUpdateNotify()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) updateChoose(skillId int32, heroUniId string,
|
|
cb func (int32, string)) {
|
|
params := map[string]string{
|
|
"c": "User",
|
|
"a": "updateBattleInfo",
|
|
"account_id": this.accountId,
|
|
"session_id": this.sessionId,
|
|
"skill_id": q5.ToString(skillId),
|
|
"hero_uniid": heroUniId,
|
|
}
|
|
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
|
|
f5.GetHttpCliMgr().SendJsStyleRequest(
|
|
url,
|
|
params,
|
|
func(rsp f5.HttpCliResponse) {
|
|
if this.GetTeam() != nil && !this.GetTeam().IsLock() {
|
|
if rsp.GetErr() != nil {
|
|
cb(500, "server internal error")
|
|
return
|
|
}
|
|
}
|
|
rspObj := common.UpdateBattleInfoRsp{}
|
|
{
|
|
f5.GetSysLog().Info("updateBattleinfo:%s", rsp.GetRawData())
|
|
err := json.Unmarshal([]byte(rsp.GetRawData()), &rspObj)
|
|
if err != nil {
|
|
cb(500, "server internal error")
|
|
return
|
|
}
|
|
{
|
|
this.name = rspObj.Info.UserInfo.Name
|
|
this.avatarUrl = rspObj.Info.UserInfo.HeadId
|
|
this.headFrame = rspObj.Info.UserInfo.HeadFrame
|
|
q5.DuckToSimple(rspObj.Info.UserInfo.AdmissionItemNum, &this.admissionItemNum)
|
|
q5.DuckToSimple(rspObj.Info.UserInfo.CircuitScore, &this.circuitScore)
|
|
q5.DuckToSimple(rspObj.Info.UserInfo.TotalLucky, &this.totalLucky)
|
|
{
|
|
this.hero.heroUniId = rspObj.Info.HeroInfo.HeroUniId
|
|
this.hero.heroId = q5.ToInt32(rspObj.Info.HeroInfo.HeroId)
|
|
this.hero.quality = q5.ToInt32(rspObj.Info.HeroInfo.Quality)
|
|
this.hero.specSkill = q5.ToInt32(rspObj.Info.HeroInfo.SpecSkill)
|
|
q5.DuckToSimple(rspObj.Info.HeroInfo.Wealth, &this.hero.wealth)
|
|
q5.DuckToSimple(rspObj.Info.HeroInfo.ValidLefttime, &this.hero.validLeftTime)
|
|
q5.DuckToSimple(rspObj.Info.HeroInfo.CurrentTimes, &this.hero.currentTimes)
|
|
q5.DuckToSimple(rspObj.Info.HeroInfo.TotalTimes, &this.hero.totalTimes)
|
|
q5.DuckToSimple(rspObj.Info.HeroInfo.SkinId, &this.hero.skinId)
|
|
}
|
|
cb(0, "")
|
|
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) updateMap(modeId int32, mapId int32,
|
|
cb func (int32, string)) {
|
|
params := map[string]string{
|
|
"c": "User",
|
|
"a": "getMapConf",
|
|
"account_id": this.accountId,
|
|
"session_id": this.sessionId,
|
|
"mode_id": q5.ToString(modeId),
|
|
"map_id": q5.ToString(mapId),
|
|
}
|
|
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
|
|
f5.GetHttpCliMgr().SendJsStyleRequest(
|
|
url,
|
|
params,
|
|
func(rsp f5.HttpCliResponse) {
|
|
if this.GetTeam() != nil && !this.GetTeam().IsLock() {
|
|
if rsp.GetErr() != nil {
|
|
cb(500, "server internal error")
|
|
return
|
|
}
|
|
}
|
|
rspObj := common.MapInfoRsp{}
|
|
{
|
|
f5.GetSysLog().Info("updateMap:%s", rsp.GetRawData())
|
|
err := json.Unmarshal([]byte(rsp.GetRawData()), &rspObj)
|
|
if err != nil {
|
|
cb(500, "server internal error")
|
|
return
|
|
}
|
|
if rspObj.MapId == 0 {
|
|
cb(1, "map error")
|
|
return
|
|
}
|
|
if rspObj.IsOpen == 0 {
|
|
cb(2, "map no open")
|
|
return
|
|
}
|
|
{
|
|
this.GetTeam().SetMapInfo(&rspObj)
|
|
cb(0, "")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) CMGrantInvitePermission(hdr *f5.MsgHdr, msg *cs.CMGrantInvitePermission) {
|
|
rspMsg := &cs.SMGrantInvitePermission{}
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
} else {
|
|
target := this.GetTeam().GetMemberByAccountId(msg.GetTargetId())
|
|
if target != nil {
|
|
target.(*player).permission = 1
|
|
}
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
this.GetTeam().SendUpdateNotify()
|
|
}
|
|
|
|
func (this *player) CMChooseBattleItem(hdr *f5.MsgHdr, msg *cs.CMChooseBattleItem) {
|
|
rspMsg := &cs.SMChooseBattleItem{}
|
|
if this.GetTeam().IsLock() {
|
|
rspMsg.Errcode = proto.Int32(1)
|
|
rspMsg.Errmsg = proto.String("team already started")
|
|
} else {
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
this.GetTeam().SendUpdateNotify()
|
|
}
|
|
|
|
func (this *player) IsBattling() bool {
|
|
return this.battling
|
|
}
|
|
|
|
func (this *player) SetBattling(state bool) {
|
|
this.battling = state
|
|
}
|
|
|
|
func newPlayer() *player {
|
|
hum := new(player)
|
|
return hum
|
|
}
|