Skip to content

Commit

Permalink
added 'fork-ts-checker-webpack-plugin' for better server side ts chec…
Browse files Browse the repository at this point in the history
…king
  • Loading branch information
shr0x committed May 17, 2024
1 parent 6401cfc commit 7b41cd5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
25 changes: 18 additions & 7 deletions config/webpack.server.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

const outputPath = path.join(__dirname, '../packages/server');
const pathToModules = path.join(__dirname, '../node_modules');


const entryPath = path.join(__dirname, '../source/server/index.ts');
const configPath = path.join(__dirname, '../source/server/tsconfig.json');
const sourcePath = path.join(__dirname, '../source/server/');


module.exports = {
entry: entryPath,
target: 'node',
mode: "development",
mode: 'development',
devtool: 'source-map', // Enable source maps for better error info
externals: [
nodeExternals({
modulesDir: pathToModules
})
],
plugins: [
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: configPath,
},
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader'
loader: 'ts-loader',
options: {
transpileOnly: true, // Set to true for faster builds
configFile: configPath,
},
},
exclude: pathToModules
}
]
},
resolve: {
plugins: [new TsconfigPathsPlugin({ configFile: configPath, baseUrl: sourcePath })],
extensions: ['.ts', '.js'],
extensions: ['.ts', '.tsx', '.js'],
mainFields: ['main']
},
output: {
Expand All @@ -48,5 +59,5 @@ module.exports = {
buildDependencies: {
config: [__filename]
}
}
};
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/lodash.clonedeep": "^4.5.7",
"@types/node": "^20.12.11",
"@types/uuid": "^9.0.1",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"tsconfig-paths-webpack-plugin": "^4.0.1",
"typescript": "^5.0.4",
"webpack": "^5.78.0",
Expand Down
1 change: 0 additions & 1 deletion source/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ async function initGamemode() {
console.log(green("╚██████╔╝██║ ██║██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║╚██████╔╝██████╔╝███████╗ ██║██║ ╚████║██║ ██║ "));
console.log(green(" ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝ "));
console.log(yellow("======================================================================================================"));

console.log(blue(`Server Events: ${Object.values(mp.events.binded).length}`));
console.log(blue(`Cef Events: ${RAGERP.cef.poolSize}`));
console.log(blue(`Total Commands: ${RAGERP.commands._commands.size}`));
Expand Down
12 changes: 5 additions & 7 deletions source/server/serverevents/Auth.event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { RAGERP } from "../api";
import { CefEvent } from "../classes/CEFEvent.class";
import { MainDataSource } from "../database/Database.module";
import { AccountEntity } from "../database/entity/Account.entity";
import crypto from "crypto";
import { CharacterEntity } from "../database/entity/Character.entity";
Expand All @@ -21,14 +19,14 @@ function hashPassword(text: string) {
return crypto.createHash("sha256").update(text).digest("hex");
}

CefEvent.register("auth", "register", async (player: PlayerMp, data: string) => {
RAGERP.cef.register("auth", "register", async (player: PlayerMp, data: string) => {
const { username, email, password, confirmPassword }: IPlayerRegister = JSON.parse(data);

if (username.length < 4 || username.length > 32) return player.showNotify(RageShared.Enums.NotifyType.TYPE_ERROR, "Your username must be between 4 and 32 characters.");
if (password.length < 5) return player.showNotify(RageShared.Enums.NotifyType.TYPE_ERROR, "Your password must contain at least 5 characters.");
if (password !== confirmPassword) return player.showNotify(RageShared.Enums.NotifyType.TYPE_ERROR, "Password mismatch.");

const accountExists = await MainDataSource.getRepository(AccountEntity).findOne({ where: { username, email } });
const accountExists = await RAGERP.database.getRepository(AccountEntity).findOne({ where: { username, email } });
if (accountExists) return player.showNotify(RageShared.Enums.NotifyType.TYPE_ERROR, "Account username or email exists.");

const accountData = new AccountEntity();
Expand All @@ -38,7 +36,7 @@ CefEvent.register("auth", "register", async (player: PlayerMp, data: string) =>
accountData.socialClubId = player.rgscId;
accountData.email = email;

const result = await MainDataSource.getRepository(AccountEntity).save(accountData);
const result = await RAGERP.database.getRepository(AccountEntity).save(accountData);

player.account = result;
player.name = player.account.username;
Expand All @@ -49,10 +47,10 @@ CefEvent.register("auth", "register", async (player: PlayerMp, data: string) =>
// player.showNotify("success", `Account registered successfully! Welcome ${player.account.username}`);
});

CefEvent.register("auth", "loginPlayer", async (player: PlayerMp, data: string) => {
RAGERP.cef.register("auth", "loginPlayer", async (player: PlayerMp, data: string) => {
const { username, password }: IPlayerLogin = JSON.parse(data);

const accountData = await MainDataSource.getRepository(AccountEntity).findOne({ where: { username: username.toLowerCase() } });
const accountData = await RAGERP.database.getRepository(AccountEntity).findOne({ where: { username: username.toLowerCase() } });
if (!accountData) return player.showNotify(RageShared.Enums.NotifyType.TYPE_ERROR, "We could not find that account!");

if (hashPassword(password) !== accountData.password) return player.showNotify(RageShared.Enums.NotifyType.TYPE_ERROR, "Wrong password.");
Expand Down

0 comments on commit 7b41cd5

Please sign in to comment.