Skip to content

Commit 5186db2

Browse files
committed
2 parents 9330d0c + 03dfbd8 commit 5186db2

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
all: server
44

55
server: globals.c account_login.c high_score.c main_game_server.c tictactoe.c helper.c game_dispatcher.c
6-
gcc -g globals.c helper.c account_login.c high_score.c tictactoe.c game_dispatcher.c main_game_server.c -o server
6+
gcc -Wall -g globals.c helper.c account_login.c high_score.c tictactoe.c game_dispatcher.c main_game_server.c -o server
77

88
clean:
99
rm server

helper.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ bool handle_get_version(int client_fd, char* client_str) {
1414
return true;
1515
}
1616

17+
void respond_buff_to_client(int fd, char* buff, int buff_len) {
18+
int len_htonl = htonl(buff_len);
19+
int err = send(fd, &len_htonl, sizeof(len_htonl), 0);
20+
if (err < 0) {
21+
perror("send len in respond_buff_to_client");
22+
}
23+
err = send(fd, buff, buff_len, 0);
24+
if (err < 0) {
25+
perror("send buff in respond_buff_to_client");
26+
}
27+
}
28+
1729
void respond_str_to_client(int fd, char* str) {
1830
int len_htonl = htonl(strlen(str));
1931

@@ -76,7 +88,7 @@ int get_int_from_client(int client_fd) {
7688
bool get_buffer_from_client(int client_fd, char* output, int output_size) {
7789
int client_send_len;
7890
int bytes_read = recv(client_fd, &client_send_len, sizeof(client_send_len), 0);
79-
91+
8092
if (bytes_read == -1) {
8193
perror("recv from get_str_from_client in len");
8294
}

high_score.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ char outro_message[MAX_BUF_SIZE] = {0};
1313

1414
bool handle_reset_winner_data(int client_fd, char* client_str)
1515
{
16-
memset(winners_list, sizeof(winners_list), 0);
17-
memset(outro_message, sizeof(outro_message), 0);
16+
memset(winners_list, 0, sizeof(winners_list));
17+
memset(outro_message, 0, sizeof(outro_message));
1818
strcpy(outro_message, "\nBetter Luck to our other participants next time!\n" );
1919
return true;
2020
}

0 commit comments

Comments
 (0)