Commit 2d0a05a5 authored by Simon Wüllhorst's avatar Simon Wüllhorst

Fixed a few type problems.

parent e73f9b80
cmake_minimum_required(VERSION 3.0.0)
project(4gewinnt C)
set (CMAKE_C_FLAGS "-Wall -std=gnu99 -pedantic -pthread")
set (CMAKE_C_FLAGS "-Wall -Wextra -std=gnu99 -pedantic -pthread")
include(CTest)
#enable_testing()
add_subdirectory(src)
......
#include "Socket.h"
#include "cblib.h"
#include <stdbool.h>
#include <sys/param.h>
#include <sys/types.h>
......@@ -92,8 +93,10 @@ struct game_state_t {
uint16_t current_mode;
uint16_t current_state;
uint32_t my_latest_move;
int16_t sec_my;
int16_t sec_rem_next_excepted;
uint32_t sec_my;
uint32_t sec_rem_next_excepted;
bool initial_move_me;
bool initial_move_foreign;
};
typedef struct game_state_t game_state;
......
#include "gamepeer.h"
int parse_remote_client(int argc, char** argv, game_peers_info* peers_info)
int parse_remote_client(char** argv, game_peers_info* peers_info)
{
struct addrinfo hints;
......@@ -18,7 +18,7 @@ int parse_remote_client(int argc, char** argv, game_peers_info* peers_info)
Getaddrinfo(argv[3], argv[4], &hints, &peers_info->remote);
return MODE_DIRECT;
}
int parse_remote_server(int argc, char** argv, game_peers_info* peers_info)
int parse_remote_server(char** argv, game_peers_info* peers_info)
{
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
......@@ -59,13 +59,13 @@ int parse_args(int argc, char** argv, game_peers_info* peers_info)
printf(fmt_string, argv[0]);
return -1;
}
return parse_remote_client(argc, argv, peers_info);
return parse_remote_client(argv, peers_info);
} else if (argv[2][1] == 's') {
if (argc != 7) {
printf(fmt_string, argv[0]);
return -1;
}
return parse_remote_server(argc, argv, peers_info);
return parse_remote_server(argv, peers_info);
} else {
printf("Unknown type flag, use -c or -s.\n");
return -1;
......@@ -90,10 +90,6 @@ void finalize(game_peers_info* peers_info, int exit_code, char* last_message)
exit(exit_code);
}
int handle_have_winner(game_peers_info* peers_info)
{
return 0;
}
void send_primitive_message(game_peers_info* peers_info, uint16_t type)
{
struct msg_meta_t a_meta_msg;
......@@ -136,7 +132,8 @@ int handle_foreign_move(game_peers_info* peers_info, msg_move* a_move)
a_move->column = ntohl(a_move->column);
printf("GOT MOVE: SEG_NR: %d, COLUMN: %d\n", a_move->seg_nr, a_move->column);
// Duplicate Packet, ignore it.
if (peers_info->state.sec_rem_next_excepted == -1) {
if (peers_info->state.initial_move_foreign) {
peers_info->state.initial_move_foreign = false;
peers_info->state.sec_rem_next_excepted = a_move->seg_nr;
} else {
if (a_move->seg_nr < peers_info->state.sec_rem_next_excepted) {
......@@ -247,14 +244,14 @@ void handle_rec_udp(game_peers_info* peers_info)
finalize(peers_info, -1, "Connection closed.\nLeaving the game.\n");
}
if (n < sizeof(struct msg_meta_t)) {
if (n < (ssize_t)sizeof(struct msg_meta_t)) {
send_primitive_message(peers_info, MSG_UNKNOWN_MSG_TYPE);
return;
}
meta_data = (struct msg_meta_t*)peers_info->message.buf;
meta_data->length = ntohs(meta_data->length);
meta_data->type = ntohs(meta_data->type);
if (n != meta_data->length + sizeof(struct msg_meta_t) + (4 - meta_data->length % 4) % 4) {
if (n != meta_data->length + (ssize_t)sizeof(struct msg_meta_t) + (4 - meta_data->length % 4) % 4) {
send_primitive_message(peers_info, MSG_UNKNOWN_MSG_TYPE);
return;
}
......@@ -268,7 +265,7 @@ ssize_t packet_sequenzer(game_peers_info* peers_info, ssize_t n)
uint16_t msg_len;
struct msg_meta_t* a_msg;
len = n + peers_info->message.buf_offset;
if (len < sizeof(struct msg_meta_t))
if (len < (ssize_t)sizeof(struct msg_meta_t))
return len;
a_msg = (struct msg_meta_t*)peers_info->message.buf;
......@@ -305,7 +302,11 @@ int make_own_move(game_peers_info* peers_info, int column)
fflush(stdout);
return -1;
}
++peers_info->state.sec_my;
if (peers_info->state.initial_move_me == true) {
peers_info->state.initial_move_me = false;
} else {
++peers_info->state.sec_my;
}
make_move(column, LOCAL_PLAYER);
a_move.type = htons(MSG_MOVE);
......@@ -420,8 +421,8 @@ int init_4gw(game_peers_info* peers_info)
peers_info->timer.ack_timer = create_timer((void (*)(void*)) & handle_ack_timer, peers_info, "ACK_TIMER");
start_timer(peers_info->timer.hb_timer, 10000);
peers_info->state.sec_my = -1;
peers_info->state.sec_rem_next_excepted = -1;
peers_info->state.initial_move_me = true;
peers_info->state.initial_move_foreign = true;
peers_info->timer.ack_timeout_ms = TIMEOUT_ACK_MIN_MS;
peers_info->timer.hb_timeout_ms = TIMEOUT_HB_MIN_MS;
......
......@@ -151,7 +151,7 @@ ssize_t packet_sequenzer(client_info* a_client, ssize_t n)
uint16_t msg_len;
struct msg_meta_t* a_msg;
len = n + a_client->message.buf_offset;
if (len < sizeof(struct msg_meta_t))
if (len < (ssize_t)sizeof(struct msg_meta_t))
return len;
a_msg = (struct msg_meta_t*)a_client->message.buf;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment