Beispiel #1
0
        internal sealed override void Deserialize(byte[] buffer)
        {
            using (var packetWriter = ByteArrayReaderWriter.Get(buffer))
            {
                Action = packetWriter.ReadByte();

                var haveSendTime = packetWriter.ReadByte();
                var havePayload  = packetWriter.ReadByte();

                if (havePayload == 0x1)
                {
                    _payloadLen = packetWriter.ReadUInt16();
                }

                SendType = (GProtocolSendType)packetWriter.ReadByte();
                Hash     = (long)packetWriter.ReadUInt64();

                if (havePayload == 0x1)
                {
                    Payload = packetWriter.ReadBytes(_payloadLen);
                }
                if (haveSendTime == 0x1)
                {
                    ClientSendTime = packetWriter.ReadInt64();
                }
            }
        }
        protected override void HandleResponse(Packet packet, GProtocolSendType type)
        {
            var memberId = GetStringFromBuffer(packet.Payload);

            RealTimeEventHandlers.MemberId?.Invoke(this, memberId);
            RealTimeEventHandlers.Authorized?.Invoke(this, packet.Hash);
        }
Beispiel #3
0
 protected override void HandleResponse(Packet packet, GProtocolSendType type)
 {
     try
     {
         var dataPayload = new DataPayload(packet.Payload);
         RealTimeEventHandlers.NewMessageReceived?.Invoke(this, new MessageReceiveEvent
         {
             MessageInfo = new MessageInfo
             {
                 MessageType       = MessageType.Public,
                 SendType          = type,
                 ClientReceiveTime = packet.ClientReceiveTime
             },
             Message = new Message
             {
                 Data       = dataPayload.Payload,
                 ReceiverId = dataPayload.ReceiverId,
                 SenderId   = dataPayload.SenderId
             }
         });
     }
     catch (Exception e)
     {
         e.LogException <PublicMessageResponseHandler>(DebugLocation.RealTime, "HandleResponse");
     }
 }
Beispiel #4
0
 public Packet(long hash, int action, GProtocolSendType sendType = GProtocolSendType.UnReliable,
               byte[] payload = null)
 {
     Hash     = hash;
     Action   = action;
     Payload  = payload;
     SendType = sendType;
 }
        protected override void HandleResponse(Packet packet, GProtocolSendType type)
        {
            var member = JsonConvert.DeserializeObject <Member>(GetStringFromBuffer(packet.Payload));

            RealTimeEventHandlers.LeftRoom?.Invoke(this, member);
            if (member.User.IsMe)
            {
                RealTimeEventHandlers.LeftDispose?.Invoke(this, null);
            }
        }
Beispiel #6
0
        protected override void HandleResponse(Packet packet, GProtocolSendType type)
        {
            var joinData = JsonConvert.DeserializeObject <JoinData>(GetStringFromBuffer(packet.Payload));

            RealTimeEventHandlers.JoinedRoom?.Invoke(this, new JoinEvent
            {
                Type     = GSLiveType.RealTime,
                JoinData = joinData
            });
        }
Beispiel #7
0
        protected override void HandleResponse(Packet packet, GProtocolSendType type)
        {
            if (GsLiveRealTime.InAutoMatch)
            {
                GsLiveRealTime.InAutoMatch = false;
            }

            CoreEventHandlers.Error?.Invoke(this, new ErrorEvent
            {
                Type  = GSLiveType.RealTime,
                Error = GetStringFromBuffer(packet.Payload)
            });
        }
 protected override void HandleResponse(Packet packet, GProtocolSendType type)
 {
     try
     {
         var dataPayload     = new DataPayload(packet.Payload);
         var shotsFromBuffer = GsSerializer.Object.GetSnapShotsFromBuffer(dataPayload.Payload);
         GsSerializer.OnNewSnapShotReceived?.Invoke(this, shotsFromBuffer);
     }
     catch (Exception e)
     {
         e.LogException <SnapShotResponseHandler>(DebugLocation.RealTime, "HandleResponse");
     }
 }
        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");
            }
        }
Beispiel #10
0
 protected override void HandleResponse(Packet packet, GProtocolSendType type)
 {
     try
     {
         var dataPayload = new DataPayload(packet.Payload);
         GsSerializer.OnNewEventHandler?.Invoke(this,
                                                new EventData
         {
             Caller     = dataPayload.ExtraData,
             Data       = dataPayload.Payload,
             SenderId   = dataPayload.SenderId,
             ReceiverId = dataPayload.ReceiverId
         });
     }
     catch (Exception e)
     {
         e.LogException <NewEventResponseHandler>(DebugLocation.RealTime, "HandleResponse");
     }
 }
        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");
            }
        }
        protected override void HandleResponse(Packet packet, GProtocolSendType type)
        {
            var dataPayload = new DataPayload(packet.Payload);

            RealTimeEventHandlers.NewMessageReceived?.Invoke(this, new MessageReceiveEvent
            {
                MessageInfo = new MessageInfo
                {
                    MessageType       = MessageType.Private,
                    SendType          = type,
                    ClientReceiveTime = packet.ClientReceiveTime
                },
                Message = new Message
                {
                    Data       = dataPayload.Payload,
                    ReceiverId = dataPayload.ReceiverId,
                    SenderId   = dataPayload.SenderId
                }
            });
        }
Beispiel #13
0
        public override void SendPublicMessage(byte[] data, GProtocolSendType sendType)
        {
            if (GameService.IsGuest)
            {
                throw new GameServiceException("This Function Not Working In Guest Mode").LogException <GsLiveRealTime>(
                          DebugLocation.RealTime, "SendPublicMessage");
            }
            if (data == null)
            {
                throw new GameServiceException("data Cant Be Null").LogException <GsLiveRealTime>(DebugLocation.RealTime,
                                                                                                  "SendPublicMessage");
            }
            if (GameService.GSLive.GetGsHandler().RealTimeHandler == null)
            {
                throw new GameServiceException("You Must Create or Join Room First").LogException <GsLiveRealTime>(
                          DebugLocation.RealTime, "SendPublicMessage");
            }

            GameService.GSLive.GetGsHandler().RealTimeHandler.Request(SendPublicMessageHandler.Signature, sendType,
                                                                      new DataPayload {
                Payload = data
            });
        }
Beispiel #14
0
        internal override void SendEvent(byte[] caller, byte[] data, GProtocolSendType sendType)
        {
            if (GameService.IsGuest)
            {
                throw new GameServiceException("This Function Not Working In Guest Mode").LogException <GsLiveRealTime>(
                          DebugLocation.RealTime, "SendEvent");
            }
            if (caller == null || data == null)
            {
                throw new GameServiceException("caller or data Cant Be Null").LogException <GsLiveRealTime>(
                          DebugLocation.RealTime, "SendEvent");
            }
            if (GameService.GSLive.GetGsHandler().RealTimeHandler == null)
            {
                throw new GameServiceException("You Must Create or Join Room First").LogException <GsLiveRealTime>(
                          DebugLocation.RealTime, "SendEvent");
            }

            GameService.GSLive.GetGsHandler().RealTimeHandler.Request(NewEventHandler.Signature, sendType,
                                                                      new DataPayload {
                Payload = data, ExtraData = caller
            }, false, true, true);
        }
        protected override void HandleResponse(Packet packet, GProtocolSendType type)
        {
            try
            {
                var(ownerId, payloads) = GsSerializer.Object.GetObserver(packet.Payload);

                while (payloads.Count > 0)
                {
                    var dataPayload = new DataPayload(payloads.Dequeue());
                    GsSerializer.OnNewEventHandler?.Invoke(this,
                                                           new EventData
                    {
                        Caller   = dataPayload.ExtraData,
                        Data     = dataPayload.Payload,
                        SenderId = ownerId
                    });
                }
            }
            catch (Exception e)
            {
                e.LogException <ObserverResponseHandler>(DebugLocation.RealTime, "HandleResponse");
            }
        }
Beispiel #16
0
        protected override void HandleResponse(Packet packet, GProtocolSendType type)
        {
            var roomData = JsonConvert.DeserializeObject <RoomData>(GetStringFromBuffer(packet.Payload));

            RealTimeEventHandlers.CurrentRoomInfoReceived?.Invoke(this, roomData);
        }
 internal void Request(string handlerName, GProtocolSendType type, object payload = null,
                       bool isCritical = false, bool canSendBigSize = false, bool isEvent = false)
 {
     Send(_requestHandlers[handlerName]?.HandleAction(payload), type, isCritical, canSendBigSize, isEvent);
 }
 protected abstract void HandleResponse(Packet packet, GProtocolSendType type);
 public virtual void HandlePacket(Packet packet, GProtocolSendType type)
 {
     HandleResponse(packet, type);
 }
Beispiel #20
0
 internal abstract void Send(Packet packet, GProtocolSendType type, bool canSendBigSize = false,
                             bool isCritical = false, bool isEvent = false);
        protected override void HandleResponse(Packet packet, GProtocolSendType type)
        {
            var peerConfig = JsonConvert.DeserializeObject <PeerConfig>(GetStringFromBuffer(packet.Payload));

            RealTimeEventHandlers.PeerConfig?.Invoke(this, peerConfig);
        }
 internal abstract void SendEvent(byte[] caller, byte[] data, GProtocolSendType sendType);
 /// <summary>
 ///     Send A Data To All Players in Room.
 /// </summary>
 /// <param name="data">(NOTNULL) Data To BroadCast </param>
 /// <param name="sendType">Send Type </param>
 public abstract void SendPublicMessage(byte[] data, GProtocolSendType sendType);
 protected override void HandleResponse(Packet packet, GProtocolSendType type)
 {
     RealTimeEventHandlers.MemberConnectionStateChanged?.Invoke(this,
                                                                JsonConvert.DeserializeObject <MemberConnectionState>(GetStringFromBuffer(packet.Payload)));
 }
Beispiel #25
0
 protected override void HandleResponse(Packet packet, GProtocolSendType type)
 {
     RealTimeEventHandlers.RoomMembersDetailReceived?.Invoke(this,
                                                             JsonConvert.DeserializeObject <List <Member> >(GetStringFromBuffer(packet.Payload)));
 }