初步解决pubg插件生命周期管理混乱问题
This commit is contained in:
1 parent
3af603dcaa
commit
389210b12b
20 files changed
+265
-134
No files matched your search
@@ -59,6 +59,7 @@ const (
|
||||
ServerForwardModeServerCloseNotify // 转发模式服务器断开连接通知
|
||||
ServerForwardDispatchInfoNotify // 转发模式区服信息通知
|
||||
ServerStopNotify // 停服通知
|
||||
ServerDispatchCancelNotify // 服务器取消调度通知
|
||||
)
|
||||
|
||||
type ServerMsg struct {
|
||||
@@ -71,6 +72,7 @@ type ServerMsg struct {
|
||||
ChatMsgInfo *ChatMsgInfo
|
||||
AddFriendInfo *AddFriendInfo
|
||||
ForwardDispatchInfo *ForwardDispatchInfo
|
||||
AppVersion string
|
||||
}
|
||||
|
||||
type OriginInfo struct {
|
||||
|
||||
@@ -702,23 +702,26 @@ func (k *KcpConnManager) syncMinLoadServerAppid() {
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("get gs server appid error: %v", err)
|
||||
return
|
||||
k.minLoadGsServerAppId = ""
|
||||
} else {
|
||||
k.minLoadGsServerAppId = gsServerAppId.AppId
|
||||
}
|
||||
k.minLoadGsServerAppId = gsServerAppId.AppId
|
||||
anticheatServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
|
||||
ServerType: api.ANTICHEAT,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
k.minLoadAnticheatServerAppId = ""
|
||||
} else {
|
||||
k.minLoadAnticheatServerAppId = anticheatServerAppId.AppId
|
||||
}
|
||||
k.minLoadAnticheatServerAppId = anticheatServerAppId.AppId
|
||||
pathfindingServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
|
||||
ServerType: api.PATHFINDING,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
k.minLoadPathfindingServerAppId = ""
|
||||
} else {
|
||||
k.minLoadPathfindingServerAppId = pathfindingServerAppId.AppId
|
||||
}
|
||||
k.minLoadPathfindingServerAppId = pathfindingServerAppId.AppId
|
||||
}
|
||||
|
||||
func (k *KcpConnManager) autoSyncStopServerInfo() {
|
||||
|
||||
+1
-5
@@ -65,10 +65,6 @@ func Run(ctx context.Context, configFile string) error {
|
||||
AppId: APPID,
|
||||
})
|
||||
}()
|
||||
mainGsAppid, err := discoveryClient.GetMainGameServerAppId(context.TODO(), &api.NullMsg{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.InitLogger("gs_" + APPID)
|
||||
logger.Warn("gs start, appid: %v, gsid: %v", APPID, GSID)
|
||||
@@ -87,7 +83,7 @@ func Run(ctx context.Context, configFile string) error {
|
||||
messageQueue := mq.NewMessageQueue(api.GS, APPID, discoveryClient)
|
||||
defer messageQueue.Close()
|
||||
|
||||
gameCore := game.NewGameCore(db, messageQueue, GSID, APPID, mainGsAppid.AppId, discoveryClient)
|
||||
gameCore := game.NewGameCore(db, messageQueue, GSID, APPID, APPVERSION, discoveryClient)
|
||||
defer gameCore.Close()
|
||||
|
||||
// natsrpc server
|
||||
|
||||
+34
-19
@@ -44,17 +44,18 @@ var ONLINE_PLAYER_NUM int32 = 0 // 当前在线玩家数
|
||||
var SELF *model.Player
|
||||
|
||||
type Game struct {
|
||||
discovery *rpc.DiscoveryClient // node节点服务器的natsrpc客户端
|
||||
db *dao.Dao
|
||||
snowflake *alg.SnowflakeWorker
|
||||
gsId uint32
|
||||
gsAppid string
|
||||
mainGsAppid string
|
||||
ai *model.Player // 本服的Ai玩家对象
|
||||
isStop bool
|
||||
discovery *rpc.DiscoveryClient // node节点服务器的natsrpc客户端
|
||||
db *dao.Dao
|
||||
snowflake *alg.SnowflakeWorker
|
||||
gsId uint32
|
||||
gsAppid string
|
||||
gsAppVersion string
|
||||
ai *model.Player // 本服的Ai玩家对象
|
||||
isStop bool
|
||||
dispatchCancel bool
|
||||
}
|
||||
|
||||
func NewGameCore(db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppid string, mainGsAppid string, discovery *rpc.DiscoveryClient) (r *Game) {
|
||||
func NewGameCore(db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppid string, gsAppVersion string, discovery *rpc.DiscoveryClient) (r *Game) {
|
||||
r = new(Game)
|
||||
r.discovery = discovery
|
||||
r.db = db
|
||||
@@ -62,7 +63,7 @@ func NewGameCore(db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppi
|
||||
r.snowflake = alg.NewSnowflakeWorker(int64(gsId))
|
||||
r.gsId = gsId
|
||||
r.gsAppid = gsAppid
|
||||
r.mainGsAppid = mainGsAppid
|
||||
r.gsAppVersion = gsAppVersion
|
||||
GAME = r
|
||||
LOCAL_EVENT_MANAGER = NewLocalEventManager()
|
||||
ROUTE_MANAGER = NewRouteManager()
|
||||
@@ -84,6 +85,7 @@ func NewGameCore(db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppi
|
||||
PLUGIN_MANAGER.InitPlugin()
|
||||
r.run()
|
||||
r.isStop = false
|
||||
r.dispatchCancel = false
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -95,15 +97,6 @@ func (g *Game) GetGsAppid() string {
|
||||
return g.gsAppid
|
||||
}
|
||||
|
||||
func (g *Game) GetMainGsAppid() string {
|
||||
return g.mainGsAppid
|
||||
}
|
||||
|
||||
func (g *Game) IsMainGs() bool {
|
||||
// 目前的实现逻辑是当前GsId最小的Gs做MainGs
|
||||
return g.gsAppid == g.mainGsAppid
|
||||
}
|
||||
|
||||
// GetAi 获取本服的Ai玩家对象
|
||||
func (g *Game) GetAi() *model.Player {
|
||||
return g.ai
|
||||
@@ -264,6 +257,19 @@ func (g *Game) gameMainLoop() {
|
||||
|
||||
var EXIT_SAVE_FIN_CHAN chan bool
|
||||
|
||||
func (g *Game) ServerStopNotify() {
|
||||
go func() {
|
||||
info := "服务器即将关闭。"
|
||||
GAME.ServerAnnounceNotify(1, info)
|
||||
logger.Warn("stop game server last 1 minute")
|
||||
time.Sleep(time.Minute)
|
||||
delay := GAME.GetGsId()
|
||||
logger.Warn("stop game server last %v second", delay)
|
||||
time.Sleep(time.Second * time.Duration(delay))
|
||||
GAME.Close()
|
||||
}()
|
||||
}
|
||||
|
||||
func (g *Game) Close() {
|
||||
if g.isStop {
|
||||
return
|
||||
@@ -289,12 +295,21 @@ func (g *Game) Close() {
|
||||
IsOnline: false,
|
||||
},
|
||||
})
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
// 卸载插件
|
||||
PLUGIN_MANAGER.DelAllPlugin()
|
||||
logger.Warn("stop game server finish")
|
||||
}
|
||||
|
||||
func (g *Game) ServerDispatchCancelNotify(appVersion string) {
|
||||
if appVersion != g.gsAppVersion {
|
||||
return
|
||||
}
|
||||
logger.Warn("game server dispatch cancel")
|
||||
g.dispatchCancel = true
|
||||
}
|
||||
|
||||
// SendMsgToGate 发送消息给客户端 指定网关
|
||||
func (g *Game) SendMsgToGate(cmdId uint16, userId uint32, clientSeq uint32, gateAppId string, payloadMsg pb.Message) {
|
||||
if userId < PlayerBaseUid {
|
||||
|
||||
@@ -740,7 +740,7 @@ func (c *CommandManager) NewXLuaDebugCommandController() *CommandController {
|
||||
UsageList: []string{
|
||||
"{alias} 开关xLua调试",
|
||||
},
|
||||
Perm: CommandPermNormal,
|
||||
Perm: CommandPermGM,
|
||||
Func: c.XLuaDebugCommand,
|
||||
}
|
||||
}
|
||||
@@ -769,7 +769,7 @@ func (c *CommandManager) NewGcgCommandController() *CommandController {
|
||||
UsageList: []string{
|
||||
"{alias} 测试七圣召唤",
|
||||
},
|
||||
Perm: CommandPermNormal,
|
||||
Perm: CommandPermGM,
|
||||
Func: c.GcgCommand,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,11 +232,11 @@ func (g *GMCmd) GMKillMonster(userId uint32, entityId uint32) {
|
||||
return
|
||||
}
|
||||
// 确保为怪物
|
||||
if entity.entityType != constant.ENTITY_TYPE_MONSTER {
|
||||
if entity.GetEntityType() != constant.ENTITY_TYPE_MONSTER {
|
||||
return
|
||||
}
|
||||
// 杀死怪物
|
||||
GAME.KillEntity(player, scene, entity.id, proto.PlayerDieType_PLAYER_DIE_GM)
|
||||
GAME.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM)
|
||||
}
|
||||
|
||||
// GMKillAllMonster 杀死所有怪物
|
||||
@@ -257,13 +257,13 @@ func (g *GMCmd) GMKillAllMonster(userId uint32) {
|
||||
return
|
||||
}
|
||||
// 杀死所有怪物实体
|
||||
for _, entity := range scene.entityMap {
|
||||
for _, entity := range scene.GetAllEntity() {
|
||||
// 确保为怪物
|
||||
if entity.entityType != constant.ENTITY_TYPE_MONSTER {
|
||||
if entity.GetEntityType() != constant.ENTITY_TYPE_MONSTER {
|
||||
continue
|
||||
}
|
||||
// 杀死怪物
|
||||
GAME.KillEntity(player, scene, entity.id, proto.PlayerDieType_PLAYER_DIE_GM)
|
||||
GAME.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ func (g *GMCmd) CreateRobotInAiWorld(uid uint32, name string, avatarId uint32) {
|
||||
AvatarId: avatarId,
|
||||
})
|
||||
GAME.JoinPlayerSceneReq(robot, &proto.JoinPlayerSceneReq{
|
||||
TargetUid: aiWorld.owner.PlayerId,
|
||||
TargetUid: aiWorld.GetOwner().PlayerId,
|
||||
})
|
||||
GAME.EnterSceneReadyReq(robot, &proto.EnterSceneReadyReq{
|
||||
EnterSceneToken: aiWorld.GetEnterSceneToken(),
|
||||
@@ -562,7 +562,6 @@ func (g *GMCmd) StartPubg(v bool) {
|
||||
return
|
||||
}
|
||||
pluginPubg := iPlugin.(*PluginPubg)
|
||||
logger.Error("plugin: %v", pluginPubg)
|
||||
pluginPubg.StartPubg()
|
||||
}
|
||||
|
||||
|
||||
@@ -124,8 +124,8 @@ func (p *PhysicsEngine) Update(now int64) []*RigidBody {
|
||||
hitList = append(hitList, rigidBody)
|
||||
p.DestroyRigidBody(rigidBody.entityId)
|
||||
}
|
||||
logger.Debug("[PhysicsEngineUpdate] e: %v, s: %v, p: %v, v: %v", rigidBody.entityId, rigidBody.sceneId, rigidBody.position, rigidBody.velocity)
|
||||
if p.pathTracing {
|
||||
logger.Debug("[PhysicsEngineUpdate] e: %v, s: %v, p: %v, v: %v", rigidBody.entityId, rigidBody.sceneId, rigidBody.position, rigidBody.velocity)
|
||||
GAME.CreateGadget(p.world.GetOwner(), &model.Vector{
|
||||
X: float64(rigidBody.position.X),
|
||||
Y: float64(rigidBody.position.Y),
|
||||
|
||||
@@ -382,9 +382,11 @@ func (p *PluginManager) HandleUserTimer(player *model.Player, data []any) {
|
||||
// 获取插件用户timer处理函数列表
|
||||
timerFunc, exist := plugin.userTimerMap[userTimerId]
|
||||
if !exist {
|
||||
logger.Error("plugin timer not exist, id: %v", userTimerId)
|
||||
continue
|
||||
}
|
||||
timerFunc(player, data)
|
||||
delete(plugin.userTimerMap, userTimerId)
|
||||
// 只需要执行一次
|
||||
break
|
||||
}
|
||||
|
||||
+48
-27
@@ -27,13 +27,15 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
PUBG_ATK = 100.0
|
||||
PUBG_HP = 1000.0
|
||||
PUBG_ATK = 100.0
|
||||
PUBG_HP = 1000.0
|
||||
PUBG_HP_LOST = 10.0
|
||||
)
|
||||
|
||||
// PluginPubg pubg游戏插件
|
||||
type PluginPubg struct {
|
||||
*Plugin
|
||||
seq uint32
|
||||
world *World // 世界对象
|
||||
blueAreaCenterPos *model.Vector // 蓝区中心点
|
||||
blueAreaRadius float64 // 蓝区半径
|
||||
@@ -50,6 +52,7 @@ type PluginPubg struct {
|
||||
func NewPluginPubg() *PluginPubg {
|
||||
p := &PluginPubg{
|
||||
Plugin: NewPlugin(),
|
||||
seq: 0,
|
||||
world: nil,
|
||||
blueAreaCenterPos: &model.Vector{X: 0.0, Y: 0.0, Z: 0.0},
|
||||
blueAreaRadius: 0.0,
|
||||
@@ -75,7 +78,7 @@ func (p *PluginPubg) OnEnable() {
|
||||
p.ListenEvent(PluginEventIdPostEnterScene, PluginEventPriorityNormal, p.EventPostEnterScene)
|
||||
// 添加全局定时器
|
||||
p.AddGlobalTick(PluginGlobalTickSecond, p.GlobalTickPubg)
|
||||
p.AddGlobalTick(PluginGlobalTickHourChange, p.GlobalTickHourStart)
|
||||
p.AddGlobalTick(PluginGlobalTickHourChange, p.GlobalTickHourChange)
|
||||
// 注册命令
|
||||
p.RegCommandController(p.NewPubgCommandController())
|
||||
}
|
||||
@@ -87,10 +90,10 @@ func (p *PluginPubg) EventKillAvatar(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventKillAvatar)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.id != player.WorldId {
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
p.CreateUserTimer(player.PlayerId, 10, p.UserTimerPubgDieExit)
|
||||
p.CreateUserTimer(player.PlayerId, 10, p.UserTimerPubgDieExit, p.world.GetId())
|
||||
}
|
||||
|
||||
// EventMarkMap 地图标点事件
|
||||
@@ -98,7 +101,7 @@ func (p *PluginPubg) EventMarkMap(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventMarkMap)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.id != player.WorldId {
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
GAME.SendMsg(cmd.MarkMapRsp, player.PlayerId, player.ClientSeq, &proto.MarkMapRsp{MarkList: p.GetAreaPointList()})
|
||||
@@ -110,7 +113,7 @@ func (p *PluginPubg) EventAvatarDieAnimationEnd(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventAvatarDieAnimationEnd)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.id != player.WorldId {
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
alivePlayerNum := len(p.GetAlivePlayerList())
|
||||
@@ -124,7 +127,7 @@ func (p *PluginPubg) EventGadgetInteract(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventGadgetInteract)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.id != player.WorldId {
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
req := event.Req
|
||||
@@ -176,7 +179,7 @@ func (p *PluginPubg) EventPostEnterScene(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventPostEnterScene)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.id != player.WorldId {
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
// 开启GM按钮 隐藏多人世界玩家位置地图标记
|
||||
@@ -219,7 +222,7 @@ func (p *PluginPubg) GlobalTickPubg() {
|
||||
AttackResult: &proto.AttackResult{
|
||||
AttackerId: 0,
|
||||
DefenseId: world.GetPlayerWorldAvatarEntityId(scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer)),
|
||||
Damage: 10,
|
||||
Damage: PUBG_HP_LOST,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -234,8 +237,8 @@ func (p *PluginPubg) GlobalTickPubg() {
|
||||
}
|
||||
}
|
||||
|
||||
// GlobalTickHourStart 每小时开启pubg游戏
|
||||
func (p *PluginPubg) GlobalTickHourStart() {
|
||||
// GlobalTickHourChange 每小时开启pubg游戏
|
||||
func (p *PluginPubg) GlobalTickHourChange() {
|
||||
p.StartPubg()
|
||||
}
|
||||
|
||||
@@ -243,29 +246,34 @@ func (p *PluginPubg) GlobalTickHourStart() {
|
||||
|
||||
// UserTimerPubgEnd pubg游戏结束后执行定时器
|
||||
func (p *PluginPubg) UserTimerPubgEnd(player *model.Player, data []any) {
|
||||
logger.Debug("PubgEnd")
|
||||
world := p.world
|
||||
if world == nil {
|
||||
logger.Debug("UserTimerPubgEnd, seq: %v", p.seq)
|
||||
oldWorld := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if oldWorld == nil {
|
||||
return
|
||||
}
|
||||
for _, worldPlayer := range world.GetAllPlayer() {
|
||||
if worldPlayer.PlayerId == world.GetOwner().PlayerId {
|
||||
continue
|
||||
}
|
||||
GAME.ReLoginPlayer(worldPlayer.PlayerId, true)
|
||||
}
|
||||
GAME.WorldRemovePlayer(oldWorld, player)
|
||||
newWorld := WORLD_MANAGER.CreateWorld(player)
|
||||
GAME.WorldAddPlayer(newWorld, player)
|
||||
WORLD_MANAGER.InitAiWorld(player)
|
||||
}
|
||||
|
||||
// UserTimerPubgUpdateArea 更新游戏区域
|
||||
func (p *PluginPubg) UserTimerPubgUpdateArea(player *model.Player, data []any) {
|
||||
logger.Debug("PubgUpdateArea")
|
||||
logger.Debug("UserTimerPubgUpdateArea, seq: %v", p.seq)
|
||||
if !p.IsStartPubg() {
|
||||
return
|
||||
}
|
||||
p.phase++
|
||||
p.RefreshArea()
|
||||
}
|
||||
|
||||
// UserTimerPubgDieExit pubg死亡离开
|
||||
func (p *PluginPubg) UserTimerPubgDieExit(player *model.Player, data []any) {
|
||||
logger.Debug("PubgDieExit")
|
||||
logger.Debug("UserTimerPubgDieExit, seq: %v", p.seq)
|
||||
pubgWorldId := data[0].(uint64)
|
||||
if player.WorldId != pubgWorldId {
|
||||
return
|
||||
}
|
||||
GAME.ReLoginPlayer(player.PlayerId, true)
|
||||
}
|
||||
|
||||
@@ -281,7 +289,7 @@ func (p *PluginPubg) NewPubgCommandController() *CommandController {
|
||||
UsageList: []string{
|
||||
"{alias} <start/stop> 开始或关闭pubg游戏",
|
||||
},
|
||||
Perm: CommandPermNormal,
|
||||
Perm: CommandPermGM,
|
||||
Func: p.PubgCommand,
|
||||
}
|
||||
}
|
||||
@@ -317,6 +325,8 @@ func (p *PluginPubg) StartPubg() {
|
||||
if p.IsStartPubg() {
|
||||
return
|
||||
}
|
||||
p.seq++
|
||||
logger.Debug("StartPubg, seq: %v", p.seq)
|
||||
world := WORLD_MANAGER.GetAiWorld()
|
||||
p.world = world
|
||||
for _, pubgWorldGadgetDataConfig := range gdconf.GetPubgWorldGadgetDataMap() {
|
||||
@@ -334,7 +344,6 @@ func (p *PluginPubg) StartPubg() {
|
||||
}
|
||||
p.phase = PUBG_PHASE_START
|
||||
p.RefreshArea()
|
||||
world.chatMsgList = make([]*proto.ChatInfo, 0)
|
||||
for _, player := range world.GetAllPlayer() {
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatarId := p.world.GetPlayerActiveAvatarId(player)
|
||||
@@ -359,13 +368,25 @@ func (p *PluginPubg) StopPubg() {
|
||||
if !p.IsStartPubg() {
|
||||
return
|
||||
}
|
||||
logger.Debug("StopPubg, seq: %v", p.seq)
|
||||
world := p.world
|
||||
p.world = nil
|
||||
p.blueAreaCenterPos = &model.Vector{X: 0.0, Y: 0.0, Z: 0.0}
|
||||
p.blueAreaRadius = 0.0
|
||||
p.safeAreaCenterPos = &model.Vector{X: 0.0, Y: 0.0, Z: 0.0}
|
||||
p.safeAreaRadius = 0.0
|
||||
p.phase = PUBG_PHASE_WAIT
|
||||
p.CreateUserTimer(p.world.GetOwner().PlayerId, 60, p.UserTimerPubgEnd)
|
||||
p.areaReduceRadiusSpeed = 0.0
|
||||
p.areaReduceXSpeed = 0.0
|
||||
p.areaReduceZSpeed = 0.0
|
||||
p.areaPointList = make([]*proto.MapMarkPoint, 0)
|
||||
p.entityIdWorldGadgetIdMap = make(map[uint32]int32)
|
||||
p.CreateUserTimer(world.GetOwner().PlayerId, 60, p.UserTimerPubgEnd)
|
||||
}
|
||||
|
||||
// IsStartPubg pubg游戏是否开启
|
||||
func (p *PluginPubg) IsStartPubg() bool {
|
||||
return p.world != nil && p.phase != PUBG_PHASE_WAIT
|
||||
return p.phase != PUBG_PHASE_WAIT
|
||||
}
|
||||
|
||||
// GetAreaPointList 获取游戏区域标点列表
|
||||
|
||||
@@ -209,7 +209,9 @@ func (r *RouteManager) RouteHandle(netMsg *mq.NetMsg) {
|
||||
case mq.ServerAddFriendNotify:
|
||||
GAME.ServerAddFriendNotify(serverMsg.AddFriendInfo)
|
||||
case mq.ServerStopNotify:
|
||||
go GAME.Close()
|
||||
GAME.ServerStopNotify()
|
||||
case mq.ServerDispatchCancelNotify:
|
||||
GAME.ServerDispatchCancelNotify(serverMsg.AppVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,11 +289,11 @@ func (t *TickManager) onTickSecond(now int64) {
|
||||
GAME.WorldPlayerRTTNotify(world)
|
||||
}
|
||||
// 每个场景时间+1
|
||||
for _, scene := range world.sceneMap {
|
||||
for _, scene := range world.GetAllScene() {
|
||||
if world.GetOwner().Pause {
|
||||
continue
|
||||
}
|
||||
scene.gameTime = scene.gameTime + 1%1440
|
||||
scene.ChangeGameTime(scene.GetGameTime() + 1)
|
||||
}
|
||||
}
|
||||
// GCG游戏Tick
|
||||
@@ -323,6 +323,16 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iPlugin, err := PLUGIN_MANAGER.GetPlugin(&PluginPubg{})
|
||||
if err != nil {
|
||||
logger.Error("get plugin pubg error: %v", err)
|
||||
return
|
||||
}
|
||||
pluginPubg := iPlugin.(*PluginPubg)
|
||||
if !pluginPubg.IsStartPubg() {
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetAiWorld()
|
||||
bulletPhysicsEngine := world.GetBulletPhysicsEngine()
|
||||
hitList := bulletPhysicsEngine.Update(now)
|
||||
@@ -330,12 +340,12 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
|
||||
scene := world.GetSceneById(rigidBody.sceneId)
|
||||
defAvatarEntity := scene.GetEntity(rigidBody.hitAvatarEntityId)
|
||||
defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid())
|
||||
entity := scene.GetEntity(rigidBody.avatarEntityId)
|
||||
atk := entity.fightProp[constant.FIGHT_PROP_CUR_ATTACK]
|
||||
atkAvatarEntity := scene.GetEntity(rigidBody.avatarEntityId)
|
||||
atk := atkAvatarEntity.GetFightProp()[constant.FIGHT_PROP_CUR_ATTACK]
|
||||
GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{
|
||||
AttackResult: &proto.AttackResult{
|
||||
AttackerId: rigidBody.avatarEntityId,
|
||||
DefenseId: rigidBody.hitAvatarEntityId,
|
||||
AttackerId: atkAvatarEntity.GetId(),
|
||||
DefenseId: defAvatarEntity.GetId(),
|
||||
Damage: atk,
|
||||
},
|
||||
})
|
||||
@@ -347,8 +357,8 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
|
||||
AttackResult: attackResultTemplate,
|
||||
FrameNum: 0,
|
||||
}
|
||||
evtBeingHitInfo.AttackResult.AttackerId = rigidBody.avatarEntityId
|
||||
evtBeingHitInfo.AttackResult.DefenseId = rigidBody.hitAvatarEntityId
|
||||
evtBeingHitInfo.AttackResult.AttackerId = atkAvatarEntity.GetId()
|
||||
evtBeingHitInfo.AttackResult.DefenseId = defAvatarEntity.GetId()
|
||||
evtBeingHitInfo.AttackResult.Damage = atk
|
||||
if evtBeingHitInfo.AttackResult.HitCollision == nil {
|
||||
return
|
||||
@@ -375,7 +385,7 @@ func (t *TickManager) onTick50MilliSecond(now int64) {
|
||||
world := WORLD_MANAGER.GetAiWorld()
|
||||
GAME.SendToWorldA(world, cmd.SceneAudioNotify, 0, &proto.SceneAudioNotify{
|
||||
Type: 5,
|
||||
SourceUid: world.owner.PlayerId,
|
||||
SourceUid: world.GetOwner().PlayerId,
|
||||
Param1: []uint32{1, <-AUDIO_CHAN},
|
||||
Param2: nil,
|
||||
Param3: nil,
|
||||
|
||||
+51
-14
@@ -179,10 +179,10 @@ func (s *Scene) CreateEntityNpc(pos, rot *model.Vector, npcId, roomId, parentQue
|
||||
},
|
||||
entityType: constant.ENTITY_TYPE_NPC,
|
||||
npcEntity: &NpcEntity{
|
||||
NpcId: npcId,
|
||||
RoomId: roomId,
|
||||
ParentQuestId: parentQuestId,
|
||||
BlockId: blockId,
|
||||
npcId: npcId,
|
||||
roomId: roomId,
|
||||
parentQuestId: parentQuestId,
|
||||
blockId: blockId,
|
||||
},
|
||||
configId: configId,
|
||||
groupId: groupId,
|
||||
@@ -435,12 +435,13 @@ type Entity struct {
|
||||
fightProp map[uint32]float32 // 战斗属性
|
||||
level uint8 // 等级
|
||||
entityType uint8 // 实体类型
|
||||
avatarEntity *AvatarEntity
|
||||
monsterEntity *MonsterEntity
|
||||
npcEntity *NpcEntity
|
||||
gadgetEntity *GadgetEntity
|
||||
configId uint32 // LUA配置相关
|
||||
groupId uint32
|
||||
// TODO 这堆东西变得有点答辩了 我觉得之后需要重构 做面向对象继承多态接口的设计
|
||||
avatarEntity *AvatarEntity
|
||||
monsterEntity *MonsterEntity
|
||||
npcEntity *NpcEntity
|
||||
gadgetEntity *GadgetEntity
|
||||
configId uint32 // LUA配置相关
|
||||
groupId uint32
|
||||
}
|
||||
|
||||
func (e *Entity) GetId() uint32 {
|
||||
@@ -455,18 +456,34 @@ func (e *Entity) GetLifeState() uint16 {
|
||||
return e.lifeState
|
||||
}
|
||||
|
||||
func (e *Entity) SetLifeState(lifeState uint16) {
|
||||
e.lifeState = lifeState
|
||||
}
|
||||
|
||||
func (e *Entity) GetLastDieType() int32 {
|
||||
return e.lastDieType
|
||||
}
|
||||
|
||||
func (e *Entity) SetLastDieType(lastDieType int32) {
|
||||
e.lastDieType = lastDieType
|
||||
}
|
||||
|
||||
func (e *Entity) GetPos() *model.Vector {
|
||||
return &model.Vector{X: e.pos.X, Y: e.pos.Y, Z: e.pos.Z}
|
||||
}
|
||||
|
||||
func (e *Entity) SetPos(pos *model.Vector) {
|
||||
e.pos.X, e.pos.Y, e.pos.Z = pos.X, pos.Y, pos.Z
|
||||
}
|
||||
|
||||
func (e *Entity) GetRot() *model.Vector {
|
||||
return &model.Vector{X: e.rot.X, Y: e.rot.Y, Z: e.rot.Z}
|
||||
}
|
||||
|
||||
func (e *Entity) SetRot(rot *model.Vector) {
|
||||
e.rot.X, e.rot.Y, e.rot.Z = rot.X, rot.Y, rot.Z
|
||||
}
|
||||
|
||||
func (e *Entity) GetMoveState() uint16 {
|
||||
return e.moveState
|
||||
}
|
||||
@@ -549,10 +566,26 @@ func (m *MonsterEntity) GetMonsterId() uint32 {
|
||||
}
|
||||
|
||||
type NpcEntity struct {
|
||||
NpcId uint32
|
||||
RoomId uint32
|
||||
ParentQuestId uint32
|
||||
BlockId uint32
|
||||
npcId uint32
|
||||
roomId uint32
|
||||
parentQuestId uint32
|
||||
blockId uint32
|
||||
}
|
||||
|
||||
func (n *NpcEntity) GetNpcId() uint32 {
|
||||
return n.npcId
|
||||
}
|
||||
|
||||
func (n *NpcEntity) GetRoomId() uint32 {
|
||||
return n.roomId
|
||||
}
|
||||
|
||||
func (n *NpcEntity) GetParentQuestId() uint32 {
|
||||
return n.parentQuestId
|
||||
}
|
||||
|
||||
func (n *NpcEntity) GetBlockId() uint32 {
|
||||
return n.blockId
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -663,6 +696,10 @@ func (g *GadgetVehicleEntity) GetVehicleId() uint32 {
|
||||
return g.vehicleId
|
||||
}
|
||||
|
||||
func (g *GadgetVehicleEntity) GetWorldId() uint64 {
|
||||
return g.worldId
|
||||
}
|
||||
|
||||
func (g *GadgetVehicleEntity) GetOwnerUid() uint32 {
|
||||
return g.ownerUid
|
||||
}
|
||||
|
||||
@@ -201,8 +201,10 @@ func (g *Game) SendPrivateChat(player *model.Player, targetUid uint32, content a
|
||||
chatMsg.Icon = content.(uint32)
|
||||
}
|
||||
|
||||
// 写入db
|
||||
go USER_MANAGER.SaveUserChatMsgToDbSync(chatMsg)
|
||||
if player.PlayerId != COMMAND_MANAGER.system.PlayerId && targetUid != COMMAND_MANAGER.system.PlayerId {
|
||||
// 写入db
|
||||
go USER_MANAGER.SaveUserChatMsgToDbSync(chatMsg)
|
||||
}
|
||||
|
||||
// 消息加入自己的队列
|
||||
msgList, exist := player.ChatMsgMap[targetUid]
|
||||
|
||||
@@ -170,7 +170,7 @@ func (g *Game) WorldPlayerLocationNotify(world *World) {
|
||||
func (g *Game) ScenePlayerLocationNotify(world *World) {
|
||||
for _, scene := range world.GetAllScene() {
|
||||
ntf := &proto.ScenePlayerLocationNotify{
|
||||
SceneId: scene.id,
|
||||
SceneId: scene.GetId(),
|
||||
PlayerLocList: make([]*proto.PlayerLocationInfo, 0),
|
||||
VehicleLocList: make([]*proto.VehicleLocationInfo, 0),
|
||||
}
|
||||
@@ -200,26 +200,26 @@ func (g *Game) ScenePlayerLocationNotify(world *World) {
|
||||
for _, entityId := range scenePlayer.VehicleInfo.CreateEntityIdMap {
|
||||
entity := scene.GetEntity(entityId)
|
||||
// 确保实体类型是否为载具
|
||||
if entity != nil && entity.GetEntityType() == constant.ENTITY_TYPE_GADGET && entity.gadgetEntity.gadgetVehicleEntity != nil {
|
||||
if entity != nil && entity.GetEntityType() == constant.ENTITY_TYPE_GADGET && entity.GetGadgetEntity().GetGadgetVehicleEntity() != nil {
|
||||
vehicleLocationInfo := &proto.VehicleLocationInfo{
|
||||
Rot: &proto.Vector{
|
||||
X: float32(entity.GetRot().X),
|
||||
Y: float32(entity.GetRot().Y),
|
||||
Z: float32(entity.GetRot().Z),
|
||||
},
|
||||
EntityId: entity.id,
|
||||
CurHp: entity.fightProp[constant.FIGHT_PROP_CUR_HP],
|
||||
OwnerUid: entity.gadgetEntity.gadgetVehicleEntity.ownerUid,
|
||||
EntityId: entity.GetId(),
|
||||
CurHp: entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP],
|
||||
OwnerUid: entity.GetGadgetEntity().GetGadgetVehicleEntity().GetOwnerUid(),
|
||||
Pos: &proto.Vector{
|
||||
X: float32(entity.GetPos().X),
|
||||
Y: float32(entity.GetPos().Y),
|
||||
Z: float32(entity.GetPos().Z),
|
||||
},
|
||||
UidList: make([]uint32, 0, len(entity.gadgetEntity.gadgetVehicleEntity.memberMap)),
|
||||
GadgetId: entity.gadgetEntity.gadgetVehicleEntity.vehicleId,
|
||||
MaxHp: entity.fightProp[constant.FIGHT_PROP_MAX_HP],
|
||||
UidList: make([]uint32, 0, len(entity.GetGadgetEntity().GetGadgetVehicleEntity().GetMemberMap())),
|
||||
GadgetId: entity.GetGadgetEntity().GetGadgetVehicleEntity().GetVehicleId(),
|
||||
MaxHp: entity.GetFightProp()[constant.FIGHT_PROP_MAX_HP],
|
||||
}
|
||||
for _, p := range entity.gadgetEntity.gadgetVehicleEntity.memberMap {
|
||||
for _, p := range entity.GetGadgetEntity().GetGadgetVehicleEntity().GetMemberMap() {
|
||||
vehicleLocationInfo.UidList = append(vehicleLocationInfo.UidList, p.PlayerId)
|
||||
}
|
||||
ntf.VehicleLocList = append(ntf.VehicleLocList, vehicleLocationInfo)
|
||||
|
||||
@@ -239,8 +239,9 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
|
||||
}
|
||||
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
// 玩家实体在移动
|
||||
g.SceneBlockAoiPlayerMove(player, world, scene, player.Pos, pos, entity.GetId())
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
if !WORLD_MANAGER.IsAiWorld(world) {
|
||||
g.SceneBlockAoiPlayerMove(player, world, scene, player.Pos, pos, entity.GetId())
|
||||
} else {
|
||||
g.AiWorldAoiPlayerMove(player, world, scene, player.Pos, pos)
|
||||
}
|
||||
// 更新玩家的位置信息
|
||||
@@ -248,8 +249,8 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
|
||||
player.Rot.X, player.Rot.Y, player.Rot.Z = rot.X, rot.Y, rot.Z
|
||||
}
|
||||
// 更新场景实体的位置信息
|
||||
entity.pos.X, entity.pos.Y, entity.pos.Z = pos.X, pos.Y, pos.Z
|
||||
entity.rot.X, entity.rot.Y, entity.rot.Z = rot.X, rot.Y, rot.Z
|
||||
entity.SetPos(pos)
|
||||
entity.SetRot(rot)
|
||||
if !force {
|
||||
motionInfo := moveInfo.MotionInfo
|
||||
switch entity.GetEntityType() {
|
||||
@@ -288,10 +289,6 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
|
||||
}
|
||||
|
||||
func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene *Scene, oldPos *model.Vector, newPos *model.Vector, avatarEntityId uint32) {
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
return
|
||||
}
|
||||
|
||||
if !world.IsValidSceneBlockPos(scene.GetId(), float32(newPos.X), 0.0, float32(newPos.Z)) {
|
||||
return
|
||||
}
|
||||
@@ -487,7 +484,10 @@ func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *S
|
||||
oldVisionEntityMap := g.GetVisionEntity(scene, oldPos)
|
||||
newVisionEntityMap := g.GetVisionEntity(scene, newPos)
|
||||
delEntityIdList := make([]uint32, 0)
|
||||
for entityId := range oldVisionEntityMap {
|
||||
for entityId, entity := range oldVisionEntityMap {
|
||||
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
continue
|
||||
}
|
||||
_, exist := newVisionEntityMap[entityId]
|
||||
if exist {
|
||||
continue
|
||||
@@ -496,7 +496,10 @@ func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *S
|
||||
delEntityIdList = append(delEntityIdList, entityId)
|
||||
}
|
||||
addEntityIdList := make([]uint32, 0)
|
||||
for entityId := range newVisionEntityMap {
|
||||
for entityId, entity := range newVisionEntityMap {
|
||||
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
continue
|
||||
}
|
||||
_, exist := oldVisionEntityMap[entityId]
|
||||
if exist {
|
||||
continue
|
||||
|
||||
@@ -425,7 +425,7 @@ func (g *Game) WorldRemovePlayer(world *World, player *model.Player) {
|
||||
g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerId, player.ClientSeq, delTeamEntityNotify)
|
||||
|
||||
// 清除其他玩家的载具
|
||||
if world.owner != player {
|
||||
if world.GetOwner().PlayerId != player.PlayerId {
|
||||
for vehicleId, entityId := range player.VehicleInfo.CreateEntityIdMap {
|
||||
g.DestroyVehicleEntity(player, scene, vehicleId, entityId)
|
||||
}
|
||||
@@ -569,6 +569,10 @@ func (g *Game) ServerPlayerMpReq(playerMpInfo *mq.PlayerMpInfo, gsAppId string)
|
||||
},
|
||||
})
|
||||
}
|
||||
if g.dispatchCancel {
|
||||
applyFailNotify(proto.PlayerApplyEnterMpResultNotify_PLAYER_CANNOT_ENTER_MP)
|
||||
return
|
||||
}
|
||||
hostPlayer := USER_MANAGER.GetOnlineUser(playerMpInfo.HostUserId)
|
||||
if hostPlayer == nil {
|
||||
logger.Error("player is nil, uid: %v", playerMpInfo.HostUserId)
|
||||
|
||||
+13
-13
@@ -346,7 +346,7 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
|
||||
}
|
||||
g.AddSceneEntityNotify(player, visionType, entityIdList, false, false)
|
||||
// 加载该场景的载具
|
||||
if world.owner == player {
|
||||
if world.GetOwner().PlayerId == player.PlayerId {
|
||||
vehicleEntityIdList := g.CreateSceneVehicle(scene)
|
||||
g.AddSceneEntityNotify(player, visionType, vehicleEntityIdList, false, false)
|
||||
}
|
||||
@@ -667,8 +667,8 @@ func (g *Game) RevivePlayerAvatar(player *model.Player, avatarId uint32) {
|
||||
}
|
||||
g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf, 0)
|
||||
|
||||
entity.lifeState = constant.LIFE_STATE_ALIVE
|
||||
entity.fightProp[constant.FIGHT_PROP_CUR_HP] = 100
|
||||
entity.SetLifeState(constant.LIFE_STATE_ALIVE)
|
||||
entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP] = 100
|
||||
}
|
||||
|
||||
// KillEntity 杀死实体
|
||||
@@ -678,9 +678,9 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d
|
||||
return
|
||||
}
|
||||
// 设置血量
|
||||
entity.lastDieType = int32(dieType)
|
||||
entity.lifeState = constant.LIFE_STATE_DEAD
|
||||
entity.fightProp[constant.FIGHT_PROP_CUR_HP] = 0
|
||||
entity.SetLastDieType(int32(dieType))
|
||||
entity.SetLifeState(constant.LIFE_STATE_DEAD)
|
||||
entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP] = 0
|
||||
ntf := &proto.LifeStateChangeNotify{
|
||||
EntityId: entity.GetId(),
|
||||
LifeState: uint32(entity.GetLifeState()),
|
||||
@@ -1812,10 +1812,10 @@ func (g *Game) PacketSceneMonsterInfo(entity *Entity) *proto.SceneMonsterInfo {
|
||||
|
||||
func (g *Game) PacketSceneNpcInfo(entity *NpcEntity) *proto.SceneNpcInfo {
|
||||
sceneNpcInfo := &proto.SceneNpcInfo{
|
||||
NpcId: entity.NpcId,
|
||||
RoomId: entity.RoomId,
|
||||
ParentQuestId: entity.ParentQuestId,
|
||||
BlockId: entity.BlockId,
|
||||
NpcId: entity.GetNpcId(),
|
||||
RoomId: entity.GetRoomId(),
|
||||
ParentQuestId: entity.GetParentQuestId(),
|
||||
BlockId: entity.GetBlockId(),
|
||||
}
|
||||
return sceneNpcInfo
|
||||
}
|
||||
@@ -1880,14 +1880,14 @@ func (g *Game) PacketSceneGadgetInfoClient(gadgetClientEntity *GadgetClientEntit
|
||||
}
|
||||
|
||||
func (g *Game) PacketSceneGadgetInfoVehicle(gadgetVehicleEntity *GadgetVehicleEntity) *proto.SceneGadgetInfo {
|
||||
player := USER_MANAGER.GetOnlineUser(gadgetVehicleEntity.ownerUid)
|
||||
player := USER_MANAGER.GetOnlineUser(gadgetVehicleEntity.GetOwnerUid())
|
||||
if player == nil {
|
||||
logger.Error("player is nil, userId: %v", gadgetVehicleEntity.ownerUid)
|
||||
logger.Error("player is nil, userId: %v", gadgetVehicleEntity.GetOwnerUid())
|
||||
return new(proto.SceneGadgetInfo)
|
||||
}
|
||||
sceneGadgetInfo := &proto.SceneGadgetInfo{
|
||||
GadgetId: gadgetVehicleEntity.GetVehicleId(),
|
||||
AuthorityPeerId: WORLD_MANAGER.GetWorldById(gadgetVehicleEntity.worldId).GetPlayerPeerId(player),
|
||||
AuthorityPeerId: WORLD_MANAGER.GetWorldById(gadgetVehicleEntity.GetWorldId()).GetPlayerPeerId(player),
|
||||
IsEnableInteract: true,
|
||||
Content: &proto.SceneGadgetInfo_VehicleInfo{
|
||||
VehicleInfo: &proto.VehicleInfo{
|
||||
|
||||
@@ -177,7 +177,7 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI
|
||||
// 删除玩家载具在线数据
|
||||
delete(player.VehicleInfo.CreateEntityIdMap, vehicleId)
|
||||
// 删除房主的载具存档
|
||||
world := scene.world
|
||||
world := scene.GetWorld()
|
||||
owner := world.GetOwner()
|
||||
if owner == player {
|
||||
dbWorld := owner.GetDbWorld()
|
||||
@@ -191,9 +191,9 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI
|
||||
func (g *Game) EnterVehicle(player *model.Player, entity *Entity, avatarGuid uint64) {
|
||||
gadgetEntity := entity.GetGadgetEntity()
|
||||
// 获取载具配置表
|
||||
vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetEntity.GetGadgetVehicleEntity().vehicleId))
|
||||
vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetEntity.GetGadgetVehicleEntity().GetVehicleId()))
|
||||
if vehicleDataConfig == nil {
|
||||
logger.Error("vehicle config error, vehicleId: %v", gadgetEntity.GetGadgetVehicleEntity().vehicleId)
|
||||
logger.Error("vehicle config error, vehicleId: %v", gadgetEntity.GetGadgetVehicleEntity().GetVehicleId())
|
||||
return
|
||||
}
|
||||
maxSlot := int(vehicleDataConfig.ConfigGadgetVehicle.Vehicle.MaxSeatCount)
|
||||
|
||||
@@ -106,13 +106,13 @@ func (g *Game) GetScenePointReq(player *model.Player, payloadMsg pb.Message) {
|
||||
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", world.id, player.PlayerId)
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", world.GetId(), player.PlayerId)
|
||||
g.SendError(cmd.GetScenePointRsp, player, &proto.GetScenePointRsp{})
|
||||
return
|
||||
}
|
||||
owner := world.GetOwner()
|
||||
if owner == nil {
|
||||
logger.Error("owner is nil, worldId: %v", world.id)
|
||||
logger.Error("owner is nil, worldId: %v", world.GetId())
|
||||
g.SendError(cmd.GetScenePointRsp, player, &proto.GetScenePointRsp{})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ func NewDiscoveryService(db *dao.Dao, messageQueue *mq.MessageQueue) (*Discovery
|
||||
r.messageQueue = messageQueue
|
||||
go r.removeDeadServer()
|
||||
go r.broadcastReceiver()
|
||||
go r.serverState()
|
||||
return r, nil
|
||||
}
|
||||
|
||||
@@ -418,15 +419,19 @@ func (s *DiscoveryService) GetStopServerInfo(ctx context.Context, req *api.NullM
|
||||
|
||||
// SetStopServerInfo 修改停服维护信息
|
||||
func (s *DiscoveryService) SetStopServerInfo(ctx context.Context, req *api.StopServerInfo) (*api.NullMsg, error) {
|
||||
shutdown := false
|
||||
if s.stopServerInfo.stopServer == false && req.StopServer == true {
|
||||
shutdown = true
|
||||
}
|
||||
s.stopServerInfo.stopServer = req.StopServer
|
||||
s.stopServerInfo.startTime = req.StartTime
|
||||
s.stopServerInfo.endTime = req.EndTime
|
||||
if shutdown {
|
||||
s.messageQueue.SendToAll(&mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerStopNotify,
|
||||
})
|
||||
}
|
||||
s.stopServerInfo.stopServer = req.StopServer
|
||||
s.stopServerInfo.startTime = req.StartTime
|
||||
s.stopServerInfo.endTime = req.EndTime
|
||||
return &api.NullMsg{}, nil
|
||||
}
|
||||
|
||||
@@ -467,6 +472,13 @@ func (s *DiscoveryService) ServerDispatchCancel(ctx context.Context, req *api.Se
|
||||
return true
|
||||
})
|
||||
}
|
||||
s.messageQueue.SendToAll(&mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerDispatchCancelNotify,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
AppVersion: req.AppVersion,
|
||||
},
|
||||
})
|
||||
return &api.NullMsg{}, nil
|
||||
}
|
||||
|
||||
@@ -553,3 +565,26 @@ func (s *DiscoveryService) handleServerDead(serverInstance *ServerInstance) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DiscoveryService) serverState() {
|
||||
ticker := time.NewTicker(time.Minute * 1)
|
||||
for {
|
||||
<-ticker.C
|
||||
totalGateLoad := uint32(0)
|
||||
totalGsLoad := uint32(0)
|
||||
for _, instMap := range s.serverInstanceMap {
|
||||
instMap.Range(func(appid, inst any) bool {
|
||||
serverInstance := inst.(*ServerInstance)
|
||||
logger.Info("server state, type: %v, appid: %v, load: %v", serverInstance.serverType, serverInstance.appId, serverInstance.loadCount)
|
||||
switch serverInstance.serverType {
|
||||
case api.GATE:
|
||||
totalGateLoad += serverInstance.loadCount
|
||||
case api.GS:
|
||||
totalGsLoad += serverInstance.loadCount
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
logger.Info("total gate load: %v, total gs load: %v", totalGateLoad, totalGsLoad)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user