diff options
| author | RblSb <msrblsb@gmail.com> | 2020-05-11 02:33:19 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-05-11 02:33:19 +0300 |
| commit | cd98a6fa51c8e18c13c62603d67a0880c53e729a (patch) | |
| tree | 1fec3b35cacc66d61bbbbdd68258453394382a53 /src | |
| parent | 89063941699b71cbed2a523e978477cdc286f4a4 (diff) | |
Use json2object for data validation
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/Main.hx | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/server/Main.hx b/src/server/Main.hx index 0023c5f..97e7ed7 100644 --- a/src/server/Main.hx +++ b/src/server/Main.hx @@ -11,6 +11,7 @@ import js.npm.ws.Server as WSServer; import js.npm.ws.WebSocket; import js.node.http.IncomingMessage; import js.node.Http; +import json2object.JsonParser; import Client.ClientData; import Types.Config; import Types.Permission; @@ -36,6 +37,7 @@ class Main { final userList:UserList; final clients:Array<Client> = []; final freeIds:Array<Int> = []; + final wsEventParser = new JsonParser<WsEvent>(); final consoleInput:ConsoleInput; final videoList = new VideoList(); final videoTimer = new VideoTimer(); @@ -261,7 +263,13 @@ class Main { sendClientList(); ws.on("message", data -> { - onMessage(client, Json.parse(data)); + final obj = wsEventParser.fromJson(data); + if (wsEventParser.errors.length > 0) { + trace('Wrong request for type "${obj.type}":'); + trace(wsEventParser.errors.toString()); + return; + } + onMessage(client, obj); }); ws.on("close", err -> { trace('Client ${client.name} disconnected'); |
