summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-21 15:11:21 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-21 15:11:21 -0300
commitba2c428dca0080cd79ea3e6c7d0f48764076fd2c (patch)
treeca9607b4877a0f26d15e5ae6ebd5a80ba465f6fc /src
parent8693eef8febde4df90b7fbd1fb9ac813b132fa50 (diff)
downloadjet-ba2c428dca0080cd79ea3e6c7d0f48764076fd2c.tar.gz
jet-ba2c428dca0080cd79ea3e6c7d0f48764076fd2c.zip
Revert parse_message
Diffstat (limited to 'src')
-rw-r--r--src/server/client.cpp65
1 files changed, 42 insertions, 23 deletions
diff --git a/src/server/client.cpp b/src/server/client.cpp
index 45f7501..d862b13 100644
--- a/src/server/client.cpp
+++ b/src/server/client.cpp
@@ -1,4 +1,4 @@
-#define MAX_MSG_SIZE 128
+#define MAX_MSG_SIZE 8
#define pos(x, y) (x) + (y) * window_w
struct Client {
@@ -11,29 +11,48 @@ struct Client {
void parse_message() {
int8_t message[MAX_MSG_SIZE] = {};
io.recv(message, MAX_MSG_SIZE - 1);
- switch (message[0]) {
- case OP_MOVE1:
- move(message[1]);
- break;
- case OP_MOVE2:
- move(decode2(message, 1));
- break;
- case OP_MOVE4:
- move(decode4(message, 1));
- break;
- case OP_MOVE8:
- move(decode8(message, 1));
- break;
- case OP_INSERT:
- push(message[1]);
- break;
- case OP_DELETE:
- pop();
- break;
- case OP_SHOW:
- show(decode2(message, 1), decode2(message, 3));
- break;
+ int8_t *iter = message;
+ while (iter[0]) {
+ switch (iter[0]) {
+ case OP_MOVE1:
+ move(iter[1]);
+ iter += 2;
+ break;
+ case OP_MOVE2:
+ move(decode2(iter, 1));
+ iter += 3;
+ break;
+ case OP_MOVE4:
+ move(decode4(iter, 1));
+ iter += 5;
+ break;
+ case OP_MOVE8:
+ move(decode8(iter, 1));
+ iter += 9;
+ break;
+ case OP_INSERT:
+ push(iter[1]);
+ iter += 2;
+ break;
+ case OP_DELETE:
+ pop();
+ iter += 1;
+ break;
+ case OP_SHOW:
+ show(decode2(iter, 1), decode2(iter, 3));
+ iter += 5;
+ break;
+ default:
+ iter++;
+ }
+ }
+ for (int i = 0; i < MAX_MSG_SIZE; i++) {
+ if (message[i])
+ printf("%02hhx ", message[i]);
+ else
+ printf(".. ");
}
+ printf("\n");
}
void show(size_t window_w, size_t window_h) {