王刚 3 سال پیش
والد
کامیت
fc9cab432f

+ 6 - 6
CSserver/BattleRoom/Program.cs

@@ -42,7 +42,7 @@ namespace BattleRoom
             {
                 Debug.WriteLine(ee.Message);
             }
-            RoomManager.Instance.ServerPeer = new ServerPeer(client);                    // 给管理器的服务器间socket赋值
+            RoomManager.Instance.ServerPeer = new ServerPeer(client);                     // 给管理器的服务器间socket赋值
             RoomManager.Instance.ServerPeer.OnSocketDisconnected += () => { InitServerPeer(); };
         }
 
@@ -58,14 +58,14 @@ namespace BattleRoom
         async static Task WatchConnecting()
         {
             IPAddress ip = IPAddress.Any;
-            IPEndPoint ipe = new IPEndPoint(ip, port);                                 //将IP地址和端口号绑定到网络节点point上  
+            IPEndPoint ipe = new IPEndPoint(ip, port);                                  //将IP地址和端口号绑定到网络节点point上  
 
             //定义一个套接字用于监听客户端发来的消息,包含三个参数(IP4寻址协议,流式连接,Tcp协议)  
             Socket SocketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-            SocketWatch.Bind(ipe);                                                     // 监听绑定的网络节点           
-            SocketWatch.Listen(20);                                                    // 将套接字的监听队列长度限制为20    
+            SocketWatch.Bind(ipe);                                                      // 监听绑定的网络节点           
+            SocketWatch.Listen(20);                                                     // 将套接字的监听队列长度限制为20    
 
-            while (true)                                                               // 持续不断监听客户端发来的请求     
+            while (true)                                                                // 持续不断监听客户端发来的请求     
             {
                 Socket connection;
                 try
@@ -78,7 +78,7 @@ namespace BattleRoom
                     break;
                 }
 
-                RoomManager.Instance.OnNewPeerConnected(new Peer(connection));                 // 有新客户端连入
+                RoomManager.Instance.OnNewPeerConnected(new Peer(connection));           // 有新客户端连入
             }
             SocketWatch.Close();                                                         // 结束监听socket
         }

+ 12 - 10
CSserver/PBReferens/DataBuff.cs

@@ -21,10 +21,11 @@ namespace ProtoDataBuff
     [Serializable]
     public struct sSocketData
     {
-        public byte[] _data;
+        public Int32 PackLen;
+        public UInt32 TS;
         public eProtocalCommand _protocallType;
-        public int _buffLength;
-        public int _dataLength;
+        public byte[] _data;
+     
         /// <summary>
         /// 网络结构转数据
         /// </summary>
@@ -32,17 +33,18 @@ namespace ProtoDataBuff
         /// <returns></returns>
         public byte[] ToBytes()
         {
-            byte[] _tmpBuff = new byte[_buffLength];
-            byte[] _tmpBuffLength = BitConverter.GetBytes(_buffLength);
+            byte[] _tmpBuff = new byte[PackLen];
+            byte[] _tmpBuffLength = BitConverter.GetBytes(PackLen);
             byte[] _tmpDataType = BitConverter.GetBytes((UInt16)_protocallType);
 
             Array.Copy(_tmpBuffLength, 0, _tmpBuff, 0, Constants.HEAD_DATA_LEN);//缓存总长度
             Array.Copy(_tmpDataType, 0, _tmpBuff, Constants.HEAD_DATA_LEN, Constants.HEAD_TYPE_LEN);//协议类型
-            Array.Copy(_data, 0, _tmpBuff, Constants.HEAD_LEN, _dataLength);//协议数据
+            Array.Copy(_data, 0, _tmpBuff, Constants.HEAD_LEN, DataLen());//协议数据
 
             return _tmpBuff;
         }
 
+        public int DataLen() => _data.Length;
         /// <summary>
         /// 数据转网络结构
         /// </summary>
@@ -52,8 +54,8 @@ namespace ProtoDataBuff
         public static sSocketData FromBytes(eProtocalCommand _protocalType, byte[] _data)
         {
             sSocketData tmpSocketData = new();
-            tmpSocketData._buffLength = Constants.HEAD_LEN + _data.Length;
-            tmpSocketData._dataLength = _data.Length;
+            tmpSocketData.PackLen = Constants.HEAD_LEN + _data.Length;
+          //  tmpSocketData._dataLength = _data.Length;
             tmpSocketData._protocallType = _protocalType;
             tmpSocketData._data = _data;
             return tmpSocketData;
@@ -148,8 +150,8 @@ namespace ProtoDataBuff
 
             if (_buffLength > 0 && _curBuffPosition >= _buffLength)
             {
-                _tmpSocketData._buffLength = _buffLength;
-                _tmpSocketData._dataLength = _dataLength;
+                _tmpSocketData.PackLen = _buffLength;
+                //_tmpSocketData._dataLength = _dataLength;
                 _tmpSocketData._protocallType = (eProtocalCommand)_protocalType;
                 _tmpSocketData._data = new byte[_dataLength];
                 Array.Copy(_buff, Constants.HEAD_LEN, _tmpSocketData._data, 0, _dataLength);

+ 5 - 5
CSserver/clientTest/Program.cs

@@ -167,13 +167,13 @@ namespace clientTest.bossfight
         /// <returns></returns>
         static private byte[] SocketDataToBytes(sSocketData tmpSocketData)
         {
-            byte[] _tmpBuff = new byte[tmpSocketData._buffLength];
-            byte[] _tmpBuffLength = BitConverter.GetBytes(tmpSocketData._buffLength);
+            byte[] _tmpBuff = new byte[tmpSocketData.PackLen];
+            byte[] _tmpBuffLength = BitConverter.GetBytes(tmpSocketData.PackLen);
             byte[] _tmpDataLenght = BitConverter.GetBytes((UInt16)tmpSocketData._protocallType);
 
             Array.Copy(_tmpBuffLength, 0, _tmpBuff, 0, Constants.HEAD_DATA_LEN);//缓存总长度
             Array.Copy(_tmpDataLenght, 0, _tmpBuff, Constants.HEAD_DATA_LEN, Constants.HEAD_TYPE_LEN);//协议类型
-            Array.Copy(tmpSocketData._data, 0, _tmpBuff, Constants.HEAD_LEN, tmpSocketData._dataLength);//协议数据
+            Array.Copy(tmpSocketData._data, 0, _tmpBuff, Constants.HEAD_LEN, tmpSocketData.DataLen);//协议数据
 
             return _tmpBuff;
         }
@@ -188,8 +188,8 @@ namespace clientTest.bossfight
         static private sSocketData BytesToSocketData(eProtocalCommand _protocalType, byte[] _data)
         {
             sSocketData tmpSocketData = new sSocketData();
-            tmpSocketData._buffLength = Constants.HEAD_LEN + _data.Length;
-            tmpSocketData._dataLength = _data.Length;
+            tmpSocketData.PackLen = Constants.HEAD_LEN + _data.Length;
+            // tmpSocketData._dataLength = _data.Length;
             tmpSocketData._protocallType = _protocalType;
             tmpSocketData._data = _data;
             return tmpSocketData;

+ 5 - 5
CSserver/clientTest/Program_Chat.cs

@@ -230,13 +230,13 @@ namespace clientTest.chat
         /// <returns></returns>
         static private byte[] SocketDataToBytes(sSocketData tmpSocketData)
         {
-            byte[] _tmpBuff = new byte[tmpSocketData._buffLength];
-            byte[] _tmpBuffLength = BitConverter.GetBytes(tmpSocketData._buffLength);
+            byte[] _tmpBuff = new byte[tmpSocketData.PackLen];
+            byte[] _tmpBuffLength = BitConverter.GetBytes(tmpSocketData.PackLen);
             byte[] _tmpDataLenght = BitConverter.GetBytes((UInt16)tmpSocketData._protocallType);
 
             Array.Copy(_tmpBuffLength, 0, _tmpBuff, 0, Constants.HEAD_DATA_LEN);//缓存总长度
             Array.Copy(_tmpDataLenght, 0, _tmpBuff, Constants.HEAD_DATA_LEN, Constants.HEAD_TYPE_LEN);//协议类型
-            Array.Copy(tmpSocketData._data, 0, _tmpBuff, Constants.HEAD_LEN, tmpSocketData._dataLength);//协议数据
+            Array.Copy(tmpSocketData._data, 0, _tmpBuff, Constants.HEAD_LEN, tmpSocketData.DataLen());//协议数据
 
             return _tmpBuff;
         }
@@ -251,8 +251,8 @@ namespace clientTest.chat
         static private sSocketData BytesToSocketData(eProtocalCommand _protocalType, byte[] _data)
         {
             sSocketData tmpSocketData = new sSocketData();
-            tmpSocketData._buffLength = Constants.HEAD_LEN + _data.Length;
-            tmpSocketData._dataLength = _data.Length;
+            tmpSocketData.PackLen = Constants.HEAD_LEN + _data.Length;
+          //  tmpSocketData._dataLength = _data.Length;
             tmpSocketData._protocallType = _protocalType;
             tmpSocketData._data = _data;
             return tmpSocketData;

+ 5 - 5
CSserver/clientTest/Program_MultiDup.cs

@@ -305,13 +305,13 @@ namespace clientTest.multiDup
         /// <returns></returns>
         static private byte[] SocketDataToBytes(sSocketData tmpSocketData)
         {
-            byte[] _tmpBuff = new byte[tmpSocketData._buffLength];
-            byte[] _tmpBuffLength = BitConverter.GetBytes(tmpSocketData._buffLength);
+            byte[] _tmpBuff = new byte[tmpSocketData.PackLen];
+            byte[] _tmpBuffLength = BitConverter.GetBytes(tmpSocketData.PackLen);
             byte[] _tmpDataLenght = BitConverter.GetBytes((UInt16)tmpSocketData._protocallType);
 
             Array.Copy(_tmpBuffLength, 0, _tmpBuff, 0, Constants.HEAD_DATA_LEN);//缓存总长度
             Array.Copy(_tmpDataLenght, 0, _tmpBuff, Constants.HEAD_DATA_LEN, Constants.HEAD_TYPE_LEN);//协议类型
-            Array.Copy(tmpSocketData._data, 0, _tmpBuff, Constants.HEAD_LEN, tmpSocketData._dataLength);//协议数据
+            Array.Copy(tmpSocketData._data, 0, _tmpBuff, Constants.HEAD_LEN, tmpSocketData.DataLen());//协议数据
 
             return _tmpBuff;
         }
@@ -326,8 +326,8 @@ namespace clientTest.multiDup
         static private sSocketData BytesToSocketData(eProtocalCommand _protocalType, byte[] _data)
         {
             sSocketData tmpSocketData = new sSocketData();
-            tmpSocketData._buffLength = Constants.HEAD_LEN + _data.Length;
-            tmpSocketData._dataLength = _data.Length;
+            tmpSocketData.PackLen = Constants.HEAD_LEN + _data.Length;
+            //tmpSocketData._dataLength = _data.Length;
             tmpSocketData._protocallType = _protocalType;
             tmpSocketData._data = _data;
             return tmpSocketData;