mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 16:02:26 +08:00
优化玩家管理器
This commit is contained in:
@@ -46,12 +46,11 @@ type CommandManager struct {
|
|||||||
func NewCommandManager() *CommandManager {
|
func NewCommandManager() *CommandManager {
|
||||||
r := new(CommandManager)
|
r := new(CommandManager)
|
||||||
|
|
||||||
// 创建一个公共的开放世界的AI
|
// 创建AI世界
|
||||||
GAME_MANAGER.OnRegOk(false, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: "System"}, 1, 0)
|
GAME_MANAGER.OnRegOk(false, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: "System"}, 1, 0)
|
||||||
r.system = USER_MANAGER.GetOnlineUser(1)
|
r.system = USER_MANAGER.GetOnlineUser(1)
|
||||||
// 开放大世界
|
|
||||||
r.system.SceneLoadState = model.SceneEnterDone
|
|
||||||
r.system.DbState = model.DbNormal
|
r.system.DbState = model.DbNormal
|
||||||
|
r.system.SceneLoadState = model.SceneEnterDone
|
||||||
WORLD_MANAGER.InitBigWorld(r.system)
|
WORLD_MANAGER.InitBigWorld(r.system)
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"hk4e/pkg/reflection"
|
"hk4e/pkg/reflection"
|
||||||
"hk4e/protocol/cmd"
|
"hk4e/protocol/cmd"
|
||||||
"hk4e/protocol/proto"
|
"hk4e/protocol/proto"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var GAME_MANAGER *GameManager = nil
|
var GAME_MANAGER *GameManager = nil
|
||||||
@@ -69,8 +70,10 @@ func (g *GameManager) Start() {
|
|||||||
|
|
||||||
func (g *GameManager) Stop() {
|
func (g *GameManager) Stop() {
|
||||||
// 保存玩家数据
|
// 保存玩家数据
|
||||||
USER_MANAGER.SaveUser()
|
LOCAL_EVENT_MANAGER.localEventChan <- &LocalEvent{
|
||||||
|
EventId: RunUserCopyAndSave,
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
//g.worldManager.worldStatic.SaveTerrain()
|
//g.worldManager.worldStatic.SaveTerrain()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +118,18 @@ func (g *GameManager) CommonRetError(cmdId uint16, player *model.Player, rsp pb.
|
|||||||
g.SendMsg(cmdId, player.PlayerID, player.ClientSeq, rsp)
|
g.SendMsg(cmdId, player.PlayerID, player.ClientSeq, rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommonRetSucc 通用返回成功
|
||||||
|
func (g *GameManager) CommonRetSucc(cmdId uint16, player *model.Player, rsp pb.Message) {
|
||||||
|
if rsp == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ok := reflection.SetStructFieldValue(rsp, "Retcode", int32(proto.Retcode_RET_SUCC))
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
g.SendMsg(cmdId, player.PlayerID, player.ClientSeq, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GameManager) ReconnectPlayer(userId uint32) {
|
func (g *GameManager) ReconnectPlayer(userId uint32) {
|
||||||
g.SendMsg(cmd.ClientReconnectNotify, userId, 0, new(proto.ClientReconnectNotify))
|
g.SendMsg(cmd.ClientReconnectNotify, userId, 0, new(proto.ClientReconnectNotify))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
package game
|
package game
|
||||||
|
|
||||||
|
import (
|
||||||
|
"hk4e/gs/model"
|
||||||
|
"hk4e/pkg/logger"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// 本地事件队列管理器
|
// 本地事件队列管理器
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LoadLoginUserFromDbFinish = iota
|
LoadLoginUserFromDbFinish = iota
|
||||||
CheckUserExistOnRegFromDbFinish
|
CheckUserExistOnRegFromDbFinish
|
||||||
|
RunUserCopyAndSave
|
||||||
)
|
)
|
||||||
|
|
||||||
type LocalEvent struct {
|
type LocalEvent struct {
|
||||||
@@ -26,9 +33,47 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) {
|
|||||||
switch localEvent.EventId {
|
switch localEvent.EventId {
|
||||||
case LoadLoginUserFromDbFinish:
|
case LoadLoginUserFromDbFinish:
|
||||||
playerLoginInfo := localEvent.Msg.(*PlayerLoginInfo)
|
playerLoginInfo := localEvent.Msg.(*PlayerLoginInfo)
|
||||||
|
USER_MANAGER.playerMap[playerLoginInfo.Player.PlayerID] = playerLoginInfo.Player
|
||||||
GAME_MANAGER.OnLoginOk(playerLoginInfo.UserId, playerLoginInfo.Player, playerLoginInfo.ClientSeq)
|
GAME_MANAGER.OnLoginOk(playerLoginInfo.UserId, playerLoginInfo.Player, playerLoginInfo.ClientSeq)
|
||||||
case CheckUserExistOnRegFromDbFinish:
|
case CheckUserExistOnRegFromDbFinish:
|
||||||
playerRegInfo := localEvent.Msg.(*PlayerRegInfo)
|
playerRegInfo := localEvent.Msg.(*PlayerRegInfo)
|
||||||
GAME_MANAGER.OnRegOk(playerRegInfo.Exist, playerRegInfo.Req, playerRegInfo.UserId, playerRegInfo.ClientSeq)
|
GAME_MANAGER.OnRegOk(playerRegInfo.Exist, playerRegInfo.Req, playerRegInfo.UserId, playerRegInfo.ClientSeq)
|
||||||
|
case RunUserCopyAndSave:
|
||||||
|
startTime := time.Now().UnixNano()
|
||||||
|
// 拷贝一份数据避免并发访问
|
||||||
|
insertPlayerList := make([]model.Player, 0, len(USER_MANAGER.playerMap))
|
||||||
|
updatePlayerList := make([]model.Player, 0, len(USER_MANAGER.playerMap))
|
||||||
|
for uid, player := range USER_MANAGER.playerMap {
|
||||||
|
if uid < 100000000 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch player.DbState {
|
||||||
|
case model.DbNone:
|
||||||
|
break
|
||||||
|
case model.DbInsert:
|
||||||
|
insertPlayerList = append(insertPlayerList, *player)
|
||||||
|
USER_MANAGER.playerMap[uid].DbState = model.DbNormal
|
||||||
|
case model.DbDelete:
|
||||||
|
updatePlayerList = append(updatePlayerList, *player)
|
||||||
|
delete(USER_MANAGER.playerMap, uid)
|
||||||
|
case model.DbNormal:
|
||||||
|
updatePlayerList = append(updatePlayerList, *player)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
insertPlayerPointerList := make([]*model.Player, 0, len(insertPlayerList))
|
||||||
|
updatePlayerPointerList := make([]*model.Player, 0, len(updatePlayerList))
|
||||||
|
for _, player := range insertPlayerList {
|
||||||
|
insertPlayerPointerList = append(insertPlayerPointerList, &player)
|
||||||
|
}
|
||||||
|
for _, player := range updatePlayerList {
|
||||||
|
updatePlayerPointerList = append(updatePlayerPointerList, &player)
|
||||||
|
}
|
||||||
|
USER_MANAGER.saveUserChan <- &SaveUserData{
|
||||||
|
insertPlayerList: insertPlayerPointerList,
|
||||||
|
updatePlayerList: updatePlayerPointerList,
|
||||||
|
}
|
||||||
|
endTime := time.Now().UnixNano()
|
||||||
|
costTime := endTime - startTime
|
||||||
|
logger.LOG.Info("run save user copy cost time: %v ns", costTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,9 +284,10 @@ func (g *GameManager) CreatePlayer(userId uint32, nickName string, mainCharAvata
|
|||||||
player := new(model.Player)
|
player := new(model.Player)
|
||||||
player.PlayerID = userId
|
player.PlayerID = userId
|
||||||
player.NickName = nickName
|
player.NickName = nickName
|
||||||
player.Signature = "惟愿时光记忆,一路繁花千树。"
|
player.Signature = ""
|
||||||
player.MainCharAvatarId = mainCharAvatarId
|
player.MainCharAvatarId = mainCharAvatarId
|
||||||
player.HeadImage = mainCharAvatarId
|
player.HeadImage = mainCharAvatarId
|
||||||
|
player.Birthday = [2]uint8{0, 0}
|
||||||
player.NameCard = 210001
|
player.NameCard = 210001
|
||||||
player.NameCardList = make([]uint32, 0)
|
player.NameCardList = make([]uint32, 0)
|
||||||
player.NameCardList = append(player.NameCardList, 210001, 210042)
|
player.NameCardList = append(player.NameCardList, 210001, 210042)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package game
|
package game
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hk4e/gs/dao"
|
"hk4e/gs/dao"
|
||||||
@@ -10,16 +9,22 @@ import (
|
|||||||
"hk4e/protocol/proto"
|
"hk4e/protocol/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SaveUserData struct {
|
||||||
|
insertPlayerList []*model.Player
|
||||||
|
updatePlayerList []*model.Player
|
||||||
|
}
|
||||||
|
|
||||||
type UserManager struct {
|
type UserManager struct {
|
||||||
dao *dao.Dao
|
dao *dao.Dao
|
||||||
playerMap map[uint32]*model.Player
|
playerMap map[uint32]*model.Player
|
||||||
playerMapLock sync.RWMutex
|
saveUserChan chan *SaveUserData
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserManager(dao *dao.Dao) (r *UserManager) {
|
func NewUserManager(dao *dao.Dao) (r *UserManager) {
|
||||||
r = new(UserManager)
|
r = new(UserManager)
|
||||||
r.dao = dao
|
r.dao = dao
|
||||||
r.playerMap = make(map[uint32]*model.Player)
|
r.playerMap = make(map[uint32]*model.Player)
|
||||||
|
r.saveUserChan = make(chan *SaveUserData)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +102,7 @@ func (u *UserManager) LoadTempOfflineUserSync(userId uint32) *model.Player {
|
|||||||
if player == nil {
|
if player == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
u.ChangeUserDbState(player, model.DbDelete)
|
||||||
u.playerMap[player.PlayerID] = player
|
u.playerMap[player.PlayerID] = player
|
||||||
return player
|
return player
|
||||||
}
|
}
|
||||||
@@ -141,12 +147,11 @@ func (u *UserManager) OnlineUser(userId uint32, clientSeq uint32) (*model.Player
|
|||||||
} else {
|
} else {
|
||||||
go func() {
|
go func() {
|
||||||
player = u.loadUserFromDb(userId)
|
player = u.loadUserFromDb(userId)
|
||||||
if player != nil {
|
if player == nil {
|
||||||
player.DbState = model.DbNormal
|
logger.LOG.Error("can not find user from db, uid: %v", userId)
|
||||||
u.playerMapLock.Lock()
|
return
|
||||||
u.playerMap[player.PlayerID] = player
|
|
||||||
u.playerMapLock.Unlock()
|
|
||||||
}
|
}
|
||||||
|
u.ChangeUserDbState(player, model.DbNormal)
|
||||||
LOCAL_EVENT_MANAGER.localEventChan <- &LocalEvent{
|
LOCAL_EVENT_MANAGER.localEventChan <- &LocalEvent{
|
||||||
EventId: LoadLoginUserFromDbFinish,
|
EventId: LoadLoginUserFromDbFinish,
|
||||||
Msg: &PlayerLoginInfo{
|
Msg: &PlayerLoginInfo{
|
||||||
@@ -165,70 +170,64 @@ func (u *UserManager) ChangeUserDbState(player *model.Player, state int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch player.DbState {
|
switch player.DbState {
|
||||||
|
case model.DbNone:
|
||||||
|
if state == model.DbInsert {
|
||||||
|
player.DbState = model.DbInsert
|
||||||
|
} else if state == model.DbDelete {
|
||||||
|
player.DbState = model.DbDelete
|
||||||
|
} else if state == model.DbNormal {
|
||||||
|
player.DbState = model.DbNormal
|
||||||
|
} else {
|
||||||
|
logger.LOG.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
|
||||||
|
}
|
||||||
case model.DbInsert:
|
case model.DbInsert:
|
||||||
|
logger.LOG.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
|
||||||
break
|
break
|
||||||
case model.DbDelete:
|
case model.DbDelete:
|
||||||
if state == model.DbNormal {
|
if state == model.DbNormal {
|
||||||
player.DbState = model.DbNormal
|
player.DbState = model.DbNormal
|
||||||
|
} else {
|
||||||
|
logger.LOG.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
|
||||||
}
|
}
|
||||||
case model.DbNormal:
|
case model.DbNormal:
|
||||||
if state == model.DbDelete {
|
if state == model.DbDelete {
|
||||||
player.DbState = model.DbDelete
|
player.DbState = model.DbDelete
|
||||||
|
} else {
|
||||||
|
logger.LOG.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户数据库定时同步协程
|
// 用户数据库定时同步
|
||||||
|
|
||||||
func (u *UserManager) StartAutoSaveUser() {
|
func (u *UserManager) StartAutoSaveUser() {
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(time.Minute * 5)
|
ticker := time.NewTicker(time.Minute * 5)
|
||||||
for {
|
for {
|
||||||
u.SaveUser()
|
LOCAL_EVENT_MANAGER.localEventChan <- &LocalEvent{
|
||||||
|
EventId: RunUserCopyAndSave,
|
||||||
|
}
|
||||||
<-ticker.C
|
<-ticker.C
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
saveUserData := <-u.saveUserChan
|
||||||
|
u.SaveUser(saveUserData)
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserManager) SaveUser() {
|
func (u *UserManager) SaveUser(saveUserData *SaveUserData) {
|
||||||
playerMapSave := make(map[uint32]*model.Player, len(u.playerMap))
|
err := u.dao.InsertPlayerList(saveUserData.insertPlayerList)
|
||||||
u.playerMapLock.RLock()
|
|
||||||
for k, v := range u.playerMap {
|
|
||||||
playerMapSave[k] = v
|
|
||||||
}
|
|
||||||
u.playerMapLock.RUnlock()
|
|
||||||
insertList := make([]*model.Player, 0)
|
|
||||||
updateList := make([]*model.Player, 0)
|
|
||||||
for uid, player := range playerMapSave {
|
|
||||||
if uid < 100000000 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch player.DbState {
|
|
||||||
case model.DbInsert:
|
|
||||||
insertList = append(insertList, player)
|
|
||||||
playerMapSave[uid].DbState = model.DbNormal
|
|
||||||
case model.DbDelete:
|
|
||||||
updateList = append(updateList, player)
|
|
||||||
delete(playerMapSave, uid)
|
|
||||||
case model.DbNormal:
|
|
||||||
updateList = append(updateList, player)
|
|
||||||
}
|
|
||||||
if !player.Online {
|
|
||||||
delete(playerMapSave, uid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := u.dao.InsertPlayerList(insertList)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.LOG.Error("insert player list error: %v", err)
|
logger.LOG.Error("insert player list error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = u.dao.UpdatePlayerList(updateList)
|
err = u.dao.UpdatePlayerList(saveUserData.updatePlayerList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.LOG.Error("update player list error: %v", err)
|
logger.LOG.Error("update player list error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
u.playerMapLock.Lock()
|
logger.LOG.Info("save user finish, insert user count: %v, update user count: %v", len(saveUserData.insertPlayerList), len(saveUserData.updatePlayerList))
|
||||||
u.playerMap = playerMapSave
|
|
||||||
u.playerMapLock.Unlock()
|
|
||||||
logger.LOG.Info("save user finish, insert user count: %v, update user count: %v", len(insertList), len(updateList))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ func (g *GameManager) SceneTransToPointReq(player *model.Player, payloadMsg pb.M
|
|||||||
transPointId := strconv.Itoa(int(req.SceneId)) + "_" + strconv.Itoa(int(req.PointId))
|
transPointId := strconv.Itoa(int(req.SceneId)) + "_" + strconv.Itoa(int(req.PointId))
|
||||||
transPointConfig, exist := gdc.CONF.ScenePointEntries[transPointId]
|
transPointConfig, exist := gdc.CONF.ScenePointEntries[transPointId]
|
||||||
if !exist {
|
if !exist {
|
||||||
sceneTransToPointRsp := &proto.SceneTransToPointRsp{
|
g.CommonRetError(cmd.SceneTransToPointRsp, player, &proto.SceneTransToPointRsp{})
|
||||||
Retcode: int32(proto.Retcode_RET_SVR_ERROR),
|
|
||||||
}
|
|
||||||
g.SendMsg(cmd.SceneTransToPointRsp, player.PlayerID, player.ClientSeq, sceneTransToPointRsp)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,21 +52,19 @@ func (g *GameManager) PlayerApplyEnterMpResultReq(player *model.Player, payloadM
|
|||||||
|
|
||||||
func (g *GameManager) PlayerGetForceQuitBanInfoReq(player *model.Player, payloadMsg pb.Message) {
|
func (g *GameManager) PlayerGetForceQuitBanInfoReq(player *model.Player, payloadMsg pb.Message) {
|
||||||
logger.LOG.Debug("user get world exit ban info, uid: %v", player.PlayerID)
|
logger.LOG.Debug("user get world exit ban info, uid: %v", player.PlayerID)
|
||||||
result := true
|
ok := true
|
||||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||||
for _, worldPlayer := range world.playerMap {
|
for _, worldPlayer := range world.playerMap {
|
||||||
if worldPlayer.SceneLoadState != model.SceneEnterDone {
|
if worldPlayer.SceneLoadState != model.SceneEnterDone {
|
||||||
result = false
|
ok = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playerGetForceQuitBanInfoRsp := new(proto.PlayerGetForceQuitBanInfoRsp)
|
if !ok {
|
||||||
if result {
|
g.CommonRetError(cmd.PlayerGetForceQuitBanInfoRsp, player, &proto.PlayerGetForceQuitBanInfoRsp{}, proto.Retcode_RET_MP_TARGET_PLAYER_IN_TRANSFER)
|
||||||
playerGetForceQuitBanInfoRsp.Retcode = int32(proto.Retcode_RET_SUCC)
|
return
|
||||||
} else {
|
|
||||||
playerGetForceQuitBanInfoRsp.Retcode = int32(proto.Retcode_RET_MP_TARGET_PLAYER_IN_TRANSFER)
|
|
||||||
}
|
}
|
||||||
g.SendMsg(cmd.PlayerGetForceQuitBanInfoRsp, player.PlayerID, player.ClientSeq, playerGetForceQuitBanInfoRsp)
|
g.CommonRetSucc(cmd.PlayerGetForceQuitBanInfoRsp, player, &proto.PlayerGetForceQuitBanInfoRsp{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) BackMyWorldReq(player *model.Player, payloadMsg pb.Message) {
|
func (g *GameManager) BackMyWorldReq(player *model.Player, payloadMsg pb.Message) {
|
||||||
@@ -74,13 +72,11 @@ func (g *GameManager) BackMyWorldReq(player *model.Player, payloadMsg pb.Message
|
|||||||
// 其他玩家
|
// 其他玩家
|
||||||
ok := g.UserLeaveWorld(player)
|
ok := g.UserLeaveWorld(player)
|
||||||
|
|
||||||
backMyWorldRsp := new(proto.BackMyWorldRsp)
|
if !ok {
|
||||||
if ok {
|
g.CommonRetError(cmd.BackMyWorldRsp, player, &proto.BackMyWorldRsp{}, proto.Retcode_RET_MP_TARGET_PLAYER_IN_TRANSFER)
|
||||||
backMyWorldRsp.Retcode = int32(proto.Retcode_RET_SUCC)
|
return
|
||||||
} else {
|
|
||||||
backMyWorldRsp.Retcode = int32(proto.Retcode_RET_MP_TARGET_PLAYER_IN_TRANSFER)
|
|
||||||
}
|
}
|
||||||
g.SendMsg(cmd.BackMyWorldRsp, player.PlayerID, player.ClientSeq, backMyWorldRsp)
|
g.CommonRetSucc(cmd.BackMyWorldRsp, player, &proto.BackMyWorldRsp{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) ChangeWorldToSingleModeReq(player *model.Player, payloadMsg pb.Message) {
|
func (g *GameManager) ChangeWorldToSingleModeReq(player *model.Player, payloadMsg pb.Message) {
|
||||||
@@ -88,13 +84,11 @@ func (g *GameManager) ChangeWorldToSingleModeReq(player *model.Player, payloadMs
|
|||||||
// 房主
|
// 房主
|
||||||
ok := g.UserLeaveWorld(player)
|
ok := g.UserLeaveWorld(player)
|
||||||
|
|
||||||
changeWorldToSingleModeRsp := new(proto.ChangeWorldToSingleModeRsp)
|
if !ok {
|
||||||
if ok {
|
g.CommonRetError(cmd.ChangeWorldToSingleModeRsp, player, &proto.ChangeWorldToSingleModeRsp{}, proto.Retcode_RET_MP_TARGET_PLAYER_IN_TRANSFER)
|
||||||
changeWorldToSingleModeRsp.Retcode = int32(proto.Retcode_RET_SUCC)
|
return
|
||||||
} else {
|
|
||||||
changeWorldToSingleModeRsp.Retcode = int32(proto.Retcode_RET_MP_TARGET_PLAYER_IN_TRANSFER)
|
|
||||||
}
|
}
|
||||||
g.SendMsg(cmd.ChangeWorldToSingleModeRsp, player.PlayerID, player.ClientSeq, changeWorldToSingleModeRsp)
|
g.CommonRetSucc(cmd.ChangeWorldToSingleModeRsp, player, &proto.ChangeWorldToSingleModeRsp{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) SceneKickPlayerReq(player *model.Player, payloadMsg pb.Message) {
|
func (g *GameManager) SceneKickPlayerReq(player *model.Player, payloadMsg pb.Message) {
|
||||||
@@ -102,30 +96,27 @@ func (g *GameManager) SceneKickPlayerReq(player *model.Player, payloadMsg pb.Mes
|
|||||||
req := payloadMsg.(*proto.SceneKickPlayerReq)
|
req := payloadMsg.(*proto.SceneKickPlayerReq)
|
||||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||||
if player.PlayerID != world.owner.PlayerID {
|
if player.PlayerID != world.owner.PlayerID {
|
||||||
sceneKickPlayerRsp := &proto.SceneKickPlayerRsp{
|
g.CommonRetError(cmd.SceneKickPlayerRsp, player, &proto.SceneKickPlayerRsp{})
|
||||||
Retcode: int32(proto.Retcode_RET_SVR_ERROR),
|
|
||||||
}
|
|
||||||
g.SendMsg(cmd.SceneKickPlayerRsp, player.PlayerID, player.ClientSeq, sceneKickPlayerRsp)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
targetUid := req.TargetUid
|
targetUid := req.TargetUid
|
||||||
targetPlayer := USER_MANAGER.GetOnlineUser(targetUid)
|
targetPlayer := USER_MANAGER.GetOnlineUser(targetUid)
|
||||||
ok := g.UserLeaveWorld(targetPlayer)
|
ok := g.UserLeaveWorld(targetPlayer)
|
||||||
if ok {
|
if !ok {
|
||||||
sceneKickPlayerNotify := &proto.SceneKickPlayerNotify{
|
g.CommonRetError(cmd.SceneKickPlayerRsp, player, &proto.SceneKickPlayerRsp{}, proto.Retcode_RET_MP_TARGET_PLAYER_IN_TRANSFER)
|
||||||
TargetUid: targetUid,
|
return
|
||||||
KickerUid: player.PlayerID,
|
|
||||||
}
|
|
||||||
for _, worldPlayer := range world.playerMap {
|
|
||||||
g.SendMsg(cmd.SceneKickPlayerNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, sceneKickPlayerNotify)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sceneKickPlayerRsp := new(proto.SceneKickPlayerRsp)
|
sceneKickPlayerNotify := &proto.SceneKickPlayerNotify{
|
||||||
if ok {
|
TargetUid: targetUid,
|
||||||
sceneKickPlayerRsp.TargetUid = targetUid
|
KickerUid: player.PlayerID,
|
||||||
} else {
|
}
|
||||||
sceneKickPlayerRsp.Retcode = int32(proto.Retcode_RET_MP_TARGET_PLAYER_IN_TRANSFER)
|
for _, worldPlayer := range world.playerMap {
|
||||||
|
g.SendMsg(cmd.SceneKickPlayerNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, sceneKickPlayerNotify)
|
||||||
|
}
|
||||||
|
|
||||||
|
sceneKickPlayerRsp := &proto.SceneKickPlayerRsp{
|
||||||
|
TargetUid: targetUid,
|
||||||
}
|
}
|
||||||
g.SendMsg(cmd.SceneKickPlayerRsp, player.PlayerID, player.ClientSeq, sceneKickPlayerRsp)
|
g.SendMsg(cmd.SceneKickPlayerRsp, player.PlayerID, player.ClientSeq, sceneKickPlayerRsp)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,27 +20,28 @@ func (g *GameManager) GetPlayerSocialDetailReq(player *model.Player, payloadMsg
|
|||||||
req := payloadMsg.(*proto.GetPlayerSocialDetailReq)
|
req := payloadMsg.(*proto.GetPlayerSocialDetailReq)
|
||||||
targetUid := req.Uid
|
targetUid := req.Uid
|
||||||
|
|
||||||
getPlayerSocialDetailRsp := new(proto.GetPlayerSocialDetailRsp)
|
|
||||||
// TODO 同步阻塞待优化
|
// TODO 同步阻塞待优化
|
||||||
targetPlayer := USER_MANAGER.LoadTempOfflineUserSync(targetUid)
|
targetPlayer := USER_MANAGER.LoadTempOfflineUserSync(targetUid)
|
||||||
if targetPlayer != nil {
|
if targetPlayer == nil {
|
||||||
_, exist := player.FriendList[targetPlayer.PlayerID]
|
g.CommonRetError(cmd.GetPlayerSocialDetailRsp, player, &proto.GetPlayerSocialDetailRsp{}, proto.Retcode_RET_PLAYER_NOT_EXIST)
|
||||||
socialDetail := &proto.SocialDetail{
|
return
|
||||||
Uid: targetPlayer.PlayerID,
|
}
|
||||||
ProfilePicture: &proto.ProfilePicture{AvatarId: targetPlayer.HeadImage},
|
_, exist := player.FriendList[targetPlayer.PlayerID]
|
||||||
Nickname: targetPlayer.NickName,
|
socialDetail := &proto.SocialDetail{
|
||||||
Signature: targetPlayer.Signature,
|
Uid: targetPlayer.PlayerID,
|
||||||
Level: targetPlayer.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_LEVEL],
|
ProfilePicture: &proto.ProfilePicture{AvatarId: targetPlayer.HeadImage},
|
||||||
Birthday: &proto.Birthday{Month: 2, Day: 13},
|
Nickname: targetPlayer.NickName,
|
||||||
WorldLevel: targetPlayer.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_WORLD_LEVEL],
|
Signature: targetPlayer.Signature,
|
||||||
NameCardId: targetPlayer.NameCard,
|
Level: targetPlayer.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_LEVEL],
|
||||||
IsShowAvatar: false,
|
Birthday: &proto.Birthday{Month: uint32(targetPlayer.Birthday[0]), Day: uint32(targetPlayer.Birthday[1])},
|
||||||
FinishAchievementNum: 0,
|
WorldLevel: targetPlayer.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_WORLD_LEVEL],
|
||||||
IsFriend: exist,
|
NameCardId: targetPlayer.NameCard,
|
||||||
}
|
IsShowAvatar: false,
|
||||||
getPlayerSocialDetailRsp.DetailData = socialDetail
|
FinishAchievementNum: 0,
|
||||||
} else {
|
IsFriend: exist,
|
||||||
getPlayerSocialDetailRsp.Retcode = int32(proto.Retcode_RET_PLAYER_NOT_EXIST)
|
}
|
||||||
|
getPlayerSocialDetailRsp := &proto.GetPlayerSocialDetailRsp{
|
||||||
|
DetailData: socialDetail,
|
||||||
}
|
}
|
||||||
g.SendMsg(cmd.GetPlayerSocialDetailRsp, player.PlayerID, player.ClientSeq, getPlayerSocialDetailRsp)
|
g.SendMsg(cmd.GetPlayerSocialDetailRsp, player.PlayerID, player.ClientSeq, getPlayerSocialDetailRsp)
|
||||||
}
|
}
|
||||||
@@ -48,8 +49,18 @@ func (g *GameManager) GetPlayerSocialDetailReq(player *model.Player, payloadMsg
|
|||||||
func (g *GameManager) SetPlayerBirthdayReq(player *model.Player, payloadMsg pb.Message) {
|
func (g *GameManager) SetPlayerBirthdayReq(player *model.Player, payloadMsg pb.Message) {
|
||||||
logger.LOG.Debug("user set birthday, uid: %v", player.PlayerID)
|
logger.LOG.Debug("user set birthday, uid: %v", player.PlayerID)
|
||||||
req := payloadMsg.(*proto.SetPlayerBirthdayReq)
|
req := payloadMsg.(*proto.SetPlayerBirthdayReq)
|
||||||
_ = req
|
if player.Birthday[0] != 0 || player.Birthday[1] != 0 {
|
||||||
g.CommonRetError(cmd.SetPlayerBirthdayRsp, player, &proto.SetPlayerBirthdayRsp{})
|
g.CommonRetError(cmd.SetPlayerBirthdayRsp, player, &proto.SetPlayerBirthdayRsp{})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
birthday := req.Birthday
|
||||||
|
player.Birthday[0] = uint8(birthday.Month)
|
||||||
|
player.Birthday[1] = uint8(birthday.Day)
|
||||||
|
|
||||||
|
setPlayerBirthdayRsp := &proto.SetPlayerBirthdayRsp{
|
||||||
|
Birthday: req.Birthday,
|
||||||
|
}
|
||||||
|
g.SendMsg(cmd.SetPlayerBirthdayRsp, player.PlayerID, player.ClientSeq, setPlayerBirthdayRsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) SetNameCardReq(player *model.Player, payloadMsg pb.Message) {
|
func (g *GameManager) SetNameCardReq(player *model.Player, payloadMsg pb.Message) {
|
||||||
@@ -325,6 +336,7 @@ func (g *GameManager) GetOnlinePlayerListReq(player *model.Player, payloadMsg pb
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) PacketOnlinePlayerInfo(player *model.Player) *proto.OnlinePlayerInfo {
|
func (g *GameManager) PacketOnlinePlayerInfo(player *model.Player) *proto.OnlinePlayerInfo {
|
||||||
|
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||||
onlinePlayerInfo := &proto.OnlinePlayerInfo{
|
onlinePlayerInfo := &proto.OnlinePlayerInfo{
|
||||||
Uid: player.PlayerID,
|
Uid: player.PlayerID,
|
||||||
Nickname: player.NickName,
|
Nickname: player.NickName,
|
||||||
@@ -333,11 +345,7 @@ func (g *GameManager) PacketOnlinePlayerInfo(player *model.Player) *proto.Online
|
|||||||
NameCardId: player.NameCard,
|
NameCardId: player.NameCard,
|
||||||
Signature: player.Signature,
|
Signature: player.Signature,
|
||||||
ProfilePicture: &proto.ProfilePicture{AvatarId: player.HeadImage},
|
ProfilePicture: &proto.ProfilePicture{AvatarId: player.HeadImage},
|
||||||
CurPlayerNumInWorld: 1,
|
CurPlayerNumInWorld: uint32(world.GetWorldPlayerNum()),
|
||||||
}
|
|
||||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
|
||||||
if world != nil && world.playerMap != nil {
|
|
||||||
onlinePlayerInfo.CurPlayerNumInWorld = uint32(world.GetWorldPlayerNum())
|
|
||||||
}
|
}
|
||||||
return onlinePlayerInfo
|
return onlinePlayerInfo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,7 @@ func (g *GameManager) SceneAvatarStaminaStepReq(player *model.Player, payloadMsg
|
|||||||
angleRevise = int32(req.Rot.X - 360.0)
|
angleRevise = int32(req.Rot.X - 360.0)
|
||||||
} else {
|
} else {
|
||||||
logger.LOG.Error("invalid rot x angle: %v, uid: %v", req.Rot.X, player.PlayerID)
|
logger.LOG.Error("invalid rot x angle: %v, uid: %v", req.Rot.X, player.PlayerID)
|
||||||
sceneAvatarStaminaStepRsp := &proto.SceneAvatarStaminaStepRsp{
|
g.CommonRetError(cmd.SceneAvatarStaminaStepRsp, player, &proto.SceneAvatarStaminaStepRsp{})
|
||||||
Retcode: int32(proto.Retcode_RET_FAIL),
|
|
||||||
}
|
|
||||||
g.SendMsg(cmd.SceneAvatarStaminaStepRsp, player.PlayerID, player.ClientSeq, sceneAvatarStaminaStepRsp)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 攀爬耐力修正曲线
|
// 攀爬耐力修正曲线
|
||||||
|
|||||||
@@ -16,11 +16,9 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
|
|||||||
logger.LOG.Debug("user change avatar, uid: %v", player.PlayerID)
|
logger.LOG.Debug("user change avatar, uid: %v", player.PlayerID)
|
||||||
req := payloadMsg.(*proto.ChangeAvatarReq)
|
req := payloadMsg.(*proto.ChangeAvatarReq)
|
||||||
targetAvatarGuid := req.Guid
|
targetAvatarGuid := req.Guid
|
||||||
|
|
||||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||||
scene := world.GetSceneById(player.SceneId)
|
scene := world.GetSceneById(player.SceneId)
|
||||||
playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID)
|
playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID)
|
||||||
|
|
||||||
oldAvatarId := world.GetPlayerActiveAvatarId(player)
|
oldAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||||
oldAvatar := player.AvatarMap[oldAvatarId]
|
oldAvatar := player.AvatarMap[oldAvatarId]
|
||||||
if oldAvatar.Guid == targetAvatarGuid {
|
if oldAvatar.Guid == targetAvatarGuid {
|
||||||
@@ -37,9 +35,11 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
|
|||||||
logger.LOG.Error("can not find the target avatar in team, uid: %v, target avatar guid: %v", player.PlayerID, targetAvatarGuid)
|
logger.LOG.Error("can not find the target avatar in team, uid: %v, target avatar guid: %v", player.PlayerID, targetAvatarGuid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
player.TeamConfig.CurrAvatarIndex = uint8(index)
|
if world.multiplayer {
|
||||||
world.SetPlayerLocalAvatarIndex(player, index)
|
world.SetPlayerLocalAvatarIndex(player, index)
|
||||||
|
} else {
|
||||||
|
player.TeamConfig.CurrAvatarIndex = uint8(index)
|
||||||
|
}
|
||||||
entity := scene.GetEntity(playerTeamEntity.avatarEntityMap[oldAvatarId])
|
entity := scene.GetEntity(playerTeamEntity.avatarEntityMap[oldAvatarId])
|
||||||
if entity == nil {
|
if entity == nil {
|
||||||
return
|
return
|
||||||
@@ -178,13 +178,11 @@ func (g *GameManager) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.
|
|||||||
logger.LOG.Debug("user change mp team avatar, uid: %v", player.PlayerID)
|
logger.LOG.Debug("user change mp team avatar, uid: %v", player.PlayerID)
|
||||||
req := payloadMsg.(*proto.ChangeMpTeamAvatarReq)
|
req := payloadMsg.(*proto.ChangeMpTeamAvatarReq)
|
||||||
avatarGuidList := req.AvatarGuidList
|
avatarGuidList := req.AvatarGuidList
|
||||||
|
|
||||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||||
if !world.multiplayer || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 {
|
if !world.multiplayer || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 {
|
||||||
g.CommonRetError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{})
|
g.CommonRetError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarIdList := make([]uint32, 0)
|
avatarIdList := make([]uint32, 0)
|
||||||
for _, avatarGuid := range avatarGuidList {
|
for _, avatarGuid := range avatarGuidList {
|
||||||
avatarId := player.GetAvatarIdByGuid(avatarGuid)
|
avatarId := player.GetAvatarIdByGuid(avatarGuid)
|
||||||
@@ -192,7 +190,6 @@ func (g *GameManager) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.
|
|||||||
}
|
}
|
||||||
world.SetPlayerLocalTeam(player, avatarIdList)
|
world.SetPlayerLocalTeam(player, avatarIdList)
|
||||||
world.SetPlayerLocalAvatarIndex(player, 0)
|
world.SetPlayerLocalAvatarIndex(player, 0)
|
||||||
|
|
||||||
world.UpdateMultiplayerTeam()
|
world.UpdateMultiplayerTeam()
|
||||||
scene := world.GetSceneById(player.SceneId)
|
scene := world.GetSceneById(player.SceneId)
|
||||||
scene.UpdatePlayerTeamEntity(player)
|
scene.UpdatePlayerTeamEntity(player)
|
||||||
@@ -204,7 +201,6 @@ func (g *GameManager) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.
|
|||||||
|
|
||||||
avatarId := world.GetPlayerActiveAvatarId(player)
|
avatarId := world.GetPlayerActiveAvatarId(player)
|
||||||
avatar := player.AvatarMap[avatarId]
|
avatar := player.AvatarMap[avatarId]
|
||||||
|
|
||||||
changeMpTeamAvatarRsp := &proto.ChangeMpTeamAvatarRsp{
|
changeMpTeamAvatarRsp := &proto.ChangeMpTeamAvatarRsp{
|
||||||
CurAvatarGuid: avatar.Guid,
|
CurAvatarGuid: avatar.Guid,
|
||||||
AvatarGuidList: req.AvatarGuidList,
|
AvatarGuidList: req.AvatarGuidList,
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DbNormal = iota
|
DbNone = iota
|
||||||
DbInsert
|
DbInsert
|
||||||
DbDelete
|
DbDelete
|
||||||
|
DbNormal
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -27,6 +28,7 @@ type Player struct {
|
|||||||
NickName string `bson:"nickname"` // 玩家昵称
|
NickName string `bson:"nickname"` // 玩家昵称
|
||||||
Signature string `bson:"signature"` // 玩家签名
|
Signature string `bson:"signature"` // 玩家签名
|
||||||
HeadImage uint32 `bson:"headImage"` // 玩家头像
|
HeadImage uint32 `bson:"headImage"` // 玩家头像
|
||||||
|
Birthday [2]uint8 `bson:"birthday"` // 生日
|
||||||
NameCard uint32 `bson:"nameCard"` // 当前名片
|
NameCard uint32 `bson:"nameCard"` // 当前名片
|
||||||
NameCardList []uint32 `bson:"nameCardList"` // 已解锁名片列表
|
NameCardList []uint32 `bson:"nameCardList"` // 已解锁名片列表
|
||||||
FriendList map[uint32]bool `bson:"friendList"` // 好友uid列表
|
FriendList map[uint32]bool `bson:"friendList"` // 好友uid列表
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ func (c *CmdProtoMap) registerAllMessage() {
|
|||||||
c.registerMessage(ToTheMoonEnterSceneRsp, &proto.ToTheMoonEnterSceneRsp{}) // 进入场景响应
|
c.registerMessage(ToTheMoonEnterSceneRsp, &proto.ToTheMoonEnterSceneRsp{}) // 进入场景响应
|
||||||
c.registerMessage(SetEntityClientDataNotify, &proto.SetEntityClientDataNotify{}) // 通知
|
c.registerMessage(SetEntityClientDataNotify, &proto.SetEntityClientDataNotify{}) // 通知
|
||||||
c.registerMessage(LeaveWorldNotify, &proto.LeaveWorldNotify{}) // 删除客户端世界通知
|
c.registerMessage(LeaveWorldNotify, &proto.LeaveWorldNotify{}) // 删除客户端世界通知
|
||||||
|
c.registerMessage(SceneAvatarStaminaStepReq, &proto.SceneAvatarStaminaStepReq{}) // 缓慢游泳或缓慢攀爬时消耗耐力请求
|
||||||
|
c.registerMessage(SceneAvatarStaminaStepRsp, &proto.SceneAvatarStaminaStepRsp{}) // 缓慢游泳或缓慢攀爬时消耗耐力响应
|
||||||
|
|
||||||
// 战斗与技能
|
// 战斗与技能
|
||||||
c.registerMessage(AvatarFightPropNotify, &proto.AvatarFightPropNotify{}) // 角色战斗属性通知
|
c.registerMessage(AvatarFightPropNotify, &proto.AvatarFightPropNotify{}) // 角色战斗属性通知
|
||||||
@@ -222,10 +224,6 @@ func (c *CmdProtoMap) registerAllMessage() {
|
|||||||
c.registerMessage(McoinExchangeHcoinReq, &proto.McoinExchangeHcoinReq{}) // 结晶换原石请求
|
c.registerMessage(McoinExchangeHcoinReq, &proto.McoinExchangeHcoinReq{}) // 结晶换原石请求
|
||||||
c.registerMessage(McoinExchangeHcoinRsp, &proto.McoinExchangeHcoinRsp{}) // 结晶换原石响应
|
c.registerMessage(McoinExchangeHcoinRsp, &proto.McoinExchangeHcoinRsp{}) // 结晶换原石响应
|
||||||
|
|
||||||
// 耐力
|
|
||||||
c.registerMessage(SceneAvatarStaminaStepReq, &proto.SceneAvatarStaminaStepReq{}) // 缓慢游泳或缓慢攀爬时消耗耐力请求
|
|
||||||
c.registerMessage(SceneAvatarStaminaStepRsp, &proto.SceneAvatarStaminaStepRsp{}) // 缓慢游泳或缓慢攀爬时消耗耐力响应
|
|
||||||
|
|
||||||
// 乱七八糟
|
// 乱七八糟
|
||||||
c.registerMessage(MarkMapReq, &proto.MarkMapReq{}) // 标记地图请求
|
c.registerMessage(MarkMapReq, &proto.MarkMapReq{}) // 标记地图请求
|
||||||
c.registerMessage(TowerAllDataReq, &proto.TowerAllDataReq{}) // 深渊数据请求
|
c.registerMessage(TowerAllDataReq, &proto.TowerAllDataReq{}) // 深渊数据请求
|
||||||
|
|||||||
Reference in New Issue
Block a user