forked from simrail/simrail.pro
Reviewed-on: alekswilc/simrail-logs#24 Reviewed-by: Aleksander Wilczyński <aleks@alekswilc.dev>
This commit is contained in:
commit
de985ed3fe
@ -1,6 +1,5 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { PlayerUtil } from '../../util/PlayerUtil.js';
|
|
||||||
import { msToTime } from '../../util/time.js';
|
import { msToTime } from '../../util/time.js';
|
||||||
|
|
||||||
import { PipelineStage } from 'mongoose';
|
import { PipelineStage } from 'mongoose';
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import { PlayerUtil } from '../../util/PlayerUtil.js';
|
|
||||||
import { msToTime } from '../../util/time.js';
|
import { msToTime } from '../../util/time.js';
|
||||||
import { MProfile } from '../../mongo/profile.js';
|
import { MProfile } from '../../mongo/profile.js';
|
||||||
import { MBlacklist } from '../../mongo/blacklist.js';
|
import { MBlacklist } from '../../mongo/blacklist.js';
|
||||||
|
import { SteamUtil } from '../../util/SteamUtil.js';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -18,8 +17,8 @@ export class ProfilesRoute {
|
|||||||
if (!player) return res.render('profiles/private.ejs');
|
if (!player) return res.render('profiles/private.ejs');
|
||||||
const blacklist = await MBlacklist.findOne({ steam: req.params.id! });
|
const blacklist = await MBlacklist.findOne({ steam: req.params.id! });
|
||||||
if (blacklist && blacklist.status) return res.render('profiles/private.ejs');
|
if (blacklist && blacklist.status) return res.render('profiles/private.ejs');
|
||||||
const steam = await PlayerUtil.getPlayer(player?.steam!);
|
const steam = await SteamUtil.getPlayer(player?.steam!);
|
||||||
const steamStats = await PlayerUtil.getPlayerStats(player?.steam!);
|
const steamStats = await SteamUtil.getPlayerStats(player?.steam!);
|
||||||
|
|
||||||
res.render('profiles/index.ejs', {
|
res.render('profiles/index.ejs', {
|
||||||
player, steam, steamStats: steamStats,
|
player, steam, steamStats: steamStats,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import { MLog, raw_schema } from '../../mongo/logs.js';
|
import { MLog } from '../../mongo/logs.js';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { PlayerUtil } from '../../util/PlayerUtil.js';
|
|
||||||
import { msToTime } from '../../util/time.js';
|
import { msToTime } from '../../util/time.js';
|
||||||
import { PipelineStage } from 'mongoose';
|
import { PipelineStage } from 'mongoose';
|
||||||
import { MBlacklist } from '../../mongo/blacklist.js';
|
import { MBlacklist } from '../../mongo/blacklist.js';
|
||||||
|
import { SteamUtil } from '../../util/SteamUtil.js';
|
||||||
|
|
||||||
const generateSearch = (regex: RegExp) => [
|
const generateSearch = (regex: RegExp) => [
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ export class StationsRoute {
|
|||||||
const record = await MLog.findOne({ id: req.params.id });
|
const record = await MLog.findOne({ id: req.params.id });
|
||||||
const blacklist = await MBlacklist.findOne({ steam: record?.userSteamId! });
|
const blacklist = await MBlacklist.findOne({ steam: record?.userSteamId! });
|
||||||
if (blacklist && blacklist.status) return res.redirect('/stations/');
|
if (blacklist && blacklist.status) return res.redirect('/stations/');
|
||||||
const player = await PlayerUtil.getPlayer(record?.userSteamId!);
|
const player = await SteamUtil.getPlayer(record?.userSteamId!);
|
||||||
|
|
||||||
res.render('stations/details.ejs', {
|
res.render('stations/details.ejs', {
|
||||||
record,
|
record,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { PlayerUtil } from '../../util/PlayerUtil.js';
|
|
||||||
import { msToTime } from '../../util/time.js';
|
import { msToTime } from '../../util/time.js';
|
||||||
import { PipelineStage } from 'mongoose';
|
import { PipelineStage } from 'mongoose';
|
||||||
import { MTrainLog, raw_schema } from '../../mongo/trainLogs.js';
|
import { MTrainLog, raw_schema } from '../../mongo/trainLogs.js';
|
||||||
import { MBlacklist } from '../../mongo/blacklist.js';
|
import { MBlacklist } from '../../mongo/blacklist.js';
|
||||||
|
import { SteamUtil } from '../../util/SteamUtil.js';
|
||||||
|
|
||||||
const generateSearch = (regex: RegExp) => [
|
const generateSearch = (regex: RegExp) => [
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ export class TrainsRoute {
|
|||||||
app.get('/details/:id', async (req, res) => {
|
app.get('/details/:id', async (req, res) => {
|
||||||
if (!req.params.id) return res.redirect('/trains/');
|
if (!req.params.id) return res.redirect('/trains/');
|
||||||
const record = await MTrainLog.findOne({ id: req.params.id });
|
const record = await MTrainLog.findOne({ id: req.params.id });
|
||||||
const player = await PlayerUtil.getPlayer(record?.userSteamId!);
|
const player = await SteamUtil.getPlayer(record?.userSteamId!);
|
||||||
const blacklist = await MBlacklist.findOne({ steam: record?.userSteamId! });
|
const blacklist = await MBlacklist.findOne({ steam: record?.userSteamId! });
|
||||||
if (blacklist && blacklist.status) return res.redirect('/trains/');
|
if (blacklist && blacklist.status) return res.redirect('/trains/');
|
||||||
|
|
||||||
|
@ -52,8 +52,7 @@
|
|||||||
<p>Użytkownik: <a href="/profiles/<%- record.userSteamId %>">
|
<p>Użytkownik: <a href="/profiles/<%- record.userSteamId %>">
|
||||||
<%- record.userUsername %>
|
<%- record.userUsername %>
|
||||||
</a></p>
|
</a></p>
|
||||||
<p>Stacja: <%- record.stationName %>
|
|
||||||
</p>
|
|
||||||
<p>Pociąg: <%- record.trainName %> <%- record.trainNumber %>
|
<p>Pociąg: <%- record.trainName %> <%- record.trainNumber %>
|
||||||
</p>
|
</p>
|
||||||
<p>Data wejścia: <%- record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') : '--:-- --/--/--'
|
<p>Data wejścia: <%- record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') : '--:-- --/--/--'
|
||||||
|
@ -4,28 +4,28 @@ import { IPlayer } from '../types/player.js';
|
|||||||
import { SimrailClientEvents } from '../util/SimrailClient.js';
|
import { SimrailClientEvents } from '../util/SimrailClient.js';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { MProfile } from '../mongo/profile.js';
|
import { MProfile } from '../mongo/profile.js';
|
||||||
import { PlayerUtil } from '../util/PlayerUtil.js';
|
import { SteamUtil } from '../util/SteamUtil.js';
|
||||||
|
|
||||||
export class StationsModule {
|
export class StationsModule {
|
||||||
public static load() {
|
public static load() {
|
||||||
|
|
||||||
client.on(SimrailClientEvents.StationLeft, async (server: Server, station: Station, player: IPlayer, joinedAt: number) => {
|
client.on(SimrailClientEvents.StationLeft, async (server: Server, station: Station, player: IPlayer, joinedAt: number) => {
|
||||||
const stats = await PlayerUtil.getPlayerStats(player.steamid);
|
const stats = await SteamUtil.getPlayerStats(player.steamid);
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
if (stats) {
|
if (stats) {
|
||||||
const time = (date.getTime() - joinedAt) ?? 0;
|
const time = (date.getTime() - joinedAt) ?? 0;
|
||||||
|
|
||||||
const userProfile = await MProfile.findOne({ steam: player.steamid }) ?? await MProfile.create({ steam: player.steamid, id: v4(), steamName: player.personaname });
|
const userProfile = await MProfile.findOne({ steam: player.steamid }) ?? await MProfile.create({ steam: player.steamid, id: v4(), steamName: player.personaname });
|
||||||
if (!userProfile.dispatcherStats) userProfile.dispatcherStats = {};
|
if (!userProfile.dispatcherStats) userProfile.dispatcherStats = {};
|
||||||
|
|
||||||
if (userProfile.dispatcherStats[station.Name]) {
|
if (userProfile.dispatcherStats[station.Name]) {
|
||||||
userProfile.dispatcherStats[station.Name].time = userProfile.dispatcherStats[station.Name].time + time;
|
userProfile.dispatcherStats[station.Name].time = userProfile.dispatcherStats[station.Name].time + time;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
userProfile.dispatcherStats[station.Name] = {
|
userProfile.dispatcherStats[station.Name] = {
|
||||||
time
|
time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number.isNaN(userProfile.dispatcherStats[station.Name].time)) userProfile.dispatcherStats[station.Name].time = 0;
|
if (Number.isNaN(userProfile.dispatcherStats[station.Name].time)) userProfile.dispatcherStats[station.Name].time = 0;
|
||||||
|
|
||||||
if (!userProfile.dispatcherTime) userProfile.dispatcherTime = 0;
|
if (!userProfile.dispatcherTime) userProfile.dispatcherTime = 0;
|
||||||
|
@ -14,7 +14,7 @@ const fetchFuckingSteamApi = (url: string) => {
|
|||||||
console.log('STEAM request failed! ', url.replace(STEAM_API_KEY!, '[XXX]'), retries)
|
console.log('STEAM request failed! ', url.replace(STEAM_API_KEY!, '[XXX]'), retries)
|
||||||
|
|
||||||
retries++;
|
retries++;
|
||||||
setTimeout(() => req(), 500);
|
setTimeout(() => req(), 1000);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
req();
|
req();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user