示例#1
0
    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);
        }
    }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <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);
        }
示例#4
0
        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);
        }
示例#5
0
        public static bool SendPacketToCurrentRoom(byte[] bytes, SendPolicy policy)
        {
            if (Core.IsInitialized())
            {
                return(CAPI.ovr_Net_SendPacketToCurrentRoom((UIntPtr)bytes.Length, bytes, policy));
            }

            return(false);
        }
示例#6
0
 private void SendPacketToConnectedUsers(byte[] packet, SendPolicy policy)
 {
     foreach (var user in remoteConnectionStates)
     {
         if (user.Value.networkState == ConnectionState.Connected)
         {
             Net.SendPacket(user.Key, packet, policy);
         }
     }
 }
示例#7
0
 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);
     }
 }
示例#8
0
    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);
            }
        }
    }
示例#9
0
    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);
        }
    }
示例#10
0
    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);
        }
    }
示例#11
0
 public void SendUpdate(SendPolicy policy = SendPolicy.Reliable)
 {
     canastyController.OnDeckUpdate(cards, cardIndex, policy);
 }
示例#12
0
 /// <summary>
 /// 设置数据发送策略
 /// </summary>
 /// <param name="enSendPolicy"></param>
 public void SetSendPolicy(SendPolicy policy)
 {
     HPSocketSdk.HP_Agent_SetSendPolicy(pAgent, policy);
 }
示例#13
0
 public static extern void HP_Agent_SetSendPolicy(IntPtr pAgent, SendPolicy enSendPolicy);
示例#14
0
文件: Sdk.cs 项目: yxdh/HP-Socket
 public static extern void HP_Agent_SetSendPolicy(IntPtr pAgent, SendPolicy enSendPolicy);
示例#15
0
文件: Sdk.cs 项目: yxdh/HP-Socket
 public static extern void HP_Server_SetSendPolicy(IntPtr pServer, SendPolicy enSendPolicy);
示例#16
0
 /// <summary>
 /// 设置数据发送策略
 /// </summary>
 /// <param name="enSendPolicy"></param>
 public void SetSendPolicy(SendPolicy policy)
 {
     HPSocketSdk.HP_Agent_SetSendPolicy(pAgent, policy);
 }
示例#17
0
 public void SendUpdate(SendPolicy policy = SendPolicy.Unreliable)
 {
     canastyController.OnCardHandUpdate(cards, policy);
 }
示例#18
0
 public static extern bool ovr_Net_SendPacket(UInt64 userID, uint length, byte[] bytes, SendPolicy policy);
示例#19
0
 /// <summary>
 /// 设置数据发送策略
 /// </summary>
 /// <param name="enSendPolicy"></param>
 public void SetSendPolicy(SendPolicy policy)
 {
     HPSocketSdk.HP_Server_SetSendPolicy(pServer, policy);
 }
示例#20
0
 /// <summary>
 /// 设置数据发送策略
 /// </summary>
 /// <param name="enSendPolicy"></param>
 public void SetSendPolicy(SendPolicy policy)
 {
     HPSocketSdk.HP_Server_SetSendPolicy(pServer, policy);
 }
示例#21
0
 public static extern void HP_Server_SetSendPolicy(IntPtr pServer, SendPolicy enSendPolicy);