private void CallRpcMethod(MessageTarget msg, INetworkChannel channel) { var arguments = msg.Arguments; if (msg.Method.ReturnType == typeof(void) && !msg.Await) { msg.Method.Invoke(_services[msg.Type], arguments); return; } using (var memory = new MemoryStream()) { if (msg.Method.ReturnType != typeof(void)) { var methodResult = msg.Method.Invoke(_services[msg.Type], arguments); _messageBuilder.WriteResult(memory, msg, methodResult); channel.Send(memory); } else { msg.Method.Invoke(_services[msg.Type], arguments); _messageBuilder.WriteVoidResult(memory, msg); channel.Send(memory); } } }
public bool SendHeartBeat() { if (_networkChannel.Connected) { _networkChannel.Send(_heartPacket.BuildHeartPacket()); return(true); } return(false); }
/// <summary> /// 攻击 /// </summary> public void Attack(PlayerComponent player1, PlayerComponent player2) { player2.hPComponent.AddAttackHp(200); float curHp = player2.hPComponent.GetCurHp(); channel01.Send <CSHurtInfo>(new CSHurtInfo() { AttackerId = player1.playerUnitData.PlayerId, HurterId = player2.playerUnitData.PlayerId, HurterCurHp = curHp }); }
internal void Send(QueuedMessage send) { if (clients.Count == 0) { return; } Client[] clientsTo = send.sendTo; if (clientsTo == null || clientsTo.Count() == 0) { clientsTo = new Client[] { clients[0] } } ; send.sendTo = clientsTo; string payload = GetPayload(send); foreach (Client client in clientsTo) { if (send.SendReliable) { NetworkChannel.SetReliable(); } else { NetworkChannel.SetUnreliable(); } NetworkChannel.Send(client, payload); } }
void OnConnected(object sender, EventArgs e) { var temp = e as UnityGameFramework.Runtime.NetworkConnectedEventArgs; if (temp.NetworkChannel.Name.Equals("TC")) { Debug.Log("-----------连接服务器成功-----------:"); INetworkChannel channel = GameEntry.Network.GetNetworkChannel("TC"); //channel.Send(new CSMessageTest()); Debug.Log("-----------开始发送登录请求-----------"); channel.Send(new C2R_Login() { Account = "mdzz", Password = "******" }); } else if (temp.NetworkChannel.Name.Equals("CG_TC")) { Debug.Log("-----------连接服务器再次成功-----------:"); INetworkChannel channel = GameEntry.Network.GetNetworkChannel("CG_TC"); R2C_Login r2c_Login = temp.UserData as R2C_Login; //channel.Send(new CSMessageTest()); channel.Send(new C2G_LoginGate() { Key = r2c_Login == null ? 0 : r2c_Login.Key }); } }
/// <summary> /// 创建角色事件 /// </summary> void CreatePlayerEvent(SCCreatePlayer info) { UnitData heroData = new UnitData(); heroData.HPValue = 100; heroData.IsAddSpeed = false; heroData.IsAttack = false; heroData.JiFen = 0; heroData.PlayerId = info.PlayerId; heroData.Postion = new Vector3(info.x, info.y, info.z); if (!playerDic.ContainsKey(info.PlayerId)) { var player = CreatePlayer(heroData); if (info.PlayerId == channel01.LocalPort) { CreateHero(player); } else { PlayerComponent hero = GetHeroPlayer(); channel01.Send <SCCreatePlayer>(new SCCreatePlayer() { PlayerId = hero.playerUnitData.PlayerId, x = hero.transform.position.x, y = hero.transform.position.y, z = hero.transform.position.z, }); } } }
public bool SendHeartBeat() { if (m_NetworkChannel != null) { m_NetworkChannel.Send(CSHeartBeat.Create()); } return(false); }
public void OnChannelReceived(INetworkChannel channel, object obj) { byte[] data = (byte[])obj; Log.Info("收到消息" + data.Length + "字节"); channel.Send(new byte[4] { 1, 0, 0, 0 }); }
public void OnConnected(INetworkChannel channel, bool isSuccess) { Log.Info(channel.Name + "连接成功"); channel.Send(new byte[4] { 1, 0, 0, 0 }); }
/// <summary> /// 发送心跳协议包。 /// </summary> public override bool SendHeartBeat(INetworkChannel networkChannel) { CSHeartBeat packet = new CSHeartBeat(); networkChannel.Send(packet); return(true); }
/// <summary> /// 发送心跳消息包。 /// </summary> /// <returns>是否发送心跳消息包成功。</returns> public bool SendHeartBeat() { CSHeartBeat packet = new CSHeartBeat(); m_NetworkChannel.Send(packet); return(true); }
private void CallStreamingSubUnsub(MessageTarget msg, INetworkChannel channel) { using (var memory = new MemoryStream()) { var streamer = _networkAdapters[msg.ShortTypeName]; var methodResult = msg.Method.Invoke(streamer, msg.Arguments.Concat(new [] { channel }).ToArray()); _messageBuilder.WriteResult(memory, msg, methodResult); channel.Send(memory); } }
void Update() { channel01.Send <CSPosition>(new CSPosition() { PlayerId = playerComponent.playerUnitData.PlayerId, X = delatPosition.x, Y = delatPosition.y, Z = delatPosition.z, Animation = curAnimation }); //攻击响应一次 if (curAnimation == 3) { curAnimation = 1; } }
// Use this for initialization void Start() { SyncPlayerData.Instance.CreatePlayerBack += CreatePlayerEvent; playerDic = new Dictionary <int, PlayerComponent>(); channel01 = GameEntry.Network.GetNetworkChannel("Battle"); channel01.Send <SCCreatePlayer>(new SCCreatePlayer() { PlayerId = channel01.LocalPort, x = randomTansformList[0].position.x, y = randomTansformList[0].position.y, z = randomTansformList[0].position.z, }); //channel01.Send<SCCreatePlayer>(new SCCreatePlayer() { PlayerId = channel01.LocalPort - 1, PositionId = 2 }); //channel01.Send<SCCreatePlayer>(new SCCreatePlayer() { PlayerId = channel01.LocalPort - 2, PositionId = 3 }); }
void OnClickSendBtn() { //测试案例而已,不专注性能 if (input == null) { return; } if (!string.IsNullOrEmpty(input.text)) { INetworkChannel channel = GameEntry.Network.GetNetworkChannel("CG_TC"); string str = input.text; channel.Send(new GFTestMsg() { Message = input.text }); } }
public void Send(INetworkChannel _channel) { if (null == _channel) { return; } var bodyLength = writerStream.Length - 4; //标记的tag + 及默认Size的长度 binaryWrite.Seek(2, SeekOrigin.Begin); // 将写入位置放在2的位置 binaryWrite.Write(((short)bodyLength).SwapInt16()); // 写入内容长度-实际内容长度,不包含包头 var bytes = writerStream.GetBuffer(); var sendBytes = Arr.Slice(bytes, 0, (int)writerStream.Length); _channel.Send(sendBytes); // 输出打印 if (true == IsSendLog) { LogCache.Add("message length = " + sendBytes.Length); this.Debug(LogCache.Release()); } }
/// <summary> /// 发送心跳包 /// </summary> /// <returns></returns> public bool SendHeartBeat() { m_NetworkChannel.Send <CSHeartBeat>(ReferencePool.Acquire <CSHeartBeat>()); return(true); }
public static void SendPackage(IMessage content) { Channel.Send(content.BuildPacket()); }