少年修仙传客户端代码仓库
client_Wu Xijin
2018-12-28 d9793592ffb994cbd56655b2f927c48af27ec435
3335 更新封包查看工具
3个文件已修改
101 ■■■■■ 已修改文件
Core/GameEngine/DataToCtl/PackageRegedit.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/NetPkgCtl.cs 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/Socket/ClientSocket.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/GameEngine/DataToCtl/PackageRegedit.cs
@@ -498,14 +498,14 @@
            packageInstance.socketType = socketType;
#if UNITY_EDITOR
            NetPkgCtl.AddNetPkg(socketType, vStr, NetPkgType.Server, packageInstance.ToString(), FieldPrint.PrintFields(packageInstance), FieldPrint.PrintFieldsExpand(packageInstance, true));
            NetPkgCtl.RecordPackage(socketType, vStr, NetPackagetType.Server, packageInstance.ToString(), FieldPrint.PrintFields(packageInstance), FieldPrint.PrintFieldsExpand(packageInstance, true));
#endif
            return packageInstance;
        }
        else
        {
#if UNITY_EDITOR
            NetPkgCtl.AddNetPkg(socketType, vStr, NetPkgType.Server, string.Empty, string.Empty, null);
            NetPkgCtl.RecordPackage(socketType, vStr, NetPackagetType.Server, string.Empty, string.Empty, null);
#endif
        }
        return null;
Core/NetworkPackage/NetPkgCtl.cs
@@ -7,97 +7,72 @@
public class NetPkgCtl
{
    private static List<NetPkg> _typeLst = null; //发送接收封包存储列表
    private static List<NetPkg> _tempNetPkgLst = null;//暂停时缓存的封包列表
    public static bool IsStopRec = false;
    public static bool getNewPackage = false;
    private static List<NetPackage> packages = new List<NetPackage>(); //发送接收封包存储列表
    private static List<NetPackage> tempPackages = new List<NetPackage>();//暂停时缓存的封包列表
    public static bool stopRecieve = false;
    public static int fieldMaxLength = 100;
    /// <summary>
    /// 添加封包到封包查看工具
    /// </summary>
    /// <param name="gameNetPkg"></param>
    /// <param name="typeLst"></param>
    public static void AddNetPkg( GameNetSystem.SocketType socketType, string pkgByte, NetPkgType netPkgType, string _packName, string _fields, List<string> _fieldDetails)
    public static void RecordPackage(GameNetSystem.SocketType socketType, string bytes, NetPackagetType packType, string packageName, string fields, List<string> fieldDetails)
    {
#if UNITY_EDITOR
        if (_typeLst == null)
        var package = new NetPackage();
        package.socketType = socketType;
        package.time = DateTime.Now.ToString("HH:mm:ss:fff");
        package.type = packType;
        if (string.IsNullOrEmpty(packageName))
        {
            _typeLst = new List<NetPkg>();
        }
        if (_tempNetPkgLst == null)
        {
            _tempNetPkgLst = new List<NetPkg>();
        }
        getNewPackage = true;
        NetPkg netPkg = new NetPkg();
        netPkg.socketType = socketType;
        netPkg.SendOrGetTime = DateTime.Now.ToString("HH:mm:ss:fff");
        netPkg.NetPkgTp = netPkgType;
        string netPkgStr = pkgByte.Replace(",", " ");
        netPkg.GameNetPkgStr = netPkgStr;
        var gameNetPkgName = _packName;
        string[] byteStr = netPkgStr.Split(' ');
        if (string.IsNullOrEmpty(gameNetPkgName))
        {
            package.content = bytes.Replace(",", " ");
            var byteStr = package.content.Split(' ');
            if (byteStr.Length > 1)
            {
                StringBuilder _stringBuilder = new StringBuilder();
                _stringBuilder.Append("H");
                _stringBuilder.Append(byteStr[0]);
                _stringBuilder.Append(byteStr[1]);
                _stringBuilder.Append("(未注册)");
                netPkg.GameNetName = _stringBuilder.ToString();
                _stringBuilder = null;
                package.name = StringUtility.Contact("H", byteStr[0], byteStr[1], "(未注册)");
            }
        }
        else
        {
            netPkg.GameNetName = gameNetPkgName;
            netPkg.fields = _fields;
            netPkg.fieldDetails = _fieldDetails;
            package.name = packageName;
            package.fields = fields.Length > fieldMaxLength ? fields.Substring(0, fieldMaxLength) : fields;
            package.fieldDetails = fieldDetails;
        }
        if (!IsStopRec)
        if (!stopRecieve)
        {
            _typeLst.Add(netPkg);
            packages.Add(package);
        }
        else
        {
            _tempNetPkgLst.Add(netPkg);
            tempPackages.Add(package);
        }
#endif
    }
    public static List<NetPkg> GetNetPkg()
    public static List<NetPackage> GetPackages()
    {
        return _typeLst;
        return packages;
    }
    public static List<NetPkg> GetTempNetPkg()
    public static List<NetPackage> GetTempPackages()
    {
        return _tempNetPkgLst;
        return tempPackages;
    }
    public static void WriteAllNetLog(bool @details)
    {
        if (_typeLst != null)
        if (packages != null)
        {
            var count = 0;
            var lines = new List<string>();
            for (int i = _typeLst.Count - 1; i >= 0; i--)
            for (int i = packages.Count - 1; i >= 0; i--)
            {
                if (count > 20000)
                {
                    break;
                }
                var package = _typeLst[i];
                var package = packages[i];
                var line = string.Empty;
                line = StringUtility.Contact(package.NetPkgTp == NetPkgType.Client ? "【发送】\t" : "【接收】\t", package.SendOrGetTime, ":", package.GameNetName, @details ? "\r\n" : "-->" + package.fields);
                line = StringUtility.Contact(package.type == NetPackagetType.Client ? "【发送】\t" : "【接收】\t", package.time, ":", package.name, @details ? "\r\n" : "-->" + package.fields);
                if (@details && package.fieldDetails != null)
                {
@@ -116,19 +91,19 @@
    }
}
public class NetPkg
public class NetPackage
{
    public GameNetSystem.SocketType socketType;
    public string SendOrGetTime;
    public string GameNetPkgStr;
    public string GameNetName;
    public NetPkgType NetPkgTp;
    public bool show = false;
    public string time;
    public string content;
    public string name;
    public NetPackagetType type;
    public string fields;
    public List<string> fieldDetails;
}
public enum NetPkgType
public enum NetPackagetType
{
    Client = 1,
    Server = 2,
Core/NetworkPackage/Socket/ClientSocket.cs
@@ -332,7 +332,7 @@
        }
        protocol.CombineDatas(encoder);
#if UNITY_EDITOR
        NetPkgCtl.AddNetPkg(socketType, protocol.vInfoCont, NetPkgType.Client, protocol.ToString(), FieldPrint.PrintFields(protocol), FieldPrint.PrintFieldsExpand(protocol, true));
        NetPkgCtl.RecordPackage(socketType, protocol.vInfoCont, NetPackagetType.Client, protocol.ToString(), FieldPrint.PrintFields(protocol), FieldPrint.PrintFieldsExpand(protocol, true));
#endif
        sendBytesTotal += protocol.combineBytes.Length;
        SendBytes(protocol.combineBytes);