mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 18:34:39 +00:00
* updata validation on public games
This commit is contained in:
@@ -57,7 +57,7 @@ export class UsernameInput extends LitElement {
|
||||
.value=${this.username}
|
||||
@input=${this.handleInput}
|
||||
placeholder="Enter your username"
|
||||
maxlength="123"
|
||||
maxlength="${MAX_USERNAME_LENGTH}"
|
||||
>
|
||||
${this.validationError
|
||||
? html`<div class="error">${this.validationError}</div>`
|
||||
|
||||
+38
-38
@@ -122,23 +122,20 @@ app.get('/private_lobby/:id', (req, res) => {
|
||||
|
||||
wss.on('connection', (ws, req) => {
|
||||
ws.on('message', (message: string) => {
|
||||
try {
|
||||
const clientMsg: ClientMessage = ClientMessageSchema.parse(JSON.parse(message))
|
||||
slog({
|
||||
logKey: 'websocket_msg',
|
||||
msg: 'server received websocket message',
|
||||
data: clientMsg,
|
||||
severity: LogSeverity.Debug
|
||||
})
|
||||
if (clientMsg.type == "join") {
|
||||
const forwarded = req.headers['x-forwarded-for']
|
||||
let ip = Array.isArray(forwarded)
|
||||
? forwarded[0] // Get the first IP if it's an array
|
||||
: forwarded || req.socket.remoteAddress;
|
||||
if (Array.isArray(ip)) {
|
||||
ip = ip[0]
|
||||
}
|
||||
const username = clientMsg.username;
|
||||
const clientMsg: ClientMessage = ClientMessageSchema.parse(JSON.parse(message))
|
||||
slog({
|
||||
logKey: 'websocket_msg',
|
||||
msg: 'server received websocket message',
|
||||
data: clientMsg,
|
||||
severity: LogSeverity.Debug
|
||||
})
|
||||
if (clientMsg.type == "join") {
|
||||
const forwarded = req.headers['x-forwarded-for']
|
||||
const ip = Array.isArray(forwarded)
|
||||
? forwarded[0] // Get the first IP if it's an array
|
||||
: forwarded || req.socket.remoteAddress;
|
||||
|
||||
const username = clientMsg.username;
|
||||
const { isValid, error } = validateUsername(username);
|
||||
if (!isValid) {
|
||||
const errorMsg = error || "Invalid username.";
|
||||
@@ -151,28 +148,31 @@ wss.on('connection', (ws, req) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// If username is valid, add the client
|
||||
gm.addClient(
|
||||
new Client(
|
||||
clientMsg.clientID,
|
||||
clientMsg.persistentID,
|
||||
ip,
|
||||
username,
|
||||
ws
|
||||
),
|
||||
clientMsg.gameID,
|
||||
clientMsg.lastTurn
|
||||
)
|
||||
// If username is valid, add the client
|
||||
gm.addClient(
|
||||
new Client(
|
||||
clientMsg.clientID,
|
||||
clientMsg.persistentID,
|
||||
ip,
|
||||
username,
|
||||
ws
|
||||
),
|
||||
clientMsg.gameID,
|
||||
clientMsg.lastTurn
|
||||
)
|
||||
}
|
||||
if (clientMsg.type == "log") {
|
||||
slog({
|
||||
logKey: "client_console_log",
|
||||
msg: clientMsg.log,
|
||||
severity: clientMsg.severity,
|
||||
clientID: clientMsg.clientID,
|
||||
gameID: clientMsg.gameID,
|
||||
persistentID: clientMsg.persistentID,
|
||||
})
|
||||
}
|
||||
if (clientMsg.type == "log") {
|
||||
slog({
|
||||
logKey: "client_console_log",
|
||||
msg: clientMsg.log,
|
||||
severity: clientMsg.severity,
|
||||
clientID: clientMsg.clientID,
|
||||
gameID: clientMsg.gameID,
|
||||
persistentID: clientMsg.persistentID,
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(`errror handling websocket message: ${error}`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`errror handling websocket message: ${error}`)
|
||||
|
||||
Reference in New Issue
Block a user