少年修仙传客户端代码仓库
client_linchunjie
2018-10-18 f93c57bfd57f97e78c3a00a29f302f5e8c83cdee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Text;
using System.IO;
 
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;
 
    /// <summary>
    /// 添加封包到封包查看工具
    /// </summary>
    /// <param name="gameNetPkg"></param>
    /// <param name="typeLst"></param>
    public static void AddNetPkg(string pkgByte, NetPkgType netPkgType, string _packName, string _fields, List<string> _fieldDetails)
    {
#if UNITY_EDITOR
        if (_typeLst == null)
        {
            _typeLst = new List<NetPkg>();
        }
        if (_tempNetPkgLst == null)
        {
            _tempNetPkgLst = new List<NetPkg>();
        }
 
        getNewPackage = true;
 
        NetPkg netPkg = new NetPkg();
        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))
        {
            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;
            }
        }
        else
        {
            netPkg.GameNetName = gameNetPkgName;
            netPkg.fields = _fields;
            netPkg.fieldDetails = _fieldDetails;
        }
 
        if (!IsStopRec)
        {
            _typeLst.Add(netPkg);
        }
        else
        {
            _tempNetPkgLst.Add(netPkg);
        }
#endif
    }
 
    public static List<NetPkg> GetNetPkg()
    {
        return _typeLst;
    }
 
    public static List<NetPkg> GetTempNetPkg()
    {
        return _tempNetPkgLst;
    }
 
    public static void WriteAllNetLog(bool @details)
    {
        if (_typeLst != null)
        {
            var count = 0;
            var lines = new List<string>();
            for (int i = _typeLst.Count - 1; i >= 0; i--)
            {
                if (count > 20000)
                {
                    break;
                }
 
                var package = _typeLst[i];
                var line = string.Empty;
                line = StringUtility.Contact(package.NetPkgTp == NetPkgType.Client ? "【发送】\t" : "【接收】\t", package.SendOrGetTime, ":", package.GameNetName, @details ? "\r\n" : "-->" + package.fields);
 
                if (@details && package.fieldDetails != null)
                {
                    for (int j = 0; j < package.fieldDetails.Count; j++)
                    {
                        line = StringUtility.Contact(line, "\t\t\t", package.fieldDetails[j], "\r\n");
                    }
                }
 
                lines.Add(line);
                count++;
            }
 
            File.WriteAllLines(Application.dataPath + "/PackageLogs_" + (@details ? "details" : "abstract") + "_" + DateTime.Now.ToString("HH_mm_ss") + ".txt", lines.ToArray());
        }
    }
}
 
public class NetPkg
{
    public string SendOrGetTime;
    public string GameNetPkgStr;
    public string GameNetName;
    public NetPkgType NetPkgTp;
    public string fields;
    public List<string> fieldDetails;
 
}
 
public enum NetPkgType
{
    Client = 1,
    Server = 2,
    All = 3,
}