]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Add instructions
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 24 Mar 2021 10:53:17 +0000 (11:53 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 24 Mar 2021 10:53:17 +0000 (11:53 +0100)
BUILDING.md [new file with mode: 0644]
Makefile
README.md [new file with mode: 0644]
client.c
node.h

diff --git a/BUILDING.md b/BUILDING.md
new file mode 100644 (file)
index 0000000..6bf62f5
--- /dev/null
@@ -0,0 +1,15 @@
+# Building instructions
+
+## Available targets
+- `all` (default)
+- `Dragonblocks`
+- `DragonblocksServer`
+- `clean`
+- `clobber`
+
+Debug flag (`-g`) is set by default.
+
+## Release Build
+```bash
+make clobber && make all RELEASE=TRUE -j$(nproc) && make clean
+```
index b54c3d4d7e9aea2788e81a3004ee8c05896fc0b6..98ea2a2382b94838b5b867d4a7a2211d3d22db52 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,17 +1,23 @@
 COMMON = array.o binsearch.o linkedlist.o map.o signal.o util.o types.o
 SERVER = $(COMMON) server.o servercommands.o
 CLIENT = $(COMMON) client.o clientcommands.o
+LIBRARIES = -lpthread -lm
+FLAGS = -g
+
+ifdef RELEASE
+FLAGS = -O3
+endif
 
 all: Dragonblocks DragonblocksServer
 
 Dragonblocks: $(CLIENT)
-       cc -g -o Dragonblocks $(CLIENT) -pthread -lm
+       cc $(FLAGS) -o Dragonblocks $(CLIENT) $(LIBRARIES)
 
 DragonblocksServer: $(SERVER)
-       cc -g -o DragonblocksServer $(SERVER) -pthread -lm
+       cc $(FLAGS) -o DragonblocksServer $(SERVER) $(LIBRARIES)
 
 %.o: %.c
-       cc -c -g -o $@ -Wall -Wextra -Wpedantic -Werror $<
+       cc $(FLAGS) -o $@ -c -Wall -Wextra -Wpedantic -Werror $<
 
 clean:
        rm -rf *.o
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..225e72a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,26 @@
+# Dragonblocks alpha
+
+## Usage
+```bash
+./DragonblocksServer <port>
+./Dragonblocks <address> <port>
+```
+
+## Client commands:
+- `setnode <x> <y> <z> <node>`: set a node somewhere
+- `getnode <x> <y> <z>`: download the mapblock containing the node at x y z from server
+- `printnode <x> <y> <z>`: print the node at x y z (download the mapblock using getnode first)
+- `kick <name>`: kick a player
+- `disconnect`: disconnect from server
+
+All positions are signed integers (`s32`)
+
+## Nodes:
+- `unloaded`: used for nodes in unloaded mapblocks
+- `air`: default node in newly generated mapblocks
+- `dirt`
+- `grass`
+- `stone`
+- `invalid`: unknown nodes received from server
+
+Interrupt handlers for SIGINT und SIGTERM are implemented.
index dd48e307261979888f4665cc12ffd75a555631ed..62afbda07e3c5c5d593b1aa4d926ca6c36565bd1 100644 (file)
--- a/client.c
+++ b/client.c
@@ -87,8 +87,7 @@ static void client_loop(Client *client)
                                        printf("Invalid node\n");
                                } else {
                                        pthread_mutex_lock(&client->mtx);
-                                       if (write_u32(client->fd, SC_SETNODE) && write_v3s32(client->fd, pos))
-                                               write_u32(client->fd, node_type);
+                                       (void) (write_u32(client->fd, SC_SETNODE) && write_v3s32(client->fd, pos) && write_u32(client->fd, node_type));
                                        pthread_mutex_unlock(&client->mtx);
                                }
                        } else if (strcmp(buffer, "getnode") == 0) {
@@ -96,8 +95,7 @@ static void client_loop(Client *client)
                                if (scanf("%d %d %d", &pos.x, &pos.y, &pos.z) == EOF)
                                        return;
                                pthread_mutex_lock(&client->mtx);
-                               if (write_u32(client->fd, SC_GETBLOCK))
-                                       write_v3s32(client->fd, map_node_to_block_pos(pos, NULL));
+                               (void) (write_u32(client->fd, SC_GETBLOCK) && write_v3s32(client->fd, map_node_to_block_pos(pos, NULL)));
                                pthread_mutex_unlock(&client->mtx);
                        } else if (strcmp(buffer, "printnode") == 0) {
                                v3s32 pos;
@@ -131,8 +129,7 @@ static void client_loop(Client *client)
                                if (scanf("%s", target_name) == EOF)
                                        return;
                                pthread_mutex_lock(&client->mtx);
-                               if (write_u32(client->fd, SC_KICK))
-                                       write(client->fd, target_name, strlen(target_name) + 1);
+                               (void) (write_u32(client->fd, SC_KICK) && write(client->fd, target_name, strlen(target_name) + 1) != -1);
                                pthread_mutex_unlock(&client->mtx);
                        } else {
                                printf("Invalid command: %s\n", buffer);
diff --git a/node.h b/node.h
index 25f02156d81954a37c27a6c1ec5749af8e3fbe84..3d96e71225785356e58b9220abe1abe8cc007f13 100644 (file)
--- a/node.h
+++ b/node.h
@@ -8,7 +8,7 @@ typedef enum
        NODE_GRASS,
        NODE_DIRT,
        NODE_STONE,
-       NODE_INVALID,           // Used for invalid nodes sent by server (caused by outdated clients)
+       NODE_INVALID,           // Used for invalid nodes received from server (caused by outdated clients)
 } Node;
 
 #endif