NOT-OMEGA commited on
Commit
84452a8
·
verified ·
1 Parent(s): 1c73348

Update main.cpp

Browse files
Files changed (1) hide show
  1. main.cpp +14 -11
main.cpp CHANGED
@@ -303,17 +303,20 @@ private:
303
  void handle_message(const std::string& raw,
304
  std::shared_ptr<collab::Document> doc)
305
  {
306
- json msg;
307
- try { msg = json::parse(raw); } catch (...) { return; }
308
-
309
- std::string type = msg.value("type", "");
310
- if (type == "operation") handle_operation(msg, doc);
311
- else if (type == "cursor") handle_cursor(msg);
312
- else if (type == "title_change") handle_title_change(msg);
313
- else if (type == "ping") {
314
- json pong = msg;
315
- pong["type"] = "pong";
316
- enqueue_send(pong.dump());
 
 
 
317
  }
318
  }
319
 
 
303
  void handle_message(const std::string& raw,
304
  std::shared_ptr<collab::Document> doc)
305
  {
306
+ try {
307
+ json msg = json::parse(raw);
308
+ std::string type = msg.value("type", "");
309
+ if (type == "operation") handle_operation(msg, doc);
310
+ else if (type == "cursor") handle_cursor(msg);
311
+ else if (type == "title_change") handle_title_change(msg);
312
+ else if (type == "ping") {
313
+ json pong = msg;
314
+ pong["type"] = "pong";
315
+ enqueue_send(pong.dump());
316
+ }
317
+ } catch (...) {
318
+ // Ignore malformed messages or type errors to prevent crashing
319
+ return;
320
  }
321
  }
322