예제 #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);