玩家上下分修改
This commit is contained in:
parent
8160786ac0
commit
e4fcf367d6
|
@ -26,6 +26,7 @@ import (
|
|||
var PlayerMgrSington = &PlayerMgr{
|
||||
sidMap: make(map[int64]*Player),
|
||||
snidMap: make(map[int32]*Player),
|
||||
usernameMap: make(map[string]*Player),
|
||||
accountMap: make(map[string]*Player),
|
||||
players: make([]*Player, 0, 1024),
|
||||
playerOfPlatform: make(map[string]map[int32]*Player),
|
||||
|
@ -45,6 +46,9 @@ type PlayerMgr struct {
|
|||
snidMap map[int32]*Player
|
||||
// 以账号为索引
|
||||
accountMap map[string]*Player
|
||||
// 以username为索引
|
||||
usernameMap map[string]*Player
|
||||
|
||||
// 只有真实玩家,不包括机器人
|
||||
players []*Player
|
||||
// 平台id:snid:真实玩家
|
||||
|
@ -113,6 +117,7 @@ func (this *PlayerMgr) AddPlayer(sid int64, playerInfo *model.PlayerData, s *net
|
|||
}
|
||||
this.snidMap[player.SnId] = player
|
||||
this.accountMap[player.AccountId] = player
|
||||
this.usernameMap[player.Username] = player
|
||||
|
||||
if !player.IsRob {
|
||||
var found bool
|
||||
|
@ -217,6 +222,8 @@ func (this *PlayerMgr) DelPlayer(snid int32) bool {
|
|||
}
|
||||
delete(this.snidMap, player.SnId)
|
||||
delete(this.accountMap, player.AccountId)
|
||||
delete(this.usernameMap, player.Username)
|
||||
|
||||
if !player.IsRob {
|
||||
index := -1
|
||||
for i, p := range this.players {
|
||||
|
@ -328,6 +335,13 @@ func (this *PlayerMgr) GetPlayerByAccount(acc string) *Player {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (this *PlayerMgr) GetPlayerByUsername(username string) *Player {
|
||||
if p, ok := this.usernameMap[username]; ok {
|
||||
return p
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// BroadcastMessage 给所有玩家发消息
|
||||
func (this *PlayerMgr) BroadcastMessage(packetid int, rawpack interface{}) bool {
|
||||
sc := &srvproto.BCSessionUnion{}
|
||||
|
|
|
@ -2967,10 +2967,12 @@ func init() {
|
|||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/platform/upscore", WebAPIHandlerWrapper(
|
||||
func(tNode *transact.TransNode, params []byte) (int, interface{}) {
|
||||
|
||||
var jsonDataRsp []byte
|
||||
var msg *webapi.PlatfromUpScoreReq
|
||||
err := json.Unmarshal(params, &msg)
|
||||
if err != nil {
|
||||
logger.Logger.Error("Unmarshal webapi.PlatfromUpScoreReq error:", err)
|
||||
return common.ResponseTag_ParamError, jsonDataRsp
|
||||
}
|
||||
|
||||
logger.Logger.Tracef("/api/platform/upscore upScoreReqInfo%v", msg)
|
||||
|
@ -2980,33 +2982,27 @@ func init() {
|
|||
Message: "未知错误",
|
||||
}
|
||||
|
||||
var jsonDataRsp []byte
|
||||
player := PlayerMgrSington.GetPlayerByAccount(msg.Username)
|
||||
|
||||
var remainNum int64
|
||||
var addcoin int64
|
||||
var logtype = int32(common.GainWayPlatformUpScore)
|
||||
addcoin, err = strconv.ParseInt(msg.Count, 10, 64)
|
||||
if err != nil {
|
||||
logger.Logger.Error("Unmarshal webapi.PlatfromUpScoreReq strconv.ParseInt error:", err)
|
||||
return common.ResponseTag_ParamError, jsonDataRsp
|
||||
}
|
||||
|
||||
if addcoin <= 0 {
|
||||
logger.Logger.Error("/api/platform/upscore addcoin:%v less 0", addcoin)
|
||||
return common.ResponseTag_ParamError, jsonDataRsp
|
||||
}
|
||||
|
||||
player := PlayerMgrSington.GetPlayerByUsername(msg.Username)
|
||||
|
||||
//玩家在线
|
||||
if player != nil {
|
||||
if player != nil && player.IsOnLine() {
|
||||
|
||||
remainNum = player.Coin
|
||||
platform := player.Platform
|
||||
//玩家在游戏内
|
||||
if player.scene != nil {
|
||||
pack.Code = int(webapiproto.TagCode_FAILED)
|
||||
pack.Message = "Unsupported!!! because player in scene!"
|
||||
return common.ResponseTag_ParamError, pack
|
||||
}
|
||||
if len(platform) > 0 {
|
||||
pack.Code = int(webapiproto.TagCode_FAILED)
|
||||
pack.Message = "player platform forbit!"
|
||||
return common.ResponseTag_ParamError, pack
|
||||
}
|
||||
|
||||
if player.Coin+addcoin < 0 {
|
||||
pack.Code = int(webapiproto.TagCode_FAILED)
|
||||
|
@ -3151,14 +3147,14 @@ func init() {
|
|||
}
|
||||
|
||||
var jsonDataRsp []byte
|
||||
player := PlayerMgrSington.GetPlayerByAccount(msg.Username)
|
||||
player := PlayerMgrSington.GetPlayerByUsername(msg.Username)
|
||||
|
||||
var remainNum int64
|
||||
var addcoin int64
|
||||
var logtype = int32(common.GainWayPlatformDownScore)
|
||||
|
||||
//玩家在线
|
||||
if player != nil {
|
||||
if player != nil && player.IsOnLine() {
|
||||
|
||||
addcoin = -player.Coin
|
||||
remainNum = player.Coin
|
||||
|
@ -3321,10 +3317,10 @@ func init() {
|
|||
logger.Logger.Tracef("/api/platform/getstatus %v", pack)
|
||||
|
||||
var jsonDataRsp []byte
|
||||
player := PlayerMgrSington.GetPlayerByAccount(msg.Username)
|
||||
player := PlayerMgrSington.GetPlayerByUsername(msg.Username)
|
||||
|
||||
//玩家在线
|
||||
if player != nil {
|
||||
if player != nil && player.IsOnLine() {
|
||||
pack.Code = int(webapiproto.TagCode_SUCCESS)
|
||||
pack.Message = "返回成功"
|
||||
pack.Success = true
|
||||
|
|
Loading…
Reference in New Issue