public void OnCardHandUpdate(LinkedList <GameObject> cards, SendPolicy policy = SendPolicy.Unreliable) { if (!userInRoom) { return; } List <byte> cardIds = new List <byte>(10); foreach (var card in cards) { if (card != null) { cardIds.Add(byte.Parse(card.name.Substring(4))); } } using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(128))) { binaryWriter.Write((byte)PacketType.CARD_HAND_UPDATE); binaryWriter.Write(localUser.ID); binaryWriter.Write((byte)cardIds.Count); binaryWriter.Write(cardIds.ToArray()); SendPacketToConnectedUsers(((MemoryStream)binaryWriter.BaseStream).ToArray(), policy); } }
/// <summary> /// Sends a single message. /// </summary> /// <param name="message">The message we want to send.</param> internal async Task Send([NotNull] T message) { var qMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))) { ContentType = "application/json", Label = message.GetType().GetEntityName() }; await SendPolicy.ExecuteAsync( async() => { try { using (await SenderLock.ReaderLockAsync()) { await Sender.SendAsync(qMessage).ConfigureAwait(false); } } catch { await RebuildSender().ConfigureAwait(false); throw; } }).ConfigureAwait(false); }
/// <summary> /// Sends a single message. /// </summary> /// <param name="message">The message we want to send.</param> internal async Task Send([NotNull] T message) { var qMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))) { ContentType = "application/json", Label = message.GetType().GetEntityName() }; await SendPolicy.ExecuteAsync( async() => { try { using (await SenderLock.ReaderLockAsync()) { await Sender.SendAsync(qMessage).ConfigureAwait(false); } } /** * we want to minimize the client rebuild frequency and ideally to reverse the approach * rebuild only when there is valid reason to do so * this list will need to be compiled/maintained */ catch (QuotaExceededException) //let the polly deal with this - retry if allowed { throw; } catch { await RebuildSender().ConfigureAwait(false); throw; } }).ConfigureAwait(false); }
public static bool SendPacket(UInt64 userID, byte[] bytes, SendPolicy policy) { if (Core.IsInitialized()) { return(CAPI.ovr_Net_SendPacket(userID, (UIntPtr)bytes.Length, bytes, policy)); } return(false); }
public static bool SendPacketToCurrentRoom(byte[] bytes, SendPolicy policy) { if (Core.IsInitialized()) { return(CAPI.ovr_Net_SendPacketToCurrentRoom((UIntPtr)bytes.Length, bytes, policy)); } return(false); }
private void SendPacketToConnectedUsers(byte[] packet, SendPolicy policy) { foreach (var user in remoteConnectionStates) { if (user.Value.networkState == ConnectionState.Connected) { Net.SendPacket(user.Key, packet, policy); } } }
public void OnRigidBodyUpdate(Rigidbody rigidBody, SendPolicy policy = SendPolicy.Unreliable) { using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(64))) { binaryWriter.Write((byte)PacketType.RIGID_BODY_UPDATE); binaryWriter.Write(localUser.ID); binaryWriter.Write(rigidBody.gameObject.name); binaryWriter.Write(rigidBody.position); binaryWriter.Write(rigidBody.rotation); SendPacketToConnectedUsers(((MemoryStream)binaryWriter.BaseStream).ToArray(), policy); } }
public void OnReset(SendPolicy policy = SendPolicy.Reliable) { UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Info, "Broadcast - game reset"); using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(64))) { binaryWriter.Write((byte)PacketType.RESET); binaryWriter.Write(localUser.ID); SendPacketToConnectedUsers(((MemoryStream)binaryWriter.BaseStream).ToArray(), policy); } resetGame(); if (room != null) { List <CardHandController> handControllers = new List <CardHandController>(); foreach (var user in room.UsersOptional) { if (user.ID == localUser.ID) { handControllers.Add(cardHandController); } else if (remoteCardHands.ContainsKey(user.ID)) { handControllers.Add(remoteCardHands[user.ID]); } } for (int i = 0; i < 13; i++) { foreach (var hand in handControllers) { var card = deckController.getNextCard(Vector3.zero, Quaternion.identity); hand.AddCard(card); } } foreach (var hand in handControllers) { hand.SortCards(); } deckController.SendUpdate(SendPolicy.Reliable); cardHandController.SendUpdate(SendPolicy.Reliable); foreach (var remoteCardHand in remoteCardHands.Values) { remoteCardHand.SendUpdate(SendPolicy.Reliable); } } }
public void OnTrackedObjectUpdate(GameObject obj, SendPolicy policy = SendPolicy.Unreliable) { if (!userInRoom) { return; } using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(64))) { binaryWriter.Write((byte)PacketType.TRACKED_OBJECT_UPDATE); binaryWriter.Write(localUser.ID); binaryWriter.Write(obj.name); binaryWriter.Write(obj.transform.position); binaryWriter.Write(obj.transform.rotation); SendPacketToConnectedUsers(((MemoryStream)binaryWriter.BaseStream).ToArray(), policy); } }
public void OnDeckUpdate(List <byte> cards, int cardIndex, SendPolicy policy = SendPolicy.Reliable) { if (!userInRoom) { UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Warning, "Attempted to update deck while not in room"); Debug.LogError("Attempted to update deck while not in room"); return; } UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Info, "Broadcast - deck update - Card index " + cardIndex); using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(256))) { binaryWriter.Write((byte)PacketType.DECK_UPDATE); binaryWriter.Write(localUser.ID); binaryWriter.Write((byte)cards.Count); binaryWriter.Write((byte)cardIndex); binaryWriter.Write(cards.ToArray()); SendPacketToConnectedUsers(((MemoryStream)binaryWriter.BaseStream).ToArray(), policy); } }
public void SendUpdate(SendPolicy policy = SendPolicy.Reliable) { canastyController.OnDeckUpdate(cards, cardIndex, policy); }
/// <summary> /// 设置数据发送策略 /// </summary> /// <param name="enSendPolicy"></param> public void SetSendPolicy(SendPolicy policy) { HPSocketSdk.HP_Agent_SetSendPolicy(pAgent, policy); }
public static extern void HP_Agent_SetSendPolicy(IntPtr pAgent, SendPolicy enSendPolicy);
public static extern void HP_Server_SetSendPolicy(IntPtr pServer, SendPolicy enSendPolicy);
public void SendUpdate(SendPolicy policy = SendPolicy.Unreliable) { canastyController.OnCardHandUpdate(cards, policy); }
public static extern bool ovr_Net_SendPacket(UInt64 userID, uint length, byte[] bytes, SendPolicy policy);
/// <summary> /// 设置数据发送策略 /// </summary> /// <param name="enSendPolicy"></param> public void SetSendPolicy(SendPolicy policy) { HPSocketSdk.HP_Server_SetSendPolicy(pServer, policy); }