/// <summary>
        /// Sends an <see cref="ExtendSessionPacket"/> to the server to extend the current session.
        /// </summary>
        /// <param name="sessionId">Session ID</param>
        private void sendExtendSessionPacket(string sessionId)
        {
            RaiseLogEntry(new LogEventArgs("Sending ExtendSessionPacket", LogLevel.DEBUG));

            // Create and pack a session extension packet
            ExtendSessionPacket packet = new ExtendSessionPacket
            {
                SessionId = sessionId
            };
            Any packedPacket = ProtobufPacketHelper.Pack(packet);

            // Send it on its way
            netClient.Send(MODULE_NAME, packedPacket.ToByteArray());
        }
Exemple #2
0
        /// <summary>
        /// Handles incoming <see cref="ExtendSessionPacket"/>s from clients trying to extend their session expiry.
        /// </summary>
        /// <param name="connectionId">Original connection ID</param>
        /// <param name="packet">Incoming <see cref="ExtendSessionPacket"/></param>
        private void extendSessionPacketHandler(string connectionId, ExtendSessionPacket packet)
        {
            // Lock the sessions dictionary to prevent other threads from messing with it
            lock (sessionsLock)
            {
                // Make sure the session is still valid
                if (IsAuthenticated(connectionId, packet.SessionId))
                {
                    // Extend the session expiry to 30 minutes from now
                    sessions[connectionId].Expiry = DateTime.UtcNow + TimeSpan.FromMinutes(30);

                    // Send a successful response
                    sendSuccessfulExtendSessionResponsePacket(connectionId, sessions[connectionId].Expiry);
                }
                else
                {
                    // Send a failed response
                    sendFailedExtendSessionResponsePacket(connectionId);
                }
            }
        }