Merge branch 'develop' into sdk
This commit is contained in:
commit
6f7a9ab741
@ -112,6 +112,9 @@ func SendServerMsg(m *msg.Msg, serverId int) error {
|
||||
if m.UniKey == "" {
|
||||
m.UniKey = GoUtil.UniKey(fmt.Sprintf("%v,Cluster Msg", m))
|
||||
}
|
||||
if m.SendT == 0 {
|
||||
m.SendT = GoUtil.Now()
|
||||
}
|
||||
if v, ok := serverAgent.Load(serverId); ok {
|
||||
data, err := GoUtil.GobMarshal(m)
|
||||
if err != nil {
|
||||
@ -128,6 +131,9 @@ func CallServerMsg(m *msg.Msg, serverId int) (*msg.Msg, error) {
|
||||
if m.UniKey == "" {
|
||||
m.UniKey = GoUtil.UniKey(fmt.Sprintf("%v,Cluster Msg", m))
|
||||
}
|
||||
if m.SendT == 0 {
|
||||
m.SendT = GoUtil.Now()
|
||||
}
|
||||
v, ok := serverAgent.Load(serverId)
|
||||
// 之后再发送消息
|
||||
if !ok {
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
"AppID": 0,
|
||||
"LogLevel": "debug",
|
||||
"LogPath": "./log",
|
||||
"TCPAddr": ":3601",
|
||||
"WSAddr": ":3566",
|
||||
"TCPAddr": ":3602",
|
||||
"WSAddr": ":3567",
|
||||
"MySqlAddr": "127.0.0.1",
|
||||
"MySqlPort": "3306",
|
||||
"MySqlUsr": "root",
|
||||
@ -25,9 +25,9 @@
|
||||
"ServerCenter" : 0,
|
||||
"GameConfPath": "D:/Github/pet_home_server/src/server/gamedata/config/",
|
||||
|
||||
"ListenAddr":":9001",
|
||||
"ListenAddr":":9002",
|
||||
"CenterAddr": "127.0.0.1:7000",
|
||||
"RemoteAddr":"127.0.0.1:9001",
|
||||
"RemoteAddr":"127.0.0.1:9002",
|
||||
|
||||
"RedisAddr":"127.0.0.1",
|
||||
"RedisPort" :"6379",
|
||||
|
||||
@ -894,7 +894,7 @@ func (ad *GameLogic) GetStartTime() int64 {
|
||||
func NotifyPlayer(Uid int, m *MsgMod.Msg) {
|
||||
m.To = Uid
|
||||
m.HandleType = MsgMod.HANDLE_MOD_PLAYER_MSG
|
||||
CenterPlayerMsgHandler(m)
|
||||
NotifyPlayerMsgAsync(m)
|
||||
}
|
||||
|
||||
func Destroy() {
|
||||
|
||||
@ -124,6 +124,27 @@ func (m *MessageMgr) MessageMgrInit() {
|
||||
m.Use(TimeoutMiddleware(5 * time.Second))
|
||||
m.NodeRegister()
|
||||
m.CenterRegister()
|
||||
FixBug()
|
||||
}
|
||||
|
||||
func FixBug() {
|
||||
messageMgrData := getMessageData()
|
||||
// 先更新 PlayerList(需要加锁)
|
||||
messageMgrData.mu.Lock()
|
||||
defer messageMgrData.mu.Unlock()
|
||||
for k, v := range messageMgrData.MessageList {
|
||||
if k < 100000 {
|
||||
delete(messageMgrData.MessageList, k)
|
||||
continue
|
||||
}
|
||||
// 反向遍历以安全删除元素
|
||||
for i := len(v.Messages) - 1; i >= 0; i-- {
|
||||
if v.Messages[i].Type == msg.HANDLE_TYPE_CHAMPSHIP_NOTIFY {
|
||||
// 删除消息
|
||||
v.Messages = append(v.Messages[:i], v.Messages[i+1:]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 注册处理器
|
||||
@ -308,22 +329,39 @@ func ComsumerMsgHandler(data *msg.Msg) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func NotifyPlayerMsgAsync(m *msg.Msg) {
|
||||
messageMgrData := getMessageData()
|
||||
// 检查玩家是否在线(需要加锁)
|
||||
messageMgrData.mu.Lock()
|
||||
node, ok := messageMgrData.PlayerList[int64(m.To)]
|
||||
messageMgrData.mu.Unlock()
|
||||
// 在线则直接发送消息
|
||||
if ok {
|
||||
SendMsgToNodeAsync(m, node)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理玩家消息
|
||||
func CenterPlayerMsgHandler(data *msg.Msg) (interface{}, error) {
|
||||
PlayerId := int64(data.To)
|
||||
messageMgrData := getMessageData()
|
||||
// 遍历消息列表,发送消息给在线玩家
|
||||
messages := getMessge(PlayerId)
|
||||
messages.mu.Lock()
|
||||
messages.Messages = append(messages.Messages, data)
|
||||
messages.mu.Unlock()
|
||||
|
||||
// 检查玩家是否在线(需要加锁)
|
||||
messageMgrData.mu.Lock()
|
||||
node, ok := messageMgrData.PlayerList[int64(PlayerId)]
|
||||
messageMgrData.mu.Unlock()
|
||||
|
||||
// 在线则直接发送消息
|
||||
if ok {
|
||||
SendMsgToNodeAsync(data, node)
|
||||
} else {
|
||||
// 不在线则存储消息
|
||||
if !GoUtil.InArray(data.Type, notify_msg_type) {
|
||||
messages := getMessge(PlayerId)
|
||||
messages.mu.Lock()
|
||||
messages.Messages = append(messages.Messages, data)
|
||||
messages.mu.Unlock()
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user