pet_home_server/src/server/game/BanMgr.go
2025-07-30 15:02:37 +08:00

59 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package game
import (
"encoding/gob"
"server/GoUtil"
)
type BanMgr struct {
*ServerMod
}
type BanData struct {
NewBanList map[int64]*BanInfo // 新增的封禁列表
}
type BanInfo struct {
UserId int64 // 玩家ID
EndTime int64 // 封禁结束时间0表示永久封禁
Reason string // 封禁原因
}
func (f *BanMgr) Init() {
gob.Register(&BanData{})
f.key = BAN_MGR_KEY
f.data = &BanData{
NewBanList: make(map[int64]*BanInfo),
}
// 注册处理函数
f.init()
if f.data.(*BanData).NewBanList == nil {
f.data.(*BanData).NewBanList = make(map[int64]*BanInfo)
}
}
func (f *BanMgr) IsBanned(userId int64) bool {
if f.data.(*BanData).NewBanList == nil {
return false
}
Info, banned := f.data.(*BanData).NewBanList[userId]
if !banned {
return false
}
return Info.EndTime > GoUtil.Now() || Info.EndTime == -1 // 如果EndTime为0表示永久封禁
}
func (f *BanMgr) BanUser(userId int64, endTime int64, reason string) {
f.data.(*BanData).NewBanList[userId] = &BanInfo{
UserId: userId,
EndTime: endTime,
Reason: reason,
}
f.SaveData()
}
func (f *BanMgr) UnbanUser(userId int64) {
delete(f.data.(*BanData).NewBanList, userId)
f.SaveData()
}