Compare commits
13 Commits
1e43573346
...
a663003bc5
Author | SHA1 | Date |
---|---|---|
Eyal Sawady | a663003bc5 | |
Eyal Sawady | 584ddb3654 | |
Ultracoolguy | 83d06b048e | |
Eyal Sawady | c3f2d9d552 | |
Philip K | 6693c97749 | |
Eyal Sawady | 9a742e0ca6 | |
Philip K | 94b7c83fd4 | |
Philip K | a990d49313 | |
Ultracoolguy | 6d74f2c4b9 | |
j3s | f9cf6faa70 | |
j3s | 4aeebd4f53 | |
Ultracoolguy | e69c479dd5 | |
Ultracoolguy | 6ff83c2761 |
|
@ -1,2 +1,3 @@
|
|||
among-sus
|
||||
build
|
||||
*.o
|
||||
|
|
5
Makefile
5
Makefile
|
@ -1,6 +1,9 @@
|
|||
.POSIX:
|
||||
all:
|
||||
$(CC) -o among-sus $(CFLAGS) main.c $(LDFLAGS)
|
||||
$(CC) -o among-sus $(CFLAGS) \
|
||||
$$(git rev-parse --short HEAD >/dev/null 2>/dev/null && \
|
||||
printf -- '-DVERSION="%s"' "$$(git rev-parse --short HEAD)") \
|
||||
main.c $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f among-sus
|
||||
|
|
41
main.c
41
main.c
|
@ -17,6 +17,10 @@
|
|||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#ifndef VERSION
|
||||
#define VERSION "unknown"
|
||||
#endif
|
||||
|
||||
#define NUM_PLAYERS 10
|
||||
#define NUM_SHORT 6
|
||||
#define NUM_LONG 2
|
||||
|
@ -430,7 +434,7 @@ check_win_condition(void)
|
|||
}
|
||||
|
||||
if (nalive == 1) {
|
||||
broadcast("The impostor is alone with the last crewmate and murders him", -1);
|
||||
broadcast("The impostor is alone with the last crewmate and murders them", -1);
|
||||
snprintf(buf, sizeof(buf), "The impostor was [%s] all along...", players[iid].name);
|
||||
broadcast(buf, -1);
|
||||
end_game();
|
||||
|
@ -681,8 +685,9 @@ discussion(size_t pid, char *input)
|
|||
}
|
||||
}
|
||||
|
||||
if(vote < -1 || vote > NUM_PLAYERS-1 || players[vote].fd == -1
|
||||
|| players[vote].stage != PLAYER_STAGE_DISCUSS) {
|
||||
if (vote != -1 && (vote < -1 || vote > NUM_PLAYERS-1
|
||||
|| players[vote].fd == -1
|
||||
|| players[vote].stage != PLAYER_STAGE_DISCUSS)) {
|
||||
snprintf(buf, sizeof(buf), "Invalid vote, no such player\n");
|
||||
write(players[pid].fd, buf, strlen(buf));
|
||||
return;
|
||||
|
@ -1371,6 +1376,9 @@ welcome_player(int fd)
|
|||
continue;
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "among-sus server: version %s\n", VERSION);
|
||||
write(fd, buf, strlen(buf));
|
||||
|
||||
if(state.stage != STAGE_LOBBY) {
|
||||
snprintf(buf, sizeof(buf), "There is a game in progress, waiting for the match to finish...\n");
|
||||
write(fd, buf, strlen(buf));
|
||||
|
@ -1406,13 +1414,20 @@ main(int argc, char *argv[])
|
|||
int opt;
|
||||
while ((opt = getopt(argc, argv, "hp:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
port = strtol(optarg, &endptr, 10);
|
||||
case 'p':;
|
||||
errno = 0;
|
||||
long _port = strtol(optarg, &endptr, 10);
|
||||
if (*endptr != '\0' || errno != 0 ||
|
||||
_port <= 0 || _port >= 65536) {
|
||||
fprintf(stderr, "Invalid port: %s\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
port = (uint16_t) _port;
|
||||
break;
|
||||
case 'h':
|
||||
printf("%s", usage);
|
||||
exit(EXIT_SUCCESS);
|
||||
case '?':
|
||||
default:
|
||||
printf("%s", usage);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -1428,19 +1443,25 @@ main(int argc, char *argv[])
|
|||
}
|
||||
srand((unsigned)time(NULL));
|
||||
|
||||
listen_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
listen6_fd = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
if ((listen_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||
perror("IPv4 socket");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if ((listen6_fd = socket(AF_INET6, SOCK_STREAM, 0)) == -1) {
|
||||
perror("IPv6 socket");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
i = 1;
|
||||
if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
&i, sizeof(i))) {
|
||||
perror("setsockopt");
|
||||
perror("IPv4 setsockopt");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (setsockopt(listen6_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
&i, sizeof(i))) {
|
||||
perror("setsockopt");
|
||||
perror("IPv6 setsockopt");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue