RunicVTT Open Source Virtual Tabletop for TTRPG using P2P
Loading...
Searching...
No Matches
msg Namespace Reference

Namespaces

namespace  chatkey
 
namespace  dc
 
namespace  key
 
namespace  signaling
 
namespace  value
 

Classes

struct  BoardMeta
 
struct  InboundRaw
 
struct  MarkerMeta
 
struct  NetEvent
 
struct  ReadyMessage
 

Typedefs

using Json = nlohmann::json
 

Enumerations

enum class  DCType : uint8_t {
  Snapshot_GameTable = 100 , Snapshot_Board = 101 , CommitMarker = 102 , CommitBoard = 103 ,
  ImageChunk = 104 , MarkerMove = 150 , MarkerMoveState = 151 , MarkerCreate = 1 ,
  MarkerUpdate = 2 , MarkerDelete = 3 , FogCreate = 4 , FogUpdate = 5 ,
  FogDelete = 6 , GridUpdate = 7 , NoteCreate = 8 , NoteUpdate = 9 ,
  NoteDelete = 10 , UserNameUpdate = 105 , ChatGroupCreate = 200 , ChatGroupUpdate = 201 ,
  ChatGroupDelete = 202 , ChatMessage = 203
}
 
enum class  ImageOwnerKind : uint8_t { Board = 0 , Marker = 1 }
 

Functions

std::string DCtypeString (DCType type)
 
const char * DCTypeToJson (DCType t)
 
bool DCTypeFromJson (std::string_view s, DCType &out)
 
Json makeChatGroupCreate (uint64_t tableId, uint64_t groupId, const std::string &name, const std::set< std::string > &participants)
 
Json makeChatGroupUpdate (uint64_t tableId, uint64_t groupId, const std::string &name, const std::set< std::string > &participants)
 
Json makeChatGroupDelete (uint64_t tableId, uint64_t groupId)
 
Json makeChatMessage (uint64_t tableId, uint64_t groupId, uint64_t ts, const std::string &username, const std::string &text)
 
Json makeOffer (const std::string &from, const std::string &to, const std::string &sdp, const std::string &username, const std::string &uniqueId, const std::string &broadcast=msg::value::False)
 
Json makeAnswer (const std::string &from, const std::string &to, const std::string &sdp, const std::string &username, const std::string &uniqueId, const std::string &broadcast=msg::value::False)
 
Json makeCandidate (const std::string &from, const std::string &to, const std::string &cand, const std::string &broadcast=msg::value::False)
 
Json makePresence (const std::string &event, const std::string &clientId)
 
nlohmann::json makePeerDisconnect (const std::string &targetPeerId, bool broadcast=true)
 
Json makeBroadcastShutdown ()
 
Json makePing (const std::string &from)
 
Json makeAuth (const std::string &token, const std::string &username, const std::string &uniqueId)
 
nlohmann::json makeAuthResponse (const std::string ok, const std::string &msg, const std::string &clientId, const std::string &username, const std::vector< std::string > &clients={}, const std::string &gmPeerId="", const std::string &uniqueId="")
 
Json makeText (const std::string &from, const std::string &to, const std::string &text, bool broadcast=false)
 
bool isType (const Json &j, std::string t)
 
std::string getString (const Json &j, std::string k, std::string def={})
 
int getInt (const Json &j, std::string k, int def=0)
 
bool getBool (const Json &j, std::string k, bool def=false)
 

Typedef Documentation

◆ Json

using msg::Json = nlohmann::json

Definition at line 363 of file Message.h.

Enumeration Type Documentation

◆ DCType

enum class msg::DCType : uint8_t
strong
Enumerator
Snapshot_GameTable 
Snapshot_Board 
CommitMarker 
CommitBoard 
ImageChunk 
MarkerMove 
MarkerMoveState 
MarkerCreate 
MarkerUpdate 
MarkerDelete 
FogCreate 
FogUpdate 
FogDelete 
GridUpdate 
NoteCreate 
NoteUpdate 
NoteDelete 
UserNameUpdate 
ChatGroupCreate 
ChatGroupUpdate 
ChatGroupDelete 
ChatMessage 

Definition at line 30 of file Message.h.

31 {
32 // Snapshots and Composite Operations
34 Snapshot_Board = 101,
35 CommitMarker = 102,
36 CommitBoard = 103,
37 ImageChunk = 104,
38
39 //Operations
40 MarkerMove = 150,
41 MarkerMoveState = 151,
42 MarkerCreate = 1,
43 MarkerUpdate = 2, //Position and/or Visibility
44 MarkerDelete = 3,
45 FogCreate = 4,
46 FogUpdate = 5, //Size and/or Visibility
47 FogDelete = 6,
48 GridUpdate = 7, //Position, Size and/or Visibility
49 NoteCreate = 8,
50 NoteUpdate = 9, //Metadata and/or Content
51 NoteDelete = 10,
52
53 UserNameUpdate = 105, // Game channel: broadcast username changes
54
55 // chat ops (binary)
56 ChatGroupCreate = 200,
57 ChatGroupUpdate = 201,
58 ChatGroupDelete = 202,
59 ChatMessage = 203
60 };

◆ ImageOwnerKind

enum class msg::ImageOwnerKind : uint8_t
strong
Enumerator
Board 
Marker 

Definition at line 139 of file Message.h.

140 {
141 Board = 0,
142 Marker = 1
143 };

Function Documentation

◆ DCTypeFromJson()

bool msg::DCTypeFromJson ( std::string_view s,
DCType & out )
inline

Definition at line 322 of file Message.h.

323 {
324 if (s == "ChatGroupCreate")
325 {
326 out = DCType::ChatGroupCreate;
327 return true;
328 }
329 if (s == "ChatGroupUpdate")
330 {
331 out = DCType::ChatGroupUpdate;
332 return true;
333 }
334 if (s == "ChatGroupDelete")
335 {
336 out = DCType::ChatGroupDelete;
337 return true;
338 }
339 if (s == "ChatMessage")
340 {
341 out = DCType::ChatMessage;
342 return true;
343 }
344 return false;
345 }
Here is the caller graph for this function:

◆ DCtypeString()

std::string msg::DCtypeString ( DCType type)
inline

Definition at line 61 of file Message.h.

62 {
63 std::string type_str;
64 switch (type)
65 {
67 type_str = "Snapshot_GameTable";
68 break;
70 type_str = "Snapshot_Board";
71 break;
73 type_str = "CommitMarker";
74 break;
76 type_str = "CommitBoard";
77 break;
79 type_str = "ImageChunk";
80 break;
82 type_str = "MarkerCreate";
83 break;
85 type_str = "MarkerUpdate";
86 break;
88 type_str = "MarkerDelete";
89 break;
91 type_str = "FogCreate";
92 break;
94 type_str = "FogUpdate";
95 break;
97 type_str = "FogDelete";
98 break;
100 type_str = "GridUpdate";
101 break;
103 type_str = "NoteCreate";
104 break;
106 type_str = "NoteUpdate";
107 break;
109 type_str = "NoteDelete";
110 break;
112 type_str = "ChatThreadCreate";
113 break;
115 type_str = "ChatThreadUpdate";
116 break;
118 type_str = "ChatThreadDelete";
119 break;
121 type_str = "ChatMessage";
122 break;
124 type_str = "MarkerMove";
125 break;
127 type_str = "MarkerMoveState";
128 break;
130 type_str = "UserNameUpdate";
131 break;
132 default:
133 type_str = "UnkownType";
134 break;
135 }
136 return type_str;
137 }
Here is the caller graph for this function:

◆ DCTypeToJson()

const char * msg::DCTypeToJson ( DCType t)
inline

Definition at line 306 of file Message.h.

307 {
308 switch (t)
309 {
310 case DCType::ChatGroupCreate:
311 return "ChatGroupCreate";
312 case DCType::ChatGroupUpdate:
313 return "ChatGroupUpdate";
314 case DCType::ChatGroupDelete:
315 return "ChatGroupDelete";
316 case DCType::ChatMessage:
317 return "ChatMessage";
318 default:
319 return "";
320 }
321 }
Here is the caller graph for this function:

◆ getBool()

bool msg::getBool ( const Json & j,
std::string k,
bool def = false )
inline

Definition at line 589 of file Message.h.

590 {
591 auto it = j.find(std::string(k));
592 return (it != j.end() && it->is_boolean()) ? it->get<bool>() : def;
593 }

◆ getInt()

int msg::getInt ( const Json & j,
std::string k,
int def = 0 )
inline

Definition at line 584 of file Message.h.

585 {
586 auto it = j.find(std::string(k));
587 return (it != j.end() && it->is_number_integer()) ? it->get<int>() : def;
588 }

◆ getString()

std::string msg::getString ( const Json & j,
std::string k,
std::string def = {} )
inline

Definition at line 579 of file Message.h.

579 {})
580 {
581 auto it = j.find(std::string(k));
582 return (it != j.end() && it->is_string()) ? it->get<std::string>() : std::move(def);
583 }
Here is the caller graph for this function:

◆ isType()

bool msg::isType ( const Json & j,
std::string t )
inline

Definition at line 572 of file Message.h.

573 {
574 auto it = j.find(std::string(key::Type));
575 return it != j.end() && it->is_string() && it->get_ref<const std::string&>() == t;
576 }

◆ makeAnswer()

Json msg::makeAnswer ( const std::string & from,
const std::string & to,
const std::string & sdp,
const std::string & username,
const std::string & uniqueId,
const std::string & broadcast = msg::value::False )
inline

Definition at line 433 of file Message.h.

437 {
438 return Json{
439 {std::string(key::Type), std::string(signaling::Answer)},
440 {std::string(key::From), from},
441 {std::string(key::To), to},
442 {std::string(key::Broadcast), broadcast},
443 {std::string(key::Sdp), sdp},
444 {std::string(key::Username), username},
445 {std::string(key::UniqueId), uniqueId},
446 };
447 }
nlohmann::json Json
Definition Message.h:363
Here is the caller graph for this function:

◆ makeAuth()

Json msg::makeAuth ( const std::string & token,
const std::string & username,
const std::string & uniqueId )
inline

Definition at line 495 of file Message.h.

498 {
499 return Json{
500 {std::string(key::Type), std::string(signaling::Auth)},
501 {std::string(key::AuthToken), token},
502 {std::string(key::Username), username},
503 {std::string(key::UniqueId), uniqueId},
504 };
505 }
Here is the caller graph for this function:

◆ makeAuthResponse()

nlohmann::json msg::makeAuthResponse ( const std::string ok,
const std::string & msg,
const std::string & clientId,
const std::string & username,
const std::vector< std::string > & clients = {},
const std::string & gmPeerId = "",
const std::string & uniqueId = "" )
inline

Definition at line 506 of file Message.h.

508 {},
509 const std::string& gmPeerId = "",
510 const std::string& uniqueId = "")
511 {
512 auto j = nlohmann::json{
513 {std::string(key::Type), std::string(signaling::AuthResponse)},
514 {std::string(key::AuthOk), ok},
515 {std::string(key::AuthMsg), msg},
516 {std::string(key::ClientId), clientId},
517 {std::string(key::Username), username}};
518 if (!clients.empty())
519 j[std::string(msg::key::Clients)] = clients;
520 if (!gmPeerId.empty())
521 j[key::GmId] = gmPeerId;
522 if (!uniqueId.empty())
523 j[std::string(key::UniqueId)] = uniqueId;
524 return j;
525 }
constexpr std::string_view Clients
Definition Message.h:235
Definition Message.h:28
Here is the caller graph for this function:

◆ makeBroadcastShutdown()

Json msg::makeBroadcastShutdown ( )
inline

Definition at line 474 of file Message.h.

475 {
476 return Json{
478 {std::string(msg::key::Broadcast), std::string(msg::value::True)}};
479 }
constexpr std::string_view Type
Definition Message.h:229
constexpr std::string_view Broadcast
Definition Message.h:232
constexpr std::string_view ServerDisconnect
Definition Message.h:281
constexpr std::string True
Definition Message.h:288
Here is the caller graph for this function:

◆ makeCandidate()

Json msg::makeCandidate ( const std::string & from,
const std::string & to,
const std::string & cand,
const std::string & broadcast = msg::value::False )
inline

Definition at line 448 of file Message.h.

449 {
450 return Json{
451 {std::string(key::Type), std::string(signaling::Candidate)},
452 {std::string(key::From), from},
453 {std::string(key::To), to},
454 {std::string(key::Broadcast), broadcast},
455 {std::string(key::Candidate), cand}};
456 }
Here is the caller graph for this function:

◆ makeChatGroupCreate()

Json msg::makeChatGroupCreate ( uint64_t tableId,
uint64_t groupId,
const std::string & name,
const std::set< std::string > & participants )
inline

Definition at line 366 of file Message.h.

369 {
370 Json j = {
371 {std::string(chatkey::Type), DCTypeToJson(DCType::ChatGroupCreate)},
372 {std::string(chatkey::TableId), tableId},
373 {std::string(chatkey::GroupId), groupId},
374 {std::string(chatkey::Name), name},
375 {std::string(chatkey::Parts), Json::array()}};
376 for (auto& p : participants)
377 j[std::string(chatkey::Parts)].push_back(p);
378 return j;
379 }
constexpr std::string_view Parts
Definition Message.h:354
const char * DCTypeToJson(DCType t)
Definition Message.h:306
Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeChatGroupDelete()

Json msg::makeChatGroupDelete ( uint64_t tableId,
uint64_t groupId )
inline

Definition at line 396 of file Message.h.

397 {
398 return Json{
399 {std::string(chatkey::Type), DCTypeToJson(DCType::ChatGroupDelete)},
400 {std::string(chatkey::TableId), tableId},
401 {std::string(chatkey::GroupId), groupId}};
402 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeChatGroupUpdate()

Json msg::makeChatGroupUpdate ( uint64_t tableId,
uint64_t groupId,
const std::string & name,
const std::set< std::string > & participants )
inline

Definition at line 381 of file Message.h.

384 {
385 Json j = {
386 {std::string(chatkey::Type), DCTypeToJson(DCType::ChatGroupUpdate)},
387 {std::string(chatkey::TableId), tableId},
388 {std::string(chatkey::GroupId), groupId},
389 {std::string(chatkey::Name), name},
390 {std::string(chatkey::Parts), Json::array()}};
391 for (auto& p : participants)
392 j[std::string(chatkey::Parts)].push_back(p);
393 return j;
394 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeChatMessage()

Json msg::makeChatMessage ( uint64_t tableId,
uint64_t groupId,
uint64_t ts,
const std::string & username,
const std::string & text )
inline

Definition at line 404 of file Message.h.

407 {
408 return Json{
409 {std::string(chatkey::Type), DCTypeToJson(DCType::ChatMessage)},
410 {std::string(chatkey::TableId), tableId},
411 {std::string(chatkey::GroupId), groupId},
412 {std::string(chatkey::Ts), ts},
413 {std::string(chatkey::Username), username},
414 {std::string(chatkey::Text), text}};
415 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeOffer()

Json msg::makeOffer ( const std::string & from,
const std::string & to,
const std::string & sdp,
const std::string & username,
const std::string & uniqueId,
const std::string & broadcast = msg::value::False )
inline

Definition at line 417 of file Message.h.

421 {
422 return Json{
423 {std::string(key::Type), std::string(signaling::Offer)},
424 {std::string(key::From), from},
425 {std::string(key::To), to},
426 {std::string(key::Broadcast), broadcast},
427 {std::string(key::Sdp), sdp},
428 {std::string(key::Username), username},
429 {std::string(key::UniqueId), uniqueId},
430 };
431 }
Here is the caller graph for this function:

◆ makePeerDisconnect()

nlohmann::json msg::makePeerDisconnect ( const std::string & targetPeerId,
bool broadcast = true )
inline

Definition at line 466 of file Message.h.

467 {
468 return nlohmann::json{
469 {std::string(key::Type), std::string(signaling::PeerDisconnect)},
470 {std::string(key::Broadcast), broadcast ? std::string(msg::value::True) : std::string(msg::value::False)},
471 {std::string(key::Target), targetPeerId}};
472 }
Here is the caller graph for this function:

◆ makePing()

Json msg::makePing ( const std::string & from)
inline

Definition at line 481 of file Message.h.

482 {
483 return Json{
484 {std::string(key::Type), std::string(signaling::Ping)},
485 {std::string(key::From), from}};
486 }

◆ makePresence()

Json msg::makePresence ( const std::string & event,
const std::string & clientId )
inline

Definition at line 458 of file Message.h.

459 {
460 return Json{
461 {std::string(key::Type), std::string(signaling::Presence)},
462 {std::string(key::Event), event},
463 {std::string(key::ClientId), clientId}};
464 }

◆ makeText()

Json msg::makeText ( const std::string & from,
const std::string & to,
const std::string & text,
bool broadcast = false )
inline

Definition at line 561 of file Message.h.

562 {
563 return Json{
564 {std::string(key::Type), std::string(signaling::Text)},
565 {std::string(key::From), from},
566 {std::string(key::To), to},
567 {std::string(key::Broadcast), broadcast},
568 {std::string(key::Text), text}};
569 }