Skip to content

Commit

Permalink
JSON API: first 22 bytes are no longer the server init
Browse files Browse the repository at this point in the history
  • Loading branch information
Istador committed Apr 28, 2024
1 parent a1db092 commit a325c38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 0 additions & 2 deletions Server/JsonApi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ to fill up and exactly match a complete normal game packet header (to identify a

A complete request can have a size of up to 512 characters (arbitrary limit that could be increased if needed).

The first 22 bytes of binary data returned from the server (`InitPacket`) need to be ignored to parse the rest as valid JSON.

---

Every request to the server needs to be authorized by containing a secret token.
Expand Down
15 changes: 14 additions & 1 deletion Server/JsonApi/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,22 @@ if [ $# -gt 1 ] ; then
DATA=",\"Data\":\"${@:2}\""
fi

# backwards compatible way to dynamically trim binary before the first '{' character
function trim_start () {
local IFS
local LC_ALL
local c
while IFS= LC_ALL=C read -rd '' -n1 c ; do
[ "$c" == "{" ] && echo -n "$c" && break
done
while IFS= LC_ALL=C read -rd '' -n1 c ; do
echo -n "$c"
done
}

echo -n "{\"API_JSON_REQUEST\":{\"Token\":\"${TOKEN}\",\"Type\":\"$TYPE\"$DATA}}" \
| timeout 5.0 nc $HOST $PORT \
| tail -c+23 \
| trim_start \
| jq \
;
echo ""

0 comments on commit a325c38

Please sign in to comment.