feat(observer): add observer mode and disconnect recovery
This commit is contained in:
@@ -123,6 +123,15 @@ static int payload_field_allowed(maze32_message_type_t type, const char* key, ch
|
||||
*fields |= 1U;
|
||||
return 1;
|
||||
}
|
||||
if (type == MAZE32_MESSAGE_MOVE && strcmp(key, "direction") == 0 && !(*fields & 1U)) {
|
||||
if (strcmp(value, "north") != 0 && strcmp(value, "east") != 0 &&
|
||||
strcmp(value, "south") != 0 && strcmp(value, "west") != 0) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(message->direction, value, strlen(value) + 1U);
|
||||
*fields |= 1U;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -159,6 +168,9 @@ static int parse_payload(json_cursor_t* cursor, maze32_client_message_t* message
|
||||
if (message->type == MAZE32_MESSAGE_RESTORE) {
|
||||
return fields == 1U;
|
||||
}
|
||||
if (message->type == MAZE32_MESSAGE_MOVE) {
|
||||
return fields == 1U;
|
||||
}
|
||||
return fields == 0U;
|
||||
}
|
||||
|
||||
@@ -172,6 +184,12 @@ static maze32_message_type_t message_type(const char* value) {
|
||||
if (strcmp(value, "start") == 0) {
|
||||
return MAZE32_MESSAGE_START;
|
||||
}
|
||||
if (strcmp(value, "move") == 0) {
|
||||
return MAZE32_MESSAGE_MOVE;
|
||||
}
|
||||
if (strcmp(value, "drop_key") == 0) {
|
||||
return MAZE32_MESSAGE_DROP_KEY;
|
||||
}
|
||||
if (strcmp(value, "heartbeat") == 0) {
|
||||
return MAZE32_MESSAGE_HEARTBEAT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user