mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-12-03 05:10:04 +01:00
Validate editor actions and note length
This commit is contained in:
1 parent
e37036a67f
commit
a95f62e236
1 file changed
+21
-2
@@ -59,6 +59,8 @@ const playerActionNames = [
|
||||
];
|
||||
|
||||
const editorAdded = new Map<string, AddedEntity[]>();
|
||||
const MAX_EDITOR_BRUSH_SIZE = 16;
|
||||
const MAX_NOTE_LENGTH = 2000;
|
||||
const debugRate = DEVELOPMENT ? '1000/s' : '';
|
||||
|
||||
@Socket({
|
||||
@@ -517,7 +519,8 @@ export class ServerActions implements IServerActions, SocketServer {
|
||||
this.updateLastAction();
|
||||
|
||||
const client = this.getClientForModAction(entityId, 'setNote');
|
||||
await this.accountService.update(client.accountId, { note: text });
|
||||
const note = text === null ? text : text.substr(0, MAX_NOTE_LENGTH);
|
||||
await this.accountService.update(client.accountId, { note });
|
||||
}
|
||||
@Method({ rateLimit: '5/s', binary: [Bin.Obj] })
|
||||
async saveSettings(settings: AccountSettings) {
|
||||
@@ -668,6 +671,10 @@ export class ServerActions implements IServerActions, SocketServer {
|
||||
}
|
||||
@Method({ binary: [Bin.Obj] })
|
||||
editorAction(action: EditorAction) {
|
||||
if (!action || typeof action !== 'object') {
|
||||
throw new Error(`Invalid editor action`);
|
||||
}
|
||||
|
||||
if (this.server.flags.editor && this.client.isMod) {
|
||||
const added = editorAdded.get(this.client.accountId) || [];
|
||||
editorAdded.set(this.client.accountId, added);
|
||||
@@ -686,6 +693,10 @@ export class ServerActions implements IServerActions, SocketServer {
|
||||
}
|
||||
break;
|
||||
case 'move':
|
||||
if (!Array.isArray(action.entities)) {
|
||||
throw new Error(`Invalid editor action (move)`);
|
||||
}
|
||||
|
||||
for (const { id, x, y } of action.entities) {
|
||||
const entity = this.world.getEntityById(id);
|
||||
|
||||
@@ -715,6 +726,10 @@ export class ServerActions implements IServerActions, SocketServer {
|
||||
this.client.entityList(existingEntities);
|
||||
break;
|
||||
case 'remove':
|
||||
if (!Array.isArray(action.entities)) {
|
||||
throw new Error(`Invalid editor action (remove)`);
|
||||
}
|
||||
|
||||
for (const id of action.entities) {
|
||||
const entity = this.world.getEntityById(id);
|
||||
|
||||
@@ -724,7 +739,11 @@ export class ServerActions implements IServerActions, SocketServer {
|
||||
}
|
||||
break;
|
||||
case 'tile': {
|
||||
const { x, y, tile, size } = action;
|
||||
const { x, y, tile } = action;
|
||||
validateNumber(x, 'x');
|
||||
validateNumber(y, 'y');
|
||||
validateNumber(action.size, 'size');
|
||||
const size = clamp(action.size | 0, 1, MAX_EDITOR_BRUSH_SIZE);
|
||||
|
||||
if (isValidModTile(tile)) {
|
||||
for (let iy = 0; iy < size; iy++) {
|
||||
|
||||
Reference in new issue
Block a user