summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c58
1 files changed, 47 insertions, 11 deletions
diff --git a/main.c b/main.c
index b0c94a8..eca82be 100644
--- a/main.c
+++ b/main.c
@@ -90,8 +90,6 @@ void *client_loop(void *ign) {
continue;
while (1) {
- WRITES(1, STRING("Recvd: "));
- write(1, full_msg.data, msg_len+1); // +1: \n
if (full_msg.data[msg_len - 1] == '\r')
msg_len--;
@@ -170,16 +168,37 @@ void *client_loop(void *ign) {
int (*func)(uint64_t argc, struct string *argv) = get_table_index(client_network_commands, command);
+#if LOGALL
+#if COLORIZE
+ WRITES(1, STRING("\x1b[34m[Client->Us] \x1b[33m"));
+#else
+ WRITES(1, STRING("[Client->Us] "));
+#endif
+#if COLORIZE
+ write(1, full_msg.data, msg_len);
+ WRITES(1, STRING("\x1b[0m\n"));
+#else
+ write(1, full_msg.data, msg_len+1); // +1: \n
+#endif
+#endif
+
if (func == 0) {
+#if !LOGALL
+ WRITES(2, STRING("[Client] "));
+ write(2, full_msg.data, msg_len+1); // +1: \n
+#endif
WRITES(2, STRING("WARNING: Command is unknown, ignoring...\n"));
+ WRITES(2, STRING("\n"));
} else {
+#if LOGALL
+ WRITES(1, STRING("\n"));
+#endif
int err = func(argc, argv);
if (err) {
WRITES(1, STRING("Disconnecting client by result of the network command handler...\n"));
goto disconnect_client;
}
}
- write(1, "\n", 1);
if (full_msg.data[msg_len] == '\r')
msg_len++;
@@ -274,15 +293,12 @@ int main(void) {
continue;
while (1) {
- WRITES(1, STRING("Recvd: "));
- write(1, full_msg.data, msg_len+1); // +1: \n
-
uint64_t offset = 0;
while (offset < msg_len && full_msg.data[offset] == ' ')
offset++;
if (msg_len == offset) {
- puts("Protocol violation: Empty message.");
+ WRITES(2, STRING("Protocol violation: Empty message.\n"));
return 2;
}
@@ -299,7 +315,7 @@ int main(void) {
}
}
if (!found || source.len + 1 == msg_len) {
- puts("Protocol violation: Sender but no command.");
+ WRITES(2, STRING("Protocol violation: Sender but no command."));
return 2;
}
} else {
@@ -311,7 +327,7 @@ int main(void) {
offset++;
if (offset == msg_len) {
- puts("Protocol violation: No command.");
+ WRITES(2, STRING("Protocol violation: No command."));
return 2;
}
@@ -381,17 +397,37 @@ int main(void) {
int (*func)(struct string source, uint64_t argc, struct string *argv) = get_table_index(server_network_commands, command);
+#if LOGALL
+#if COLORIZE
+ WRITES(1, STRING("\x1b[35m[Server->Us] \x1b[36m"));
+#else
+ WRITES(1, STRING("[Server->Us] "));
+#endif
+#if COLORIZE
+ write(1, full_msg.data, msg_len);
+ WRITES(1, STRING("\x1b[0m\n"));
+#else
+ write(1, full_msg.data, msg_len+1); // +1: \n
+#endif
+#endif
+
if (func == 0) {
+#if !LOGALL
+ WRITES(2, STRING("[Server] "));
+ write(2, full_msg.data, msg_len+1); // +1: \n
+#endif
WRITES(2, STRING("WARNING: Command is unknown, ignoring...\n"));
+ WRITES(2, STRING("\n"));
} else {
- write(1, "\n", 1);
+#if LOGALL
+ WRITES(1, STRING("\n"));
+#endif
int err = func(source, argc, argv);
if (err) {
WRITES(1, STRING("Disconnecting by result of the network command handler...\n"));
return 0;
}
}
- write(1, "\n", 1);
memmove(full_msg.data, full_msg.data+msg_len+1, full_msg.len - msg_len - 1);
full_msg.len -= msg_len+1;