优化初始资源

This commit is contained in:
hahwu 2025-07-30 10:40:45 +08:00
parent cd687ee1e2
commit 659e9dc135
6 changed files with 123 additions and 10 deletions

View File

@ -12,6 +12,7 @@ const (
Protocol_Error_Account_Device_Error int32 = 106 Protocol_Error_Account_Device_Error int32 = 106
Protocol_Error_Id_Not_Verify int32 = 107 Protocol_Error_Id_Not_Verify int32 = 107
Protocol_Error_Id_Verify_Error int32 = 108 Protocol_Error_Id_Verify_Error int32 = 108
Protocol_Error_Account_Ban int32 = 109
Protocol_Res_Buy_Cnt_Limit int32 = 110 Protocol_Res_Buy_Cnt_Limit int32 = 110
Protocol_Res_Buy_CD int32 = 111 Protocol_Res_Buy_CD int32 = 111

View File

@ -6,10 +6,14 @@ import (
"server/pkg/github.com/name5566/leaf/log" "server/pkg/github.com/name5566/leaf/log"
) )
var CFG_NAME = "UserData" const (
CFG_NAME = "UserData"
CFG_NANE_CONST = "UserDataConst"
)
func init() { func init() {
gamedata.InitCfg(CFG_NAME) gamedata.InitCfg(CFG_NAME)
gamedata.InitCfg(CFG_NANE_CONST)
} }
// 获取用户能量倍数 // 获取用户能量倍数
@ -103,3 +107,30 @@ func GetUnlock(Lv int) string {
s2 := gamedata.GetStringValue(data, "Unlock_2") s2 := gamedata.GetStringValue(data, "Unlock_2")
return s1 + "," + s2 return s1 + "," + s2
} }
func GetInitEnergy() int {
data, err := gamedata.GetDataByKey(CFG_NANE_CONST, "Energy")
if err != nil {
log.Debug("UserDataCfg GetInitEnergy not found")
return 0
}
return gamedata.GetIntValue(data, "Value")
}
func GetInitDiamond() int {
data, err := gamedata.GetDataByKey(CFG_NANE_CONST, "Diamond")
if err != nil {
log.Debug("UserDataCfg GetInitDiamond not found")
return 0
}
return gamedata.GetIntValue(data, "Value")
}
func GetInitStar() int {
data, err := gamedata.GetDataByKey(CFG_NANE_CONST, "Star")
if err != nil {
log.Debug("UserDataCfg GetInitStar not found")
return 0
}
return gamedata.GetIntValue(data, "Value")
}

51
src/server/game/BanMgr.go Normal file
View File

@ -0,0 +1,51 @@
package game
import (
"encoding/gob"
"server/GoUtil"
)
type BanMgr struct {
*ServerMod
}
type BanData struct {
BanList map[int64]int64 // 玩家ID -> 是否被封禁
}
func (f *BanMgr) Init() {
gob.Register(&VarGoldCard{})
f.key = VAR_MGR_KEY
f.data = &BanData{
BanList: make(map[int64]int64),
}
// 注册处理函数
f.init()
if f.data.(*BanData).BanList == nil {
f.data.(*BanData).BanList = make(map[int64]int64)
}
if f.data.(*VarData).UserVar == nil {
f.data.(*VarData).UserVar = make(map[string]*VarUserData)
}
}
func (f *BanMgr) IsBanned(userId int64) bool {
if f.data.(*BanData).BanList == nil {
return false
}
EndTime, banned := f.data.(*BanData).BanList[userId]
if !banned {
return false
}
return EndTime > GoUtil.Now() || EndTime == 0 // 如果EndTime为0表示永久封禁
}
func (f *BanMgr) BanUser(userId int64, endTime int64) {
f.data.(*BanData).BanList[userId] = endTime
f.SaveData()
}
func (f *BanMgr) UnbanUser(userId int64) {
delete(f.data.(*BanData).BanList, userId)
f.SaveData()
}

View File

@ -9,6 +9,7 @@ import (
"server/GoUtil" "server/GoUtil"
"server/MergeConst" "server/MergeConst"
"server/conf" "server/conf"
userCfg "server/conf/user"
"strconv" "strconv"
"sync" "sync"
@ -83,6 +84,7 @@ type GameLogic struct {
MailMgr *MailMgr // 邮件管理器 MailMgr *MailMgr // 邮件管理器
ChampshipMgr *ChampshipMgr // 锦标赛管理器 ChampshipMgr *ChampshipMgr // 锦标赛管理器
VarMgr *VarMgr // 变量管理器 VarMgr *VarMgr // 变量管理器
BanMgr *BanMgr // 封号管理器
StartTime int64 // 服务器启动时间 StartTime int64 // 服务器启动时间
} }
@ -102,9 +104,6 @@ func (gl *GameLogic) ZeroFlush() {
}) })
var a1 = []interface{}{gl.DailyTaskTimestamp} var a1 = []interface{}{gl.DailyTaskTimestamp}
GoUtil.CallEvent(MergeConst.Notify_Daily_Renew, a1) GoUtil.CallEvent(MergeConst.Notify_Daily_Renew, a1)
// gl.RankMgrSend(MsgMod.MSG_ZERO_UPDATE) // 零点更新排行榜
// gl.ChampshipMgrSend(MsgMod.MSG_ZERO_UPDATE) // 零点更新锦标赛
// gl.VarMgrSend(MsgMod.MSG_ZERO_UPDATE) // 零点更新变量
gl.NotifyAll(MsgMod.MSG_ZERO_UPDATE) gl.NotifyAll(MsgMod.MSG_ZERO_UPDATE)
gl.CreateDailyLogFile() gl.CreateDailyLogFile()
log.Debug("Server ZeroFlush") log.Debug("Server ZeroFlush")
@ -185,10 +184,10 @@ func (ad *GameLogic) NewAccountInsertDataToDB() bool {
insertId = insertId + int64(conf.Server.ServerID*100000) + int64(conf.Server.AppID*100000000) insertId = insertId + int64(conf.Server.ServerID*100000) + int64(conf.Server.AppID*100000000)
playerInfo := &db.ResPlayerBaseInfo{} playerInfo := &db.ResPlayerBaseInfo{}
playerInfo.DwUin = int64(insertId) playerInfo.DwUin = int64(insertId)
playerInfo.Energy = 100 playerInfo.Energy = int32(userCfg.GetInitEnergy())
playerInfo.Star = 0 playerInfo.Star = int32(userCfg.GetInitStar())
playerInfo.RecoverTime = int32(time.Now().Unix()) playerInfo.RecoverTime = int32(time.Now().Unix())
playerInfo.Diamond = 0 playerInfo.Diamond = int32(userCfg.GetInitDiamond())
playerInfo.Level = 1 playerInfo.Level = 1
playerInfo.Exp = 0 playerInfo.Exp = 0
playerInfo.StartOrderId = "1" playerInfo.StartOrderId = "1"
@ -400,6 +399,26 @@ func (ad *GameLogic) VarMgrCall(m *MsgMod.Msg) interface{} {
return result return result
} }
// 封号管理器
func (ad *GameLogic) CreateBanMgr() {
ad.BanMgr = &BanMgr{
ServerMod: new(ServerMod),
}
ad.BanMgr.Init()
}
func (ad *GameLogic) BanMgrSend(m *MsgMod.Msg) {
ad.BanMgr.Send(m)
}
func (ad *GameLogic) BanMgrCall(m *MsgMod.Msg) interface{} {
result, err := ad.BanMgr.Call(m)
if err != nil {
return nil
}
return result
}
func (ad *GameLogic) GetSimplePlayerByUid(Id int) *PlayerSimpleData { func (ad *GameLogic) GetSimplePlayerByUid(Id int) *PlayerSimpleData {
if Id == 0 { if Id == 0 {
return nil return nil
@ -480,6 +499,7 @@ func G_getGameLogic() *GameLogic {
G_GameLogicPtr.CreateMailMgr() //创建邮件管理器 G_GameLogicPtr.CreateMailMgr() //创建邮件管理器
G_GameLogicPtr.CreateChampshipMgr() // 创建竞标赛管理器 G_GameLogicPtr.CreateChampshipMgr() // 创建竞标赛管理器
G_GameLogicPtr.CreateVarMgr() // 创建变量管理器 G_GameLogicPtr.CreateVarMgr() // 创建变量管理器
G_GameLogicPtr.CreateBanMgr() // 创建封号管理器
ClusterMgrInit() //初始化集群 ClusterMgrInit() //初始化集群
G_GameLogicPtr.StartTime = time.Now().Unix() G_GameLogicPtr.StartTime = time.Now().Unix()
// G_GameLogicPtr.CreateHttpManager() // G_GameLogicPtr.CreateHttpManager()
@ -946,6 +966,7 @@ func Destroy() {
G_GameLogicPtr.ChampshipMgr.SaveData() G_GameLogicPtr.ChampshipMgr.SaveData()
G_GameLogicPtr.MailMgr.SaveData() G_GameLogicPtr.MailMgr.SaveData()
G_GameLogicPtr.VarMgr.SaveData() G_GameLogicPtr.VarMgr.SaveData()
G_GameLogicPtr.BanMgr.SaveData()
G_GameLogicPtr.MLogManager.Close() G_GameLogicPtr.MLogManager.Close()
} }
log.Debug("服务器下线完成") log.Debug("服务器下线完成")

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/gob" "encoding/gob"
"fmt" "fmt"
userCfg "server/conf/user"
"server/db" "server/db"
"server/game/mod/activity" "server/game/mod/activity"
"server/game/mod/avatar" "server/game/mod/avatar"
@ -145,9 +146,9 @@ func (p *PlayerModData) InitMod(player *Player) (bool, error) {
BaseMod.SetAccount(PlayerBaseMod.Data.UserName) BaseMod.SetAccount(PlayerBaseMod.Data.UserName)
BaseMod.SetLevel(int(PlayerBaseMod.Data.Level)) BaseMod.SetLevel(int(PlayerBaseMod.Data.Level))
BaseMod.SetExp(int(PlayerBaseMod.Data.Exp)) BaseMod.SetExp(int(PlayerBaseMod.Data.Exp))
BaseMod.SetEnergy(int(PlayerBaseMod.Data.Energy)) BaseMod.SetEnergy(userCfg.GetInitEnergy())
BaseMod.SetStar(int(PlayerBaseMod.Data.Star)) BaseMod.SetStar(userCfg.GetInitStar())
BaseMod.SetDiamond(int(PlayerBaseMod.Data.Diamond)) BaseMod.SetDiamond(userCfg.GetInitDiamond())
BaseMod.SetRecoverTime(int64(PlayerBaseMod.Data.RecoverTime)) BaseMod.SetRecoverTime(int64(PlayerBaseMod.Data.RecoverTime))
BaseMod.FackBookId = PlayerBaseMod.Data.FaceBookId BaseMod.FackBookId = PlayerBaseMod.Data.FaceBookId
is_update = true is_update = true

View File

@ -87,6 +87,14 @@ func VerifyUser(accountInfo *db.Db_Account, detail *msg.ReqLogin) (ResLogin *msg
return return
} }
if G_GameLogicPtr.BanMgr.IsBanned(playerbaseinfo.DwUin) {
ResLogin = &msg.ResLogin{
ResultCode: MergeConst.Protocol_Error_Account_Ban,
DwUin: 0,
}
return
}
ResLogin = &msg.ResLogin{ ResLogin = &msg.ResLogin{
ResultCode: 0, ResultCode: 0,
DwUin: playerbaseinfo.DwUin, DwUin: playerbaseinfo.DwUin,