You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2191 lines
79 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Reflection;
using Sog;
using ProtoCSStruct;
using Sog.IO;
using LitJson;
using System.Text;
using Sog.Gate;
namespace Game
{
public static class GmStaticData
{
public static SimpleRobotPool robotPool = new SimpleRobotPool();
public static SimpleRobotList robotList = new SimpleRobotList();
}
public partial class GmCmdSvc : BaseReloadableService
{
public override int GetServiceType()
{
return GameServiceType.GmCmdSvc;
}
//销毁的时候清空指令注册
public override void Dispose()
{
GmCommandMgr.Instance.ClearAll();
}
//构造的时候注册所有指令
public GmCmdSvc()
{
GmCommandMgr.Instance.Init(this);
RegisterAllGmCmd();
ScanGmRequestApi();
}
private void ScanGmRequestApi()
{
var methods = this.GetType().GetMethods();
foreach (var method in methods)
{
var attribute = method.GetCustomAttribute<GmApiMapping>();
if (attribute == null)
{
continue;
}
GmCommandMgr.Instance.Register(attribute, method);
}
}
/**
* <summary>
* 不建议使用这个方法,因为这样客户端就没办法拿到关于某个接口的信息,还需要手动输入,
* 建议采用 <see cref="GmApiMapping"/> 方式,客户端能够自动拉去gm相关的api以及
* 对应的参数。通过可视化窗口填入对应的数值即可完成相关的调用。
* 随着新的业务开发,渐渐的把这老的方式都替换去掉
* </summary>
*/
[Obsolete("不建议使用")]
private void RegisterAllGmCmd()
{
//注册广播事件
GmCommandMgr.Instance.NotifyWorldBroadCastGMCmdToServer = NotifyWorldBroadCastGMCmdToServer;
}
public static void OnCliGmCmd(PlayerSession playerSession, StructPacket packet)
{
PlayerOnGame player = playerSession.Player;
if (player == null)
{
TraceLog.Error("GmCmdSvc.OnCliGmCmd uid {0} no player obj", playerSession.UserID);
return;
}
var cfg = GameServerUtils.GetServerConfig();
if (cfg.isAllGM != 1 && (cfg.gmUid == null || !cfg.gmUid.Contains(player.UserID)))
{
TraceLog.Error("GmCmdSvc.OnCliGmCmd uid {0} not gm", player.UserID);
return;
}
ref CSGmCmd Gm = ref packet.GetMessage<CSGmCmd>();
long opUid = player.UserID;
if (Gm.CmdStr.ToString().Contains(' '))
{
List<string> initgmCmdParams = new List<string>();
string[] splitStr = Gm.CmdStr.ToString().Split(' ');
string gmcmd = splitStr[0];
List<string> paramList = new List<string>();
paramList.AddRange(splitStr);
for (int i = 1; i < paramList.Count; i++)
{
string param = paramList[i];
//gm指令本身支持base64转码
//gmcmd AddGold 500000000 -t 1000001
// -txxxxx
if (param.Length >= 6 && param[0] == '-' && param[1] == 't')
{
long.TryParse(param.Substring(2), out opUid);
continue;
}
if (param == "-t")
{
if (i <= paramList.Count - 2)
{
i++;
long.TryParse(paramList[i], out opUid);
continue;
}
else
{
TraceLog.Error("OnCliGmCmd error");
return;
}
}
//用base64编码替换AddChip后面的参数
//gmcmd AddGold -bNTAwMDAwMDAwIC10IDEwMDAwMDE=
//gmcmd AddGold -b NTAwMDAwMDAwIC10IDEwMDAwMDE=
//以上两种都可以
//处理一下base64编码参数
string base64 = null;
// -bxxxxx
if (param.Length >= 6 && param[0] == '-' && param[1] == 'b')
{
base64 = param.Substring(2);
}
if (param == "-b")
{
if (i <= paramList.Count - 2)
{
i++;
base64 = paramList[i];
}
}
if (base64 != null)
{
byte[] byte64 = Convert.FromBase64String(base64);
string decodeText = Encoding.UTF8.GetString(byte64);
string[] decodesplitStr = decodeText.Split(' ');
paramList.AddRange(decodesplitStr);
}
else
{
if (paramList[i] != "")
{
initgmCmdParams.Add(paramList[i]);
}
}
}
string[] gmCmdParams = initgmCmdParams.ToArray();
string allparamString = string.Empty;
for (int i = 0; i < gmCmdParams.Length; i++)
{
allparamString += gmCmdParams[i];
if (i != gmCmdParams.Length - 1)
{
allparamString += ' ';
}
}
TraceLog.Debug("ProcessShmCommand_GmCommand cmd:{0} userid {1} params {2}"
, gmcmd, playerSession.UserID, allparamString);
GmCommandMgr.Instance.HandlerGmCommand(gmcmd, opUid, gmCmdParams, false);
}
//派发一个使用GM的事件,用来刷新数据
GameServerUtils.GetEventHandlerMgr().OnClientUseGM(player);
}
//广播来的指令
public static void OnWorldNotifyDealGmCmd(StructPacket packet)
{
ref SSNotifyServerDealGMCmd gmCmd = ref packet.GetMessage<SSNotifyServerDealGMCmd>();
string[] splitStr = gmCmd.CmdParams.GetString().Split(' ');
GmCommandMgr.Instance.HandlerGmCommand(gmCmd.GmCmd.GetString(), gmCmd.UserId, splitStr, true, true);
}
/// <summary>
/// 是否过滤GM账号
/// </summary>
/// <param name="uid"></param>
/// <returns>true, 要过滤, false 不要过滤</returns>
public static bool IsGMFilter(long uid)
{
var cfg = GameServerUtils.GetServerConfig();
if (cfg.isAllGM != 1 && cfg.gmUid != null && cfg.gmUid.Contains(uid))
{
TraceLog.Trace("GmCmdSvc.IsGMFilter uid {0}", uid);
return true;
}
return false;
}
/// <summary>
/// 是否GM
/// </summary>
/// <param name="uid"></param>
/// <returns>true, 是GM, false 不是GM/returns>
public static bool IsGM(long uid)
{
GameServerConfig cfg = GameServerUtils.GetServerConfig();
if (cfg.isAllGM == 1)
{
return true;
}
if (cfg.gmUid != null && cfg.gmUid.Contains(uid))
{
return true;
}
return false;
}
[GmApiMapping(desc: "添加经验",help: "添加后自动升级")]
public int AddExp(long userid, int iExp)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddExp can not find palyer by uid {0}", userid);
return -2;
}
player.Trace("GmCmdSvc.AddExp uid {0} exp {1}", userid, iExp);
LevelUtils.AddExp(player, iExp, BillChangeItemReason.GmCmd);
TraceLog.TraceDetail("GmCmdSvc.AddExp day param player:{0} cm:{1}", player.UserID, iExp);
return 0;
}
// filename chip diamond itemId itemNum
[GmApiMapping(desc: "删除邮件",group:GmGroup.SERVER)]
public int DeleteMail(long userid, uint mailID)
{
if (mailID == 0)
{
TraceLog.Error("GmCmdSvc.DeleteMail invalid mailid param {0}", mailID);
return -2;
}
DBMail mail = new DBMail();
mail.MailID = mailID;
mail.Uid = userid;
MailSender.SendMailOpReqToDB(0, MailOpType.Delete, ref mail);
return 0;
}
[GmApiMapping(desc: "发送邮件", group: GmGroup.SERVER)]
public int SendMail(long userid, int mailID)
{
if (mailID == 0)
{
TraceLog.Error("GmCmdSvc.SendMail invalid mailid param {0}", mailID);
return -2;
}
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
MailSender.SendNewMailToPlayer(player, mailID);
return 0;
}
[GmApiMapping(desc: "设置服务器时间", group: GmGroup.SERVER)]
public int AddServerTime(long userid, uint second)
{
if (GameServerUtils.GetServerConfig().permitAddServerTime != 1)
{
TraceLog.Error(
"GmCmdSvc.AddServerTime this server can not exec AddServerTime, server config permitAddServerTime = {0}"
, GameServerUtils.GetServerConfig().permitAddServerTime);
return -1;
}
if (second == 0)
{
TraceLog.Error("GmCmdSvc.AddServerTime invalid timesecond param {0}", second);
return -2;
}
long nowOffset = GameServerUtils.GetApp().Time.AddOffset(second);
GameServerUtils.GetApp().Time.UpdateTime();
// 在线玩家同步最新时间
CSPing ping = new CSPing { ServerTime = GameServerUtils.GetTimeMs() };
var sessionTable = GameServerUtils.GetPlayerTable().m_sessionsTable;
foreach (PlayerSession session in sessionTable.Values)
{
GateService.SendToGate(session.UserID, GameServerUtils.GetApp().GetCluster()
, session.GateServerID, session.SessionID, (int)CSGameMsgID.Ping, ref ping);
}
SSAddServerTimeSync sync = new SSAddServerTimeSync();
sync.Offset = nowOffset;
//同步给world
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.AddServerTimeSync, ref sync, 0);
//同步给Rank
GameServerUtils.GetPacketSender().SendToRankServer((int)SSGameMsgID.AddServerTimeSync, ref sync, 0);
//同步Battle
GameServerUtils.GetPacketSender()
.Broadcast((int)ServerType.Battle, (int)SSGameMsgID.AddServerTimeSync, ref sync, 0, 0);
//同步GameDB
GameServerUtils.GetPacketSender()
.Broadcast((int)ServerType.GameDb, (int)SSGameMsgID.AddServerTimeSync, ref sync, 0, 0);
//同步Mail
GameServerUtils.GetPacketSender()
.Broadcast((int)ServerType.Mail, (int)SSGameMsgID.AddServerTimeSync, ref sync, 0, 0);
TraceLog.Debug("GmCmdSvc.AddServerTime now server offset {0}", nowOffset);
return 0;
}
[GmApiMapping(desc: "清理服务器时间", group: GmGroup.SERVER)]
public int CliAddServerTime(long userid, uint second)
{
if (GameServerUtils.GetServerConfig().permitCliAddServerTime != 1)
{
TraceLog.Error(
"GmCmdSvc.CliAddServerTime this server can not exec AddServerTime, server config permitCliAddServerTime = {0}"
, GameServerUtils.GetServerConfig().permitCliAddServerTime);
return -1;
}
string[] cmdParams = { second + "" };
GmCommandMgr.Instance.HandlerGmCommand("AddServerTime", 0, cmdParams, true);
TraceLog.Debug("GmCmdSvc.CliAddServerTime now server");
return 0;
}
[GmApiMapping(desc: "停服", group: GmGroup.SERVER, ignore: true)]
public int StopServer(long userid, int minute)
{
StopServerSvc.StartStopServer(minute);
TraceLog.Debug("GmCmdSvc.StopServer, server will stop after {0} minute", minute);
return 0;
}
[GmApiMapping(desc: "添加道具", group: GmGroup.EQUIPMENT,help:"count 上线99999")]
public int AddItem(long userid, string itemId, long count)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddGold can not find palyer by uid {0}", userid);
return -2;
}
if (count == 0)
{
TraceLog.Error("GmCmdSvc.AddGold invalid addvalue param {0}", count);
return -3;
}
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.GmCmd);
var ret = count > 0 ? bagOp.AddItem(itemId, count) : bagOp.CostItem(itemId, -count);
CSErrCode iRet = bagOp.DoOp(true, true);
if (ret != 0 || iRet != 0)
{
player.Error("GmCmdSvc.AddGold uid {0} bagOp.DoOp failed ret {1}", player.UserID, iRet);
return -4;
}
player.Trace("GmCmdSvc.AddGold uid {0} addchip success add chip {1}", player.UserID, count);
return 0;
}
[GmApiMapping(desc: "添加钻石", group: GmGroup.EQUIPMENT)]
public int AddDiamond(long userid, int addValue)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddDiamond can not find palyer by uid {0}", userid);
return -2;
}
if (addValue == 0)
{
TraceLog.Error("GmCmdSvc.AddDiamond invalid addvalue param {0}", addValue);
return -3;
}
// gm扣钱超过背包时,直接为0
if (addValue < 0 && (-addValue) > player.GetDiamond())
{
addValue = (int)player.GetDiamond();
addValue = -addValue;
}
//int reasonId = BillChangeItemReasonMap.Instance.GetReasonIntType(BillChangeItemReason.GmCmd, false);
UnifyOp Op = new UnifyOp(player, BillChangeItemReason.GmCmd, "GMAddDiamond");
if (addValue > 0)
{
Op.AddDiamond(addValue, 10000000);
}
else
{
Op.CostDiamond(-addValue);
}
var ret = Op.DoOp();
if (ret != CSErrCode.None)
{
return -4;
}
player.Trace("GmCmdSvc.AddDiamond uid {0} add diamond success add diamond {1}", player.UserID, addValue);
return 0;
}
[GmApiMapping(desc: "添加代金券", group: GmGroup.EQUIPMENT)]
public int AddToken(long userid, int addValue)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddToken can not find palyer by uid {0}", userid);
return -2;
}
if (addValue == 0)
{
TraceLog.Error("GmCmdSvc.AddToken invalid addvalue param {0}", addValue);
return -3;
}
// gm扣钱超过背包时,直接为0
if (addValue < 0 && (-addValue) > player.GetDiamond())
{
addValue = (int)player.GetDiamond();
addValue = -addValue;
}
var op = new UnifyOp(player, BillChangeItemReason.GmCmd, "GMAddAddToken");
if (addValue > 0)
{
op.AddItem(ItemId.Token,addValue);
}
else
{
op.CostItem(ItemId.Token,-addValue);
}
var ret = op.DoOp();
if (ret != CSErrCode.None)
{
return -4;
}
player.Trace("GmCmdSvc.AddToken uid {0} add token success add token {1}", player.UserID, addValue);
return 0;
}
[GmApiMapping(desc: "FirebasePush", help: "服务器上传文件用", group: GmGroup.SERVER,ignore:true)]
public int FirebasePush(long userid, string key, string value, string content)
{
SSGoogleFirebasePush data = new SSGoogleFirebasePush();
if (key != "no")
{
data.ParamKey.SetString(key);
}
if (value != "no")
{
data.ParamValue.SetString(value);
}
string addContent = "";
var st = content.Split(" ");
for (int i = 2; i < st.Length; i++)
{
if (i != 0)
{
addContent += " ";
}
addContent += st[i];
}
data.Content.SetString(addContent);
//有uid表示对一个玩家发,否则表示全服发
if (userid > 0)
{
TraceLog.Debug("GmCmdSvc.FirebasePush with uid {0}, add it", userid);
data.PushUids.Add(userid);
}
TraceLog.Debug("GmCmdSvc.FirebasePush content {0} uid {1}", data.Content, userid);
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.GooglePushInfo, ref data, 0);
return 0;
}
[GmApiMapping(desc: "PushReadFile", help: "服务器上传文件用", group: GmGroup.SERVER,ignore:true)]
public int PushReadFile(long userid, string filename, string fullPath)
{
if (!File.Exists(fullPath))
{
TraceLog.Error("GmCmdSvc.PushReadFile file {0} not exists", filename);
return -1;
}
string[] allline = File.ReadAllLines(fullPath);
if (allline.Length < 2)
{
TraceLog.Error("GmCmdSvc.PushReadFile file {0} need 2 line", filename);
return -1;
}
List<long> uids = new List<long>();
if (userid > 0)
{
uids.Add(userid);
}
bool bAllUser = false;
string firstline = allline[0];
int linepos = 0;
if (firstline.Length >= 3 && firstline[0] == 'u' && firstline[1] == 'i' && firstline[2] == 'd')
{
linepos++;
string[] uidsplit = firstline.Split('|');
for (int i = 1; i < uidsplit.Length; i++)
{
//支持所有玩家
if (uidsplit[i] == "all")
{
bAllUser = true;
break;
}
long uidparse = 0;
if (true == long.TryParse(uidsplit[i], out uidparse))
{
if (uidparse > 0)
{
uids.Add(uidparse);
}
}
}
}
string content = allline[linepos];
linepos++;
SSGoogleFirebasePush data = new SSGoogleFirebasePush();
data.Content.SetString(content);
//命令参数指定了uid表示对一个玩家发,其实没啥用
if (userid > 0)
{
TraceLog.Debug("GmCmdSvc.PushReadFile with uid {0}, add it", userid);
data.PushUids.Add(userid);
}
if (bAllUser)
{
TraceLog.Debug("GmCmdSvc.PushReadFile send to all content {0}", content);
}
else
{
foreach (var uid in uids)
{
data.PushUids.Add(uid);
}
if (data.PushUids.Count == 0)
{
TraceLog.Error("GmCmdSvc.PushReadFile no uid , please add it");
return -1;
}
TraceLog.Debug("GmCmdSvc.PushReadFile send to uid count {0} content {1}", data.PushIds.Count, content);
}
TraceLog.Debug("GmCmdSvc.PushReadFile content {0} uid {1}", data.Content, userid);
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.GooglePushInfo, ref data, 0);
return 0;
}
[GmApiMapping(desc: "添加物品", group: GmGroup.EQUIPMENT,help:"type =1 道具,2=武器")]
public int AddGoods(long userid, string itemid, int itemcount, int itemType = 1)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddItem can not find palyer by uid {0}", userid);
return -1;
}
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.GmCmd);
if (itemcount > 0)
{
bagOp.AddGoods(itemType, itemid, itemcount);
}
else
{
bagOp.CostGoods(itemType, itemid, -itemcount);
}
CSErrCode iRet = bagOp.DoOp(true, true, true);
if (iRet != 0)
{
player.Error("GmCmdSvc.AddItem uid {0} bagOp.DoOp failed ret {1}", player.UserID, iRet);
return -1;
}
player.Trace("GmCmdSvc.AddItem uid {0} add item success add item {1} count {2}", player.UserID, itemid,
itemcount);
return 0;
}
[GmApiMapping(desc: "添加时装", group: GmGroup.EQUIPMENT,help:"RoleModel 表id")]
public int AddEquipSkin(long uid,string id)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddEquipSkin can not find palyer by uid {0}", uid);
return -1;
}
var bagOp = new UnifyOp(player, BillChangeItemReason.GmCmd);
bagOp.AddGoods((int)GoodsType.EquipSkin, id, 1);
CSErrCode iRet = bagOp.DoOp(sendGetItemMsg:true);
if (iRet != 0)
{
player.Error("GmCmdSvc.AddItem uid {0} bagOp.DoOp failed ret {1}", player.UserID, iRet);
return -1;
}
player.MakeDirty();
return 0;
}
[GmApiMapping(desc: "一键添加所有时装", group: GmGroup.EQUIPMENT,help:"RoleModel 表id")]
public int AddAllEquipSkin(long uid)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddAllEquipSkin can not find palyer by uid {0}", uid);
return -1;
}
var bagOp = new UnifyOp(player, BillChangeItemReason.GmCmd);
foreach (var kv in RoleModelDescMgr.Instance.ItemTable)
{
bagOp.AddGoods((int)GoodsType.EquipSkin, kv.Value.InternalId, 1);
}
CSErrCode iRet = bagOp.DoOp(sendGetItemMsg:true);
if (iRet != 0)
{
player.Error("GmCmdSvc.AddAllEquipSkin uid {0} bagOp.DoOp failed ret {1}", player.UserID, iRet);
return -1;
}
player.MakeDirty();
return 0;
}
[GmApiMapping(desc: "一键添加所有道具", group: GmGroup.EQUIPMENT)]
public int AddAllItem(long userid)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddAllItem can not find palyer by uid {0}", userid);
return -1;
}
int itemcount = 99999;
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.GmCmd);
foreach (var item in ItemDescMgr.Instance.ItemTable)
{
var desc = item.Value;
var type = (int)GoodsType.Items;
if(desc.type == ItemType.RandomItem)
{
itemcount = 1;
}
bagOp.AddGoods(type, desc.itemID, itemcount);
}
CSErrCode iRet = bagOp.DoOp(true,true,true);
if (iRet != 0)
{
player.Error("GmCmdSvc.AddAllItem uid {0} bagOp.DoOp failed ret {1}", player.UserID, iRet);
return -1;
}
return 0;
}
[GmApiMapping(desc: "添加头像框", group: GmGroup.ROLE)]
public int AddIconFrame(long userid, int frameId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddIconFrame can not find palyer by uid {0}", userid);
return -2;
}
if (frameId == 0)
{
TraceLog.Error("GmCmdSvc.AddIconFrame invalid itemid param {0}", frameId);
return -3;
}
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.GmCmd);
CSErrCode iRet = bagOp.DoOp(true, true);
if (iRet != 0)
{
player.Error("GmCmdSvc.AddIconFrame uid {0} bagOp.DoOp failed ret {1}", player.UserID, iRet);
return -5;
}
player.Trace("GmCmdSvc.AddIconFrame uid {0} add item success add frameId {1}", player.UserID, frameId);
return 0;
}
[GmApiMapping(desc: "更改名称", group: GmGroup.ROLE)]
public int ChangeNick(long userid, string newNick)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ChangeNick can not find palyer by uid {0}", userid);
return -2;
}
int iRet = PlayerUtils.CheckRenameValid(newNick);
if (iRet != 0)
{
player.Error("GmCmdSvc.ChangeNick uid {0} CheckRenameValid failed ret {1}", player.UserID, iRet);
return -3;
}
player.RoleBase.Nick.SetString(newNick);
player.MakeDirty();
player.Trace("GmCmdSvc.ChangeNick uid {0} success new nick {1}", player.UserID, newNick);
return 0;
}
[GmApiMapping(desc: "设置每日统计", group: GmGroup.SERVER)]
public int SetDailyStat(long userid, int statId, int statValue)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.SetDailyStat can not find palyer by uid {0}", userid);
return -2;
}
if (statId <= 0 || statId > (int)CSRoleStatisticsID.MaxID)
{
TraceLog.Error("GmCmdSvc.SetDailyStat invalid statId param {0} max {1}", statId,
(int)CSRoleStatisticsID.MaxID);
return -5;
}
RoleStatChgOp statChgOp = new RoleStatChgOp(player);
statChgOp.SetIDDaily(statId, statValue);
//可以不通知
statChgOp.NotifyClient();
player.Trace("GmCmdSvc.SetDailyStat uid {0} success", player.UserID);
return 0;
}
[GmApiMapping(desc: "设置历史总统计", group: GmGroup.SERVER)]
public int SetTotalStat(long userid, int statId, int statValue)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.SetTotalStat can not find palyer by uid {0}", userid);
return -2;
}
if (statId <= 0 || statId > (int)CSRoleStatisticsID.MaxID)
{
TraceLog.Error("GmCmdSvc.SetTotalStat invalid statId param {0} max {1}", statId,
(int)CSRoleStatisticsID.MaxID);
return -5;
}
RoleStatChgOp statChgOp = new RoleStatChgOp(player);
statChgOp.SetIDTotal(statId, statValue);
//可以不通知
statChgOp.NotifyClient();
player.Trace("GmCmdSvc.SetTotalStat uid {0} success", player.UserID);
return 0;
}
[GmApiMapping(desc: "清理支付", group: GmGroup.PAYMENT)]
public int ClearPay(long userid, int clearAll)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ClearPay can not find player by uid {0}", userid);
return -1;
}
if (clearAll == 1)
{
foreach (QuestEXDesc taskDesc in QuestEXDescMgr.Instance.ItemTable.Values)
{
//if (taskDesc.questType == (int)TaskType.Passcard)
//{
// TaskEXSvc.DeleteTask(player, taskDesc.questId);
//}
}
player.RoleData.PayData.Clear();
for (int i = 0; i < 7; i++)
{
player.RoleData.PayData.MaxPayMoneyLast7Days.Add(0);
}
player.RoleData.PayData.LastUpdateMaxPayMoneyTime = (int)GameServerUtils.GetTimeSecond();
}
else
{
player.RoleData.PayData.PayItemRecord.Clear();
}
PlayerNotify.NotifyPlayerPayDataChange(player);
player.Debug("GmCmdSvc.ClearPay uid {0} clearAll {1} succ", player.UserID, clearAll);
return 0;
}
[GmApiMapping(desc: "伪造支付", group: GmGroup.PAYMENT)]
public int FakePay(long uid, int itemId)
{
return PayCommSvc.FakePay(uid, itemId);
}
[GmApiMapping(desc: "代币支付", group: GmGroup.PAYMENT)]
public int TokenPay(long uid, int itemId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.PopPayTest uid {0} no player obj", uid);
return 0;
}
StructPacket packet = new StructPacket();
packet.Header.Type = (int)CSGameMsgID.PayGoogleReq;
StructMessageParser<CSPayGoogleReq> parser = new StructMessageParser<CSPayGoogleReq>();
packet.Parser = parser;
ref var req = ref packet.GetMessage<CSPayGoogleReq>();
req.ItemID = itemId;
req.Uid = player.UserID;
PayHandler payHandler = GameServerUtils.GetPayHandler();
PlayerSession playerSession = GameServerUtils.GetPlayerTableOp().GetPlayerSession(player.SessionID);
payHandler.ProcessPayGoogleReq(playerSession, packet, false);
TraceLog.Trace("GmCmdSvc.PopPayTest uid {0}!", uid);
return 0;
}
[GmApiMapping(desc: "封号", group: GmGroup.SERVER)]
public int SetFreezeTime(long userId, int hour)
{
if (userId == 0)
{
TraceLog.Error("GmCmdSvc.SetFreezeTime invalid uid param {0}", userId);
return -1;
}
long freezeEndTime = GameServerUtils.GetTimeSecond() + hour * 3600;
SSGMSetFreezeTime req = new SSGMSetFreezeTime();
req.FreezeTime = freezeEndTime;
req.Uid = userId;
req.OpSource.SetString("gm");
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.GmSetFreezeTime, ref req, req.Uid);
GameBillLogUtils.LogFreezePlayer(req.Uid, hour);
return 0;
}
[GmApiMapping(desc: "添加玩家等级", group: GmGroup.ROLE)]
public int AddLevel(long userid, int level)
{
var player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddLevel uid {0} not in table", userid);
return -1;
}
player.AddLevel(level);
TraceLog.TraceDetail("GmCmdSvc.AddLevel day param player:{0} cm:{1}", player.UserID, level);
return 0;
}
[GmApiMapping(desc: "添加支付道具", group: GmGroup.PAYMENT)]
public int AddPayItem(long userid, int payItemId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddPayItem can not find player by uid {0}", userid);
return -1;
}
PlayerSession playerSession = GameServerUtils.GetPlayerTableOp().GetPlayerSession(player.SessionID);
if (playerSession == null)
{
TraceLog.Error("GmCmdSvc.AddPayItem can not find PlayerSession by uid {0}, session id {1}", userid,
player.SessionID);
return -1;
}
var desc = PayDiamondDescMgr.Instance.GetConfig(payItemId);
if (desc == null)
{
TraceLog.Error("GmCmdSvc.AddPayItem invalid itemId {0}", payItemId);
return -1;
}
var notify = new CSPayNewItemNotify();
notify.ItemID = desc.itemID;
int index = PlayerPayUtil.GetPaySuccessRecordIndex(player, desc.itemID);
if (index == -1)
{
PlayerPayUtil.AddPaySuccRecordIfNotExist(player, desc);
var res = new CSPayGoogleSuccessRes();
GameServerUtils.GetEventHandlerMgr().TriggerPlayerPaySuccess(player, desc.itemID,
0, 0, 0, false, 0, ref res);
}
else
{
ref var record = ref PlayerPayUtil.GetPayItemRecordByIndex(player, index);
}
// 每次gm指令都发消息通知, 方便客户端测试
PlayerNotify.NotifyPlayerPayDataChange(player);
player.SendToClient((int)CSGameMsgID.PayNewItemNotify, ref notify);
return 0;
}
private static void GMTestHeroPaySucc(PlayerOnGame player, string orderId, int payType)
{
// uid - time - orderSeq - serverId - itemId - param1 - param2
var arr = orderId.Split('-');
var desc = PayDiamondDescMgr.Instance.GetConfig(int.Parse(arr[4]));
if (desc == null)
{
TraceLog.Error("GmCmdSvc.GMTestHeroPaySucc invalid itemId {0}", arr[4]);
return;
}
SSGMTestHeroPaySucc req = new SSGMTestHeroPaySucc();
req.Uid = player.UserID;
req.ItemID = int.Parse(arr[4]);
req.OrderId.SetString(orderId);
req.OrderId3rd.SetString("gm_test_" + GameServerUtils.GetTimeMs());
req.MoneyUSD = (int)desc.currencyRes * 100;
req.PayTime = GameServerUtils.GetTimeSecond();
req.PayType = payType;
if (arr.Length >= 7)
{
int.TryParse(arr[5], out req.PayParam1);
int.TryParse(arr[6], out req.PayParam2);
}
GameServerUtils.GetPacketSender()
.SendToWorldServer((int)SSGameMsgID.GmTestHeroPaySucc, ref req, player.UserID);
}
public static void OnGmTestPayReqSuccess(PlayerOnGame player, ref SSPayGoogleRes res)
{
PlayerSession playerSession = GameServerUtils.GetPlayerTableOp().GetPlayerSession(player.SessionID);
if (playerSession == null)
{
TraceLog.Error("GmCmdSvc.OnGmTestPayReqSuccess can not find PlayerSession by uid {0}, session id {1}"
, player.UserID, player.SessionID);
return;
}
string orderId = res.OrderId.GetString();
// 英雄支付
if (PlayerPayUtil.GetPlayerPayType(player) == PayType.Hero
|| PlayerPayUtil.GetPlayerPayType(player) == PayType.MiniPay)
{
GMTestHeroPaySucc(player, orderId, (int)PlayerPayUtil.GetPlayerPayType(player));
return;
}
PayHandler payHandler = GameServerUtils.GetPayHandler();
StructPacket packet = new StructPacket();
packet.Header.Type = (int)CSGameMsgID.PayGoogleSuccessReq;
StructMessageParser<CSPayGoogleSuccessReq> parser = new StructMessageParser<CSPayGoogleSuccessReq>();
packet.Parser = parser;
ref CSPayGoogleSuccessReq req = ref parser.GetMessage();
req.Uid = player.UserID;
req.Signature.SetString("no signature");
req.OrderId.SetString(orderId);
JsonData purchaseData = new JsonData();
//google的字段,ios反正加密了,gm测试的时候不需要
purchaseData["developerPayload"] = orderId;
purchaseData["orderId"] = "testOrder3rd-" + GameServerUtils.GetTimeMs().ToString();
req.PurchaseData.SetString(purchaseData.ToJson());
payHandler.ProcessPayGoogleSuccessReq(playerSession, packet, true);
}
[GmApiMapping("服务器卡10秒",group: GmGroup.SERVER,ignore:true)]
public int TestDeadLoop(long userid)
{
long tMs = AppTime.GetNowSysMs();
//卡10秒
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(1000);
}
return 0;
}
//如果是需要广播的,通知下world进行广播
private void NotifyWorldBroadCastGMCmdToServer(long userId, string gmCmd, string cmdParams)
{
SSNotifyWorldBroadCastGMCmd notify = new SSNotifyWorldBroadCastGMCmd();
notify.UserId = userId;
notify.GmCmd.SetString(gmCmd);
notify.CmdParams.SetString(cmdParams);
notify.OnlyBroadCastSpec = userId > 0; //如果到了这里,userId又大于0 则是需要指定广播了
GameServerUtils.GetPacketSender()
.SendToWorldServer((int)SSGameMsgID.NotifyworldBroadcastgmcmd, ref notify, 0, 0);
}
[GmApiMapping("测试广播一条信息到网关", group: GmGroup.SERVER,ignore:true)]
public int TestBroadcastGate(long userid)
{
CSChatRes res = new CSChatRes();
res.Message.SetString("broadcast message");
uint gateServerID =
ServerIDUtils.GetLevel1ServerIDByType(GameServerUtils.GetAppID(), (int)ServerType.GameGate, 1);
List<long> sessionIDList = new List<long>();
foreach (var playersession in GameServerUtils.GetPlayerTable().m_sessionsTable)
{
if (playersession.Value.Player != null)
{
sessionIDList.Add(playersession.Key);
//测试一下而已
if (sessionIDList.Count > 100)
{
break;
}
}
}
Sog.Gate.GateService.BroadcastToGate(0
, GameServerUtils.GetApp().GetCluster()
, gateServerID
, sessionIDList
, (int)CSGameMsgID.ChatRes
, ref res);
return 0;
}
[GmApiMapping("添加一个装备", group: GmGroup.EQUIPMENT)]
public int AddEquipment(long userid, string equipmentId)
{
StructPacket packet = new StructPacket();
MessageData messageData = new MessageData();
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddEquipment can not find palyer by uid {0}", userid);
return -2;
}
UnifyOp op = new UnifyOp(player, BillChangeItemReason.GmCmd);
op.AddGoods((int)GoodsType.Equipment, equipmentId, 1);
op.DoOp();
return 0;
}
[GmApiMapping("一键添加红武器", group: GmGroup.EQUIPMENT)]
public int AddRedEquipment(long userid, int level)
{
StructPacket packet = new StructPacket();
MessageData messageData = new MessageData();
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddEquipment can not find palyer by uid {0}", userid);
return -2;
}
UnifyOp op = new UnifyOp(player, BillChangeItemReason.GmCmd);
foreach (var item in GmDescMgr.Instance.ItemTable.Values)
{
if(item.type.Equals("1"))
{
var slv = string.Format("{0:D3}", level);
string equipId = item.gmweapon1 + "" + slv + item.gmweapon2;
op.AddGoods((int)GoodsType.Equipment, equipId, 1);
}
}
op.DoOp(true, true, true);
return 0;
}
[GmApiMapping("一键添加非红武器", group: GmGroup.EQUIPMENT, help: "品质 1 白 2蓝 3紫 4金 5彩")]
public int AddNoneRedEquipment(long userid, int quality, int level)
{
StructPacket packet = new StructPacket();
MessageData messageData = new MessageData();
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddEquipment can not find palyer by uid {0}", userid);
return -2;
}
UnifyOp op = new UnifyOp(player, BillChangeItemReason.GmCmd);
foreach (var item in GmDescMgr.Instance.ItemTable.Values)
{
if (item.type.Equals("2"))
{
string equipId = item.gmweapon1 + "_" + (quality * 1000 + level) + item.gmweapon2;
op.AddGoods((int)GoodsType.Equipment, equipId, 1);
}
}
op.DoOp(true, true, true);
return 0;
}
[GmApiMapping("一键添防具", group: GmGroup.EQUIPMENT, help: "品质 1 白 2蓝 3紫 4金 5彩")]
public int AddDefEquipment(long userid, int quality, int level)
{
StructPacket packet = new StructPacket();
MessageData messageData = new MessageData();
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddEquipment can not find palyer by uid {0}", userid);
return -2;
}
var list = new List<string>();
foreach (var item in GmDescMgr.Instance.ItemTable.Values)
{
if (item.type.Equals("3"))
{
string equipId = item.gmweapon1 + "" + (quality * 1000 + level) + item.gmweapon2;
var equipDesc=EquipDescMgr.Instance.GetConfig(equipId);
if (equipDesc == null)
{
continue;
}
if (list.Count >= 49)
{
Send(player, list);
list.Clear();
}
list.Add(equipId);
}
}
Send(player, list);
return 0;
}
private static void Send(PlayerOnGame player,List<string>equipList)
{
UnifyOp op = new UnifyOp(player, BillChangeItemReason.GmCmd);
foreach (var equipId in equipList)
{
op.AddGoods((int)GoodsType.Equipment, equipId, 1);
}
op.DoOp(true, true, true);
}
[GmApiMapping(desc: "压缩数据", group: GmGroup.SERVER,ignore:true)]
public int ZipRole(long userid)
{
PlayerDataSvc.testZipRole = 1;
return 0;
}
[GmApiMapping(desc: "踢出玩家下线", help: "1:踢出账号,2:踢出游戏", group: GmGroup.SERVER)]
public int KickOutAllPlayer(long userid, int type)
{
var allplayer = GameServerUtils.GetPlayerTableOp();
CSLoginRes loginResCS = new CSLoginRes();
loginResCS.Ret = (int)CSErrCode.InvalidAccount;
loginResCS.ServerTime = GameServerUtils.GetTimeMs();
loginResCS.Uid = 0;
loginResCS.LoginToken = 0;
loginResCS.TimeZone = AppTime.TimeZone;
foreach (var player in allplayer.Table.m_uidTable)
{
PlayerSession session = GameServerUtils.GetPlayerTableOp().GetPlayerSession(player.Value.SessionID);
if (session != null)
{
switch (type)
{
case 1: //踢出账号
GateService.SendToGate(session.UserID, GameServerUtils.GetApp().GetCluster(),
session.GateServerID,
session.SessionID, (int)CSGameMsgID.LoginRes, ref loginResCS);
break;
case 2: //踢出游戏
loginResCS.Ret = (int)CSErrCode.ResetGame;
GateService.SendToGate(session.UserID, GameServerUtils.GetApp().GetCluster(),
session.GateServerID,
session.SessionID, (int)CSGameMsgID.LoginRes, ref loginResCS);
break;
}
//其它的断开链接重连
GateService.NotifyGateServerDisconnect(GameServerUtils.GetApp(), session.GateServerID,
session.SessionID);
}
}
return 0;
}
[GmApiMapping(desc: "获取在线玩家数量", group: GmGroup.SERVER)]
public int GetOnlinePlayer(long userid)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.GetOnlinePlayer can not find palyer by uid {0}", userid);
return -1;
}
CSGmGetOnlinePlayerNotify res = new CSGmGetOnlinePlayerNotify();
res.OnlinePlayer = GameServerUtils.GetPlayerTableOp().GetOnlinePlayer();
player.SendToClient((int)CSGameMsgID.GmGetOnlineplayerNotify, ref res);
return 0;
}
[GmApiMapping("生成机器人数据", group: GmGroup.SERVER)]
public int GenRobot(long userid)
{
ref SimpleRobotPool robotPool = ref GmStaticData.robotPool;
ref SimpleRobotList robotList = ref GmStaticData.robotList;
robotPool.Clear();
var robot = new SimpleRobot();
int count = 0;
for (int i = 1; i <= 120; i++)
{
robotList.Clear();
for (int j = 0; j < 50; j++)
{
robot.Clear();
ProcessGenRobot(i, 1000 + count, ref robot);
robotList.List.Add(ref robot);
count++;
}
robotPool.Pool.Add(ref robotList);
}
TraceLog.Debug("GmCmdSvc.GenRobot count {0}", count);
FileDBSave.SaveToFile(ref robotPool, "../cfg/data/robot.bin");
return 0;
}
[GmApiMapping("生成单个机器人", group: GmGroup.SERVER)]
public int GenSingleRobot(long userid, int level, int uid)
{
var robot = new SimpleRobot();
ProcessGenRobot(level, uid, ref robot);
// todo 存入文件或是替代内存
FileDBSave.SaveToFile(ref robot, "../cfg/data/singleRobot.bin");
return 0;
}
private static string GetRobotLastNameByIdx(int idx)
{
string name = "";
var desc = RandNameDescMgr.Instance.GetConfig(idx);
if (desc != null)
{
int randNameRow = 0;
string strRandNameRow =
GameServerUtils.GetApp().GetCluster().GetAppParamByKey("randNameRow"); //读第几列,从0开始
if (!string.IsNullOrEmpty(strRandNameRow))
{
int.TryParse(strRandNameRow, out randNameRow);
}
if (randNameRow + 1 <= desc.name.Length)
{
if (!string.IsNullOrEmpty(desc.name[randNameRow].LastName))
{
name = desc.name[randNameRow].LastName;
}
}
}
return name;
}
private static void ProcessGenRobot(int level, int uid, ref SimpleRobot robot)
{
int baseRate = 0;
int nameIdx = uid % RandNameDescMgr.Instance.ItemTable.Count + 1;
long nowSec = GameServerUtils.GetTimeSecond();
var noneEquip = new DBEquipment();
var hero = new HeroInfo();
var roleBase = new DBRoleBase();
// RoleBase
roleBase.Uid = uid;
roleBase.Nick.SetString(GetRobotLastNameByIdx(nameIdx));
roleBase.Gender = 0;
roleBase.Icon.SetString(IconUtils.GetRandFreeIcon());
roleBase.Exp = 0;
roleBase.Level = level;
roleBase.VipLevel = 0;
roleBase.Chip = 0;
roleBase.Diamond = 0;
roleBase.LastLoginTime = GameServerUtils.GetTimeSecond();
roleBase.CreateTime = GameServerUtils.GetTimeSecond();
roleBase.OnlineTime = GameServerUtils.GetTimeSecond();
roleBase.VipExp = 0;
roleBase.HeroExpPool = 0;
roleBase.RoleCreateComplete = 0;
roleBase.Power = 0;
// DBHero
hero.Dbhero.Level = level;
hero.Dbhero.DescId = 100;
for (int j = 0; j < hero.Dbhero.WearEquip.GetMaxCount(); j++)
{
hero.Dbhero.WearEquip.Add(ref noneEquip);
}
int wearNum = 0;
var equip = new DBEquipment();
int chestLv = Math.Max(hero.Dbhero.Level / 10, 3);
while (wearNum < hero.Dbhero.WearEquip.GetMaxCount())
{
//EquipmentSvc.CreateEquip(level, chestLv, ref equip);
//// 没有装备
//int idx = equip.Pos - 1;
//if (idx == -1)
//{
// continue;
//}
//if (hero.Dbhero.WearEquip[idx].Pos == 0)
//{
// hero.Dbhero.WearEquip[idx] = equip;
// wearNum += 1;
//}
equip.Pos = ++wearNum;
hero.Dbhero.WearEquip.Add(ref equip);
}
//hero.LineupPos = 1;
// 生成属性并填充对应字段
//var heroProp = new RoleProp();
//RolePropUtil.RecalRoleProp(player, heroProp);
//heroProp.BeginChange();
//heroProp.SetValueNoCheck(CSPropIDType.HpMax, heroProp.GetValueNoCheck(CSPropIDType.HpMax) * baseRate / 10000);
//heroProp.SetValueNoCheck(CSPropIDType.Atk, heroProp.GetValueNoCheck(CSPropIDType.Atk) * baseRate / 10000);
//heroProp.SetValueNoCheck(CSPropIDType.Def, heroProp.GetValueNoCheck(CSPropIDType.Def) * baseRate / 10000);
//heroProp.SetValueNoCheck(CSPropIDType.Speed, heroProp.GetValueNoCheck(CSPropIDType.Speed) * baseRate / 10000);
//heroProp.EndChange();
//HeroPropUtils.FillHeroInfoProp(ref hero, heroProp);
//robot.HeroInfo.CopyFrom(ref hero);
//robot.RoleBase.CopyFrom(ref roleBase);
//robot.RandNameIdx = nameIdx;
TraceLog.Debug("GmCmdSvc.ProcessGenRobot uid {0} icon {1} roleBase.level {2} heroInfo.level {3} nameIdx {4}"
, uid, roleBase.Icon, robot.RoleBase.Level, robot.HeroInfo.Dbhero.Level, robot.RandNameIdx);
}
/// <summary>
/// 查询其他玩家测试接口
/// </summary>
/// <param name="userid"></param>
/// <param name="cmdParams"></param>
/// <returns></returns>
public int GetOtherInfo(long userid, long targetUid = 100002)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.GetOtherInfo invalid uid {0}", userid);
return -1;
}
CSPlayerQueryOtherRoleInfoReq req = new CSPlayerQueryOtherRoleInfoReq();
req.QueryRoleType = QueryRoleType.None;
req.TargetUid = targetUid;
PlayerOnGame target = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(req.TargetUid);
if (target == null)
{
//直接给world就好了
GameServerUtils.GetPacketSender()
.SendToWorldServer((int)CSGameMsgID.PlayerQueryOtherRoleInfoReq, ref req, userid);
}
else
{
//CSPlayerQueryOtherRoleInfoRes queryRes = new CSPlayerQueryOtherRoleInfoRes();
//queryRes.FromUid = player.UserID;
//queryRes.Ret = CSErrCode.None;
//HeroPropUtils.FillHeroInfo(ref queryRes.ShowInfo.HeroInfo, ref target.RoleData, target.knight.prop);
//PlayerUtils.GetRoleBaseInfo(target, ref queryRes.ShowInfo.RoleBaseInfo);
//player.SendToClient((int)CSGameMsgID.PlayerQueryOtherRoleInfoRes, ref queryRes);
}
return 0;
}
[GmApiMapping(desc: "清理广告数据", group: GmGroup.SERVER)]
public int ClearAd(long userid)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(userid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ClearAd invalid uid {0}", userid);
return -1;
}
HomeAdEvent.OnNewDay(player, true);
player.MakeDirty();
return 0;
}
[GmApiMapping("清理支付记录", group: GmGroup.PAYMENT)]
public int ClearPayRecord(long uid, int itemId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.RecalcWingProp uid {0} no player obj", uid);
return 0;
}
for (int i = player.RoleData.PayData.PayItemRecord.Count - 1; i >= 0; i--)
{
ref var record = ref player.RoleData.PayData.PayItemRecord[i];
if (record.ItemId == itemId)
{
player.RoleData.PayData.PayItemRecord.RemoveAt(i);
player.MakeDirty();
break;
}
}
return 0;
}
[GmApiMapping(desc: "添加奖励", group: GmGroup.EQUIPMENT)]
public int AddReward(long uid, string rewardId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddReward uid {0} no player obj", uid);
return 0;
}
var res = RewardSvc.Reward(player, rewardId);
res.ForEach(r => { TraceLog.Trace("rewardres {0}", r); });
return 0;
}
[GmApiMapping(desc: "速通关卡", group: GmGroup.CHAPTER,help:"chapter表里面的id和chapterbattle表id")]
public int OnSkipChapter(long uid, int chapterId, int battleId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.OnSkipChapter uid {0} no player obj", uid);
return 0;
}
if (player.RoleData.IsInBattle)
{
TraceLog.Error("GmCmdSvc.OnSkipChapter player in battle .can not skip ", uid);
return -1;
}
var desc = ChapterDescMgr.Instance.GetConfig(chapterId);
if (desc == null)
{
return -1;
}
var battleDesc = ChapterBattleDescMgr.Instance.GetConfig(battleId);
if (battleDesc == null)
{
return -1;
}
var targetId = desc.firstChapterBattleId;
var vaild = targetId == battleId;
while (targetId != 0)
{
var _battleDesc = ChapterBattleDescMgr.Instance.GetConfig(targetId);
if (_battleDesc == null || _battleDesc.nextChapterBattleId == 0)
{
break;
}
targetId = _battleDesc.nextChapterBattleId;
if (targetId == battleId)
{
vaild = true;
break;
}
}
if (!vaild)
{
return -1;
}
var minChapterId = CommParamDescMgr.Instance.MainLandFirstId.int_val;
while (minChapterId <= chapterId)
{
var chapterDesc = ChapterDescMgr.Instance.GetConfig(minChapterId);
minChapterId = chapterDesc.nextChapterId;
var firstChapterBattleId = chapterDesc.firstChapterBattleId;
while (firstChapterBattleId != 0)
{
var chapterBattleDesc = ChapterBattleDescMgr.Instance.GetConfig(firstChapterBattleId);
firstChapterBattleId = chapterBattleDesc.nextChapterBattleId;
var stageId = chapterBattleDesc.firstChapterBattleStageId;
while (stageId != 0)
{
var stageDesc = ChapterBattleStageDescMgr.Instance.GetConfig(stageId);
stageId = stageDesc.nextStageId;
ChapterHelper.SetEffectiveStage(player, stageDesc.stageIndex);
if (stageId == 0)
{
break;
}
}
ChapterHelper.SetPerfectPass(player,chapterBattleDesc.chapterIndex);
if (firstChapterBattleId > battleId)
{
break;
}
if (firstChapterBattleId == 0)
{
break;
}
}
if (minChapterId == 0)
{
break;
}
}
player.RoleData.ChapterData.ChapterId = chapterId;
player.RoleData.ChapterData.BattleId = battleId;
RankSvc.UpdateRankScore(player, 1, battleId, 10);
ChapterSvc.SyncChapterInfo(player);
player.MakeDirty();
return 0;
}
[GmApiMapping(desc: "进入指定关卡", group: GmGroup.CHAPTER)]
public static int OnEnterChapter(long uid, int chapterId, int battleId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.OnSkipChapter uid {0} no player obj", uid);
return 0;
}
// if (player.RoleData.IsInBattle)
// {
// TraceLog.Error("GmCmdSvc.OnSkipChapter player in battle .can not skip ", uid);
// return -1;
// }
// if (chapterId > player.RoleData.ChapterData.ChapterId)
// {
// player.RoleData.ChapterData.ChapterId = chapterId;
// }
//
// if (battleId > player.RoleData.ChapterData.BattleId)
// {
// player.RoleData.ChapterData.BattleId = battleId;
// }
var packet = new StructPacket();
packet.Header.Type = (int)CSGameMsgID.BattleBeginReq;
var parser = new StructMessageParser<OnBattleBeginReq>();
packet.Parser = parser;
ref var req = ref packet.GetMessage<OnBattleBeginReq>();
req.ChapterId = chapterId;
req.BattleId = battleId;
req.IsGm = false;
ChapterSvc.OnBattleBegin(player,packet);
return 0;
}
[GmApiMapping(desc: "奖励关出来", group: GmGroup.CHAPTER,help:"ChapterBattle表里面的id")]
public static int InitRewardChapter(long uid,int battleId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.OnSkipChapter uid {0} no player obj", uid);
return 0;
}
var desc = ChapterBattleDescMgr.Instance.GetConfig(battleId);
if (desc == null || desc.chapterBattleType != ChapterBattleType.RewardBattle)
{
return 0;
}
player.RoleData.ChapterData.RewardBattleData.BattleId = battleId;
var duration = CommParamDescMgr.Instance.RwdChapterTime.int_val;
player.RoleData.ChapterData.RewardBattleData.LoseTime = GameServerUtils.GetTimeSecond() + duration;
ChapterSvc.SyncChapterInfo(player);
player.MakeDirty();
return 0;
}
[GmApiMapping(desc: "排行榜", group: GmGroup.SERVER, help: "")]
public int RankOper(long uid, int rankId, int score)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.AddReward uid {0} no player obj", uid);
return 0;
}
RankSvc.UpdateRankScore(player, rankId, score, 0, false);
return 0;
}
[GmApiMapping(desc: "激活月卡", group: GmGroup.PAYMENT, help: "cardid 月卡表里面的id")]
public int ActiveMonthlyCard(long uid, int cardId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
var desc = MonthlyCardDescMgr.Instance.GetConfig(cardId);
MonthlyCardSvc.OnActiveMonthlyCard(player,desc.id);
return 0;
}
[GmApiMapping(desc: "添加BP点数", group: GmGroup.PAYMENT, help: "activity 表 id")]
public int BattleAddPoint(long uid, int actId,int count)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
if (ActivitySvc.GetActivityState(player, actId) != ActivityState.InProgress)
{
return 0;
}
ref var battlePassData = ref player.RoleData.ActExtraInfo.BattlePassData;
var index = -1;
for (int i = 0; i < battlePassData.Count; i++)
{
ref var battlePass = ref battlePassData[i];
if (battlePass.ActId == actId)
{
index = i;
break;
}
}
if (index < 0)
{
return -1;
}
battlePassData[index].Point += count;
player.MakeDirty();
BattlePassSvc.SyncBattlesInfo(player);
return 0;
}
[GmApiMapping(desc: "抽卡", group: GmGroup.PAYMENT, help: "Gacha表id ,抽卡数量")]
public int Recruit(long uid, string poolId, int num)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
var desc = GachaDescMgr.Instance.GetConfig(poolId);
var unifyOp = new UnifyOp(player, BillChangeItemReason.RecruitAdv);
var result = new List<TypeIDValueString>();
for (int i = 0; i < num; i++)
{
RecruitSvc.RecruitOne(player,unifyOp,desc.InternalId,result);
}
unifyOp.DoOp(sendGetItemMsg: true);
return 0;
}
[GmApiMapping(desc: "战斗所有章节", group: GmGroup.BATCHTEST, ignore: true)]
public int TestImport(long uid, int chapterId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
var item = ChapterDescMgr.Instance.GetConfig(chapterId);
var battleId = item.firstChapterBattleId;
while (battleId != 0)
{
var desc = ChapterBattleDescMgr.Instance.GetConfig(battleId);
ChapterTest.TestImport(player, chapterId, battleId);
battleId = desc.nextChapterBattleId;
}
return 0;
}
[GmApiMapping(desc: "添加所有宝石", group: GmGroup.EQUIPMENT, help: "count")]
public int AddAllGem(long uid, int count )
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
UnifyOp op = new UnifyOp(player, "GM");
var items = GemDescMgr.Instance.ItemTable.Values;
for (int i = 0; i < items.Count; i++)
{
op.AddGoods((int)GoodsType.Gem, items[i].id, count);
if(i % 60 == 0)
{
op.DoOp(true, true, true);
}
}
op.DoOp(true, true, true);
return 0;
}
[GmApiMapping(desc: "添加宝石", group: GmGroup.EQUIPMENT, help: "头1护甲2首套3护腿4鞋5配件6饰品7芯片8万能10 白1蓝2紫3金4深金5红6")]
public int AddGem(long uid, int count, int pos, int quality)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
UnifyOp op = new UnifyOp(player, "GM");
var items = GemDescMgr.Instance.ItemTable.Values;
for (int i = 0; i < items.Count; i++)
{
var c = items[i];
if ((int)c.position == pos && (int)c.quality == quality)
{
op.AddGoods((int)GoodsType.Gem, items[i].id, count);
if (i % 60 == 0)
{
op.DoOp(true, true, true);
}
}
}
op.DoOp(true, true, true);
return 0;
}
[GmApiMapping(desc: "跳过所有引导", group: GmGroup.BEGINNER)]
public int FinishAllGuide(long uid)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
var newVal = new RepeatedInt_64();
foreach (var desc in NoviceGuidanceDescMgr.Instance.ItemTable.Values)
{
newVal.Add(desc.id);
}
player.RoleData.BeginnerGuide = newVal;
var res = new CSBeginnerGuideChangeRes();
res.BeginnerGuide.CopyFrom(ref player.RoleData.BeginnerGuide);
player.SendToClient((int)CSGameMsgID.BeginnerGuideChangeRes, ref res);
player.MakeDirty();
return 0;
}
[GmApiMapping(desc: "解锁所有系统", group: GmGroup.BEGINNER)]
public int UnLockAllSystem(long uid)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.UnLockAll uid {0} no player obj", uid);
return 0;
}
var tempList = new List<int>();
foreach (var c in UnlockSystemDescMgr.Instance.ItemTable.Values)
{
bool unlock = false;
for(int i = 0; i < player.RoleData.SysUnlockData.SysUnlockDataOne.Count; i++)
{
if (player.RoleData.SysUnlockData.SysUnlockDataOne[i].SysID == c.id)
{
unlock = true;
break;
}
}
if(!unlock)
{
DBSysUnlockDataOne unlockData = new DBSysUnlockDataOne();
unlockData.SysID = c.id;
unlockData.SysUnlockTime = GameServerUtils.GetTimeSecond();
player.RoleData.SysUnlockData.SysUnlockDataOne.Add(unlockData);
GameServerUtils.GetEventHandlerMgr().TriggerSystemUnlock(player, c.id);
tempList.Add(c.id);
}
}
player.MakeDirty();
if (tempList.Count > 0)
{
SystemUnlockEvent.SendSyn(tempList, player);
}
return 0;
}
[GmApiMapping(desc: "作战手册任务全完成", group: GmGroup.ACTIVITY)]
public int DoneAllSignTasks(long uid,int actId)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
if (actId == 0)
{
return 0;
}
var desc = ActivityDescMgr.Instance.GetConfig(actId);
if (desc is not { type: ActivityType.HandBook })
{
return 0;
}
HandBookAct.DoneAllTask(player,actId);
return 0;
}
[GmApiMapping(desc: "血厚和暴击", group: GmGroup.CHAPTER)]
public int RoleFight(long uid)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
player.RoleData.GmProp.Clear();
player.RoleData.GmProp.Add(new IDValue64(){Id =(int)PropertyDef.HpPercentIncrease,Value = 10000*10000 });
player.RoleData.GmProp.Add(new IDValue64(){Id =(int)PropertyDef.CriticalRate,Value = 100_0000 });
RolePropUtil.RecalRoleProp(player, true);
player.MakeDirty();
return 0;
}
[GmApiMapping(desc: "我无敌", group: GmGroup.CHAPTER,help:"0:无敌,1:清理无敌")]
public int OverKiller(long uid, int clear = 0)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.OverKiller uid {0} no player obj", uid);
return 0;
}
if (clear == 1)
{
player.RoleData.GmProp.Clear();
RolePropUtil.RecalRoleProp(player, true);
player.MakeDirty();
return 0;
}
player.RoleData.GmProp.Clear();
player.RoleData.GmProp.Add(new IDValue64(){Id =(int)PropertyDef.HpPercentIncrease,Value = 10000_00 });
player.RoleData.GmProp.Add(new IDValue64(){Id =(int)PropertyDef.DamageRate,Value = 100_00 });
player.RoleData.GmProp.Add(new IDValue64(){Id =(int)PropertyDef.CriticalRate,Value = 100_000 });
player.RoleData.GmProp.Add(new IDValue64(){Id =(int)PropertyDef.AtkFixedIncrease,Value = 30000_0000 });
player.RoleData.GmProp.Add(new IDValue64(){Id =(int)PropertyDef.PhyDamage,Value = 10000_000 });
player.RoleData.GmProp.Add(new IDValue64(){Id =(int)PropertyDef.DamageResistance,Value = 10000_000 });
RolePropUtil.RecalRoleProp(player, true);
player.MakeDirty();
return 0;
}
[GmApiMapping(desc: "功能全部解锁", group: GmGroup.BEGINNER)]
public int UnlockAll(long uid)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.ActiveMonthlyCard uid {0} no player obj", uid);
return 0;
}
List<int> tempList = new List<int>();
foreach (var c in UnlockSystemDescMgr.Instance.ItemTable.Values)
{
bool unlock = false;
for (int i = 0; i < player.RoleData.SysUnlockData.SysUnlockDataOne.Count; i++)
{
if (player.RoleData.SysUnlockData.SysUnlockDataOne[i].SysID == c.id)
{
unlock = true;
break;
}
}
if (!unlock)
{
DBSysUnlockDataOne unlockData = new DBSysUnlockDataOne();
unlockData.SysID = c.id;
unlockData.SysUnlockTime = GameServerUtils.GetTimeSecond();
player.RoleData.SysUnlockData.SysUnlockDataOne.Add(unlockData);
tempList.Add(c.id);
GameServerUtils.GetEventHandlerMgr().TriggerSystemUnlock(player, c.id);
}
}
if (tempList.Count > 0 )
{
SystemUnlockEvent.SendSyn(tempList, player);
}
return 0;
}
public static void CollectGmProp(ref DBRoleData roleDat, RoleProp roleProp)
{
for (int i = 0; i < roleDat.GmProp.Count; i++)
{
roleProp.AddProp((int)roleDat.GmProp[i].Id, roleDat.GmProp[i].Value);
}
}
[GmApiMapping(desc: "翅膀一键满级", group: GmGroup.ROLE)]
public int WingMax(long uid)
{
var player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.WingMax uid {0} no player obj", uid);
return 0;
}
ref var wingData = ref player.RoleData.WingData;
wingData.Wing.LevelId = WingsLevelDescMgr.Instance.ItemTable.Values.Last().id;
wingData.Wing.RankId = WingsRankDescMgr.Instance.ItemTable.Values.Last().id;
wingData.Wing.StarId = WingsStarDescMgr.Instance.ItemTable.Values.Last().id;
wingData.Wing.WearId = WingsStarDescMgr.Instance.ItemTable.Values.Last().id;
WingSvc.RecWinsProp(player);
WingSvc.SyncData(player);
return 0;
}
[GmApiMapping(desc: "解锁天赋", group: GmGroup.TALENT, help: "0 普通天赋,1巅峰天赋")]
public int ActiveTalent(long uid, int page)
{
var player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.WinMainOption uid {0} no player obj", uid);
return 0;
}
var packet = new StructPacket();
packet.Header.Type = (int)CSGameMsgID.TalentOptionsReq;
var parser = new StructMessageParser<CSTalentOptionsReq>();
packet.Parser = parser;
ref var req = ref packet.GetMessage<CSTalentOptionsReq>();
req.PageIndex = page;
TalentSvc.OnTalentOption(player, packet);
return 0;
}
[GmApiMapping(desc: "激活/回退天赋点", group: GmGroup.TALENT, help: "page:0 普通天赋,1巅峰天赋, talentId 天赋id, backup 0激活,1回退")]
public int TalentOptaion(long uid,int page,int talentId, int backup)
{
var player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.WinMainOption uid {0} no player obj", uid);
return 0;
}
var packet = new StructPacket();
packet.Header.Type = (int)CSGameMsgID.TalentOptionsReq;
var parser = new StructMessageParser<CSTalentActiveReq>();
packet.Parser = parser;
ref var req = ref packet.GetMessage<CSTalentActiveReq>();
req.TalentId = talentId;
req.Backup = backup != 0;
req.PageIndex = page;
TalentSvc.OnActiveOption(player, packet);
return 0;
}
[GmApiMapping(desc: "领取体力", group: GmGroup.ROLE, help: "all:0 领取一个,1 全部领取")]
public int GainPower(long uid, int all)
{
var player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
if (player == null)
{
TraceLog.Error("GmCmdSvc.WinMainOption uid {0} no player obj", uid);
return 0;
}
var packet = new StructPacket();
packet.Header.Type = (int)CSGameMsgID.TalentOptionsReq;
var parser = new StructMessageParser<GainPowerReq>();
packet.Parser = parser;
ref var req = ref packet.GetMessage<GainPowerReq>();
req.All = all == 1;
PlayerDataSvc.GainPower(player,packet);
return 0;
}
}
}