Skip to content

Commit

Permalink
feat: Renamed KEYOVERLAY_POLL_RATE to PRECISE_DATA_POLL_RATE
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark authored and KotRikD committed Mar 10, 2024
1 parent a77f737 commit bc9dadd
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 100 deletions.
51 changes: 32 additions & 19 deletions packages/common/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ const configPath = path.join(
'pkg' in process ? path.dirname(process.execPath) : process.cwd(),
'tsosu.env'
);
if (!fs.existsSync(configPath)) {
fs.writeFileSync(
configPath,
`# The config implies a set of key-values to enable/disable tosu functionality

const createConfig = () => {
if (!fs.existsSync(configPath)) {
fs.writeFileSync(
configPath,
`# The config implies a set of key-values to enable/disable tosu functionality
# Below you can see that there is EVERY_THE_FUNCTION=true/false,
# true = on
# false = off
Expand All @@ -23,9 +25,9 @@ ENABLE_KEY_OVERLAY=true
# Reference: 1 second = 1000 milliseconds
# Once in what value, the programme should read the game values (in milliseconds)
POLL_RATE=150
POLL_RATE=100
# Once per value, the programme should read the values of keys K1/K2/M1/M2 (in milliseconds)
KEYOVERLAY_POLL_RATE=150
PRECISE_DATA_POLL_RATE=100
# Enables/disables the in-game gosumemory overlay (!!!I AM NOT RESPONSIBLE FOR USING IT!!!).
ENABLE_GOSU_OVERLAY=false
Expand All @@ -44,9 +46,10 @@ SERVER_IP=127.0.0.1
SERVER_PORT=24050
# The folder from which the overlays will be taken.
STATIC_FOLDER_PATH=./static`,
'utf8'
);
}
'utf8'
);
}
};

dotenv.config({ path: configPath });

Expand All @@ -55,7 +58,11 @@ export const config = {
calculatePP: (process.env.CALCULATE_PP || '') === 'true',
enableKeyOverlay: (process.env.ENABLE_KEY_OVERLAY || '') === 'true',
pollRate: Number(process.env.POLL_RATE || '500'),
keyOverlayPollRate: Number(process.env.KEYOVERLAY_POLL_RATE || '100'),
preciseDataPollRate: Number(
process.env.PRECISE_DATA_POLL_RATE ||
process.env.KEYOVERLAY_POLL_RATE ||
'100'
),
serverIP: process.env.SERVER_IP || '127.0.0.1',
serverPort: Number(process.env.SERVER_PORT || '24050'),
staticFolderPath: process.env.STATIC_FOLDER_PATH || './static',
Expand Down Expand Up @@ -83,12 +90,12 @@ export const updateConfigFile = () => {

if (!process.env.POLL_RATE) {
newOptions += 'POLL_RATE, ';
fs.appendFileSync(configPath, '\nPOLL_RATE=150', 'utf8');
fs.appendFileSync(configPath, '\nPOLL_RATE=100', 'utf8');
}

if (!process.env.KEYOVERLAY_POLL_RATE) {
newOptions += 'KEYOVERLAY_POLL_RATE, ';
fs.appendFileSync(configPath, '\nKEYOVERLAY_POLL_RATE=150', 'utf8');
if (!process.env.PRECISE_DATA_POLL_RATE) {
newOptions += 'PRECISE_DATA_POLL_RATE, ';
fs.appendFileSync(configPath, '\n\nPRECISE_DATA_POLL_RATE=100', 'utf8');
}

if (!process.env.SERVER_IP) {
Expand Down Expand Up @@ -127,6 +134,10 @@ export const watchConfigFile = ({
updateConfigFile();
}

if (!fs.existsSync(configPath)) {
createConfig();
}

const stat = fs.statSync(configPath);
if (config.timestamp != stat.mtimeMs) {
refreshConfig(httpServer, true);
Expand All @@ -153,8 +164,10 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => {
const serverPort = Number(parsed.SERVER_PORT || '24050');
const calculatePP = (parsed.CALCULATE_PP || '') === 'true';
const enableKeyOverlay = (parsed.ENABLE_KEY_OVERLAY || '') === 'true';
const pollRate = Number(parsed.POLL_RATE || '500');
const keyOverlayPollRate = Number(parsed.KEYOVERLAY_POLL_RATE || '100');
const pollRate = Number(parsed.POLL_RATE || '100');
const preciseDataPollRate = Number(
parsed.PRECISE_DATA_POLL_RATE || parsed.KEYOVERLAY_POLL_RATE || '100'
);
const staticFolderPath = parsed.STATIC_FOLDER_PATH || './static';
const enableGosuOverlay = (parsed.ENABLE_GOSU_OVERLAY || '') === 'true';

Expand All @@ -164,7 +177,7 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => {
config.calculatePP != calculatePP ||
config.enableKeyOverlay != enableKeyOverlay ||
config.pollRate != pollRate ||
config.keyOverlayPollRate != keyOverlayPollRate ||
config.preciseDataPollRate != preciseDataPollRate ||
config.staticFolderPath != staticFolderPath ||
config.enableGosuOverlay != enableGosuOverlay ||
config.serverIP != serverIP ||
Expand Down Expand Up @@ -192,8 +205,8 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => {
config.calculatePP = calculatePP;
config.enableKeyOverlay = enableKeyOverlay;
config.pollRate = pollRate >= 0 ? pollRate : 100;
config.keyOverlayPollRate =
keyOverlayPollRate >= 0 ? keyOverlayPollRate : 100;
config.preciseDataPollRate =
preciseDataPollRate >= 0 ? preciseDataPollRate : 100;
config.staticFolderPath = staticFolderPath;
config.enableGosuOverlay = enableGosuOverlay;

Expand Down
8 changes: 4 additions & 4 deletions packages/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export class Server {
pollRateFieldName: 'pollRate',
stateFunctionName: 'getStateV2'
});
const WS_V2_KEYS = new Websocket({
const WS_V2_PRECISE = new Websocket({
instanceManager: this.instanceManager,
pollRateFieldName: 'keyOverlayPollRate',
stateFunctionName: 'getKeyOverlay'
pollRateFieldName: 'preciseDataPollRate',
stateFunctionName: 'getPreciseData'
});

buildBaseApi(this);
Expand All @@ -41,7 +41,7 @@ export class Server {
buildV2Api({
app: this.app,
websocket: WS_V2,
keysWebsocket: WS_V2_KEYS
preciseWebsocket: WS_V2_PRECISE
});

this.app.listen(config.serverPort, config.serverIP);
Expand Down
10 changes: 5 additions & 5 deletions packages/server/router/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { directoryWalker } from '../utils/directories';
export default function buildV2Api({
app,
websocket,
keysWebsocket
preciseWebsocket
}: {
app: HttpServer;
websocket: Websocket;
keysWebsocket: Websocket;
preciseWebsocket: Websocket;
}) {
app.server.on('upgrade', function (request, socket, head) {
if (request.url == '/websocket/v2') {
Expand All @@ -25,12 +25,12 @@ export default function buildV2Api({
}

if (request.url == '/websocket/v2/keys') {
keysWebsocket.socket.handleUpgrade(
preciseWebsocket.socket.handleUpgrade(
request,
socket,
head,
function (ws) {
keysWebsocket.socket.emit('connection', ws, request);
preciseWebsocket.socket.emit('connection', ws, request);
}
);
}
Expand Down Expand Up @@ -58,7 +58,7 @@ export default function buildV2Api({
return sendJson(res, { error: 'not_ready' });
}

const json = osuInstances[0].getKeyOverlay();
const json = osuInstances[0].getPreciseData();
sendJson(res, json);
});

Expand Down
35 changes: 13 additions & 22 deletions packages/server/utils/counters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export function buildSettings(res: http.ServerResponse) {
.replace('{NAME}', `ENABLE_KEY_OVERLAY`)
.replace(
'{DESCRIPTION}',
`Enables/disables reading K1/K2/M1/M2 keys on the keyboard`
`Enables/disable reading of K1/K2/M1/M2 keys from osu`
)
.replace(
'{INPUT}',
Expand All @@ -378,7 +378,7 @@ export function buildSettings(res: http.ServerResponse) {
.replace('{NAME}', `ENABLE_GOSU_OVERLAY`)
.replace(
'{DESCRIPTION}',
`Enables/disables the in-game gosumemory overlay<br>(!!!I AM NOT RESPONSIBLE FOR USING IT!!!)`
`Enables/disable in-game <b>gosumemory</b> overlay<br />(!!!I AM NOT RESPONSIBLE FOR USING IT!!!)`
)
.replace(
'{INPUT}',
Expand All @@ -395,7 +395,7 @@ export function buildSettings(res: http.ServerResponse) {
.replace('{NAME}', `POLL_RATE`)
.replace(
'{DESCRIPTION}',
`Once in what value, the programme should read the game values (in milliseconds)`
`Frequency in milliseconds for updating information.`
)
.replace(
'{INPUT}',
Expand All @@ -406,27 +406,24 @@ export function buildSettings(res: http.ServerResponse) {
.replace('{VALUE}', `${config.pollRate}`)
);

const keyOverlayPollRateHTML = settingsItemHTML
.replace('{NAME}', `KEYOVERLAY_POLL_RATE`)
const preciseDataPollRateHTML = settingsItemHTML
.replace('{NAME}', `PRECISE_DATA_POLL_RATE`)
.replace(
'{DESCRIPTION}',
`Once per value, the programme should read the values of keys K1/K2/M1/M2 (in milliseconds)`
`Frequency in milliseconds for updating precise information. (Key overlay and HitErrorData)`
)
.replace(
'{INPUT}',
inputHTML
.replace('{TYPE}', 'number')
.replace(/{NAME}/gm, 'KEYOVERLAY_POLL_RATE')
.replace('{ADDON}', config.keyOverlayPollRate ? 'min="0"' : '')
.replace('{VALUE}', `${config.keyOverlayPollRate}`)
.replace(/{NAME}/gm, 'PRECISE_DATA_POLL_RATE')
.replace('{ADDON}', config.preciseDataPollRate ? 'min="0"' : '')
.replace('{VALUE}', `${config.preciseDataPollRate}`)
);

const serverIPHTML = settingsItemHTML
.replace('{NAME}', `SERVER_IP`)
.replace(
'{DESCRIPTION}',
`IP address where the websocket api server will be registered`
)
.replace('{DESCRIPTION}', `The IP address for the API and WebSocket.`)
.replace(
'{INPUT}',
inputHTML
Expand All @@ -438,10 +435,7 @@ export function buildSettings(res: http.ServerResponse) {

const serverPortHTML = settingsItemHTML
.replace('{NAME}', `SERVER_PORT`)
.replace(
'{DESCRIPTION}',
`The port on which the websocket api server will run`
)
.replace('{DESCRIPTION}', `The port for the API and WebSocket.`)
.replace(
'{INPUT}',
inputHTML
Expand All @@ -453,10 +447,7 @@ export function buildSettings(res: http.ServerResponse) {

const staticFolderPathtHTML = settingsItemHTML
.replace('{NAME}', `STATIC_FOLDER_PATH`)
.replace(
'{DESCRIPTION}',
`The folder from which the overlays will be taken.`
)
.replace('{DESCRIPTION}', `The directory path containing PP counters.`)
.replace(
'{INPUT}',
inputHTML
Expand All @@ -472,7 +463,7 @@ export function buildSettings(res: http.ServerResponse) {
${enableKeyOverlayHTML}
${enableGosuOverlayHTML}
${pollRateHTML}
${keyOverlayPollRateHTML}
${preciseDataPollRateHTML}
${serverIPHTML}
${serverPortHTML}
${staticFolderPathtHTML}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/utils/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Websocket {
}: {
instanceManager: any;
pollRateFieldName: string;
stateFunctionName: string;
stateFunctionName: 'getState' | 'getStateV2' | 'getPreciseData';
}) {
this.socket = new WebSocket.Server({ noServer: true });

Expand Down
28 changes: 9 additions & 19 deletions packages/tosu/src/api/types/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,29 +457,19 @@ export interface Combo2 {
max: number;
}

export interface ApiKeysAnswer {
k1: K1;
k2: K2;
m1: M1;
m2: M2;
export interface PreciseApiAnswer {
keys: KeyOverlay;
hitErrors: number[];
}

export interface K1 {
isPressed: boolean;
count: number;
}

export interface K2 {
isPressed: boolean;
count: number;
}

export interface M1 {
isPressed: boolean;
count: number;
interface KeyOverlay {
k1: KeyOverlayButton;
k2: KeyOverlayButton;
m1: KeyOverlayButton;
m2: KeyOverlayButton;
}

export interface M2 {
interface KeyOverlayButton {
isPressed: boolean;
count: number;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/tosu/src/api/utils/buildResultV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { fixDecimals } from '@/utils/converters';
import { getOsuModsString } from '@/utils/osuMods';

import {
ApiKeysAnswer,
ApiV2Answer,
BanchoStatusEnum,
BeatmapStatuses,
Expand All @@ -18,6 +17,7 @@ import {
Leaderboard,
LeaderboardType,
Modes,
PreciseApiAnswer,
ProgressBarType,
ScoreMeterType,
SortType,
Expand Down Expand Up @@ -455,7 +455,7 @@ export const buildResult = (
};
};

export const buildKeyOverlay = (service: DataRepo): ApiKeysAnswer => {
export const buildPreciseResult = (service: DataRepo): PreciseApiAnswer => {
const { gamePlayData } = service.getServices(['gamePlayData']);

return {
Expand Down
Loading

0 comments on commit bc9dadd

Please sign in to comment.