Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions server/db/logbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { isAdmin } from '../middleware/isAdmin.js';

export async function initializeLogbookTables() {
try {

await pool.query(`
CREATE TABLE IF NOT EXISTS logbook_flights (
id SERIAL PRIMARY KEY,
Expand Down Expand Up @@ -258,9 +257,9 @@ export async function initializeLogbookTables() {
}

export async function createFlight({ userId, robloxUserId, robloxUsername, callsign, departureIcao, arrivalIcao, route, aircraftIcao }) {

const crypto = await import('crypto');
const shareToken = crypto.randomBytes(4).toString('hex');
const shareToken = crypto.randomBytes(4).toString('hex');

const result = await pool.query(`
INSERT INTO logbook_flights (
Expand Down Expand Up @@ -342,7 +341,7 @@ export async function addApproachAltitude(robloxUsername, altitude, timestamp) {
}

export async function calculateLandingRate(robloxUsername) {

const flightResult = await pool.query(`
SELECT laf.flight_id, lf.waypoint_landing_rate
FROM logbook_active_flights laf
Expand Down Expand Up @@ -663,7 +662,7 @@ export async function completeFlightByCallsign(callsign) {
await updateUserStatsCache(flightData.user_id);
} catch (error) {
console.error('Error updating user stats cache:', error);

}

return flightData.id;
Expand Down Expand Up @@ -701,7 +700,7 @@ function calculateFlightStats(flightData, telemetryData, activeFlight) {
if (prev.x && prev.y && curr.x && curr.y) {
const dx = curr.x - prev.x;
const dy = curr.y - prev.y;
const distance = Math.sqrt(dx * dx + dy * dy) / 1852;
const distance = Math.sqrt(dx * dx + dy * dy) / 1852;
totalDistance += distance;
}
}
Expand Down Expand Up @@ -745,25 +744,25 @@ function calculateFlightStats(flightData, telemetryData, activeFlight) {

if (prev.speed_kts != null && curr.speed_kts != null) {
const speedChange = Math.abs(curr.speed_kts - prev.speed_kts);
if (speedChange > 30) speedPenalty += 3;
else if (speedChange > 20) speedPenalty += 2;
else if (speedChange > 10) speedPenalty += 1;
if (speedChange > 30) speedPenalty += 3;
else if (speedChange > 20) speedPenalty += 2;
else if (speedChange > 10) speedPenalty += 1;
}

if (prev.vertical_speed_fpm != null && curr.vertical_speed_fpm != null) {
const vsChange = Math.abs(curr.vertical_speed_fpm - prev.vertical_speed_fpm);
if (vsChange > 500) verticalSpeedPenalty += 3;
else if (vsChange > 300) verticalSpeedPenalty += 2;
else if (vsChange > 150) verticalSpeedPenalty += 1;
if (vsChange > 500) verticalSpeedPenalty += 3;
else if (vsChange > 300) verticalSpeedPenalty += 2;
else if (vsChange > 150) verticalSpeedPenalty += 1;
}

if (prev.heading != null && curr.heading != null) {

let headingChange = Math.abs(curr.heading - prev.heading);
if (headingChange > 180) headingChange = 360 - headingChange;

if (headingChange > 30) headingPenalty += 2;
else if (headingChange > 20) headingPenalty += 1;
if (headingChange > 30) headingPenalty += 2;
else if (headingChange > 20) headingPenalty += 1;
}
}

Expand Down Expand Up @@ -843,7 +842,7 @@ export async function getFlightById(flightId) {
}

export async function getActiveFlightData(flightId) {

const flight = await getFlightById(flightId);
if (!flight) return null;

Expand Down Expand Up @@ -964,7 +963,7 @@ export async function getUserStats(userId) {
`, [userId]);

if (result.rows.length === 0) {

await pool.query(`
INSERT INTO logbook_stats_cache (user_id)
VALUES ($1)
Expand All @@ -980,7 +979,6 @@ export async function getUserStats(userId) {
}

export async function generateShareToken(flightId, userId) {

const flight = await pool.query(`
SELECT share_token, user_id FROM logbook_flights WHERE id = $1
`, [flightId]);
Expand Down Expand Up @@ -1346,7 +1344,7 @@ export async function finalizeLandingFromWaypoints(robloxUsername) {

const recentCluster = waypoints.filter(w => {
const timeDiff = maxTimestamp - w.timestamp;
return timeDiff <= 90;
return timeDiff <= 90;
});

if (recentCluster.length === 0) {
Expand Down
41 changes: 0 additions & 41 deletions src/components/ACARSPanel.tsx

This file was deleted.

62 changes: 37 additions & 25 deletions src/components/AccessDenied.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ interface AccessDeniedProps {
| 'invalid-session'
| 'banned'
| 'tester-required'
| 'pilot-not-found';
| 'pilot-not-found'
| 'flight-not-found';
}

export default function AccessDenied({
Expand All @@ -25,27 +26,6 @@ export default function AccessDenied({
let displayMessage = message;
let displayDescription = description;

const bgGradient =
errorType === 'invalid-session'
? 'from-black via-zinc-900 to-yellow-700'
: errorType === 'banned'
? 'from-black via-zinc-900 to-red-900'
: errorType === 'tester-required'
? 'from-black via-zinc-900 to-cyan-900'
: errorType === 'pilot-not-found'
? 'from-black via-zinc-900 to-blue-900'
: 'from-black via-zinc-900 to-red-950';
const textGradient =
errorType === 'invalid-session'
? 'from-yellow-400 to-yellow-700'
: errorType === 'banned'
? 'from-red-400 to-red-700'
: errorType === 'tester-required'
? 'from-cyan-400 to-cyan-700'
: errorType === 'pilot-not-found'
? 'from-blue-400 to-blue-700'
: 'from-red-400 to-red-900';

if (errorType === 'invalid-session') {
displayMessage = displayMessage || 'Invalid Session';
displayDescription =
Expand All @@ -66,13 +46,43 @@ export default function AccessDenied({
displayDescription =
displayDescription ||
'The pilot you are looking for could not be found.';
} else if (errorType === 'flight-not-found') {
displayMessage = displayMessage || 'Flight Not Found';
displayDescription =
displayDescription ||
'The flight you are looking for could not be found or the link has expired.';
} else {
displayMessage = displayMessage || 'Access Denied';
displayDescription =
displayDescription ||
"You don't have permission to access this session";
}

const bgGradient =
errorType === 'invalid-session'
? 'from-black via-zinc-900 to-yellow-700'
: errorType === 'banned'
? 'from-black via-zinc-900 to-red-900'
: errorType === 'tester-required'
? 'from-black via-zinc-900 to-cyan-900'
: errorType === 'pilot-not-found'
? 'from-black via-zinc-900 to-blue-900'
: errorType === 'flight-not-found'
? 'from-black via-zinc-900 to-blue-900'
: 'from-black via-zinc-900 to-red-950';
const textGradient =
errorType === 'invalid-session'
? 'from-yellow-400 to-yellow-700'
: errorType === 'banned'
? 'from-red-400 to-red-700'
: errorType === 'tester-required'
? 'from-cyan-400 to-cyan-700'
: errorType === 'pilot-not-found'
? 'from-blue-400 to-blue-700'
: errorType === 'flight-not-found'
? 'from-blue-400 to-blue-700'
: 'from-red-400 to-red-900';

return (
<div
className={`min-h-screen bg-gradient-to-b ${bgGradient} text-white flex flex-col`}
Expand All @@ -84,7 +94,8 @@ export default function AccessDenied({
className={`text-[10rem] font-extrabold bg-gradient-to-br ${textGradient} bg-clip-text text-transparent -mb-8`}
>
{errorType === 'invalid-session' ||
errorType === 'pilot-not-found'
errorType === 'pilot-not-found' ||
errorType === 'flight-not-found'
? '404'
: '403'}
</h1>
Expand All @@ -95,10 +106,11 @@ export default function AccessDenied({
{displayDescription}
</p>
{errorType === 'tester-required' ||
errorType === 'pilot-not-found' ? (
errorType === 'pilot-not-found' ||
errorType === 'flight-not-found' ? (
<Link
to="https://pfconnect.online/discord"
className={`inline-flex items-center px-8 py-4 rounded-full ${'bg-[#4f62a5] hover:bg-[#384366]'} text-white text-xl font-medium transition-all duration-300 shadow-lg hover:shadow-xl`}
className={`inline-flex items-center px-8 py-4 rounded-full ${'bg-[#4f62a5] hover:bg-[#45568f]'} text-white text-xl font-medium transition-all duration-300 shadow-lg hover:shadow-xl`}
>
<FaDiscord className="mr-3 h-6 w-6 group-hover:-translate-x-1 transition-transform duration-300" />
Support Server
Expand Down
12 changes: 10 additions & 2 deletions src/components/buttons/UserButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ export default function CustomUserButton({

<button
onClick={() => {
window.location.href = '/settings';
window.open(
'/settings',
'_blank',
'noopener,noreferrer'
);
}}
className="w-full flex items-center space-x-3 px-4 py-3 text-gray-300 hover:text-white hover:bg-zinc-800/60 rounded-xl transition-all duration-200 font-medium"
>
Expand Down Expand Up @@ -281,7 +285,11 @@ export default function CustomUserButton({

<button
onClick={() => {
window.location.href = '/settings';
window.open(
'/settings',
'_blank',
'noopener,noreferrer'
);
}}
className="w-full flex items-center space-x-3 px-4 py-3 text-gray-300 hover:bg-blue-600/20 hover:text-white transition-all duration-200 group"
>
Expand Down
Loading
Loading