summary refs log tree commit diff homepage
path: root/server.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2017-08-02 00:55:52 -0400
committerJune McEnroe <june@causal.agency>2017-08-02 00:55:52 -0400
commit9595969f2e916e800ec029623305920e11ef182b (patch)
treed8268b6e015cce74a71523114afc5d2dd5c50e2b /server.c
parentMadvise RANDOM and NOSYNC (diff)
downloadtorus-9595969f2e916e800ec029623305920e11ef182b.tar.gz
torus-9595969f2e916e800ec029623305920e11ef182b.zip
Split tile access and modify
Diffstat (limited to '')
-rwxr-xr-xserver.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/server.c b/server.c
index 97d4230..fc3b3d0 100755
--- a/server.c
+++ b/server.c
@@ -56,11 +56,23 @@ static struct Tile *tileGet(uint32_t tileX, uint32_t tileY) {
         memset(tile->colors, COLOR_WHITE, CELLS_SIZE);
         tile->create = time(NULL);
     }
+    return tile;
+}
+
+static struct Tile *tileAccess(uint32_t tileX, uint32_t tileY) {
+    struct Tile *tile = tileGet(tileX, tileY);
     tile->access = time(NULL);
     tile->accessCount++;
     return tile;
 }
 
+static struct Tile *tileModify(uint32_t tileX, uint32_t tileY) {
+    struct Tile *tile = tileGet(tileX, tileY);
+    tile->modify = time(NULL);
+    tile->modifyCount++;
+    return tile;
+}
+
 static struct Client {
     int fd;
 
@@ -102,7 +114,7 @@ static bool clientSend(const struct Client *client, const struct ServerMessage *
     if (len < 0) return false;
 
     if (msg->type == SERVER_TILE) {
-        struct Tile *tile = tileGet(client->tileX, client->tileY);
+        struct Tile *tile = tileAccess(client->tileX, client->tileY);
         len = send(client->fd, tile, sizeof(*tile), 0);
         if (len < 0) return false;
     }
@@ -227,7 +239,7 @@ static bool clientMove(struct Client *client, int8_t dx, int8_t dy) {
 }
 
 static bool clientPut(const struct Client *client, uint8_t color, char cell) {
-    struct Tile *tile = tileGet(client->tileX, client->tileY);
+    struct Tile *tile = tileModify(client->tileX, client->tileY);
     tile->colors[client->cellY][client->cellX] = color;
     tile->cells[client->cellY][client->cellX] = cell;