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.
936 lines
34 KiB
936 lines
34 KiB
/*
|
|
Sog 游戏基础库
|
|
2016 by zouwei
|
|
*/
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
using Sog.Log;
|
|
using System;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Game
|
|
{
|
|
// 系统消息: ping chat sysnotice
|
|
public class SysHandler : BasePacketHandler
|
|
{
|
|
public override int GetServiceType()
|
|
{
|
|
return GameServiceType.SysHandler;
|
|
}
|
|
|
|
//销毁的时候置空
|
|
public override void Dispose()
|
|
{
|
|
}
|
|
|
|
public SysHandler()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public override void HandlerClientPacket(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
if (playerSession.Player == null)
|
|
{
|
|
TraceLog.Debug("SysHandler HandlerClientPacket drop message id {0} because session {1} no player object", packet.MsgID, playerSession.SessionID);
|
|
return;
|
|
}
|
|
|
|
switch (packet.MsgID)
|
|
{
|
|
case (int)CSGameMsgID.Ping:
|
|
ProcessPing(playerSession, packet);
|
|
break;
|
|
case (int)CSGameMsgID.Gmcmd:
|
|
GmCmdSvc.OnCliGmCmd(playerSession, packet);
|
|
break;
|
|
|
|
|
|
case (int)CSGameMsgID.RenameReq:
|
|
PlayerOnGame player = playerSession.Player;
|
|
ProcessRenameReq(player, packet);
|
|
break;
|
|
case (int)CSGameMsgID.ChangeIconReq:
|
|
ProcessChangeIconReq(playerSession, packet);
|
|
break;
|
|
case (int)CSGameMsgID.CliReportBillReq:
|
|
ProcessCliReportBillReq(playerSession, packet);
|
|
break;
|
|
case (int)CSGameMsgID.SaveClientDataReq:
|
|
ProcessSaveClientDataReq(playerSession, packet);
|
|
break;
|
|
case (int)CSGameMsgID.SaveClientBitFlagReq:
|
|
ClientBitFlagSvc.ProcessSaveClientBitFlagReq(playerSession, packet);
|
|
break;
|
|
case (int)CSGameMsgID.TipOffPlayerReq:
|
|
ProcessTipOffPlayerReq(playerSession, packet);
|
|
break;
|
|
case (int)CSGameMsgID.HideMyInfoReq:
|
|
ProcessHideMyInfoReq(playerSession, packet);
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (int)CSGameMsgID.RolebaseChgReq:
|
|
ProcessRolebaseChgReq(playerSession, packet);
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (int)CSGameMsgID.PlayerSearchRoleBynameReq:
|
|
//直接给world就好了
|
|
GameServerUtils.GetPacketSender().SendToWorldServer<CSPlayerSearchRoleByNameReq>(packet, playerSession.Player.UserID);
|
|
break;
|
|
case (int)CSGameMsgID.PlayerQueryOtherRoleInfoReq:
|
|
OnPlayerQueryOtherRoleInfoReq(playerSession.Player, packet);
|
|
break;
|
|
|
|
case (int)CSGameMsgID.LogClientBdcReq:
|
|
BillLogWriter.Instance.SendCliToBillBDCLogSvr(packet);
|
|
break;
|
|
|
|
case (int)CSGameMsgID.LogClientTaReq:
|
|
BillLogWriter.Instance.SendCliToBillTALogSvr(packet);
|
|
break;
|
|
case (int)CSGameMsgID.SetLanguageReq:
|
|
OnSetLanguageReq(playerSession, packet);
|
|
break;
|
|
|
|
|
|
case (int)CSGameMsgID.PowerCliReq:
|
|
OnPowerCliReq(playerSession.Player, packet);
|
|
break;
|
|
|
|
|
|
case (int)CSGameMsgID.SyspaychanelReq:
|
|
OnSysPayChanelReq(playerSession.Player, packet);
|
|
break;
|
|
|
|
case (int)CSGameMsgID.TalentActiveReq:
|
|
TalentSvc.OnActiveOption(playerSession.Player,packet);
|
|
break;
|
|
case (int)CSGameMsgID.TalentOptionsReq:
|
|
TalentSvc.OnTalentOption(playerSession.Player,packet);
|
|
break;
|
|
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override void HandlerServerPacket(uint serverID, StructPacket packet)
|
|
{
|
|
switch (packet.MsgID)
|
|
{
|
|
//case (int)CSGameMsgID.ChatRes:
|
|
// ChatSvc.OnChatRes(serverID, packet);
|
|
// break;
|
|
//case (int)SSGameMsgID.ChatConsumeReq:
|
|
// ChatSvc.OnChatConsumeReq(serverID, packet);
|
|
// break;
|
|
|
|
//case (int)CSGameMsgID.QueryOtherDetailRes:重复了
|
|
// OnQueryOtherDetailRes(serverID, packet);
|
|
// break;
|
|
//case (int)CSGameMsgID.GagChatNotify:
|
|
// OnGagChatNotify(serverID, packet);
|
|
// break;
|
|
|
|
case (int)SSMsgID.RealmBriefRes:
|
|
OnRealmBriefRes(serverID, packet);
|
|
break;
|
|
case (int)SSGameMsgID.StatisticsChg:
|
|
OnStatisticsChg(serverID, packet);
|
|
break;
|
|
case (int)SSGameMsgID.DealgmcmdNotify:
|
|
GmCmdSvc.OnWorldNotifyDealGmCmd(packet);
|
|
break;
|
|
case (int)SSGameMsgID.PlayerQueryOfflineRoleReq:
|
|
OnPlayerQueryOfflineRoleReq(serverID, packet);
|
|
break;
|
|
case (int)SSGameMsgID.PlayerSearchRoledbBynameRes:
|
|
//数据库查询后返回了
|
|
OnPlayerSearchRoledbBynameRes(serverID, packet);
|
|
break;
|
|
case (int)CSGameMsgID.PlayerQueryOtherRoleInfoRes:
|
|
//数据库查询后返回了
|
|
OnPlayerQueryOtherRoleInfoRes(serverID, packet);
|
|
break;
|
|
case (int)SSGameMsgID.CheckDirtyStringRes:
|
|
DirtyStringSvc.OnCheckDirtyStringRes(serverID, packet);
|
|
break;
|
|
case (int)SSGameMsgID.PlaydataOpRes:
|
|
OnPlaydataOpRes(serverID, packet);
|
|
break;
|
|
case (int)SSGameMsgID.GmChangeRoleNameReq:
|
|
ProcessSSRenameReq(serverID, packet);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
private int ProcessPing(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
ref CSPing pingReq = ref packet.GetMessage<CSPing>();
|
|
|
|
PlayerOnGame player = playerSession.Player;
|
|
if (player == null)
|
|
{
|
|
TraceLog.Debug("SysHandler.ProcessPing no player object, session {0}", playerSession.SessionID);
|
|
return -2;
|
|
}
|
|
|
|
long now = GameServerUtils.GetTimeMs();
|
|
|
|
//记一下时间
|
|
player.PingInfo.LastRecvPingTime = GameServerUtils.GetTimeSecond();
|
|
|
|
//客户端发给服务器
|
|
if (pingReq.ServerTime == 0)
|
|
{
|
|
pingReq.ServerTime = now;
|
|
SendToPlayer<CSPing>(playerSession, packet);
|
|
return 0;
|
|
}
|
|
|
|
long thisPing = now - pingReq.ServerTime;
|
|
|
|
//统计客户端的ping
|
|
player.Trace("SysHandler.ProcessPing player {0} ping {1} clienttime {2} servertime {3}"
|
|
, player.UserID, thisPing, pingReq.ClientTime, pingReq.ServerTime);
|
|
|
|
if (player.PingInfo.MaxPingTime < thisPing)
|
|
{
|
|
player.PingInfo.MaxPingTime = thisPing;
|
|
}
|
|
|
|
if (player.PingInfo.MinPingTime == 0 || player.PingInfo.MinPingTime > thisPing)
|
|
{
|
|
player.PingInfo.MinPingTime = thisPing;
|
|
}
|
|
|
|
player.PingInfo.TotalPingTime += thisPing;
|
|
player.PingInfo.PingCount++;
|
|
|
|
long nowSecond = GameServerUtils.GetTimeSecond();
|
|
//一分钟log一条ping消息
|
|
if (nowSecond - player.PingInfo.LastLogTime >= 60)
|
|
{
|
|
player.PingInfo.LastLogTime = nowSecond;
|
|
|
|
GameBillLogUtils.LogPlayerPingInfo(player.UserID, player.PingInfo);
|
|
|
|
player.Trace("SysHandler.ProcessPing player {0} min {1} max {2} avg {3}"
|
|
, player.UserID, player.PingInfo.MinPingTime, player.PingInfo.MaxPingTime, player.PingInfo.TotalPingTime / player.PingInfo.PingCount);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ProcessRenameReq(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
if (player == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ref CSRenameReq req = ref packet.GetMessage<CSRenameReq>();
|
|
|
|
CSRenameRes res = new CSRenameRes();
|
|
res.NewName = req.NewName;
|
|
|
|
string newNameStr = req.NewName.GetString();
|
|
|
|
int iRet = PlayerUtils.CheckRenameValid(newNameStr);
|
|
if (iRet != 0)
|
|
{
|
|
player.Trace("SysHandler.ProcessRenameReq uid {0} CheckRenameValid failed ret {1} newNameStr [{2}]"
|
|
, player.UserID, iRet, newNameStr);
|
|
res.Ret = (int)CSErrCode.IncludeIllegalWord;
|
|
player.SendToClient((int)CSGameMsgID.RenameRes, ref res);
|
|
return;
|
|
}
|
|
DirtyStringSvc.DealDirtyStringCheck(player, DirtyStringCheckType.CSRenameReq, ref req, newNameStr);
|
|
}
|
|
|
|
public void ProcessSSRenameReq(uint serverID, StructPacket packet)
|
|
{
|
|
ref SSGmChangeRoleNameReq req = ref packet.GetMessage<SSGmChangeRoleNameReq>();
|
|
TraceLog.Debug("SysHandler-ProcessSSRenameReq req:{0}", req.ToString());
|
|
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(req.Uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.ProcessSSRenameReq query uid {0} not in memory,skip"
|
|
, packet.ObjectID);
|
|
return;
|
|
}
|
|
|
|
SSGmChangeRoleNameRes res = new SSGmChangeRoleNameRes();
|
|
res.Name = req.Name;
|
|
res.Uid = req.Uid;
|
|
res.Id = req.Id;
|
|
|
|
string newNameStr = req.Name.GetString();
|
|
|
|
int iRet = PlayerUtils.CheckRenameValid(newNameStr);
|
|
if (iRet != 0)
|
|
{
|
|
player.Trace("SysHandler.ProcessSSRenameReq uid {0} CheckRenameValid failed ret {1} newNameStr [{2}]"
|
|
, player.UserID, iRet, newNameStr);
|
|
res.Ret = (int)CSErrCode.IncludeIllegalWord;
|
|
GameServerUtils.GetPacketSender().SendToServerByID(serverID, (int)SSGameMsgID.GmChangeRoleNameRes, ref res, player.UserID);
|
|
return;
|
|
}
|
|
DirtyStringSvc.DealDirtyStringCheck(player, DirtyStringCheckType.SSRenameReq, ref req, newNameStr);
|
|
}
|
|
|
|
private void ProcessChangeIconReq(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
PlayerOnGame player = playerSession.Player;
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.ProcessChangeIconReq uid {0} no player", playerSession.UserID);
|
|
return;
|
|
}
|
|
|
|
ref CSChangeIconReq req = ref packet.GetMessage<CSChangeIconReq>();
|
|
var res = new CSChangeIconRes { Ret = -1, NewIcon = req.NewIcon };
|
|
|
|
string newIcon = req.NewIcon.GetString();
|
|
|
|
if (string.IsNullOrEmpty(newIcon) || newIcon.Equals("nil"))
|
|
{
|
|
TraceLog.Trace("SysHandler.ProcessChangeIconReq uid {0} req invalid icon {1}", player.UserID, newIcon);
|
|
player.SendToClient((int)CSGameMsgID.ChangeIconRes, ref res);
|
|
return;
|
|
}
|
|
|
|
if (!int.TryParse(newIcon, out int iconId) || iconId == 0)
|
|
{
|
|
TraceLog.Trace("SysHandler.ProcessChangeIconReq uid {0} req invalid icon {1}", player.UserID, newIcon);
|
|
player.SendToClient((int)CSGameMsgID.ChangeIconRes, ref res);
|
|
return;
|
|
}
|
|
|
|
if (!SysSvc.IsPlayerIconUnlock(player, iconId))
|
|
{
|
|
TraceLog.Trace("SysHandler.ProcessChangeIconReq uid {0} icon {1} is lock", player.UserID, iconId);
|
|
player.SendToClient((int)CSGameMsgID.ChangeIconRes, ref res);
|
|
|
|
var notify = new CSIconDataNotify { Data = player.RoleData.IconData };
|
|
player.SendToClient((int)CSGameMsgID.IconDataNotify, ref notify);
|
|
return;
|
|
}
|
|
|
|
player.RoleBase.Icon = req.NewIcon;
|
|
player.MakeDirty();
|
|
|
|
player.Trace("SysHandler.ProcessChangeIconReq uid {0} change new icon {1}", player.UserID, newIcon);
|
|
res.Ret = 0;
|
|
player.SendToClient((int)CSGameMsgID.ChangeIconRes, ref res);
|
|
|
|
PlayerNotify.NotifyPlayerShowInfoChange(player);
|
|
GameServerUtils.GetPlayerDataSvc().UpdateRoleBriefToDB(player);
|
|
}
|
|
|
|
|
|
private void ProcessCliReportBillReq(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
ref CSCliReportBillReq req = ref packet.GetMessage<CSCliReportBillReq>();
|
|
|
|
string strContent = "";
|
|
|
|
if (req.ReportStr.IsEmpty() == false)
|
|
{
|
|
strContent = req.ReportStr.GetString().Replace("\n", " ");
|
|
strContent = strContent.Replace("\r", " ");
|
|
}
|
|
|
|
GameBillLogUtils.LogCliReportBill(playerSession.UserID, req.ReportType.GetString(), strContent);
|
|
}
|
|
|
|
private void ProcessSaveClientDataReq(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
PlayerOnGame player = playerSession.Player;
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.ProcessSaveClientDataReq no player object uid {0}"
|
|
, playerSession.UserID);
|
|
return;
|
|
}
|
|
|
|
|
|
ref CSSaveClientDataReq req = ref packet.GetMessage<CSSaveClientDataReq>();
|
|
|
|
int maxLength = 256;
|
|
|
|
//设一下最大值,不能超过256字节
|
|
if (req.ClientData.Count > maxLength)
|
|
{
|
|
player.Error("SysHandler.ProcessSaveClientDataReq uid {0} data length too long, max {1}"
|
|
, playerSession.UserID, maxLength);
|
|
return;
|
|
}
|
|
|
|
player.unimportanceData.ClientData = req.ClientData;
|
|
player.MakeDirty();
|
|
|
|
CSSaveClientDataRes res = new CSSaveClientDataRes();
|
|
res.ClientData = req.ClientData;
|
|
|
|
player.SendToClient((int)CSGameMsgID.SaveClientDataRes, ref res);
|
|
|
|
player.Trace("SysHandler.ProcessSaveClientDataReq uid {0} ", playerSession.UserID);
|
|
|
|
}
|
|
|
|
private void OnQueryOtherDetailRes(uint serverID, StructPacket packet)
|
|
{
|
|
ref var res = ref packet.GetMessage<CSQueryOtherDetailRes>();
|
|
|
|
//发给客户端的
|
|
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Trace("SysHandler.OnQueryOtherDetailRes query uid {0} not in memory,skip"
|
|
, packet.ObjectID);
|
|
return;
|
|
}
|
|
|
|
player.SendToClient<CSQueryOtherDetailRes>(packet);
|
|
}
|
|
|
|
|
|
private void OnPlayerQueryOtherRoleInfoRes(uint serverID, StructPacket packet)
|
|
{
|
|
//发给客户端的
|
|
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Trace("SysHandler.OnPlayerQueryOtherRoleInfoRes query uid {0} not in memory,skip"
|
|
, packet.ObjectID);
|
|
return;
|
|
}
|
|
ref var res = ref packet.GetMessage<CSPlayerQueryOtherRoleInfoRes>();
|
|
if (res.QueryRoleType == QueryRoleType.CBC)
|
|
{
|
|
CBattleSvc.CbcPlayerRes(ref res);
|
|
}
|
|
else
|
|
{
|
|
player.SendToClient<CSPlayerQueryOtherRoleInfoRes>(packet);
|
|
}
|
|
|
|
}
|
|
|
|
private void OnPlaydataOpRes(uint serverID, StructPacket packet)
|
|
{
|
|
//
|
|
ref var res = ref packet.GetMessage<SSPlayDataOpRes>();
|
|
TraceLog.Debug("SysHandler-OnPlaydataOpRes res:{0}", res.ToString());
|
|
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(res.Uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.OnPlaydataOpRes query uid {0} not in memory,skip"
|
|
, packet.ObjectID);
|
|
return;
|
|
}
|
|
|
|
UnifyOp op = new UnifyOp(player, BillChangeItemReason.OssPlayerData);
|
|
for (int i = 0; i < res.OpData.Count; i++)
|
|
{
|
|
var opData = res.OpData[i];
|
|
if (opData.Id <= player.RoleData.OssMaxPlayerDataId)
|
|
{
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
player.RoleData.OssMaxPlayerDataId = opData.Id;
|
|
}
|
|
op = new UnifyOp(player, BillChangeItemReason.OssPlayerData, opData.Id.ToString());
|
|
|
|
CSErrCode code = CSErrCode.None;
|
|
switch (opData.Type)
|
|
{
|
|
case OpPlayDataHandleType.None:
|
|
break;
|
|
case OpPlayDataHandleType.Currency:
|
|
if (opData.OpType == 2)
|
|
{
|
|
op.AddItem(opData.OpId.ToString(), opData.OpNum);
|
|
}
|
|
else if (opData.OpType == 1)
|
|
{
|
|
op.CostItem(opData.OpId.ToString(), opData.OpNum);
|
|
}
|
|
break;
|
|
case OpPlayDataHandleType.Hero:
|
|
if (opData.OpType == 2)
|
|
{
|
|
//op.AddHero((int)opData.OpId, opData.OpNum);
|
|
}
|
|
else if (opData.OpType == 1)
|
|
{
|
|
}
|
|
break;
|
|
case OpPlayDataHandleType.BagItem:
|
|
if (opData.OpType == 2)
|
|
{
|
|
op.AddItem(opData.OpId.ToString(), opData.OpNum);
|
|
}
|
|
else if (opData.OpType == 1)
|
|
{
|
|
op.CostItem(opData.OpId.ToString(), opData.OpNum);
|
|
}
|
|
break;
|
|
case OpPlayDataHandleType.BagEquip:
|
|
if (opData.OpType == 2)
|
|
{
|
|
}
|
|
else if (opData.OpType == 1)
|
|
{
|
|
}
|
|
break;
|
|
case OpPlayDataHandleType.VipActivity:
|
|
|
|
break;
|
|
case OpPlayDataHandleType.Debug:
|
|
TraceLog.Error("SysHandler - OnPlaydataOpRes uid:{4} id:{0} opId:{1} OpType:{2} OpNum:{3}",
|
|
opData.Id, opData.OpId, opData.OpType, opData.OpNum, res.Uid);
|
|
code = CSErrCode.SysFailure;
|
|
break;
|
|
default:
|
|
code = CSErrCode.SysFailure;
|
|
break;
|
|
}
|
|
if (code != CSErrCode.None)
|
|
{
|
|
TraceLog.Error("SysHandler-OnPlaydataOpRes error, code {0}", code);
|
|
continue;
|
|
}
|
|
code = op.CheckOp();
|
|
if (code != CSErrCode.None)
|
|
{
|
|
TraceLog.Error("SysHandler-OnPlaydataOpRes error,op check code {0}", code);
|
|
continue;
|
|
}
|
|
code = op.DoOp();
|
|
|
|
if (code != CSErrCode.None)
|
|
{
|
|
TraceLog.Error("SysHandler-OnPlaydataOpRes error,op doop code {0}", code);
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
TraceLog.Trace("SysHandler-OnPlaydataOpRes success uid {0} id {1}", player.UserID, opData.Id);
|
|
//bill Log
|
|
}
|
|
}
|
|
|
|
// 结束后判断最大值是否更新
|
|
if (res.MaxId > player.RoleData.OssMaxPlayerDataId)
|
|
player.RoleData.OssMaxPlayerDataId = res.MaxId;
|
|
return;
|
|
}
|
|
|
|
|
|
private void ProcessTipOffPlayerReq(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
PlayerOnGame player = playerSession.Player;
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.ProcessTipOffPlayerReq no player object uid {0}"
|
|
, playerSession.UserID);
|
|
return;
|
|
}
|
|
|
|
//转给world
|
|
GameServerUtils.GetPacketSender().SendToWorldServer<CSTipOffPlayerReq>(packet, player.UserID);
|
|
}
|
|
|
|
private void OnGagChatNotify(uint serverID, StructPacket packet)
|
|
{
|
|
ref var gagChatNotify = ref packet.GetMessage<CSGagChatNotify>();
|
|
|
|
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Trace("SysHandler.OnGagChatNotify uid {0} not in memory", packet.ObjectID);
|
|
return;
|
|
}
|
|
|
|
player.GagChatEndTime = gagChatNotify.GagEndTime;
|
|
|
|
player.SendToClient<CSGagChatNotify>(packet);
|
|
}
|
|
|
|
private void ProcessHideMyInfoReq(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
PlayerOnGame player = playerSession.Player;
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.ProcessHideMyInfoReq no player object uid {0}"
|
|
, playerSession.UserID);
|
|
return;
|
|
}
|
|
|
|
ref CSHideMyInfoReq req = ref packet.GetMessage<CSHideMyInfoReq>();
|
|
|
|
if (req.Hide != 0 && req.Hide != 1)
|
|
{
|
|
player.Error("SysHandler.ProcessHideMyInfoReq player uid {0} invalid param hide {1}"
|
|
, player.UserID, req.Hide);
|
|
return;
|
|
}
|
|
|
|
player.RoleData.OtherData.HideMyInfo = req.Hide;
|
|
player.MakeDirty();
|
|
|
|
//好友里也需要,发给world
|
|
GameServerUtils.GetPacketSender().SendToWorldServer<CSHideMyInfoReq>(packet, player.UserID);
|
|
|
|
CSHideMyInfoRes res = new CSHideMyInfoRes();
|
|
res.Hide = req.Hide;
|
|
|
|
player.Debug("SysHandler.ProcessHideMyInfoReq player uid {0} hide {1} success"
|
|
, player.UserID, req.Hide);
|
|
|
|
player.SendToClient((int)CSGameMsgID.HideMyInfoRes, ref res);
|
|
|
|
GameBillLogUtils.LogHideMyInfo(player.UserID, req.Hide);
|
|
|
|
}
|
|
|
|
private void OnSetLanguageReq(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
PlayerOnGame player = playerSession.Player;
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.OnSetLanguageReq no player object uid {0}", playerSession.UserID);
|
|
return;
|
|
}
|
|
|
|
ref var req = ref packet.GetMessage<CSSetLanguageReq>();
|
|
req.Lang.SetString(Sog.Lang.LanguageUtils.GetLangByClientOsLanguage(req.Lang.GetString()));
|
|
|
|
playerSession.Lang = req.Lang.GetString();
|
|
player.Lang = playerSession.Lang;
|
|
player.RoleBase.Lang.SetString(playerSession.Lang);
|
|
player.MakeDirty();
|
|
//转给world
|
|
GameServerUtils.GetPacketSender().SendToWorldServer<CSSetLanguageReq>(packet, player.UserID);
|
|
// 转给mail
|
|
GameServerUtils.GetPacketSender().SendToMailServer<CSSetLanguageReq>((int)CSGameMsgID.SetLanguageReq, ref req, player.UserID);
|
|
|
|
TraceLog.Trace("SysHandler.OnSetLanguageReq uid {0} lang {1}", player.UserID, req.Lang);
|
|
|
|
var res = new CSSetLanguageRes();
|
|
res.Lang = req.Lang;
|
|
player.SendToClient((int)CSGameMsgID.SetLanguageRes, ref res);
|
|
|
|
}
|
|
|
|
private void OnRealmBriefRes(uint serverID, StructPacket packet)
|
|
{
|
|
ref var res = ref packet.GetMessage<SSRealmBriefRes>();
|
|
|
|
var svrData = GameServerUtils.GetGameServerData();
|
|
|
|
for (int i = 0; i < res.RealmList.Count; i++)
|
|
{
|
|
var realm = new RealmBriefInfo(ref res.RealmList[i]);
|
|
svrData.m_allRealm[realm.realmId] = realm;
|
|
}
|
|
|
|
if (!res.RealmListMd5.IsEmpty())
|
|
{
|
|
svrData.recvRealmListMd5 = res.RealmListMd5.GetString();
|
|
}
|
|
|
|
TraceLog.Trace("OnRealmBriefRes count {0} svrData.recvRealmListMd5 {1}", svrData.m_allRealm.Count, svrData.recvRealmListMd5);
|
|
}
|
|
|
|
|
|
private void OnStatisticsChg(uint serverID, StructPacket packet)
|
|
{
|
|
ref var notify = ref packet.GetMessage<SSStatisticsChg>();
|
|
long uid = packet.ObjectID;
|
|
|
|
var player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.OnStatisticsChg uid {0} not in table", uid);
|
|
return;
|
|
}
|
|
|
|
//bool updateToWorld = false;
|
|
var rolechgOp = new RoleStatChgOp(player);
|
|
|
|
for (int i = 0; i < notify.ChgStat.Count; i++)
|
|
{
|
|
ref var iv = ref notify.ChgStat[i];
|
|
rolechgOp.AddIDDaily(iv.Id, iv.Value);
|
|
|
|
// if (iv.Id == (int)CSRoleStatisticsID.BrokeGrantsCount)
|
|
//{
|
|
// updateToWorld = true;
|
|
// }
|
|
}
|
|
|
|
rolechgOp.NotifyClient();
|
|
|
|
//if (updateToWorld)
|
|
//{
|
|
// PlayerNotify.NotifySimpleRoleDataToWorld(player);
|
|
//}
|
|
}
|
|
|
|
private int CheckRolebaseChg(PlayerOnGame player, ref CSRolebaseChgReq req)
|
|
{
|
|
var nick = req.Nick.GetString();
|
|
var gender = req.Gender;
|
|
|
|
if (string.IsNullOrEmpty(nick))
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
if (gender > 2 || gender < 0)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
var bInvalidGender = gender == player.GetGender();
|
|
var bInvalidNick = nick == player.GetNick();
|
|
// 两个都没改
|
|
if (bInvalidNick && bInvalidGender)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
private void ProcessRolebaseChgReq(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
PlayerOnGame player = playerSession.Player;
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.ProcessRolebaseChgReq no player object uid {0}", playerSession.UserID);
|
|
return;
|
|
}
|
|
|
|
ref var req = ref packet.GetMessage<CSRolebaseChgReq>();
|
|
var res = new CSRolebaseChgRes();
|
|
|
|
if (CheckRolebaseChg(player, ref req) != 0)
|
|
{
|
|
TraceLog.Error("SysHandler.ProcessRolebaseChgReq uid {0} CheckRolebaseChg no invaild", player.UserID);
|
|
res.Ret = -1;
|
|
|
|
SendToPlayer(playerSession, (int)CSGameMsgID.RolebaseChgRes, ref res);
|
|
return;
|
|
}
|
|
|
|
if (req.Nick.GetString() != player.GetNick())
|
|
{
|
|
//保存在other里
|
|
player.RoleData.OtherData.NewNick = req.Nick;
|
|
player.RoleBase.Nick = req.Nick;
|
|
}
|
|
|
|
if (player.GetGender() != req.Gender)
|
|
{
|
|
//保存在other里
|
|
player.RoleData.OtherData.NewGender = req.Gender;
|
|
player.RoleBase.Gender = req.Gender;
|
|
}
|
|
player.MakeDirty();
|
|
|
|
//通知world
|
|
PlayerNotify.NotifyWorldPlayerRolebaseChangeUpdate(player);
|
|
|
|
TraceLog.Trace("SysHandler.ProcessRolebaseChgReq uid {0} nick {1} gender {2} success"
|
|
, player.UserID, player.GetNick(), player.GetGender());
|
|
|
|
res.Ret = 0;
|
|
res.Nick.SetString(player.GetNick());
|
|
res.Gender = player.GetGender();
|
|
SendToPlayer(playerSession, (int)CSGameMsgID.RolebaseChgRes, ref res);
|
|
}
|
|
|
|
|
|
|
|
public void OnPlayerQueryOtherRoleInfoReq(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref CSPlayerQueryOtherRoleInfoReq req = ref packet.GetMessage<CSPlayerQueryOtherRoleInfoReq>();
|
|
PlayerOnGame target = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(req.TargetUid);
|
|
if (target == null)
|
|
{
|
|
//直接给world就好了
|
|
GameServerUtils.GetPacketSender().SendToWorldServer<CSPlayerQueryOtherRoleInfoReq>(packet, player.UserID);
|
|
}
|
|
else
|
|
{
|
|
CSPlayerQueryOtherRoleInfoRes queryRes = new CSPlayerQueryOtherRoleInfoRes();
|
|
queryRes.FromUid = player.UserID;
|
|
queryRes.Ret = CSErrCode.None;
|
|
queryRes.QueryRoleType = req.QueryRoleType;
|
|
HeroPropUtils.FillHeroInfo(ref queryRes.ShowInfo.HeroInfo, ref target.RoleData );
|
|
PlayerUtils.GetRoleBaseInfo(target, ref queryRes.ShowInfo.RoleBaseInfo);
|
|
player.SendToClient((int)CSGameMsgID.PlayerQueryOtherRoleInfoRes, ref queryRes);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//这里只是借用下个协议,实际上world检测到在线,发到这里来拿TargetUid的数据的
|
|
private void OnPlayerQueryOfflineRoleReq(uint serverID, StructPacket packet)
|
|
{
|
|
ref SSPlayerQueryOfflineRoleReq queryRoleReq = ref packet.GetMessage<SSPlayerQueryOfflineRoleReq>();
|
|
|
|
SSPlayerQueryOfflineRoleRes queryRoleRes = new SSPlayerQueryOfflineRoleRes();
|
|
queryRoleRes.Ret = CSErrCode.None;
|
|
queryRoleRes.CallBackReq.CopyFrom(ref queryRoleReq);
|
|
|
|
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(queryRoleReq.TargetUid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("SysHandler.OnPlayerQueryOfflineRoleReq uid {0} not in table", queryRoleReq.TargetUid);
|
|
queryRoleRes.Ret = CSErrCode.SysFailure;
|
|
}
|
|
else
|
|
{
|
|
queryRoleRes.TargetIsOnline = player.SessionID > 0;
|
|
queryRoleRes.RoleBase.CopyFrom(ref player.RoleBase);
|
|
queryRoleRes.RoleData.CopyFrom(ref player.RoleData);
|
|
queryRoleRes.TargetRealmId = player.RealmID;
|
|
}
|
|
|
|
GameServerUtils.GetPacketSender().SendToServerByID(serverID,
|
|
(int)SSGameMsgID.PlayerQueryOfflineRoleRes, ref queryRoleRes, packet.ObjectID);
|
|
}
|
|
|
|
private void OnPlayerSearchRoledbBynameRes(uint serverID, StructPacket packet)
|
|
{
|
|
ref SSPlayerSearchRoleDBByNameRes dbRes = ref packet.GetMessage<SSPlayerSearchRoleDBByNameRes>();
|
|
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(dbRes.FromUid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("OnPlayerSearchRoledbBynameRes FromUid {0} not in table", dbRes.FromUid);
|
|
return;
|
|
}
|
|
|
|
CSPlayerSearchRoleByNameRes res = new CSPlayerSearchRoleByNameRes();
|
|
res.Ret = dbRes.Ret;
|
|
if (dbRes.Ret == CSErrCode.None)
|
|
{
|
|
res.TargetUid.CopyFrom(ref dbRes.TargetUid);
|
|
}
|
|
|
|
SendToPlayer(player, (int)CSGameMsgID.PlayerSearchRoleBynameRes, ref res);
|
|
}
|
|
|
|
private void OnPowerCliReq(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref CsPowerCliReq req = ref packet.GetMessage<CsPowerCliReq>();
|
|
|
|
PlayerNotify.NotifyPlayerPowerChange(player, 1, req.BoxChange);
|
|
GameServerUtils.GetEventHandlerMgr().TriggerHeroPowerChanged(player, player.RoleBase.Power);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnSysPayChanelReq(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref var req = ref packet.GetMessage<CSSysPayChanelReq>();
|
|
var res = new CSSysPayChanelRes();
|
|
res.Seq = req.Seq;
|
|
var config = GameServerUtils.GetServerConfig();
|
|
res.ClosePayChanel = config.closePayChanel;
|
|
player.SendToClient<CSSysPayChanelRes>((int)CSGameMsgID.SyspaychanelRes, ref res);
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SysSvc
|
|
{
|
|
// 更新调查问卷地址
|
|
|
|
public static void RealmOnline(int realmId)
|
|
{
|
|
var online = GameServerUtils.GetGameServerData().realmOnline;
|
|
if (!online.ContainsKey(realmId))
|
|
{
|
|
online[realmId] = 0;
|
|
}
|
|
|
|
online[realmId]++;
|
|
}
|
|
|
|
public static void RealmOffline(int realmId)
|
|
{
|
|
var online = GameServerUtils.GetGameServerData().realmOnline;
|
|
if (online.ContainsKey(realmId))
|
|
{
|
|
online[realmId]--;
|
|
}
|
|
}
|
|
|
|
|
|
public static void updateSysPayChanel(PlayerOnGame player)
|
|
{
|
|
var config = GameServerUtils.GetServerConfig();
|
|
if (player.RoleData.OtherData.ClosePayChanel != config.closePayChanel)
|
|
{
|
|
player.RoleData.OtherData.ClosePayChanel = config.closePayChanel;
|
|
var res = new CSSysPayChanelRes();
|
|
res.ClosePayChanel = config.closePayChanel;
|
|
player.SendToClient<CSSysPayChanelRes>((int)CSGameMsgID.SyspaychanelRes, ref res);
|
|
player.MakeDirty();
|
|
}
|
|
}
|
|
|
|
|
|
public static bool IsPlayerIconUnlock(PlayerOnGame player, int iconId)
|
|
{
|
|
//GameServerUtils.GetSequenceCheckIndex(iconId, out int index, out int bitIdx);
|
|
//if (index < 0 || index >= player.RoleData.IconData.IconUnlockBits.Count)
|
|
//{
|
|
// TraceLog.Error("SysSvc.IsPlayerIconUnlock uid {0} icon {1} no space", player.UserID, iconId);
|
|
// return false;
|
|
//}
|
|
|
|
//return GameServerUtils.CheckInSequence(bitIdx, player.RoleData.IconData.IconUnlockBits[index]);
|
|
for (int i = 0; i < player.RoleData.IconData.Unlocked.Count; i++)
|
|
{
|
|
if (player.RoleData.IconData.Unlocked.Get(i) == iconId)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|