/// <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()); }
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]; //} }
protected void SendPingToClient(byte clientId) { ProtocolBase protocol = new ByteProtocol(); protocol.push((byte)MessageType.Ping); protocol.push((byte)MessageType.end); this.SendToClient(clientId, protocol.GetByteStream()); }
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); }