private void ProcessData(Connection connection) { if (connection.length < sizeof(Int32)) { // Debug.Log("获取不到信息大小重新接包解析:" + connection.length.ToString()); return; } Array.Copy(connection.readBuff, connection.lenBytes, sizeof(Int32)); connection.msgLength = BitConverter.ToInt32(connection.lenBytes, 0); if (connection.length < connection.msgLength + sizeof(Int32)) { //Debug.Log("信息大小不匹配重新接包解析:" + connection.msgLength.ToString()); return; } ProtocolBase message = new ByteProtocol(); message.InitMessage(connection.ReceiveBytes); ParseMessage(connection, message); int count = connection.length - connection.msgLength - sizeof(Int32); Array.Copy(connection.readBuff, sizeof(Int32) + connection.msgLength, connection.readBuff, 0, count); connection.length = count; if (connection.length > 0) { ProcessData(connection); } }
protected void HandlerData(NetworkConnection conn) { if (conn.recvLen < sizeof(Int32)) { Debug.Log("Can not get message size" + conn.recvLen.ToString()); return; } Array.Copy(conn.readBuff, conn.lenBytes, sizeof(Int32)); conn.msgLen = BitConverter.ToInt32(conn.lenBytes, 0); if (conn.recvLen < conn.msgLen + sizeof(Int32)) { Debug.Log("Package size error " + conn.recvLen.ToString() + ":" + (conn.msgLen + 4).ToString()); return; } INetworkProtocol msg = new ByteProtocol(); msg.Init(conn.ReceiveBytes); MessageQue.Enqueue(msg); int count = conn.recvLen - conn.msgLen - sizeof(Int32); Array.Copy(conn.readBuff, sizeof(Int32) + conn.msgLen, conn.readBuff, 0, count); conn.recvLen = count; if (conn.recvLen > 0) { HandlerData(conn); } }
public void Serialize(ByteProtocol protocol) { protocol.push((int)weaponId); protocol.push((int)weaponType); protocol.push((int)defalutSkillId); fixedParams.Serialize(protocol); }
/// <summary> /// 解析字节数据 /// </summary> /// <param name="connection">要解析数据的连接</param> private void ProcessData(Connection connection) { if (connection.length < sizeof(Int32)) { Debug.Log("获取不到信息大小重新接包解析:" + connection.length.ToString()); return; } Array.Copy(connection.readBuff, connection.lenBytes, sizeof(Int32)); connection.msgLength = BitConverter.ToInt32(connection.lenBytes, 0); if (connection.length < connection.msgLength + sizeof(Int32)) { Debug.Log("信息大小不匹配重新接包解析:" + connection.length + ":" + (connection.msgLength + 4).ToString()); return; } //ServerDebug.Log("接收信息大小:" + connection.msgLength.ToString(), 1); // string str = Encoding.UTF8.GetString(connection.readBuff, sizeof(Int32), connection.length); ProtocolBase message = new ByteProtocol(); // Debug.Log(DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond+"接收消息大小:" + connection.msgLength); message.InitMessage(connection.ReceiveBytes); MessageList.Enqueue(message); // Debug.Log("ProcessDataOver"); //Send(connection, str); int count = connection.length - connection.msgLength - sizeof(Int32); Array.Copy(connection.readBuff, sizeof(Int32) + connection.msgLength, connection.readBuff, 0, count); connection.length = count; if (connection.length > 0) { ProcessData(connection); } }
/// <summary> /// 发送本地客户端帧信息 /// </summary> protected void SendClientFrame(object sender, ElapsedEventArgs e) { if (client.ServerCon.clientId < 0) { return; } ProtocolBase protocol = new ByteProtocol(); protocol.push((byte)MessageType.Frame); protocol.push((byte)client.ServerCon.clientId); foreach (var bt in sendKey.GetBytes()) { protocol.push(bt); } protocol.push((byte)joySticks.Count); // Debug.LogError("len"+joySticks.Count); foreach (var joy in joySticks) { // Debug.LogError("key"+joy.Key); protocol.push((byte)joy.Key); protocol.push(joy.Value.direction); } client.Send(protocol.GetByteStream()); }
public virtual void Deserialize(ByteProtocol protocol) { trigger = (SkillTrigger)protocol.getInt32(); type = (SkillNodeType)protocol.getInt32(); // UnityEngine.Debug.LogError("get type" +(Int32)type); var len = protocol.getInt32(); // UnityEngine.Debug.LogError("get nextNode Count" +len); nextNodes.Clear(); for (int i = 0; i < len; i++) { var node = new SkillNode(); node.Deserialize(protocol); nextNodes.Add(node); } len = protocol.getInt32(); boolParams.Clear(); for (int i = 0; i < len; i++) { boolParams.Add(protocol.getBoolean()); } len = protocol.getInt32(); fixedParams.Clear(); for (int i = 0; i < len; i++) { fixedParams.Add(protocol.getRatio()); } }
public void Deserialize(ByteProtocol protocol) { weaponId = (WeaponId)protocol.getInt32(); weaponType = (WeaponType)protocol.getInt32(); defalutSkillId = (SkillId)protocol.getInt32(); fixedParams.Deserialize(protocol); }
protected void SendStepAll(object sender, ElapsedEventArgs e) { if (ClientPool.ActiveCount <= 0) { if (FrameList.Count > 0) { ServerLog.LogServer("所有客户端退出游戏 战斗结束!!!", 1); FrameList.Clear(); } return; } if (FrameList.Count == 0) { ServerLog.LogServer("玩家进入服务器 战斗开始!!!", 1); } ServerLog.LogServer("0[" + FrameList.Count + "]", 1); byte[][] temp = StepMessage; int length = temp.Length; ProtocolBase protocol = new ByteProtocol(); protocol.push((byte)MessageType.Frame); protocol.push((byte)length); //ServerLog.LogServer("获取[" + FrameList.Count + "]", 1); for (int i = 0; i < length; i++) { protocol.push(temp[i] != null); protocol.push(temp[i]); } if (FrameList.Count == 0) { protocol.push((byte)MessageType.RandomSeed); Random rand = new Random(); protocol.push(rand.Next(10000)); } protocol.push((byte)MessageType.end); ServerLog.LogServer("生成帧信息[" + length + "]", 1); byte[] temp2 = protocol.GetByteStream(); FrameList.Add(temp2); ClientPool.Foreach((con) => { SendToClient(con.clientId, temp2); if (!con.ActiveCheck()) { ServerLog.LogClient("客户端断线 中止连接:" + ClientPool[con.clientId].socket.LocalEndPoint + "ClientID:" + con.clientId, 0, con.clientId); con.socket.Close(); ClientPool.Recover(con.clientId); } }); ServerLog.LogServer("帧同步[" + FrameList.Count + "]", 2); //StepMessage = new byte[ClientPool.Count][]; //for (int i = 0; i < StepMessage.Length; i++) //{ // StepMessage[i] = new byte[framSize]; //} }
public override void Serialize(ByteProtocol protocol) { protocol.push(Weaponname); protocol.push(WeaponInfo); protocol.push(ObjToId(uiIcon)); protocol.push(ObjToId(animation)); protocol.push(ObjToId(ItemPrefab)); }
public override void Deserialize(ByteProtocol protocol) { Weaponname = protocol.getString(); WeaponInfo = protocol.getString(); uiIcon = IdToObj <Sprite>(protocol.getInt32()); idleAnim = IdToObj <AnimationClip>(protocol.getInt32()); ItemPrefab = IdToObj <GameObject>(protocol.getInt32()); }
protected void SendPingToClient(byte clientId) { ProtocolBase protocol = new ByteProtocol(); protocol.push((byte)MessageType.Ping); protocol.push((byte)MessageType.end); this.SendToClient(clientId, protocol.GetByteStream()); }
public override void Deserialize(ByteProtocol protocol) { skillId = (SkillId)protocol.getInt32(); // UnityEngine.Debug.LogError("get skillId" +(Int32)skillId); coolDownTime = protocol.getRatio(); animTime = protocol.getRatio(); key = (KeyNum)protocol.getByte(); base.Deserialize(protocol); }
public override void Serialize(ByteProtocol protocol) { protocol.push((Int32)skillId); // UnityEngine.Debug.LogError("push skillId" +(Int32)skillId); protocol.push(coolDownTime); protocol.push(animTime); protocol.push((byte)key); base.Serialize(protocol); }
public override void Deserialize(ByteProtocol protocol) { skillname = protocol.getString(); skillInfo = protocol.getString(); uiIcon = IdToObj <Sprite>(protocol.getInt32()); useOverAnim = IdToObj <AnimationClip>(protocol.getInt32()); useOverAnimSspeed = protocol.getRatio().ToFloat(); ItemPrefab = IdToObj <GameObject>(protocol.getInt32()); }
public override void Serialize(ByteProtocol protocol) { protocol.push(skillname); protocol.push(skillInfo); protocol.push(ObjToId(uiIcon)); protocol.push(ObjToId(useOverAnim)); protocol.push(useOverAnimSspeed.ToFixed()); protocol.push(ObjToId(ItemPrefab)); }
protected void SendIninInfo(byte clientId) { ProtocolBase protocol = new ByteProtocol(); protocol.push((byte)MessageType.Init); protocol.push(clientId); protocol.push((byte)MessageType.end); SendToClient(clientId, protocol.GetByteStream()); ServerLog.LogClient("客户端连接成功:" + ClientPool[clientId].socket.LocalEndPoint + "ClientID:" + clientId, 0, clientId); }
public virtual void Serialize(ByteProtocol protocol) { protocol.push((Int32)intType); protocol.push(childNodes.Count); foreach (var node in childNodes) { node.Serialize(protocol); } }
public virtual void Deserialize(ByteProtocol protocol) { intType = protocol.getInt32(); var len = protocol.getInt32(); childNodes.Clear(); for (int i = 0; i < len; i++) { var node = new AINode(); node.Deserialize(protocol); childNodes.Add(node); } }
public void On(JoinCompleteEvent e) { var bp = new ByteProtocol<Player>(this._byteChannel); var cc = new ChatChannel(new CompressionChannel<Player>(bp.RegisterProtocol("EE Chat"))); ThreadPool.QueueUserWorkItem(o => { while (true) { cc.Send(Console.ReadLine()); } }); cc.Receive += this.Cc_Receive; }
public void On(JoinCompleteEvent e) { var bp = new ByteProtocol <Player>(this._byteChannel); var cc = new ChatChannel(new CompressionChannel <Player>(bp.RegisterProtocol("EE Chat"))); ThreadPool.QueueUserWorkItem(o => { while (true) { cc.Send(Console.ReadLine()); } }); cc.Receive += this.Cc_Receive; }
private void SendFrame(object sender, ElapsedEventArgs args) { if (Gamedata.Instance.ClinetId < 0) { return; } INetworkProtocol protocol = new ByteProtocol(); protocol.Push((byte)BattleNetworkHandler.MessageType.Frame); protocol.Push((byte)Gamedata.Instance.ClinetId); protocol.Push(movement.Direction); handler.SendMessage(protocol.OutputBytesStream()); }
public void On(JoinCompleteEvent e) { this._byteChannel = new ByteChannel<Player>(new CoinChannel()); var bp = new ByteProtocol<Player>(this._byteChannel); var up = new UserProtocol<Player>(bp.RegisterProtocol("ByetUserStreams.Demo"), p => (uint)p.UserId); var stream = new ByteStream(up.GetUserChannel(this.Players.OwnPlayer, this.Players.OwnPlayer)); { var writer = new StreamWriter(stream) {AutoFlush = true}; writer.Write("Hello world!\n"); var reader = new StreamReader(stream); ThreadPool.QueueUserWorkItem(o => { while (true) { Console.Write((char) reader.Read()); } }); } }
public void On(JoinCompleteEvent e) { this._byteChannel = new ByteChannel <Player>(new CoinChannel()); var bp = new ByteProtocol <Player>(this._byteChannel); var up = new UserProtocol <Player>(bp.RegisterProtocol("ByetUserStreams.Demo"), p => (uint)p.UserId); var stream = new ByteStream(up.GetUserChannel(this.Players.OwnPlayer, this.Players.OwnPlayer)); { var writer = new StreamWriter(stream) { AutoFlush = true }; writer.Write("Hello world!\n"); var reader = new StreamReader(stream); ThreadPool.QueueUserWorkItem(o => { while (true) { Console.Write((char)reader.Read()); } }); } }
public virtual void Serialize(ByteProtocol protocol) { protocol.push((Int32)trigger); protocol.push((Int32)type); // UnityEngine.Debug.LogError("push type" +(Int32)type); protocol.push(nextNodes.Count); // UnityEngine.Debug.LogError("nextNode Count" +nextNodes.Count); foreach (var node in nextNodes) { node.Serialize(protocol); } protocol.push(boolParams.Count); foreach (var b in boolParams) { protocol.push(b); } protocol.push(fixedParams.Count); foreach (var b in fixedParams) { protocol.push(b); } }
public override void Serialize(ByteProtocol protocol) { protocol.push(name); base.Serialize(protocol); }
public override void Deserialize(ByteProtocol protocol) { name = protocol.getString(); base.Deserialize(protocol); }