| | |
| | |
|
| | | 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)
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | 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,
|