Beispiel #1
0
        public async Task <KeepAliveStatus> KeepAlive()
        {
            Log.Information("Sending keepalive");

            var status = KeepAliveStatus.Unknown;

            try
            {
                Log.Debug("Posting keepalive to {KeepAliveUrl}", keepAliveUrl);
                // The Alarm.com web interface does this with an empty POST, but it seems to work using GET, and makes more sense that way
                var response = await httpClient.GetAsync($"{keepAliveUrl}?timestamp={DateTimeOffset.Now.ToUnixTimeMilliseconds()}").ConfigureAwait(false);

                var result = KeepAliveResponse.FromJson(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
                status = result.Status;
                if (status == KeepAliveStatus.Success)
                {
                    Log.Debug("Keepalive successful");
                }
                else
                {
                    Log.Error("Keepalive failed: {Status}", status);
                }
            }
            catch (HttpRequestException e)
            {
                Log.Error(e, "Keepalive failed");
            }

            return(status);
        }
Beispiel #2
0
    public bool KeepAlive(skidata.com.tdi.common.v1.data.AuthenticationHeader AuthenticationHeader)
    {
        KeepAliveRequest inValue = new KeepAliveRequest();

        inValue.AuthenticationHeader = AuthenticationHeader;
        KeepAliveResponse retVal = ((CarAccessTransactionEventInterface)(this)).KeepAlive(inValue);

        return(retVal.KeepAliveSignal);
    }
Beispiel #3
0
 internal void HandleKeepAlivePacket(KeepAliveResponse packet, Client client)
 {
     foreach (KeepAlive keepAlive in _keepAlives)
     {
         if (keepAlive.TimeSent == packet.TimeSent && keepAlive.Client == client)
         {
             _keepAlives.Remove(keepAlive);
             break;
         }
     }
 }
        public static KeepAliveResponse Unmarshall(UnmarshallerContext _ctx)
        {
            KeepAliveResponse keepAliveResponse = new KeepAliveResponse();

            keepAliveResponse.HttpResponse = _ctx.HttpResponse;
            keepAliveResponse.Status       = _ctx.BooleanValue("KeepAlive.Status");
            keepAliveResponse.Msg          = _ctx.StringValue("KeepAlive.Msg");
            keepAliveResponse.Data         = _ctx.StringValue("KeepAlive.Data");
            keepAliveResponse.ErrorCode    = _ctx.StringValue("KeepAlive.ErrorCode");
            keepAliveResponse.RequestId    = _ctx.StringValue("KeepAlive.RequestId");

            return(keepAliveResponse);
        }
        public static KeepAliveResponse Unmarshall(UnmarshallerContext context)
        {
			KeepAliveResponse keepAliveResponse = new KeepAliveResponse();

			keepAliveResponse.HttpResponse = context.HttpResponse;
			keepAliveResponse.Status = context.BooleanValue("KeepAlive.Status");
			keepAliveResponse.Msg = context.StringValue("KeepAlive.Msg");
			keepAliveResponse.Data = context.StringValue("KeepAlive.Data");
			keepAliveResponse.ErrorCode = context.StringValue("KeepAlive.ErrorCode");
			keepAliveResponse.RequestId = context.StringValue("KeepAlive.RequestId");
        
			return keepAliveResponse;
        }
Beispiel #6
0
        void HandleNormalPackets(Queue <BasePacket> listOfPackets)
        {
            foreach (var packet in listOfPackets)
            {
                numPacketsReceived++;
                // normal processing
                EntityPacket ep = packet as EntityPacket;
                if (ep != null)
                {
                    //entityId = ep.entityId;
                    int tempEntityId = ep.entityId;
                    if (entityId == tempEntityId)
                    {
                        Console.Write("This entity packet updated {0}\n", tempEntityId);
                    }
                    else
                    {
                        Console.Write("Entity update packet {0}\n", tempEntityId);
                    }
                    entityId = tempEntityId;
                    continue;
                }
                KeepAlive ka = packet as KeepAlive;
                if (ka != null)
                {
                    KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                    socket.Send(kar);
                }

                if (packet is ServerPingHopperPacket)
                {
                    ServerPingHopperPacket hopper = packet as ServerPingHopperPacket;
                    hopper.Stamp("client end");
                    hopper.PrintList();
                }
                if (packet.PacketType == PacketType.DataBlob)
                {
                    HandleBlobData(packet as DataBlob);
                }
            }
            foreach (var packet in listOfPackets)
            {
                if (packet.PacketType != PacketType.DataBlob)// tyhese need special handling
                {
                    IntrepidSerialize.ReturnToPool(packet);
                }
            }
        }
Beispiel #7
0
            public override void HandlePackets(Queue <BasePacket> listOfPackets)
            {
                server.numPacketsReceived += listOfPackets.Count;
                foreach (var packet in listOfPackets)
                {
                    // normal processing
                    ServerConnectionHeader sch = packet as ServerConnectionHeader;// should be converted to a wrapper
                    if (sch != null)
                    {
                        server.NextConnectionId = sch.connectionId;
                        continue;
                    }
                    PlayerSaveStatePacket pss = packet as PlayerSaveStatePacket;
                    if (pss != null)
                    {
                        server.LogInPlayer(server.NextConnectionId, pss.state);

                        // send all entities in area to player eventually.
                        // notify all other players that this player is here.
                        continue;
                    }

                    //--------------------------------------------
                    KeepAlive ka = packet as KeepAlive;
                    if (ka != null)
                    {
                        KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                        //gatewaySocket.Send(kar);
                        server.AddOutgoingPacket(kar, ServerNetworking.InvalidConnectionId);
                        continue;
                    }

                    if (server.connectedClients.ContainsKey(server.NextConnectionId))
                    {
                        server.connectedClients[server.NextConnectionId].AddIncomingPacket(packet);
                    }
                }
            }
        public KeepAliveResponse KeepAlive(KeepAliveRequest request)
        {
            KeepAliveResponse response = new KeepAliveResponse();

            AuthToken authToken = null;

            try
            {
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.AuthToken, "Auth Token");

                if (!UserController.ValidateSession(request.AuthToken, out authToken))
                {
                    throw new AuthenticationException("Authentication failed.");
                }

                var newAuthToken = UserController.KeepSessionAlive(authToken);

                response.NewAuthToken  = UserController.CreateSessionCookie(newAuthToken);
                response.ExpirySeconds = (int)Settings.Default.SessionExpiryInterval.TotalSeconds;
            }
            catch (AuthenticationException ex)
            {
                throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.Unauthorized);
            }
            catch (Common.Exceptions.ValidationException ex)
            {
                throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.Unauthorized);
            }
            catch (Exception ex)
            {
                ExceptionHelper.Log(ex, authToken == null ? null : authToken.Username);
                throw new WebFaultException <string>("An unknown error has occurred.", System.Net.HttpStatusCode.InternalServerError);
            }

            return(response);
        }
Beispiel #9
0
        internal void HandleKeepAlivePacket(KeepAliveResponse packet, Client client)
        {
            if (_keepAlives.Count == 0)
            {
                return;
            }

            lock (_keepAlives)
            {
                for (int i = 0; i < _keepAlives.Count; i++)
                {
                    KeepAlive keepAlive = _keepAlives[i];
                    if (keepAlive.TimeSent == packet.TimeSent && keepAlive.Client == client)
                    {
                        _keepAlives.Remove(keepAlive);
                        keepAlive.Dispose();
                        keepAlive = null;
                        break;
                    }
                }
            }
            packet.Dispose();
            packet = null;
        }
 protected override void ResponseConstruct()
 {
     _response = new KeepAliveResponse(_request, _result);
 }
Beispiel #11
0
 public Task SendResponseAsync(KeepAliveResponse response, CancellationToken cancellationToken = default)
 {
     return(base.SendResponseAsync(response, cancellationToken));
 }
Beispiel #12
0
 public void SendResponse(KeepAliveResponse response)
 {
     base.SendResponse(response);
 }
Beispiel #13
0
 public static void HandleClientKeepAliveResponse(Session session, KeepAliveResponse keepAlive)
 {
     session.Heartbeat.CalculateLatency(keepAlive.Timestamp);
 }
Beispiel #14
0
        void HandleNormalPackets(Queue <BasePacket> listOfPackets)
        {
            foreach (var packet in listOfPackets)
            {
                //Console.WriteLine("normal packet received {0} .. isLoggedIn = true", packet.PacketType);
                numPacketsReceived++;
                // normal processing
                if (packet is PlayerFullPacket && localPlayer.entityId == 0)
                {
                    localPlayer.entityId = (packet as PlayerFullPacket).entityId;
                }

                /*     ServerTick st = packet as ServerTick;
                 *   if(st != null)
                 *   {
                 *       Console.WriteLine("server tick {0}", st.TickCount);
                 *
                 *       continue;
                 *   }*/
                KeepAlive ka = packet as KeepAlive;
                if (ka != null)
                {
                    KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                    socket.Send(kar);
                }

                if (packet is ServerPingHopperPacket)
                {
                    ServerPingHopperPacket hopper = packet as ServerPingHopperPacket;
                    hopper.Stamp("client end");
                    hopper.PrintList();
                }
                if (packet is WorldEntityPacket)
                {
                    WorldEntityPacket wep = packet as WorldEntityPacket;
                    if (localPlayer.entityId == wep.entityId)
                    {
                        localPlayer.position = wep.position.Get();
                        localPlayer.rotation = wep.rotation.Get();
                    }
                }
                EntityPacket ep = packet as EntityPacket;
                if (ep != null)
                {
                    //entityId = ep.entityId;
                    int tempEntityId = ep.entityId;
                    if (localPlayer.entityId == tempEntityId)
                    {
                        Console.Write("This entity packet updated {0}\n", tempEntityId);
                    }

                    /* else
                     * {
                     *   Console.Write("Entity update packet {0}\n", tempEntityId);
                     * }*/
                    continue;
                }

                // Console.WriteLine("normal packet received {0}", packet.PacketType);

                IntrepidSerialize.ReturnToPool(packet);
            }
        }
        public override Task<KeepAliveResponse> KeepAlive(KeepAliveRequest request, ServerCallContext context)
        {
            // Store interaction time
            this._lastInteractionTime = DateTime.Now;

            KeepAliveResponse response = new KeepAliveResponse
            {

            };
            return Task.FromResult(response);
        }
        private void Sock_OnPacketsReceived(IPacketSend arg1, Queue <BasePacket> listOfPackets)
        {
            // all of these boolean checks should be replaced by a Strategy
            if (isBoundToGateway == true)
            {
                foreach (var packet in listOfPackets)
                {
                    numPacketsReceived++;
                    // normal processing

                    KeepAlive ka = packet as KeepAlive;
                    if (ka != null)
                    {
                        KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                        socket.Send(kar);
                        continue;
                    }
                    WorldEntityPacket wep = packet as WorldEntityPacket;
                    if (wep != null)
                    {
                        foreach (var playerId in playerIds)
                        {
                            if (playerId.entityId == wep.entityId)
                            {
                                playerId.position = wep.position.Get();
                                playerId.rotation = wep.rotation.Get();

                                SendAllEntityPositions();
                            }
                        }
                        continue;
                    }

                    ServerConnectionHeader sch = packet as ServerConnectionHeader;
                    if (sch != null)
                    {
                        nextConnectionId = sch.connectionId;
                        continue;
                    }
                    PlayerSaveStatePacket pss = packet as PlayerSaveStatePacket;
                    if (pss != null)
                    {
                        HandlePlayerSaveState(pss);
                        continue;
                    }
                    if (packet is ServerPingHopperPacket)
                    {
                        HandleServerHopping(packet as ServerPingHopperPacket);
                        continue;
                    }
                }
            }
            else
            {
                foreach (var packet in listOfPackets)
                {
                    numPacketsReceived++;
                    if (packet is ServerIdPacket)
                    {
                        ServerIdPacket id = packet as ServerIdPacket;
                        if (id != null && id.Type == ServerIdPacket.ServerType.Gateway)
                        {
                            isBoundToGateway = true;
                            break;
                        }
                    }
                }
            }
        }