代码拉取完成,页面将自动刷新
package logic
import (
"encoding/json"
"math/rand"
"strings"
"time"
csv "gitee.com/liuxuezhan/mylib/GameServer/CSV"
"gitee.com/liuxuezhan/mylib/GameServer/GameDB"
"gitee.com/liuxuezhan/mylib/GameServer/JsonConfig"
"gitee.com/liuxuezhan/mylib/GameServer/cache"
"gitee.com/liuxuezhan/mylib/GameServer/observer"
"gitee.com/liuxuezhan/mylib/GameServer/oss"
proto "gitee.com/liuxuezhan/mylib/Protocol"
"gitee.com/liuxuezhan/mylib/Utils/wlog"
"gitee.com/liuxuezhan/mylib/common"
"gitee.com/liuxuezhan/mylib/wtime"
"github.com/kataras/go-errors"
"gopkg.in/mgo.v2/bson"
)
var (
GMCommandHandlerMap map[string]func(string) (error, string)
)
func getBuildingID(buildings []*proto.ST_Building_PB, buildingType uint32) []uint32 {
ret := make([]uint32, 0)
for _, v := range buildings {
if v.GetBuildingtype() == buildingType {
ret = append(ret, v.GetBuildingID())
}
}
return ret
}
func SetBuildingLevel(userData *cache.Info, buildinglevel uint32) {
buildingAsset := userData.GetBuildings()
for _, v := range csv.Mgr.CSV_BuildingConfig.GetIDList() {
bConfig := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(v)
if bConfig.TagType == 4 || bConfig.IsDisuse == 1 {
continue
}
maxCount := int(bConfig.MaxCount)
maxlevel := uint32(bConfig.MaxLevel)
if buildinglevel < maxlevel {
maxlevel = buildinglevel
}
buildingIDList := getBuildingID(buildingAsset, uint32(v))
for _, v := range buildingIDList {
userData.SetBuildingLevel(v, maxlevel)
if bConfig.Type == int64(proto.BuildingType_BT_BASE_STATION) {
userData.SetMainCityLevel(maxlevel)
wdata := cache.Instance_GlobalAssetWorldData.GetWorldData(userData.GetWorldDataId())
if wdata != nil {
dataEntry := wdata.GetWorldDataEntry()
dataEntry.Z = proto.SetInt32(int32(maxlevel))
wdata.SetWorldDataEntry(dataEntry)
}
//>>>主城升级事件
observer.ObserverSingleton.AsyncNotify(observer.MainCityLevelUpgradeEvent, []interface{}{userData})
}
}
needAdd := maxCount - len(buildingIDList)
for i := 0; i < needAdd; i++ {
width := uint32(bConfig.Width)
height := uint32(bConfig.Height)
find := false
var x, y uint32
for {
x = uint32(common.GetRandomNum(150))
y = uint32(common.GetRandomNum(150))
tileid := common.ConvertMainCityCoordinateToId(x, y)
if cache.SafeCheckTileCanUse(userData, x, y, width, height) && userData.CheckBuildingIndex(tileid, width, height) {
find = true
break
}
}
if find {
tileid := common.ConvertMainCityCoordinateToId(x, y)
bID := userData.AllocBuildingID()
userData.AddBuildingWithLevel(tileid, bID, uint32(v), maxlevel)
//userData.UpdateBuildingIndex(tileid, width, height, bID)
if bConfig.Type == int64(proto.BuildingType_BT_BASE_STATION) {
wdata := cache.Instance_GlobalAssetWorldData.GetWorldData(userData.GetWorldDataId())
if wdata != nil {
dataEntry := wdata.GetWorldDataEntry()
dataEntry.Z = proto.SetInt32(int32(maxlevel))
wdata.SetWorldDataEntry(dataEntry)
}
//>>>主城升级事件
observer.ObserverSingleton.AsyncNotify(observer.MainCityLevelUpgradeEvent, []interface{}{userData})
}
if bConfig.Type == int64(proto.BuildingType_BT_EQUIP_FACTORY) {
processFactoryLevelUp(userData)
}
}
}
}
}
func ResetBuildingPos(userData *cache.Info) {
buildingAsset := userData.GetBuildings()
for _, v := range buildingAsset {
bConfig := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(v.GetBuildingtype()))
if bConfig.TagType == 4 {
continue
}
width := uint32(bConfig.Width)
height := uint32(bConfig.Height)
find := false
var x, y uint32
for {
x = uint32(common.GetRandomNum(150))
y = uint32(common.GetRandomNum(150))
tileid := common.ConvertMainCityCoordinateToId(x, y)
if cache.SafeCheckTileCanUse(userData, x, y, width, height) && userData.CheckBuildingIndex(tileid, width, height) {
find = true
break
}
}
if find {
userData.UpdateBuildingLocation(v.GetBuildingID(), x, y)
}
}
}
func DropTest(userData *cache.Info, dropid int32) bool {
itemList := csv.GetDropItem(dropid)
wlog.Info(itemList)
for _, v := range itemList {
AddItem(userData, v.GetItemId(), v.GetItemNum(), oss.AddCashSrcTypeGM)
}
return true
}
/**
@brief GM发送邮件
*/
func SendGMMail(userData *cache.Info) {
title := "此处应该是title"
content := "此处应该是content"
details := "内容还是省略吧"
if 0 == rand.Int()%2 {
for i := 0; i < 10; i++ {
userData.AddTextMailAsset(uint32(proto.MailType_MT_SYSTEM), 0, userData.GetUid(), 0, int32(proto.MailSourceType_MST_GM), title, content, "", details, "", -1)
}
} else {
title := "还是给点奖励吧"
itemIdList := csv.Mgr.CSV_ItemList.GetIDList()
rewardList := &proto.ST_MailRewardList_PB{}
for i := 0; i < int(rand.Int31n(5)); i++ {
randomIndex := rand.Int31n(int32(len(itemIdList)))
entry := csv.Mgr.CSV_ItemList.GetEntryPtr(itemIdList[randomIndex])
rewardList.Reward = append(rewardList.Reward, &proto.ST_Vector4Int_PB{
X: proto.SetInt32(2),
Y: proto.SetInt32(int32(entry.ID)),
Z: proto.SetInt32(1),
W: proto.SetInt32(int32(rand.Int31n(10) + 1)),
})
}
rewardStr := string(proto.Marshal(rewardList))
for i := 0; i < 10; i++ {
userData.AddTextMailAsset(uint32(proto.MailType_MT_SYSTEM), 0, userData.GetUid(), 0, int32(proto.MailSourceType_MST_GM), title, content, rewardStr, details, "", -1)
}
}
}
func ExeGMCommand(command, params string) (error, string) {
if handler, ok := GMCommandHandlerMap[command]; ok {
wlog.Info("ExeGMCommand ", command)
return handler(params)
}
return errors.New("query type error"), ""
}
func registerGMCommandHandler() {
GMCommandHandlerMap = map[string]func(string) (error, string){
"10": handleQueryAccountInfo,
"11": handleQueryCharBasicInfo,
"14": handleQueryItemPack,
"18": handleQueryHero,
"19": handleQueryBuilding,
"110": handleQueryUnit,
"111": handleQueryTech,
"15": handleQueryTalent,
"37": handleQueryPower,
"38": handleQueryPayHistory30,
"39": handleQueryStatistics,
"40": handleQueryForbiddenInfo,
"410": handleQueryResource,
"41": handleForbiddenChatAll,
"42": handleOpenChatAll,
"43": handleForbidLogin,
"44": handleOpenLogin,
"45": handleKickOut,
"46": handleForbidChatWorld,
"47": handleOpenChatWorld,
"48": handleForbidChatLeague,
"49": handleOpenChatLeague,
"411": handleModifyResource,
"71": handleQueryServerStatus,
"412": handleModifySpecialItem,
"21": handleAndEveryoneMail,
"22": handleRemoveEveryoneMail,
"10000": handleKickOutAll,
"60": handleGiftPackOperator,
"63": handleOfferGiftOperator,
"51": handleArchonNoticeOperator,
"52": handleQueryArchonNotice,
"50": handleSendGlobalMessage,
"80": handleBoonActivityOper,
"82": handleQueryBoonActivity,
"84": handleLuckyStarOperator,
"85": handleWorldSituationSet,
"87": handleAddTBActivity,
"88": handleCloseTBActivity,
"90": handleAddStrongestCommander,
"91": handleCloseStrongestCommander,
}
}
func handleWorldSituationSet(num string) (error, string) {
err, ret := WorldSituationSet(common.StringToUint64(num))
ret = common.Base64Encode(string(ret))
if err == "" {
return nil, ret
} else {
return errors.New(err), ret
}
}
func handleQueryCharBasicInfo(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
basicInfo := &proto.ST_GM_CharBasic_PB{
Uid: proto.SetUint64(userData.GetUid()),
Name: proto.SetString(userData.GetUserName()),
VipLevel: proto.SetUint32(userData.GetVipLevel()),
LeagueID: proto.SetUint64(userData.GetLeagueID()),
Resource: userData.GetCashAsset(),
Power: proto.SetUint64(userData.GetPower()),
LeagueName: proto.SetString(userData.GetLeagueName()),
CreateTime: proto.SetUint64(userData.GetCreateTime()),
CommanderLevel: proto.SetUint32(userData.GetLevel()),
BaseLevel: proto.SetUint32(userData.GetMainCityLevel()),
Language: proto.SetUint32(userData.GetLanguage()),
Channel: proto.SetUint32(0),
LeagueLevel: proto.SetInt32(cache.Instance_GlobalAssetLeague.GetMemberLevel(userData.GetLeagueID(), userData.GetUid())),
KillNum: proto.SetUint64(userData.GetKillUnitNum()),
Location: proto.SetInt32(userData.GetLocation()),
Sid: proto.SetUint64(uint64(JsonConfig.GlobalConfig.Basic.ServerID)),
TotalPay: proto.SetUint32(userData.GetTotalPay()),
CurLabel: proto.SetUint64(userData.GetCurLabel()),
IP: proto.SetString(userData.GetIP()),
}
if cache.Sessionkey.IsRealOnline(uid) {
basicInfo.OnlineStatus = proto.SetUint32(1)
}
if userData.GetForbidLogin() > wtime.GetNow() {
basicInfo.ForbiddenTime = proto.SetUint64(userData.GetForbidLogin())
basicInfo.ForbiddenStatus = proto.SetUint32(1)
}
b := proto.Marshal(basicInfo)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryAccountInfo(params string) (error, string) {
cname := params
if len(cname) <= 0 {
return errors.New("cname error"), ""
}
err, accounts := GameDB.Characteristic.FindUsersByName(cname, bson.M{"_id": 1, "user_name": 1}, 50)
if err != nil {
return errors.New("query err"), ""
}
accountInfos := &proto.ST_AccountInfos_PB{}
for _, v := range accounts {
info := &proto.ST_AccountInfo_PB{
Uid: proto.SetUint32(uint32(v.UserId)),
Name: proto.SetString(v.UserName),
}
accountInfos.Infos = append(accountInfos.Infos, info)
}
b := proto.Marshal(accountInfos)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryItemPack(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
asset := userData.GetItemPackAsset()
b := proto.Marshal(asset)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryPayHistory30(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
asset := userData.GetHistory30()
b := proto.Marshal(asset)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryHero(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
heros := userData.GetAllHero()
b := proto.Marshal(heros)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryBuilding(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
buildingAsset := &proto.ST_GM_Buildings_PB{}
for _, v := range userData.GetBuildings() {
building := &proto.ST_GM_Building_PB{
BuildingID: proto.SetUint32(v.GetBuildingID()),
X: proto.SetUint32(v.GetX()),
Y: proto.SetUint32(v.GetY()),
Buildingtype: proto.SetUint32(v.GetBuildingtype()),
Buildinglevel: proto.SetUint32(v.GetBuildinglevel()),
}
userData.SafeForeachLocalAction(true, func(action *proto.ST_LocalActionEntry_PB) bool {
if action.GetBuildingID() == v.GetBuildingID() &&
(action.GetActiontype() == uint32(proto.ActionType_AT_BUILD_LEVELUP) || action.GetActiontype() == uint32(proto.ActionType_AT_BUILD_EMPTY)) {
building.Status = proto.SetUint32(1)
return false
}
return true
})
buildingAsset.Buildings = append(buildingAsset.Buildings, building)
}
b := proto.Marshal(buildingAsset)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryUnit(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
unitAsset := userData.GetUnitAsset()
if unitAsset == nil || unitAsset.Units == nil {
unitAsset = &proto.ST_UnitAsset_PB{
Units: make([]*proto.ST_Unit_PB, 0),
}
}
for _, v := range userData.GetGlobalActionIDs() {
action := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(v)
if nil != action && (action.Actiondata.GetActiontype() > uint32(proto.ActionType_AT_WORLDMAP_BEGIN) &&
action.Actiondata.GetActiontype() < uint32(proto.ActionType_AT_WORLDMAP_END)) && action.Actiondata.GetHit() == 0 {
if action.Actiondata.GetUnits() != nil {
unitAsset.Units = common.CombineUnitMap(unitAsset.Units, action.Actiondata.GetUnits().Units)
}
}
}
b := proto.Marshal(unitAsset)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryTech(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
b := proto.Marshal(userData.GetResearchAsset())
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryTalent(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
b := proto.Marshal(userData.GetTalentAsset())
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryPower(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
totalPower := uint64(0)
powerPB := &proto.ST_GM_Power_PB{}
powerPB.BuildingPower = proto.SetUint64(userData.CalcBuildingPower())
powerPB.HeroPower = proto.SetUint64(userData.CalcAllHeroPower())
powerPB.TechPower = proto.SetUint64(userData.CalcResearchPower())
powerPB.TelentPower = proto.SetUint64(userData.CalcTelentPower())
powerPB.UnitPower = proto.SetUint64(userData.CalcUnitPower())
powerPB.LorderPower = proto.SetUint64(userData.CalcLordPower())
totalPower = powerPB.GetBuildingPower() + powerPB.GetHeroPower() + powerPB.GetTechPower() + powerPB.GetTelentPower() +
powerPB.GetUnitPower() + powerPB.GetLorderPower()
powerPB.TotalPower = proto.SetUint64(totalPower)
b := proto.Marshal(powerPB)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryStatistics(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
b := proto.Marshal(userData.CopyStatisticsAsset())
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryForbiddenInfo(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
forbidden := &proto.ST_GM_Forbidden_PB{}
forbidden.ForbiddenChat = userData.GetForbidChatInfo()
startTime, dur, msg := userData.GetForbidLoginInfo()
forbidden.ForbiddenLoginStart = proto.SetUint64(startTime)
forbidden.ForbiddenLoginDur = proto.SetUint64(dur)
forbidden.ForbiddenLoginMsg = proto.SetString(msg)
b := proto.Marshal(forbidden)
result := common.Base64Encode(string(b))
return nil, result
}
func handleQueryResource(params string) (error, string) {
uid := common.StringToUint64(params)
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
resourceInfo := &proto.ST_GM_Resource_PB{
Uid: proto.SetUint64(uid),
Name: proto.SetString(userData.GetUserName()),
RegionID: proto.SetUint32(0),
CreateTime: proto.SetUint64(userData.GetCreateTime()),
Resource: userData.GetCashAsset(),
}
b := proto.Marshal(resourceInfo)
result := common.Base64Encode(string(b))
return nil, result
}
func handleForbiddenChatAll(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
now := wtime.GetNow()
endTime := common.StringToUint64(p[1])
msg := p[2]
if endTime < now {
return errors.New("param time error"), ""
}
userData.SetForbidChat(uint32(proto.ForbiddenChatType_FCT_ALL_CHAT), endTime-now, msg)
if userData.GetLeagueID() != 0 {
ForbidLeagueChat(userData.GetLeagueID(), userData.GetUid(), endTime-now)
}
return nil, ""
}
func handleOpenChatAll(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
msg := p[2]
userData.SetForbidChat(uint32(proto.ForbiddenChatType_FCT_ALL_CHAT), 0, msg)
if userData.GetLeagueID() != 0 {
ForbidLeagueChat(userData.GetLeagueID(), userData.GetUid(), 1)
}
return nil, ""
}
func handleForbidLogin(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
now := wtime.GetNow()
endTime := common.StringToUint64(p[1])
msg := p[2]
if endTime < now {
return errors.New("param time error"), ""
}
userData.SetForbidLogin(endTime-now, msg)
cache.Sessionkey.Delete(uid)
return nil, ""
}
func handleOpenLogin(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
msg := p[2]
userData.SetForbidLogin(0, msg)
return nil, ""
}
func handleKickOut(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
cache.Sessionkey.Delete(uid)
return nil, ""
}
func handleKickOutAll(params string) (error, string) {
cache.Sessionkey.DeleteAll()
return nil, ""
}
func handleForbidChatWorld(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
now := wtime.GetNow()
endTime := common.StringToUint64(p[1])
msg := p[2]
if endTime < now {
return errors.New("param time error"), ""
}
userData.SetForbidChat(uint32(proto.ForbiddenChatType_FCT_WORLD_CHAT), endTime-now, msg)
return nil, ""
}
func handleOpenChatWorld(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
msg := p[2]
userData.SetForbidChat(uint32(proto.ForbiddenChatType_FCT_WORLD_CHAT), 0, msg)
return nil, ""
}
func handleForbidChatLeague(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
now := wtime.GetNow()
endTime := common.StringToUint64(p[1])
msg := p[2]
if endTime < now {
return errors.New("param time error"), ""
}
userData.SetForbidChat(uint32(proto.ForbiddenChatType_FCT_LEAGUE_CHAT), endTime-now, msg)
if userData.GetLeagueID() != 0 {
ForbidLeagueChat(userData.GetLeagueID(), userData.GetUid(), endTime-now)
}
return nil, ""
}
func handleOpenChatLeague(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 3 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
msg := p[2]
userData.SetForbidChat(uint32(proto.ForbiddenChatType_FCT_LEAGUE_CHAT), 0, msg)
if userData.GetLeagueID() != 0 {
ForbidLeagueChat(userData.GetLeagueID(), userData.GetUid(), 1)
}
return nil, ""
}
func handleQueryServerStatus(params string) (error, string) {
serverStatus := &proto.ST_GM_ServerStatus_PB{
ServerID: proto.SetUint32(JsonConfig.GlobalConfig.Basic.ServerID),
ServerName: proto.SetString(JsonConfig.GlobalConfig.Basic.ServerName),
OnlineCount: proto.SetUint32(cache.Sessionkey.Count()),
MaxLimit: proto.SetUint32(0),
GameVersion: proto.SetString(""),
ServerStatus: proto.SetUint32(0),
}
b := proto.Marshal(serverStatus)
result := common.Base64Encode(string(b))
return nil, result
}
func handleModifyResource(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 5 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
if common.StringToInt32(p[4]) < 0 {
return errors.New("number error"), ""
}
itemType := p[1]
if itemType == "410" {
cashType := common.StringToUint32(p[2])
if cashType != uint32(proto.CashType_CASH_TYPE_1) &&
cashType != uint32(proto.CashType_CASH_TYPE_2) &&
cashType != uint32(proto.CashType_CASH_TYPE_3) &&
cashType != uint32(proto.CashType_CASH_TYPE_4) &&
cashType != uint32(proto.CashType_CASH_TYPE_5) &&
cashType != uint32(proto.CashType_CASH_TYPE_100) &&
cashType != uint32(proto.CashType_CASH_TYPE_EXPEDITION) {
return errors.New("item id err"), ""
}
status := p[3]
number := common.StringToUint64(p[4])
if status == "1" || status == "3" {
userData.AddCash(cashType, number, oss.AddCashSrcTypeGM)
} else if status == "2" {
if !userData.ReduceCash(cashType, number, oss.ReduceCashSrcTypeGM) {
return errors.New("number error"), ""
}
} else {
return errors.New("status err"), ""
}
} else if itemType == "14" {
itemID := common.StringToInt64(p[2])
if !csv.Mgr.CSV_ItemList.ContainsID(itemID) {
return errors.New("item id err"), ""
}
status := p[3]
number := common.StringToUint32(p[4])
if status == "1" || status == "3" {
AddItem(userData, uint32(itemID), number, oss.AddCashSrcTypeGM)
} else if status == "2" {
if !userData.CheckItem(uint32(itemID), number) {
return errors.New("number error"), ""
}
userData.ReduceItem(uint32(itemID), number, oss.ReduceCashSrcTypeGM)
} else {
return errors.New("status err"), ""
}
} else {
return errors.New("item type err"), ""
}
return nil, ""
}
func handleModifySpecialItem(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 4 {
return errors.New("param count error"), ""
}
uid := common.StringToUint64(p[0])
userData := cache.GetCharinfo(uid)
if nil == userData {
return errors.New("uid error"), ""
}
itemType := p[1]
switch itemType {
case "18":
itemStr := p[2]
type Hero struct {
Name string
Id string
Level string
Quality string
}
hero := &Hero{}
err := json.Unmarshal([]byte(itemStr), hero)
if err != nil {
return err, ""
}
id := common.StringToUint32(hero.Id)
star := common.StringToUint32(hero.Quality)
level := common.StringToUint32(hero.Level)
userData.InitHeroByParm(id, level, star)
case "19":
{
type Building struct {
Name string `json:"name"`
Location string `json:"location"`
Id string `json:"id"`
Index string `json:"index"`
Level string `json:"level"`
Status string `json:"status"`
}
itemStr := p[2]
building := &Building{}
err := json.Unmarshal([]byte(itemStr), building)
if err != nil {
return err, ""
}
buidingId := common.StringToUint32(building.Index)
buildingAsset := userData.GetBuildingAssetByBuildingId(buidingId)
if nil == buildingAsset {
return errors.New("building id err"), ""
}
del := p[3]
if del == "0" {
userData.DeleteBuildingAsset(buidingId)
return nil, ""
}
buildingType := common.StringToUint32(building.Id)
if buildingAsset.GetBuildingtype() != buildingType {
return errors.New("building id err"), ""
}
level := common.StringToUint32(building.Level)
if level != buildingAsset.GetBuildinglevel() {
buildingConf := csv.GetDoubleKeyBuildingLevel(buildingType, level)
if nil == buildingConf {
return errors.New("building level err"), ""
}
conf := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(buildingType))
if nil == conf {
return errors.New("buildng type err"), ""
}
userData.SetBuildingLevel(buidingId, level)
if conf.Type == int64(proto.BuildingType_BT_BASE_STATION) {
wdata := cache.Instance_GlobalAssetWorldData.GetWorldData(userData.GetWorldDataId())
if wdata != nil {
dataEntry := wdata.GetWorldDataEntry()
dataEntry.Z = proto.SetInt32(int32(level))
wdata.SetWorldDataEntry(dataEntry)
}
//>>>主城升级事件
observer.ObserverSingleton.AsyncNotify(observer.MainCityLevelUpgradeEvent, []interface{}{userData})
}
}
}
default:
return errors.New("item type err"), ""
}
return nil, ""
}
func handleAndEveryoneMail(params string) (error, string) {
everyoneMail := &proto.ST_EveryOneMail{}
err := proto.Unmarshal([]byte(params), everyoneMail)
if err != nil {
return err, ""
}
cache.EveryoneMail.AddEveryoneMailAsset(everyoneMail.GetReward(), everyoneMail.Content)
return nil, ""
}
func handleRemoveEveryoneMail(params string) (error, string) {
cache.EveryoneMail.RemoveEveryoneMailAsset(params)
return nil, ""
}
/**
@brief 实时更新OSS变化礼包
*/
func syncOssGiftInfo(giftPackConfig *proto.ST_GiftPackConfig) {
v := giftPackConfig
packEntry := csv.Mgr.CSV_GiftPackList.GetEntryPtr(int64(v.GetGiftId()))
if packEntry == nil {
return
}
entry := csv.Mgr.CSV_GiftList.GetEntryPtr(int64(packEntry.StartGiftID))
if nil == entry {
return
}
// 此处只处理在线玩家的礼包删除
if v.GetOpType() != 3 {
return
}
wlog.Info("delete gift pack begin---------------------------------")
// 如果是当前正在开启的礼包则修改玩家资产
now := wtime.GetNow()
if now >= v.GetRunTime() && now <= v.GetCloseTime() {
cache.ForeachUser(func(userData *cache.Info) bool {
if !userData.IsRealOnline() {
return true
}
giftAsset := userData.GetGiftAsset()
_, giftIndex := userData.CheckGiftIndex(entry)
if giftIndex != -1 {
giftData := giftAsset.AssetData.GiftList[giftIndex]
giftAsset.Lock()
// 删除直接设置endtime 为 0
giftData.EndTimeStamp = proto.SetUint64(0)
giftData.IsOssControl = proto.SetBool(false)
giftData.OnSale = proto.SetBool(false)
giftAsset.Unlock()
giftAsset.Dirty()
userData.DirtyAll()
wlog.Info(userData.GetUid(), giftData)
}
return true
})
}
wlog.Info("delete gift pack---------------------------------")
}
func handleGiftPackOperator(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 1 {
return errors.New("param count error"), ""
}
giftPackConfig := &proto.ST_GiftPackConfig{}
err := proto.Unmarshal([]byte(params), giftPackConfig)
if nil != err {
wlog.Error(err.Error())
return errors.New("giftpack proto unmarshal error"), ""
}
//
respon := &proto.ST_CS2GS_GetGiftPackConfigs_Response{
Result: proto.SetInt32(1),
Configs: []*proto.ST_GiftPackConfig{giftPackConfig},
}
err, result := csv.UpdateOssGiftInfo(false, respon)
if err != nil {
return err, result
}
go syncOssGiftInfo(giftPackConfig)
return nil, ""
}
func handleOfferGiftOperator(params string) (error, string) {
p := strings.Split(params, " ")
if len(p) < 1 {
return errors.New("param count error"), ""
}
giftPackConfig := &proto.ST_OfferGiftPack{}
err := proto.Unmarshal([]byte(params), giftPackConfig)
if nil != err {
wlog.Error(err.Error())
return errors.New("giftpack proto unmarshal error"), ""
}
if nil == csv.OfferGiftMap {
csv.OfferGiftMap = &csv.SafeOssGiftPackMap{}
}
csv.UpdateOfferGiftUser = &csv.SafeUpdateOssGiftCharMap{}
//缓存中如果存在相同index,则先删除后再重新添加
ossIndex := int64(giftPackConfig.GetId())
if tmp, ok := csv.OfferGiftMap.DataMap.Load(ossIndex); ok {
if old, ok := tmp.(*proto.ST_OfferGiftPack); ok {
if giftPackConfig.GetOp() == 2 {
old.Op = proto.SetInt32(2)
giftPackConfig = old
}
csv.OfferGiftMap.DataMap.Delete(ossIndex)
}
}
if giftPackConfig.GetOp() != 2 {
csv.OfferGiftMap.DataMap.Store(ossIndex, giftPackConfig)
}
if giftPackConfig.GetCond() == uint32(proto.EveryoneMailConditionType_EMCT_VipLevel) {
cache.ForeachUser(func(userData *cache.Info) bool {
if giftPackConfig.GetOp() == 4 && userData.GetVipLevel() >= common.StringToUint32(giftPackConfig.GetCondvalue1()) &&
userData.GetVipLevel() <= common.StringToUint32(giftPackConfig.GetCondvalue2()) {
userData.UpdateOfferGiftInfo(giftPackConfig)
}
if giftPackConfig.GetOp() == 2 {
userData.UpdateOfferGiftInfo(giftPackConfig)
}
return true
})
} else if giftPackConfig.GetCond() == uint32(proto.EveryoneMailConditionType_EMCT_MainCityLevel) {
cache.ForeachUser(func(userData *cache.Info) bool {
if giftPackConfig.GetOp() == 4 && userData.GetMainCityLevel() >= common.StringToUint32(giftPackConfig.GetCondvalue1()) &&
userData.GetMainCityLevel() <= common.StringToUint32(giftPackConfig.GetCondvalue2()) {
userData.UpdateOfferGiftInfo(giftPackConfig)
}
if giftPackConfig.GetOp() == 2 {
userData.UpdateOfferGiftInfo(giftPackConfig)
}
return true
})
} else if giftPackConfig.GetCond() == uint32(proto.EveryoneMailConditionType_EMCT_Uid) {
for _, uid := range strings.Split(giftPackConfig.GetCondvalue1(), ",") {
userData := cache.GetCharinfo(common.StringToUint64(uid))
if userData != nil {
userData.UpdateOfferGiftInfo(giftPackConfig)
}
}
} else if giftPackConfig.GetCond() == uint32(proto.EveryoneMailConditionType_EMCT_RegionId) {
cache.ForeachUser(func(userData *cache.Info) bool {
if giftPackConfig.GetOp() == 4 {
is := false
for _, MaxLabel := range strings.Split(giftPackConfig.GetCondvalue1(), ",") {
if userData.GetMaxLabel() == common.StringToUint64(MaxLabel) {
is = true
break
}
}
if !is {
return true
}
is = false
for _, CurLabel := range strings.Split(giftPackConfig.GetCondvalue2(), ",") {
if userData.GetCurLabel() == common.StringToUint64(CurLabel) {
is = true
break
}
}
if is {
if giftPackConfig.GetCondvalue3() == "0" || userData.GetCurLabelNum() == common.StringToUint64(giftPackConfig.GetCondvalue3()) {
userData.UpdateOfferGiftInfo(giftPackConfig)
}
}
}
if giftPackConfig.GetOp() == 2 {
userData.UpdateOfferGiftInfo(giftPackConfig)
}
return true
})
}
return nil, ""
}
func handleLuckyStarOperator(params string) (error, string) {
luckyStar := &proto.ST_LuckyStar_PB{}
err := proto.Unmarshal([]byte(params), luckyStar)
if err != nil {
wlog.Error(err.Error())
return errors.New("lucky star proto unmarshal error"), ""
}
cache.Instance_GlobalAssetLuckyStar.Update(luckyStar)
return nil, ""
}
func handleAddStrongestCommander(params string) (error, string) {
info := &proto.ST_StrongestCommander_Entry{}
err := proto.Unmarshal([]byte(params), info)
if err != nil {
wlog.Error(err.Error())
return errors.New("ST_StrongestCommander_Entry proto unmarshal error"), ""
}
InitStrongestCommander(info)
return nil, ""
}
func handleCloseStrongestCommander(params string) (error, string) {
info := &proto.ST_StrongestCommander_Entry{}
err := proto.Unmarshal([]byte(params), info)
if err != nil {
wlog.Error(err.Error())
return errors.New("ST_StrongestCommander_Entry proto unmarshal error"), ""
}
InitStrongestCommander(info)
return nil, ""
}
func handleAddTBActivity(params string) (error, string) {
info := &proto.ST_TransferBattle_Group_Entry{}
err := proto.Unmarshal([]byte(params), info)
if err != nil {
wlog.Error(err.Error())
return errors.New("ST_TransferBattle_Group_Entry proto unmarshal error"), ""
}
InitTransferBattle(info)
return nil, ""
}
func handleCloseTBActivity(params string) (error, string) {
info := &proto.ST_TransferBattle_Group_Entry{}
err := proto.Unmarshal([]byte(params), info)
if err != nil {
wlog.Error(err.Error())
return errors.New("ST_TransferBattle_Group_Entry proto unmarshal error"), ""
}
InitTransferBattle(info)
return nil, ""
}
func handleArchonNoticeOperator(params string) (error, string) {
request := &proto.ST_ModifyArchonNotice_Request{}
err := proto.Unmarshal([]byte(params), request)
if err != nil {
return errors.New(err.Error()), ""
}
ret := true
cache.Instance_GlobalMiracleWarAsset.WithMiracleWarAsset(false, 7305001, func(asset *proto.ST_MiracleWar_PB) bool {
if asset.GetNotice() == nil {
ret = false
return false
}
switch request.GetOperType() {
case 1:
asset.Notice.Notice = proto.SetString(request.GetContent())
case 2, 3:
asset.Notice = nil
}
return true
})
if ret {
return nil, ""
}
return errors.New("archon notice is nil"), ""
}
func handleQueryArchonNotice(params string) (error, string) {
archonInfo := &proto.ST_GM_ArchonNoticeInfo{}
cache.Instance_GlobalMiracleWarAsset.WithMiracleWarAsset(true, 7305001, func(asset *proto.ST_MiracleWar_PB) bool {
if asset.GetNotice() != nil {
notice := asset.GetNotice()
archonInfo.Uid = proto.SetUint64(notice.GetUid())
if userData := cache.GetCharinfo(notice.GetUid()); nil != userData {
archonInfo.UserName = proto.SetString(userData.GetUserName())
}
archonInfo.Content = proto.SetString(notice.GetNotice())
archonInfo.SendTime = proto.SetUint64(notice.GetTime())
}
return false
})
return nil, common.Base64Encode(string(proto.Marshal(archonInfo)))
}
func handleSendGlobalMessage(params string) (error, string) {
request := &proto.ST_GlobalMessage_PB{}
err := proto.Unmarshal([]byte(params), request)
if err != nil {
return errors.New(err.Error()), ""
}
cache.Instance_GlobalAssetChat.AddGlobalMessage(request)
return nil, ""
}
func handleBoonActivityOper(params string) (error, string) {
request := &proto.ST_GM_BoonActivityOper{}
err := proto.Unmarshal([]byte(params), request)
if err != nil {
return errors.New(err.Error()), ""
}
// todo 修改福利活动奖励配置
ret := cache.SetBoonRewardConfig(request)
if ret != "" {
return errors.New(ret), ""
} else {
return nil, ""
}
}
func handleQueryBoonActivity(param string) (error, string) {
boonActivities := &proto.ST_GM_BoonActivities{}
// todo 查询福利奖励配置
for _, id := range csv.Mgr.CSV_BoonCenter.GetIDList() {
if conf := csv.Mgr.CSV_BoonCenter.GetEntryPtr(id); conf != nil {
// 调查询接口
if activity := cache.GetBoonDetailsGM(id); activity.GetDuration() != 0 {
boonActivities.Activities = append(boonActivities.Activities, activity)
}
}
}
return nil, common.Base64Encode(string(proto.Marshal(boonActivities)))
}
func ProduceResource(uid uint64) {
userData := cache.GetCharinfo(uid)
if nil == userData {
return
}
var buildingIds []uint32
for _, building := range userData.GetBuildings() {
buildingConfig := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(building.GetBuildingtype()))
if nil == buildingConfig || "2" != strings.TrimSpace(buildingConfig.FuncType) {
continue
}
buildingLevelUpConfig := csv.GetDoubleKeyBuildingLevel(building.GetBuildingtype(), building.GetBuildinglevel())
if nil == buildingLevelUpConfig {
continue
}
fnMap := common.ParseParameterStringToMap(buildingLevelUpConfig.Function)
v1, ok1 := fnMap["producetype"]
v2, ok2 := fnMap["capability"]
if !ok1 || !ok2 {
continue
}
pro := common.ParseStringToVector4(v1)[0]
cap := common.StringToUint64(v2)
resource := common.NewCashAsset()
switch pro.GetY() {
case int32(proto.CashType_CASH_TYPE_1):
resource.Cash1 = proto.SetUint64(cap)
case int32(proto.CashType_CASH_TYPE_2):
resource.Cash2 = proto.SetUint64(cap)
case int32(proto.CashType_CASH_TYPE_3):
resource.Cash3 = proto.SetUint64(cap)
case int32(proto.CashType_CASH_TYPE_4):
resource.Cash4 = proto.SetUint64(cap)
case int32(proto.CashType_CASH_TYPE_5):
resource.Cash5 = proto.SetUint64(cap)
case int32(proto.CashType_CASH_TYPE_EXPEDITION):
resource.CashExpedition = proto.SetUint64(cap)
}
userData.WithBuildingAsset(false, func(asset *cache.Asset_Building) {
if asset.AddResource(building.GetBuildingID(), resource) {
buildingIds = append(buildingIds, building.GetBuildingID())
userData.DirtyAll()
}
})
}
userData.WithLocalAction(false, func(asset *cache.Asset_LocalAction) {
for _, action := range asset.AssetData.ActionList {
if uint32(proto.ActionType_AT_PRODUCTION_RESOURCE) != action.GetActiontype() {
continue
}
for _, buildingId := range buildingIds {
if buildingId == action.GetBuildingID() {
action.Starttime = proto.SetUint64(0)
userData.AddSyncAsset(proto.SyncType_SetLocalActionStartTime, &proto.ST_LocalActionEntry_PB{
Actionid: action.Actionid,
Starttime: action.Starttime,
})
asset.ServerDirty()
userData.DirtyAll()
break
}
}
}
})
}
func AddAllHero(uid uint64) {
userData := cache.GetCharinfo(uid)
if nil == userData {
return
}
for _, v := range csv.Mgr.CSV_HeroList.GetIDList() {
heroEntry := csv.Mgr.CSV_HeroList.GetEntryPtr(int64(v))
if heroEntry.HeroMainType == int64(1) {
userData.InitHeroByParm(uint32(v), 1, 1)
}
}
}
func ResearchMax(uid uint64) {
userData := cache.GetCharinfo(uid)
if nil == userData {
return
}
asset := userData.GetResearchAsset()
if nil != asset {
for _, item := range asset.EntryList {
csvConfig := csv.Mgr.CSV_TechnologyLevelUp.GetEntryPtr(int64(item.GetRID()))
if csvConfig == nil {
continue
}
rType := uint32(csvConfig.FuncType)
researchTypeID := userData.GetResearchIDByType(rType)
researchConfig := csv.Mgr.CSV_TechnologyLevelUp.GetEntryPtr(int64(researchTypeID))
if researchConfig != nil {
cache.ReduceAttribute(userData, researchConfig.Function, uint32(proto.AttributeSource_Research)) //ok
}
}
userData.ResetResearch()
}
tMap := make(map[uint32]uint32)
for _, id := range csv.Mgr.CSV_TechnologyLevelUp.GetIDList() {
entry := csv.Mgr.CSV_TechnologyLevelUp.GetEntryPtr(id)
if v, ok := tMap[uint32(entry.FuncType)]; !ok || v < uint32(entry.ID) {
tMap[uint32(entry.FuncType)] = uint32(entry.ID)
}
}
for k, v := range tMap {
userData.AddResearchAsset(k, v)
config := csv.Mgr.CSV_TechnologyLevelUp.GetEntryPtr(int64(v))
cache.SetAttribute(userData, config.Function, uint32(proto.AttributeSource_Research)) //ok
}
}
func GMSetMiracleWarStage(sn, stage int32) {
cid := 7305001
if sn > 0 {
cid = 7304000 + int(sn)
}
timeNow := wtime.GetNow()
cache.Instance_GlobalMiracleWarAsset.WithMiracleWarAsset(false, cid, func(asset *proto.ST_MiracleWar_PB) bool {
if stage == int32(proto.MiracleWarStage_MWS_UnOpenStage) {
asset.Number = proto.SetInt32(0)
cache.Instance_GlobalMiracleWarAsset.UnsafeStartStage(cid, int32(proto.MiracleWarStage_MWS_UnOpenStage), timeNow, timeNow+uint64(csv.GetGameConfigValueUint32("First_Miracle")),
timeNow, timeNow)
asset.HistoryArchons = make([]*proto.ST_HistoryArchon_PB, 0)
} else if stage == int32(proto.MiracleWarStage_MWS_PrepareStage) {
stageEndTime := timeNow + uint64(csv.GetGameConfigValueUint32("Ready_Miracle"))
subStageEndTime := stageEndTime - prepareStageTimes[0]
cache.Instance_GlobalMiracleWarAsset.UnsafeStartStage(cid, int32(proto.MiracleWarStage_MWS_PrepareStage),
timeNow, stageEndTime, timeNow, subStageEndTime)
} else if stage == int32(proto.MiracleWarStage_MWS_FightStage) {
cache.Instance_GlobalMiracleWarAsset.UnsafeStartStage(cid, int32(proto.MiracleWarStage_MWS_FightStage),
timeNow, timeNow, timeNow, timeNow)
resetBigMiracle(cid, false)
if cid == 7305001 {
initFightStage(asset)
}
} else if stage == int32(proto.MiracleWarStage_MWS_ProtectStage) {
occupyInfo := asset.GetOccupyInfo()
if occupyInfo != nil {
stageEndTime := timeNow + uint64(csv.GetGameConfigValueUint32("Follow_Miracle"))
subStageEndTime := stageEndTime - prepareStageTimes[0]
cache.Instance_GlobalMiracleWarAsset.UnsafeStartStage(cid, int32(proto.MiracleWarStage_MWS_ProtectStage),
timeNow, stageEndTime, timeNow, subStageEndTime)
asset.OwnerLeagueID = proto.SetUint64(occupyInfo.GetLid())
asset.Number = proto.SetInt32(asset.GetNumber() + 1)
resetBigMiracle(cid, false)
setBigMiracleOwner(cid, 0, occupyInfo.GetLid())
}
} else if stage == int32(proto.MiracleWarStage_MWS_WaitStage) {
cache.Instance_GlobalMiracleWarAsset.UnsafeStartStage(cid, int32(proto.MiracleWarStage_MWS_WaitStage), timeNow, timeNow,
timeNow, timeNow)
}
return true
})
go func() {
cache.ForeachUser(func(tmpInfo *cache.Info) bool {
if tmpInfo.IsRealOnline() {
processMiracleWarUserInfo(tmpInfo, cid)
}
time.Sleep(time.Duration(1 * time.Millisecond))
return true
})
}()
}
func GMCloseBlackMarket(uid uint64) {
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。