封号功能
This commit is contained in:
parent
da8f73020f
commit
1afbf01a1a
@ -10,39 +10,49 @@ type BanMgr struct {
|
||||
}
|
||||
|
||||
type BanData struct {
|
||||
BanList map[int64]int64 // 玩家ID -> 是否被封禁
|
||||
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{
|
||||
BanList: make(map[int64]int64),
|
||||
NewBanList: make(map[int64]*BanInfo),
|
||||
}
|
||||
// 注册处理函数
|
||||
f.init()
|
||||
if f.data.(*BanData).BanList == nil {
|
||||
f.data.(*BanData).BanList = make(map[int64]int64)
|
||||
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).BanList == nil {
|
||||
if f.data.(*BanData).NewBanList == nil {
|
||||
return false
|
||||
}
|
||||
EndTime, banned := f.data.(*BanData).BanList[userId]
|
||||
Info, banned := f.data.(*BanData).NewBanList[userId]
|
||||
if !banned {
|
||||
return false
|
||||
}
|
||||
return EndTime > GoUtil.Now() || EndTime == 0 // 如果EndTime为0,表示永久封禁
|
||||
return Info.EndTime > GoUtil.Now() || Info.EndTime == 0 // 如果EndTime为0,表示永久封禁
|
||||
}
|
||||
|
||||
func (f *BanMgr) BanUser(userId int64, endTime int64) {
|
||||
f.data.(*BanData).BanList[userId] = endTime
|
||||
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).BanList, userId)
|
||||
delete(f.data.(*BanData).NewBanList, userId)
|
||||
f.SaveData()
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ var AdminFuncMap = map[string]func([]interface{}) error{
|
||||
"ReqReloadServerMail": ReqReloadServerMail,
|
||||
"ReqReload": ReqReload,
|
||||
"ReqAdminGm": ReqAdminGm,
|
||||
"ReqAdminBan": ReqAdminGm,
|
||||
}
|
||||
|
||||
func AdminProcess(Func string, args []interface{}) {
|
||||
@ -132,6 +133,7 @@ func AdminPlayerInfo(args []interface{}) error {
|
||||
res["Cumulative"] = player.PlayMod.getBaseMod().Cumulative
|
||||
res["RegisterTime"] = player.GetPlayerBaseMod().GetRegisterTime()
|
||||
res["TodayCumulative"] = player.PlayMod.getBaseMod().TodayCumulative
|
||||
res["Ban"] = G_GameLogicPtr.BanMgr.IsBanned(player.M_DwUin)
|
||||
if online {
|
||||
res["Cumulative"] = int64(player.PlayMod.getBaseMod().Cumulative) + GoUtil.Now() - int64(player.PlayMod.getBaseMod().LoginTime)
|
||||
res["TodayCumulative"] = int64(player.PlayMod.getBaseMod().TodayCumulative) + GoUtil.Now() - int64(player.PlayMod.getBaseMod().LoginTime)
|
||||
@ -219,11 +221,6 @@ func ReqAdminGm(args []interface{}) error {
|
||||
player.lock.Lock()
|
||||
defer player.lock.Unlock()
|
||||
err := ReqGmCommand_(player, req.Command)
|
||||
|
||||
if err != nil {
|
||||
res["Code"] = 1
|
||||
res["Msg"] = err.Error()
|
||||
}
|
||||
if err != nil {
|
||||
res["Code"] = 1
|
||||
res["Msg"] = err.Error()
|
||||
@ -233,3 +230,24 @@ func ReqAdminGm(args []interface{}) error {
|
||||
AdminPlayerBack(a, res)
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReqAdminBan(args []interface{}) error {
|
||||
a, buf := ParseAdminArgs(args)
|
||||
req := &msg.ReqAdminBan{}
|
||||
proto.Unmarshal(buf, req)
|
||||
res := make(map[string]interface{})
|
||||
res["Code"] = 0
|
||||
res["Msg"] = "ok"
|
||||
player := G_GameLogicPtr.GetPlayer(req.Uid)
|
||||
if player == nil {
|
||||
res["Code"] = 1
|
||||
res["Msg"] = "player not found"
|
||||
AdminPlayerBack(a, res)
|
||||
return nil
|
||||
}
|
||||
player.lock.Lock()
|
||||
defer player.lock.Unlock()
|
||||
G_GameLogicPtr.BanMgr.BanUser(player.M_DwUin, int64(req.Time), req.Reason)
|
||||
AdminPlayerBack(a, res)
|
||||
return nil
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user