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.
144 lines
4.8 KiB
144 lines
4.8 KiB
/*
|
|
Sog 游戏基础库
|
|
2016 by zouwei
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
using Sog.Gate;
|
|
|
|
namespace Game
|
|
{
|
|
// 登录消息
|
|
public class NameHandler : BasePacketHandler
|
|
{
|
|
public override int GetServiceType()
|
|
{
|
|
return GameServiceType.NameHandler;
|
|
}
|
|
|
|
//销毁的时候置空
|
|
public override void Dispose()
|
|
{
|
|
}
|
|
|
|
public NameHandler()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public override void HandlerClientPacket(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
switch (packet.MsgID)
|
|
{
|
|
case (int)CSGameMsgID.NameQueryUsedReq:
|
|
OnNameQueryUsedReq(playerSession, packet);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override void HandlerServerPacket(uint serverID, StructPacket packet)
|
|
{
|
|
switch (packet.MsgID)
|
|
{
|
|
case (int)SSMsgID.NameQueryRes:
|
|
OnNameQueryUsedRes(serverID, packet);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void OnNameQueryUsedReq(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
//ref CSNameQueryUsedReq req = ref packet.GetMessage<CSNameQueryUsedReq>();
|
|
////checkName 不法词汇
|
|
|
|
////校验Name
|
|
//SSNameQueryReq ssreq = new SSNameQueryReq();
|
|
//ssreq.AccountID = playerSession.AccountInfo.AccountID;
|
|
//ssreq.StrName = req.StrName;
|
|
//ssreq.HashName.SetString(HashHelper.SHA1String(ssreq.StrName.GetString()));
|
|
//ssreq.CreateIfNotExist = req.CreateIfNotExist;
|
|
//ssreq.PlayerSessionID = playerSession.SessionID;
|
|
|
|
////客户端过来的请求
|
|
//GameServerUtils.GetPacketSender().SendToNameServer<SSNameQueryReq>((int) SSMsgID.NameQueryReq, ref ssreq, 0);
|
|
|
|
}
|
|
|
|
|
|
private void OnNameQueryUsedRes(uint serverID, StructPacket packet)
|
|
{
|
|
ref SSNameQueryRes ssres = ref packet.GetMessage<SSNameQueryRes>();
|
|
PlayerSession playerSession = GameServerUtils.GetPlayerTableOp().GetPlayerSession(ssres.PlayerSessionID);
|
|
if(playerSession == null)
|
|
{
|
|
TraceLog.Error("OnNameQueryUsedRes error");
|
|
return;
|
|
}
|
|
|
|
PlayerOnGame player = playerSession.Player;
|
|
|
|
//CSNameQueryUsedRes res = new CSNameQueryUsedRes();
|
|
//res.StrName = ssres.StrName;
|
|
//res.Ret = ssres.Ret;
|
|
//res.CreateIfNotExist = ssres.CreateIfNotExist;
|
|
|
|
//player.SendToClient((int)CSGameMsgID.NameQueryUsedRes, ref res);
|
|
if(ssres.Ret != 0)
|
|
{
|
|
CSRenameRes res = new CSRenameRes();
|
|
res.Ret = (int)CSErrCode.NameRepeat;
|
|
res.RenameTimes = player.RoleData.OtherData.RenameTimes;
|
|
player.SendToClient((int)CSGameMsgID.RenameRes, ref res);
|
|
}
|
|
else if(ssres.Ret == 0)
|
|
{
|
|
CSRenameRes res = new CSRenameRes();
|
|
res.NewName.SetString(ssres.StrName.GetString());
|
|
|
|
// 花钱改名, 首次免费
|
|
if (player.RoleData.OtherData.RenameTimes > 0)
|
|
{
|
|
int cost = CommParamDescMgr.Instance.RenameCost.int_val;
|
|
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.DiamondRename, ssres.StrName.GetString());
|
|
bagOp.CostDiamond(cost);
|
|
CSErrCode ret = bagOp.DoOp();
|
|
if (ret != CSErrCode.None)
|
|
{
|
|
res.Ret = (int)ret;
|
|
player.SendToClient((int)CSGameMsgID.RenameRes, ref res);
|
|
return;
|
|
}
|
|
}
|
|
|
|
player.RoleData.OtherData.NewNick.SetString(ssres.StrName.GetString());
|
|
player.RoleData.OtherData.RenameTimes++;
|
|
player.RoleBase.Nick.SetString(ssres.StrName.GetString());
|
|
player.MakeDirty();
|
|
|
|
//通知world
|
|
PlayerNotify.NotifyWorldPlayerRolebaseChangeUpdate(player);
|
|
PlayerNotify.NotifyPlayerShowInfoChange(player);
|
|
|
|
GameServerUtils.GetPlayerDataSvc().UpdateRoleBriefToDB(player);
|
|
|
|
//回应客户端
|
|
res.Ret = 0;
|
|
res.RenameTimes = player.RoleData.OtherData.RenameTimes;
|
|
player.SendToClient((int)CSGameMsgID.RenameRes, ref res);
|
|
player.Trace("PlayUtils.DealCSRenameReq player uid {0} rename success newname {1}", player.UserID, ssres.StrName.GetString());
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|