-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
677 lines (638 loc) · 19 KB
/
client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
/**
* Implementation of Dunbar's "Glass Plate Game" game, which is based off of
* Herman Hesse's novel, "The Glass Bead Game".
*
* This is the client's portion of the code.
*
* Copyright (C) 2015 "Frostsnow" (Wade T. Cline).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "client.h"
struct flub* client_nickname_write(struct client* client, char* nickname) {
struct flub* flub;
struct gls_header header;
struct gls_nick_set set;
struct gls_nick_req req;
int ret;
// Attempt to set nickname.
memset(&req, 0, sizeof(struct gls_nick_req));
strlcpy(req.nick, nickname, GLS_NICK_LENGTH);
while (1) {
// Write nickname to server.
flub = gls_nick_req_write(&req, client->sockfd);
if (flub) {
return flub_append(flub, "unable to write nickname");
} else {
g_log_info("Nickname '%s' requested.", req.nick);
}
// Read nickname from server.
flub = gls_header_read(&header, client->sockfd);
if (flub) {
// Unable to read header.
return flub_append(flub, "unable to read gls header");
}
if (header.event != GLS_EVENT_NICK_SET) {
// Unexpected event.
return g_flub_toss("Unexpected event: '%x'", header.event);
}
flub = gls_nick_set_read(&set, client->sockfd, 1);
if (flub) {
return flub_append(flub, "unable to get nick set");
}
if (set.nick[0] != '\0') {
// Nickname accepted.
break;
}
// Nickname rejected.
g_log_info("Nickname rejected: '%s'", set.reason);
while (1) {
const char* message = "Please request new nickname "
"(must be 31 alphanumeric characters or less) "
"by typing it and then pressing the 'Enter' "
"key: ";
if (write(STDOUT_FILENO, message, strlen(message)) ==
-1) {
return g_flub_toss("Unable to write new nick "
"req prompt: '%s'", g_serr(errno));
}
memset(&req, 0, sizeof(struct gls_nick_req));
if ((ret = read(STDIN_FILENO, &req.nick,
GLS_NICK_LENGTH)) == -1) {
return g_flub_toss("Unable to read new nick "
"req: '%s'", g_serr(errno));
}
req.nick[ret - 1] = '\0';
if ((flub = gls_nick_validate(req.nick, 0))) {
g_log_info("Invalid nick: '%s'", flub->message);
continue;
}
break;
}
}
return NULL;
}
int main(int argc, char* argv[]) {
struct cargs cargs;
struct client client;
int done;
char errbuf[128];
struct flub* flub;
struct gls_packet packet;
struct sockaddr_in sockaddr_in;
int ret;
// Set up the globals.
if (log_init(&g_log, NULL, LOG_DEBUG, 0) == -1) {
fprintf(stderr, "Unable to open log, QUITTING!");
exit(EXIT_FAILURE);
}
if ((ret = g_serr_init())) {
g_log_error("Unable to create system error buffer");
exit(EXIT_FAILURE);
}
ret = g_flub_init();
if (ret) {
g_log_error("Unable to initialize flub: '%s'", g_serr(ret));
exit(EXIT_FAILURE);
}
flub = gls_init();
if (flub) {
g_log_error("Unable to initialize gls buffer: '%s'",
flub->message);
exit(EXIT_FAILURE);
}
// Parse arguments.
flub = cargs_parse(&cargs, argc, argv);
if (flub) {
g_log_error("Unable to parse arguments: '%s'", flub->message);
exit(EXIT_FAILURE);
}
// Set up socket.
memset(&client.board, 0, sizeof(struct board));
client.sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (client.sockfd == -1) {
perror("Unable to create socket");
exit(EXIT_FAILURE);
}
// Connect to the server.
memset(&sockaddr_in, 0, sizeof(sockaddr_in));
sockaddr_in.sin_family = AF_INET;
sockaddr_in.sin_port = htons(13500);
sockaddr_in.sin_addr.s_addr = INADDR_ANY;
if (connect(client.sockfd, (struct sockaddr*)&sockaddr_in,
sizeof(sockaddr_in)) == -1) {
perror("Connecting to server");
exit(EXIT_FAILURE);
}
// Exchange protocol versions.
memset(&packet, 0, sizeof(struct gls_packet));
packet.header.event = GLS_EVENT_PROTOVER;
strlcpy(packet.data.protover.magic, "GLS", GLS_PROTOVER_MAGIC_LENGTH);
strlcpy(packet.data.protover.version, "0.0",
GLS_PROTOVER_VERSION_LENGTH);
strlcpy(packet.data.protover.software, "gls",
GLS_PROTOVER_SOFTWARE_LENGTH);
flub = gls_packet_write(&packet, client.sockfd);
if (flub) {
fprintf(stderr, "Unable to write protover: '%s'\n",
flub->message);
exit(EXIT_FAILURE);
}
flub = gls_packet_read(&packet, client.sockfd, 1);
if (flub) {
fprintf(stderr, "Unable to read protover ack: '%s'\n",
flub->message);
exit(EXIT_FAILURE);
} else if (packet.header.event != GLS_EVENT_PROTOVERACK) {
fprintf(stderr, "Expected protover ack ('%u'), got '%u'\n",
GLS_EVENT_PROTOVERACK, packet.header.event);
exit(EXIT_FAILURE);
}
if (!packet.data.protoverack.ack) {
fprintf(stderr, "Server refused connection: '%s'\n",
packet.data.protoverack.reason);
exit(EXIT_FAILURE);
}
// Set nickname.
flub = client_nickname_write(&client, cargs.nick);
if (flub) {
fprintf(stderr, "Nickname set failed: '%s'\n",
flub->message);
exit(EXIT_FAILURE);
} else {
fprintf(stderr, "Nickname accepted.\n");
}
// Synchronize.
do {
int i;
struct plate* plate;
// Check header.
if ((flub = gls_header_read(&packet.header, client.sockfd))) {
g_log_error("Unable to read header: '%s'",
flub->message);
exit(EXIT_FAILURE);
}
if (packet.header.event == GLS_EVENT_SYNC_END) {
// End of sync.
break;
} else if (packet.header.event == GLS_EVENT_PLATE_PLACE) {
// Read in plate.
if ((flub = gls_plate_place_read(
&packet.data.plate_place, client.sockfd, 1))) {
g_log_error("Unable to read plate: '%s'",
flub->message);
exit(EXIT_FAILURE);
}
// Copy plate to game board.
i = ((packet.data.plate_place.loc[0] - 'A') * 8) +
((packet.data.plate_place.loc[1] - '1'));
plate = ((struct plate*)client.board.plates) + i;
strlcpy(plate->abbrev, packet.data.plate_place.abbrev,
GLS_PLATE_ABBREV_LENGTH);
strlcpy(plate->description,
packet.data.plate_place.description,
GLS_PLATE_DESCRIPTION_LENGTH);
strlcpy(plate->name, packet.data.plate_place.name,
GLS_PLATE_NAME_LENGTH);
plate->empty = packet.data.plate_place.flags &
GLS_PLATE_FLAG_EMPTY;
} else if (packet.header.event == GLS_EVENT_DIE_PLACE) {
// Read in die placement.
if ((flub = gls_die_place_read(&packet.data.die_place,
client.sockfd, 1))) {
g_log_error("Unable to read die place: '%s'",
flub->message);
exit(EXIT_FAILURE);
}
// Place die.
if ((flub = board_die_place(&client.board,
packet.data.die_place.nick,
packet.data.die_place.location,
&packet.data.die_place.color,
&packet.data.die_place.die))) {
g_log_error("Unable to place die: '%s'",
flub->message);
exit(EXIT_FAILURE);
}
} else {
g_log_error("Unexpected event: '%u'",
packet.header.event);
exit(EXIT_FAILURE);
}
} while (1);
if ((flub = gls_sync_end_read(&packet.data.sync_end, client.sockfd,
1))) {
g_log_error("Unable to read sync_end packet: '%s'",
flub->message);
exit(EXIT_FAILURE);
}
if (strlen(packet.data.sync_end.motd)) {
g_log_info("MotD: '%s'", packet.data.sync_end.motd);
}
// Play the game (main loop).
done = 0;
const int REGMATCH_COUNT = 5;
regex_t regex_board;
regex_t regex_command;
regex_t regex_help;
regex_t regex_nick;
regex_t regex_place;
regex_t regex_plate;
regex_t regex_quit;
regmatch_t regmatch[REGMATCH_COUNT];
if ((ret = regcomp(®ex_board, "^board\\s*$",
REG_EXTENDED | REG_NOSUB))) {
regerror(ret, ®ex_board, errbuf, sizeof(errbuf));
g_log_error("Unable to compile board regex: '%s'", errbuf);
exit(EXIT_FAILURE);
} else if ((ret = regcomp(®ex_command, "^/(.*)$",
REG_EXTENDED))) {
regerror(ret, ®ex_command, errbuf, sizeof(errbuf));
g_log_error("Unable to compile command regex: '%s'", errbuf);
exit(EXIT_FAILURE);
} else if ((ret = regcomp(®ex_help, "^(help|\\?)\\s*$",
REG_EXTENDED | REG_NOSUB))) {
regerror(ret, ®ex_help, errbuf, sizeof(errbuf));
g_log_error("Unable to compile help regex: '%s'", errbuf);
exit(EXIT_FAILURE);
} else if ((ret = regcomp(®ex_nick, "^nick(\\s+(\\w+))?\\s*$",
REG_EXTENDED))) {
regerror(ret, ®ex_nick, errbuf, sizeof(errbuf));
g_log_error("Unable to compile nick regex: '%s'", errbuf);
exit(EXIT_FAILURE);
} else if ((ret = regcomp(®ex_place,
"^place(\\s+(\\w+)(\\s+(\\w+))?)?\\s*$", REG_EXTENDED))) {
regerror(ret, ®ex_place, errbuf, sizeof(errbuf));
g_log_error("Unable to compile place regex: '%s'", errbuf);
exit(EXIT_FAILURE);
} else if ((ret = regcomp(®ex_plate, "^plate(\\s+(\\w+))?\\s*$",
REG_EXTENDED))) {
regerror(ret, ®ex_plate, errbuf, sizeof(errbuf));
g_log_error("Unable to compile plate regex: '%s'", errbuf);
exit(EXIT_FAILURE);
} else if ((ret = regcomp(®ex_quit, "^quit\\s*$",
REG_EXTENDED | REG_NOSUB))) {
regerror(ret, ®ex_quit, errbuf, sizeof(errbuf));
g_log_error("Unable to compile quit regex: '%s'", errbuf);
exit(EXIT_FAILURE);
}
while (!done) {
int read_count;
char* cmd;
char command[CLIENT_COMMAND_SIZE];
struct gls_packet packet;
const char prompt[] = "> ";
// Read data from server.
do {
time_t tval;
struct tm tm;
char tstr[10];
// Check for data from server.
if (ioctl(client.sockfd, FIONREAD, &ret) == -1) {
g_log_error("Unable to peek socket read end: "
"'%s'", g_serr(errno));
done = 1;
break;
}
if (!ret) {
// No data from server.
break;
}
// Read data from server.
if ((flub = gls_packet_read(&packet, client.sockfd,
1))) {
g_log_error("Unable to read packet: '%s'",
flub->message);
done = 1;
break;
}
switch (packet.header.event) {
case (GLS_EVENT_DIE_PLACE):
if ((flub = board_die_place(&client.board,
packet.data.die_place.nick,
packet.data.die_place.location,
&packet.data.die_place.color,
&packet.data.die_place.die))) {
g_log_error("Unable to place die '%s':"
"%s",
packet.data.die_place.location,
flub->message);
done = 1;
break;
}
g_log_info("'%s' placed die '%u' (%s) at '%s'",
packet.data.die_place.nick,
packet.data.die_place.die,
gls_color_names[
packet.data.die_place.color],
packet.data.die_place.location);
break;
case (GLS_EVENT_DIE_PLACE_REJECT):
g_log_info("Server rejected placement of die "
"at '%s': %s",
packet.data.die_place_reject.location,
packet.data.die_place_reject.reason);
break;
case (GLS_EVENT_NICK_SET):
if (!strlen(packet.data.nick_set.nick)) {
g_log_info("Server rejected nickname: "
"'%s'",
packet.data.nick_set.reason);
} else {
g_log_info("Server set nickname to "
"'%s'",
packet.data.nick_set.nick);
}
break;
case (GLS_EVENT_NICK_CHANGE):
g_log_info("Player '%s' is now known as '%s'",
packet.data.nick_change.old,
packet.data.nick_change.new);
break;
case (GLS_EVENT_PLAYER_JOIN):
g_log_info("Player '%s' has joined",
packet.data.player_join.nick);
break;
case (GLS_EVENT_PLAYER_PART):
g_log_info("Player '%s' has parted",
packet.data.player_part.nick);
break;
case (GLS_EVENT_SHUTDOWN):
g_log_info("Server shutdown: '%s'",
packet.data.shutdown.reason);
done = 1;
break;
case (GLS_EVENT_SAY2):
// Format time.
tval = (time_t)packet.data.say2.tval;
if (localtime_r(&tval, &tm) == NULL) {
g_log_warn("Unable to get localtime: "
"'%s'", g_serr(errno));
strlcpy(tstr, "??:??", sizeof(tstr));
} else {
if (!strftime(tstr, sizeof(tstr),
"%H:%M", &tm)) {
g_log_warn("Unable to format "
"time string");
strlcpy(tstr, "??:??",
sizeof(tstr));
}
}
// Display message.
g_log_info("%s %s: %s", tstr,
packet.data.say2.nick,
packet.data.say2.message);
break;
default:
g_log_error("Unknown event: '%i'",
packet.header.event);
done = 1;
break;
}
} while (1);
if (done) {
break;
}
// Issue command prompt.
if (write(STDOUT_FILENO, prompt, sizeof(prompt)) <
sizeof(prompt)) {
g_log_error("Unable to write prompt: '%s'",
g_serr(errno));
}
// Get command from user.
memset(command, 0, sizeof(command));
read_count = read(STDIN_FILENO, command, sizeof(command));
if (read_count == -1) {
// Read error.
g_log_error("Unable to get command: '%s'",
g_serr(errno));
done = 1;
break;
} else if (!read_count) {
// EOF.
done = 1;
if (write(STDOUT_FILENO, "\n", 1) < 1) {
g_log_warn("No clean-quit on EOF: '%s'",
g_serr(errno));
}
continue;
} else if (read_count == sizeof(command)) {
// Command too long.
g_log_warn("Command too long (must be < %i bytes); "
"skipping", CLIENT_COMMAND_SIZE);
continue;
}
command[read_count - 1] = '\0';
// Process user's command.
if (!strlen(command)) {
continue;
} else if (regexec(®ex_command, command, REGMATCH_COUNT,
regmatch, 0)) {
struct gls_say1 say;
// Prepare Say1 packet.
memset(&say, 0, sizeof(struct gls_say1));
if (strlcpy(say.message, command,
GLS_SAY_MESSAGE_LENGTH) >=
GLS_SAY_MESSAGE_LENGTH) {
// TODO: Break long messages into little
// messages.
g_log_warn("Message too long; must be less "
"than '%i' characters",
GLS_SAY_MESSAGE_LENGTH);
continue;
}
// Write Say1 packet to server.
if ((flub = gls_say1_write(&say, client.sockfd))) {
g_log_warn("Unable to send message: '%s'",
flub->message);
}
continue;
}
cmd = &command[regmatch[1].rm_so];
if (!regexec(®ex_board, cmd, REGMATCH_COUNT, regmatch, 0)) {
// Print game board.
board_print(&client.board, STDOUT_FILENO);
} else if (!regexec(®ex_help, cmd, 0, NULL, 0)) {
// Print help message.
char* message =
"/board: Print the game board.\n"
"/help: Show this help menu.\n"
"/nick <nick>: Request specified nickname.\n"
"/plate <RowColumn>: Print specifed plate.\n"
"/place <Location> [color]: Place die at "
"specified location.\n"
"/quit: Exit the program.\n"
"/?: Same as 'help'.\n";
if (write(STDOUT_FILENO, message, strlen(message)) <
strlen(message)) {
g_log_error("Writing help message");
}
} else if (!regexec(®ex_nick, cmd, REGMATCH_COUNT, regmatch,
0)) {
// Send Nick Request.
struct gls_nick_req req;
regoff_t len;
// Check for nick argument.
if (regmatch[2].rm_so == -1) {
g_log_warn("Missing nickname");
continue;
}
// Read nick from client.
memset(&req, 0, sizeof(struct gls_nick_req));
len = regmatch[2].rm_eo - regmatch[2].rm_so + 1;
if (strlcpy(req.nick, &cmd[regmatch[2].rm_so],
len < GLS_NICK_LENGTH ? len : GLS_NICK_LENGTH)
>= GLS_NICK_LENGTH) {
g_log_warn("Nick must be less than '%i' "
"characters", GLS_NICK_LENGTH);
continue;
} else if ((flub = gls_nick_validate(req.nick, 0))) {
g_log_warn("Invalid nick: '%s'", flub->message);
continue;
}
// Send nick request to server.
if ((flub = gls_nick_req_write(&req, client.sockfd))) {
g_log_warn("Unable to send nick request: '%s'",
flub->message);
break;
}
g_log_info("Requested nick '%s'", req.nick);
} else if (!regexec(®ex_place, cmd, REGMATCH_COUNT, regmatch,
0)) {
uint32_t color;
char color_str[16]; // Hacky.
uint32_t die;
struct gls_die_place_try packet;
char location[GLS_LOCATION_LENGTH];
// Parse location.
if (regmatch[2].rm_so == -1) {
g_log_warn("Missing location");
continue;
}
strlcpy(location, &cmd[regmatch[2].rm_so],
GLS_LOCATION_LENGTH);
if ((flub = gls_location_validate(location))) {
g_log_warn("Unable to parse location: %s",
flub->message);
continue;
}
// Parse color.
if (regmatch[4].rm_so != -1) {
regoff_t len = regmatch[4].rm_eo -
regmatch[4].rm_so;
strlcpy(color_str, &cmd[regmatch[4].rm_so],
sizeof(color_str) < len + 1?
sizeof(color_str) : len + 1);
if (!strcasecmp(color_str, "red")) {
color = GLS_COLOR_RED;
} else if (!strcasecmp(color_str, "orange")) {
color = GLS_COLOR_ORANGE;
} else if (!strcasecmp(color_str, "yellow")) {
color = GLS_COLOR_YELLOW;
} else if (!strcasecmp(color_str, "green")) {
color = GLS_COLOR_GREEN;
} else if (!strcasecmp(color_str, "blue")) {
color = GLS_COLOR_BLUE;
} else if (!strcasecmp(color_str, "purple")) {
color = GLS_COLOR_PURPLE;
} else {
g_log_warn("Unknown color '%s'",
color_str);
continue;
}
} else {
color = GLS_COLOR_NULL;
}
// Check board.
if ((flub = board_die_place_check(&client.board,
location, &color, &die))) {
g_log_warn("Unable to place die: %s",
flub->message);
continue;
}
// Send packet.
memset(&packet, 0, sizeof(packet));
strlcpy(packet.location, location, GLS_LOCATION_LENGTH);
packet.color = color;
if ((flub = gls_die_place_try_write(&packet,
client.sockfd))) {
g_log_warn("Unable to write place die try "
"packet: %s", flub->message);
}
} else if (!regexec(®ex_plate, cmd, REGMATCH_COUNT, regmatch,
0)) {
// Print specified plate.
int column;
int offset;
int row;
// Check for plate specification.
if (regmatch[2].rm_so == -1) {
g_log_warn("Missing plate location");
continue;
}
// Parse board coordinates.
// TODO: Deal with lowercase, multiple letters/numbers,
// make less sucky in general.
offset = regmatch[2].rm_so;
if (!isalpha(cmd[offset])) {
g_log_info("Invalid row '%c'", cmd[offset]);
continue;
}
row = cmd[offset] - 'A';
if (row < 0) {
g_log_info("Row '%c' too low", cmd[offset]);
continue;
} else if (row >= GLS_BOARD_ROW_COUNT) {
g_log_info("Row '%c' too high (must be less "
"than '%c')", cmd[offset],
GLS_BOARD_ROW_COUNT + 'A');
continue;
}
offset++;
if (!isdigit(cmd[offset])) {
g_log_info("Invalid column '%c'; expected "
"digit", cmd[offset]);
continue;
}
column = cmd[offset] - '1';
if (column < 0) {
g_log_info("Column '%c' too low", cmd[offset]);
continue;
} else if (column >= GLS_BOARD_COLUMN_COUNT) {
g_log_info("Column '%c' too high (must be "
"less than '%c')", cmd[offset],
GLS_BOARD_COLUMN_COUNT + '1');
continue;
}
// Print plate.
plate_print(&client.board.plates[row][column],
STDOUT_FILENO);
} else if (!regexec(®ex_quit, cmd, REGMATCH_COUNT, regmatch,
0)) {
// Quit the game.
done = 1;
} else {
// Unknown command.
g_log_info("Command not recognized");
}
} // Playing.
// Close connection to the server.
if (close(client.sockfd) == -1) {
log_error(&g_log, "Closing connection to server.");
}
// Close the logger.
log_free(&g_log);
// Return success.
exit(EXIT_SUCCESS);
}