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
--- /dev/null
+# 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.
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) {
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;
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);