internal override void Send(Packet packet, GProtocolSendType type, bool canSendBigSize = false,
                                    bool isCritical = false, bool isEvent = false)
        {
            try
            {
                if (IsConnected())
                {
                    packet.SendType = type;
                    var buffer = PacketSerializable.Serialize(packet, null, false);

                    if (!canSendBigSize && !PacketUtil.CheckPacketSize(buffer))
                    {
                        throw new GameServiceException("this Packet Is Too Big!,Max Packet Size is " +
                                                       RealTimeConst.MaxPacketSize + " bytes.")
                              .LogException <GsUdpClient>(DebugLocation.RealTime, "Send");
                    }

                    switch (type)
                    {
                    case GProtocolSendType.UnReliable:
                        Client?.SendUnReliable(buffer);
                        break;

                    case GProtocolSendType.Reliable:
                        if (isCritical)
                        {
                            Client?.SendCommand(buffer);
                        }
                        else
                        {
                            Client?.SendReliable(buffer, isEvent);
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(type), type, null);
                    }
                }
                else
                {
                    DebugUtil.LogError <GsUdpClient>(DebugLocation.RealTime, "Send", "Client not Connected!");
                }
            }
            catch (Exception e)
            {
                e.LogException <GsUdpClient>(DebugLocation.RealTime, "Send");
            }
        }
        private void Send(Packet packet, GProtocolSendType type, bool isCritical = false, bool canSendBigSize = false,
                          bool isEvent = false)
        {
            if (!_observer.Increase(isCritical))
            {
                throw new GameServiceException("Too Many Requests, You Can Send " + RealTimeConst.RealTimeSendLimit +
                                               " Requests Per Second")
                      .LogException <RealTimeHandler>(DebugLocation.RealTime, "Send");
            }

            if (IsAvailable(isCritical))
            {
                _connGateway.Send(packet, type, canSendBigSize, isCritical, isEvent);
            }
            else if (!isCritical)
            {
                throw new GameServiceException("GameService Not Available")
                      .LogException <RealTimeHandler>(DebugLocation.RealTime, "Send");
            }
        }
Beispiel #3
0
 internal abstract void Send(Packet packet, GProtocolSendType type, bool canSendBigSize = false,
                             bool isCritical = false, bool isEvent = false);