mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-16 14:42:48 +00:00
+ add validation server side
This commit is contained in:
+17
-2
@@ -12,6 +12,7 @@ import { GamePhase, GameServer } from './GameServer';
|
||||
import { archive } from './Archive';
|
||||
import { DiscordBot } from './DiscordBot';
|
||||
import {MAX_USERNAME_LENGTH, MIN_USERNAME_LENGTH} from "../core/Util";
|
||||
import {validateUsername} from "../core/validations/username";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -148,12 +149,26 @@ wss.on('connection', (ws, req) => {
|
||||
if (Array.isArray(ip)) {
|
||||
ip = ip[0]
|
||||
}
|
||||
gm.addClient(
|
||||
const username = clientMsg.username;
|
||||
const { isValid, error } = validateUsername(username);
|
||||
if (!isValid) {
|
||||
const errorMsg = error || "Invalid username.";
|
||||
// Send error back to the client
|
||||
ws.send(JSON.stringify({
|
||||
type: 'error',
|
||||
input: 'username-input',
|
||||
message: errorMsg,
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// If username is valid, add the client
|
||||
gm.addClient(
|
||||
new Client(
|
||||
clientMsg.clientID,
|
||||
clientMsg.persistentID,
|
||||
ip,
|
||||
clientMsg.username,
|
||||
username,
|
||||
ws
|
||||
),
|
||||
clientMsg.gameID,
|
||||
|
||||
Reference in New Issue
Block a user