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.
355 lines
11 KiB
355 lines
11 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
using LitJson;
|
|
using Sog.Lang;
|
|
|
|
namespace Game
|
|
{
|
|
public static class PlayerUtils
|
|
{
|
|
/// <summary>
|
|
/// 在玩牌的玩家不能退出,保证结算的时候玩家在线
|
|
/// 进入赛场的玩家也不能退出,保证比赛每张桌子都坐满,没有玩家一直等待
|
|
/// </summary>
|
|
/// <param name="player"></param>
|
|
/// <returns></returns>
|
|
public static bool PlayerCanOffline(PlayerOnGame player)
|
|
{
|
|
if (player.BattleID != 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static bool UTF8IsContainSpecialChar(string str)
|
|
{
|
|
if (str == null || str.Length == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
try
|
|
{
|
|
byte[] bytes = Encoding.GetEncoding("utf-8").GetBytes(str);
|
|
foreach (var b in bytes)
|
|
{
|
|
if (UTF8IsStartWithOver3Byte(b))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
TraceLog.Error("PlayerUtils.UTF8IsContainSpecialChar exception {0}"
|
|
, e.Message);
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//临时代码,判断 是否包含有超过3字节的utf8编码
|
|
public static bool UTF8IsStartWithOver3Byte(byte b)
|
|
{
|
|
int unsignByte = b;
|
|
return (0xf0 <= unsignByte && unsignByte <= 0xf7) ||//4字节开头
|
|
(0xf8 <= unsignByte && unsignByte <= 0xfb) ||//5字节开头
|
|
(0xfc <= unsignByte && unsignByte <= 0xfd);//6字节开头
|
|
|
|
}
|
|
|
|
public static int CheckRenameValid(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
string str = name.Trim(' ');
|
|
if (string.IsNullOrEmpty(str))
|
|
{
|
|
return -2;
|
|
}
|
|
|
|
if (name.Length >= 1)
|
|
{
|
|
//首尾不能是空格
|
|
if (name[0] == ' ' || name[^1] == ' ')
|
|
{
|
|
return -3;
|
|
}
|
|
}
|
|
|
|
// c#中char是utf-16编码, 长度是2个字节
|
|
// utf-16只有2字节, 4字节两种存储格式, 0xD800 ~ 0xDCFF
|
|
// utf-16编码的字符ToCharArray()后, unicode大于0xFFFF部分会占据4个字节, 从而1个字符string[i]变成2个char
|
|
|
|
foreach (char ch in name)
|
|
{
|
|
// 非ascii码范围内的字符都允许, 注意数据库必须设置utf8mb4
|
|
// ascii码中符号只允许空格, 字母, 数字, 避免特殊字符触发bug
|
|
if (ch <= 0xff)
|
|
{
|
|
if (ch == 0x20 // 空格
|
|
|| (ch >= 0x30 && ch <= 0x39) //数字
|
|
|| (ch >= 0x41 && ch <= 0x5a) //大写字母
|
|
|| (ch >= 0x61 && ch <= 0x7a) //小写字母
|
|
)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
TraceLog.Trace("PlayerUtils.CheckRenameValid invalid char {0}", ch);
|
|
return -4;
|
|
}
|
|
}
|
|
|
|
//if (UTF8IsContainSpecialChar(name))
|
|
//{
|
|
// return -8;
|
|
//}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
public static void OnNewDayStart(PlayerOnGame player, bool notifyClient)
|
|
{
|
|
player.Trace("PlayerUtils.OnNewDayStart uid {0}", player.UserID);
|
|
}
|
|
|
|
|
|
|
|
public static void MakeQueryRoleResFromPlayer(ref CSQueryRoleRes csroleRes, PlayerOnGame player)
|
|
{
|
|
player.RoleData.OtherData.GmLevel = 0;
|
|
var cfg = GameServerUtils.GetServerConfig();
|
|
if (cfg.isAllGM == 1 || (cfg.gmUid != null && cfg.gmUid.Contains(player.UserID)))
|
|
{
|
|
player.RoleData.OtherData.GmLevel = 1;
|
|
}
|
|
|
|
if (player.RoleData.OtherData.ClosePayChanel != cfg.closePayChanel)
|
|
{
|
|
player.RoleData.OtherData.ClosePayChanel = cfg.closePayChanel;
|
|
}
|
|
|
|
csroleRes.RoleBase = player.RoleBase;
|
|
csroleRes.RoleData = player.RoleData;
|
|
|
|
csroleRes.GagChatEndTime = player.GagChatEndTime;
|
|
|
|
//特殊处理一下,删除不需要发给客户端的数据
|
|
csroleRes.UnimportanceData = player.unimportanceData;
|
|
|
|
csroleRes.UnimportanceData.DBBagChangeRecordList.Clear();
|
|
|
|
// 生成展示属性
|
|
csroleRes.PropView.CopyFrom(ref player.RoleData.Knight.PropView);
|
|
|
|
}
|
|
|
|
|
|
public static string GetServerCurVersionForPlayer(PlatformType platform)
|
|
{
|
|
var servercfg = GameServerUtils.GetServerConfig();
|
|
if (servercfg.curVersion.Contains("|"))
|
|
{
|
|
var versionSplit = servercfg.curVersion.Split('|');
|
|
if (platform == PlatformType.PlatformType_IOS)
|
|
{
|
|
return versionSplit[1];
|
|
}
|
|
else
|
|
{
|
|
return versionSplit[0];
|
|
}
|
|
|
|
}
|
|
|
|
return servercfg.curVersion;
|
|
|
|
}
|
|
|
|
//是否是最新的apk
|
|
public static bool IsLatestApkVersion(PlayerOnGame player)
|
|
{
|
|
PlayerSession playerSession = GameServerUtils.GetPlayerTableOp().GetPlayerSession(player.SessionID);
|
|
if(playerSession == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(String.IsNullOrEmpty(playerSession.ApkVersion))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
string strserverVersion = GetServerCurVersionForPlayer(playerSession.Platform);
|
|
|
|
long playerApk = AppVersion.ToIntVersion(playerSession.ApkVersion);
|
|
long serverVersion = AppVersion.ToIntVersion(strserverVersion);
|
|
ushort playerCode = AppVersion.GetCodeFromVersion(playerApk);
|
|
ushort serverCode = AppVersion.GetCodeFromVersion(serverVersion);
|
|
|
|
if(playerCode >= serverCode)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static string GetPlayerLanguageStr(PlayerOnGame player, string content)
|
|
{
|
|
return LanguageUtils.GetLanguageString(content, player.Lang);
|
|
}
|
|
|
|
|
|
|
|
// 代币
|
|
public static string GetCurrencyJson(PlayerOnGame player)
|
|
{
|
|
JsonData currency = new JsonData();
|
|
currency[ItemId.Gold] = player.GetGold();
|
|
currency[ItemId.Diamond] = player.GetDiamond();
|
|
return currency.ToJson();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//战役进度
|
|
public static JsonData GetBattleInfoJson(PlayerOnGame player)
|
|
{
|
|
JsonData battleInfo = new JsonData();
|
|
|
|
return battleInfo;
|
|
}
|
|
|
|
// 英雄等级TopX
|
|
|
|
|
|
|
|
//public static bool CheckIsSysUnlock(PlayerOnGame player, SystemUnlockId id)
|
|
//{
|
|
// return IsUnlockSys(player, (int)id);
|
|
//}
|
|
|
|
//public static bool IsUnlockSys(PlayerOnGame player, int id)
|
|
//{
|
|
// var cfg = GameServerUtils.GetServerConfig();
|
|
// if (cfg.bCloseCheckSysUnlock)
|
|
// {
|
|
// return true;
|
|
// }
|
|
|
|
// var desc = UnlockSystemDescMgr.Instance.GetConfig(id);
|
|
// if (desc == null)
|
|
// {
|
|
// return false;
|
|
// }
|
|
|
|
// int taskId = desc.unlockCondition[0];
|
|
// int level = desc.unlockCondition[1];
|
|
// bool c1 = taskId == 0 || TaskEXSvc.IsFinishTask(player, taskId);
|
|
// bool c2 = level == 0 || player.GetLevel() >= level;
|
|
// return c1 && c2;
|
|
//}
|
|
|
|
|
|
|
|
//处理系统解锁
|
|
public static void DealSystemeOpenNotify(PlayerOnGame player, bool notifyOpen = true)
|
|
{
|
|
|
|
}
|
|
|
|
public static void OnSystemUnlock(PlayerOnGame player, ref IDValue32 iv, bool notifyOpen = true)
|
|
{
|
|
|
|
}
|
|
|
|
public static void GetRoleBaseInfo(PlayerOnGame target, ref RoleBaseInfo roleBaseInfo)
|
|
{
|
|
ref DBRoleData roleData = ref target.RoleData;
|
|
roleBaseInfo.Uid = target.RoleBase.Uid;
|
|
roleBaseInfo.Level = target.RoleBase.Level;
|
|
roleBaseInfo.Gender = target.RoleBase.Gender;
|
|
roleBaseInfo.Icon.SetString(target.RoleBase.Icon.ToString());
|
|
roleBaseInfo.Nick.SetString(target.RoleBase.Nick.ToString());
|
|
roleBaseInfo.IconFrameId = target.GetIconFrame();
|
|
roleBaseInfo.Power = (int)target.RoleBase.Power;
|
|
}
|
|
//处理系统解锁
|
|
public static void OnVipLevelUpUnlockSystem(PlayerOnGame player)
|
|
{
|
|
|
|
}
|
|
|
|
//获取战斗版本号
|
|
public static int GetPlayerBattleVersion(PlayerOnGame player)
|
|
{
|
|
return player.battleVersion;
|
|
}
|
|
|
|
|
|
public static void DealCSRenameReq(PlayerOnGame player, ref CSRenameReq req)
|
|
{
|
|
//校验Name
|
|
SSNameQueryReq ssreq = new SSNameQueryReq();
|
|
ssreq.AccountID = player.AccountInfo.AccountID;
|
|
ssreq.StrName.SetString(req.NewName.GetString());
|
|
ssreq.HashName.SetString(HashHelper.SHA1String(ssreq.StrName.GetString()));
|
|
ssreq.CreateIfNotExist = true;
|
|
ssreq.PlayerSessionID = player.SessionID;
|
|
ssreq.RealmId = player.RealmID;
|
|
//客户端过来的请求
|
|
GameServerUtils.GetPacketSender().SendToNameServer<SSNameQueryReq>((int)SSMsgID.NameQueryReq, ref ssreq, 0);
|
|
|
|
|
|
}
|
|
|
|
public static void DealSSRenameReq(PlayerOnGame player, ref SSGmChangeRoleNameReq req)
|
|
{
|
|
CSRenameRes res = new CSRenameRes();
|
|
res.NewName = req.Name;
|
|
|
|
|
|
player.RoleData.OtherData.NewNick = req.Name;
|
|
player.RoleBase.Nick = req.Name;
|
|
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.DealSSRenameReq player uid {0} rename success newname {1}", player.UserID, req.Name);
|
|
|
|
SSGmChangeRoleNameRes ress = new SSGmChangeRoleNameRes();
|
|
ress.Ret = 0;
|
|
ress.Id = req.Id;
|
|
ress.Name = req.Name;
|
|
ress.Uid = req.Uid;
|
|
GameServerUtils.GetPacketSender().SendToServerByID(GameServerUtils.GetWorldServerID(), (int)SSGameMsgID.GmChangeRoleNameRes, ref ress, player.UserID);
|
|
}
|
|
}
|
|
}
|
|
|