Skip to content

Commit

Permalink
fix: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Feb 19, 2024
1 parent fb06ca6 commit 5a5301b
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 38 deletions.
8 changes: 0 additions & 8 deletions packages/common/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ ENABLE_KEY_OVERLAY=true
POLL_RATE=150
# Once per value, the programme should read the values of keys K1/K2/M1/M2 (in milliseconds)
KEYOVERLAY_POLL_RATE=150
# Once in what value, the programme should send information about values to the websocket (overlay) (in milliseconds)
WS_SEND_INTERVAL=150
# Enables/disables the in-game gosumemory overlay (!!!I AM NOT RESPONSIBLE FOR USING IT!!!).
ENABLE_GOSU_OVERLAY=false
Expand Down Expand Up @@ -52,7 +50,6 @@ export const config = {
debugLogging: (process.env.DEBUG_LOG || '') === 'true',
calculatePP: (process.env.CALCULATE_PP || '') === 'true',
enableKeyOverlay: (process.env.ENABLE_KEY_OVERLAY || '') === 'true',
// wsSendInterval: Number(process.env.WS_SEND_INTERVAL || '500'),
pollRate: Number(process.env.POLL_RATE || '500'),
keyOverlayPollRate: Number(process.env.KEYOVERLAY_POLL_RATE || '100'),
serverIP: process.env.SERVER_IP || '127.0.0.1',
Expand All @@ -79,11 +76,6 @@ export const updateConfig = () => {
fs.appendFileSync(configPath, '\nENABLE_KEY_OVERLAY=true', 'utf8');
}

// if (!process.env.WS_SEND_INTERVAL) {
// newOptions += 'WS_SEND_INTERVAL, ';
// fs.appendFileSync(configPath, '\nWS_SEND_INTERVAL=150', 'utf8');
// }

if (!process.env.POLL_RATE) {
newOptions += 'POLL_RATE, ';
fs.appendFileSync(configPath, '\nPOLL_RATE=150', 'utf8');
Expand Down
12 changes: 4 additions & 8 deletions packages/server/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ export class HttpServer {
private middlewares: RequestHandler[] = [];
server: http.Server;
private routes: {
[method: string]: [
{
path: string | RegExp;
handler: RouteHandler;
}
];
[method: string]: {
path: string | RegExp;
handler: RouteHandler;
}[];
} = {};

constructor() {
Expand All @@ -59,10 +57,8 @@ export class HttpServer {
| 'PATCH',
handler: RouteHandler
) {
// @ts-ignore
if (this.routes[method] == null) this.routes[method] = [];

// @ts-ignore
const find = this.routes[method].find((r) => r.path == path);
if (!find) this.routes[method].push({ path, handler });
}
Expand Down
8 changes: 3 additions & 5 deletions packages/tosu/src/api/handlers/songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import path from 'path';

import { readDirectory } from '../utils/reader';

const currentVersion = require(process.cwd() + '/_version.js');

export const readSongsFolder = (
req: ExtendedIncomingMessage,
res: http.ServerResponse
Expand All @@ -21,7 +19,7 @@ export const readSongsFolder = (
);
if (osuInstances.length < 1) {
res.statusCode = 500;
return res.end('nothing');
return sendJson(res, { error: 'not_ready' });
}

const { settings } = osuInstances[0].entities.getServices(['settings']);
Expand All @@ -48,12 +46,12 @@ export const readSongsFolder = (
if (err) {
if (err.code === 'ENOENT') {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end(`[${currentVersion}] 404 Not Found`);
res.end(`404 Not Found`);
return;
}

res.writeHead(500);
res.end(`[${currentVersion}] Server Error: ${err.code}`);
res.end(`Server Error: ${err.code}`);
return;
}

Expand Down
6 changes: 2 additions & 4 deletions packages/tosu/src/api/router/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import path from 'path';

import { readDirectory } from '../utils/reader';

const currentVersion = require(process.cwd() + '/_version.js');

export const baseApi = (app: HttpServer) => {
app.route('/json', 'GET', (req, res) => {
const osuInstances: any = Object.values(
req.instanceManager.osuInstances || {}
);
if (osuInstances.length < 1) {
res.statusCode = 500;
return res.end('nothing');
return sendJson(res, { error: 'not_ready' });
}

const json = osuInstances[0].getState(req.instanceManager);
Expand Down Expand Up @@ -75,7 +73,7 @@ export const baseApi = (app: HttpServer) => {
}

res.writeHead(500);
res.end(`[${currentVersion}] Server Error: ${err.code}`);
res.end(`Server Error: ${err.code}`);
});
});
};
10 changes: 4 additions & 6 deletions packages/tosu/src/api/router/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import path from 'path';
import { readSongsFolder } from '../handlers/songs';
import { readDirectory } from '../utils/reader';

const currentVersion = require(process.cwd() + '/_version.js');

export const ApiV2 = ({
app,
webSocket,
Expand Down Expand Up @@ -38,7 +36,7 @@ export const ApiV2 = ({
);
if (osuInstances.length < 1) {
res.statusCode = 500;
return res.end('nothing');
return sendJson(res, { error: 'not_ready' });
}

const json = osuInstances[0].getStateV2(req.instanceManager);
Expand All @@ -55,7 +53,7 @@ export const ApiV2 = ({
);
if (osuInstances.length < 1) {
res.statusCode = 500;
return res.end('nothing');
return sendJson(res, { error: 'not_ready' });
}

const { settings } = osuInstances[0].entities.getServices(['settings']);
Expand Down Expand Up @@ -90,12 +88,12 @@ export const ApiV2 = ({
if (err) {
if (err.code === 'ENOENT') {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end(`[${currentVersion}] 404 Not Found`);
res.end(`404 Not Found`);
return;
}

res.writeHead(500);
res.end(`[${currentVersion}] Server Error: ${err.code}`);
res.end(`Server Error: ${err.code}`);
return;
}

Expand Down
1 change: 0 additions & 1 deletion packages/tosu/src/api/types/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ export interface Hits3 {
'300': number;
geki: number;
katu: number;
unstableRate: string;
}

export interface Mods3 {
Expand Down
7 changes: 5 additions & 2 deletions packages/tosu/src/api/utils/accuracy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface types {
export interface IRankCalculate {
(
hits: {
300: any;
Expand All @@ -12,7 +12,10 @@ export interface types {
): number;
}

const accuracyCalculator: types = (hits, mode = 'osu') => {
/**
* Used to calculate accuracy out of hits (mainly for leaderboards)
*/
const accuracyCalculator: IRankCalculate = (hits, mode = 'osu') => {
const h300 = parseInt(hits[300]);
const h100 = parseInt(hits[100]);
const h50 = parseInt(hits[50]);
Expand Down
5 changes: 1 addition & 4 deletions packages/tosu/src/api/utils/buildResultV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ export const buildResult = (
}
},
profile: {
// profile: {

id: userProfile.id,
name: userProfile.name,
mode: {
Expand Down Expand Up @@ -334,8 +332,7 @@ export const buildResult = (
100: resultsScreenData.Hit100,
katu: resultsScreenData.HitKatu,
50: resultsScreenData.Hit50,
0: resultsScreenData.HitMiss,
unstableRate: '' // dont have
0: resultsScreenData.HitMiss
},
mods: {
number: resultsScreenData.Mods,
Expand Down

0 comments on commit 5a5301b

Please sign in to comment.