竞标赛消息优化
This commit is contained in:
parent
55de1466a6
commit
7008fa4cfa
@ -30,6 +30,15 @@ var save_msg_type = []int{
|
||||
msg.HANDLE_MOD_USER_VAR_SET,
|
||||
}
|
||||
|
||||
var notify_msg_type = []int{
|
||||
msg.HANDLE_TYPE_CHAMPSHIP_GROUP, //锦标赛分组操作
|
||||
msg.HANDLE_TYPE_CHAMPSHIP_INRANK, //锦标赛入榜操作
|
||||
msg.HANDLE_TYPE_CHAMPSHIP_AI, //锦标赛入榜操作
|
||||
msg.HANDLE_TYPE_CHAMPSHIP_NOTIFY, //锦标赛排名变动通知
|
||||
msg.HANDLE_TYPE_CHAMPSHIP_ZERO, //锦标赛0点更新
|
||||
msg.HANDLE_TYPE_CHAMPSHIP_NOTIFY2, //锦标赛0.30点通知
|
||||
}
|
||||
|
||||
type MessageMgr struct {
|
||||
*ServerMod
|
||||
middlewares []MessageMiddleware
|
||||
@ -777,7 +786,10 @@ func sendMessageAsync(m *msg.Msg, node int) error {
|
||||
}()
|
||||
log.Debug("[Middleware] Send Async message to node: %d, message: %v", node, m)
|
||||
err := mergeCluster.SendServerMsg(m, node)
|
||||
if err != nil && GoUtil.InArray(m.HandleType, save_msg_type) {
|
||||
// 节点不在线且消息需要保存则保存消息
|
||||
// 需要保存的消息类型:玩家消息,锦标赛入榜,用户变量设置
|
||||
// 不需要保存的消息类型:锦标赛相关通知类消息
|
||||
if err != nil && GoUtil.InArray(m.HandleType, save_msg_type) && !GoUtil.InArray(m.Type, notify_msg_type) {
|
||||
saveMessage(m)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -64,6 +64,7 @@ type Player struct {
|
||||
activity map[int]*ActivityInfo
|
||||
stop bool
|
||||
wg sync.WaitGroup
|
||||
func_time int
|
||||
}
|
||||
|
||||
type PlayerBackUp struct {
|
||||
@ -1197,6 +1198,32 @@ func (p *Player) GetIp() string {
|
||||
return p.GetAgent().RemoteAddr().String()
|
||||
}
|
||||
|
||||
func (p *Player) func_exec_add() error {
|
||||
now := time.Now().Unix()
|
||||
|
||||
// 如果是新的一秒,重置计数
|
||||
if now != int64(p.func_time) {
|
||||
p.func_time = int(now)
|
||||
p.args["func_exec_count"] = 1
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取当前秒内的调用次数
|
||||
count := 0
|
||||
if v, ok := p.args["func_exec_count"]; ok {
|
||||
count = GoUtil.Int(v)
|
||||
}
|
||||
|
||||
// 检查是否超过限制
|
||||
if count >= 20 {
|
||||
return errors.New("func_exec_add: call limit exceeded (20 times per second)")
|
||||
}
|
||||
|
||||
// 增加计数
|
||||
p.args["func_exec_count"] = count + 1
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Player) DispatcherHandle() {
|
||||
go func() {
|
||||
var cb *timer.Timer
|
||||
|
||||
Loading…
Reference in New Issue
Block a user