59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
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()
|
||
}
|