Commit 7a4345e9 authored by Simon Wüllhorst's avatar Simon Wüllhorst

Prepare file structure for gameserver

parent a7eea05b
......@@ -18,6 +18,10 @@ target_link_libraries(gamepeer socket)
target_link_libraries(gamepeer cblib)
target_link_libraries(gamepeer 4clib)
add_executable(gameserver ${GAMESERVER_C} ${GAMESERVER_H} ${SOCKET_H})
target_link_libraries(gameserver socket)
target_link_libraries(gameserver cblib)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
#include(CPack)
......@@ -33,6 +33,7 @@ PARENT_SCOPE
set(GAMEPEER_H
${GAMEPEER_H}
${CMAKE_CURRENT_SOURCE_DIR}/game.h
${CMAKE_CURRENT_SOURCE_DIR}/gamepeer.h
PARENT_SCOPE
)
......@@ -42,6 +43,19 @@ ${CMAKE_CURRENT_SOURCE_DIR}/gamepeer.c
PARENT_SCOPE
)
set(GAMESERVER_H
${GAMESERVER_H}
${CMAKE_CURRENT_SOURCE_DIR}/game.h
${CMAKE_CURRENT_SOURCE_DIR}/gameserver.h
PARENT_SCOPE
)
set(GAMESERVER_C
${GAMESERVER_C}
${CMAKE_CURRENT_SOURCE_DIR}/gameserver.c
PARENT_SCOPE
)
set(4CLIBTEST
${4CLIBTEST}
${CMAKE_CURRENT_SOURCE_DIR}/4clibtest.c
......
#include "Socket.h"
#include "cblib.h"
#include <sys/types.h>
#ifndef GAME_H_
#define GAME_H_
/*
* Message TYPES
*/
#define BUFFER_SIZE (1 << 16)
#define MSG_REG 0
#define MSG_REG_ACK 1
#define MSG_REG_NACK 2
#define MSG_PEER_INFO 3
#define MSG_PEER_INFO_ACK 9
#define MSG_MOVE 4
#define MSG_MOVE_ACK 5
#define MSG_HEARTBEAT 6
#define MSG_HEARTBEAT_ACK 7
#define MSG_UNKNOWN_MSG_TYPE 8
#define LOCAL_START 0
#define REMOTE_START 1
#define LOCAL_PLAYER -1
#define REMOTE_PLAYER 1
//#define STATE_INIT 0
#define STATE_WAIT_FOREIGN_MOVE 1
#define STATE_WAIT_ACK 2
//#define STATE_GOT_FORGEIN_MOVE 2
#define STATE_WAIT_USER_INPUT 3
#define FIRST_SEQ_NUMBER 0
#define TIMEOUT_ACK_MIN_MS 200
#define TIMEOUT_ACK_MAX_MS 20000
#define TIMEOUT_HB_MIN_MS 2000
#define TIMEOUT_HB_MAX_MS 20000
#define DEBUG
/*
* Message STRUCTURES
*/
struct msg_meta_t {
uint16_t type;
uint16_t length;
} __attribute__((packed));
typedef struct msg_meta_t msg_reg_ack;
typedef struct msg_meta_t msg_reg_nack;
typedef struct msg_meta_t msg_peer_info_ack;
typedef struct msg_meta_t msg_unknown_msg_type;
typedef struct msg_meta_t msg_heartbeat;
typedef struct msg_meta_t msg_heartbeat_ack;
struct msg_peer_info_t {
uint16_t type;
uint16_t length;
uint32_t net_addr;
uint16_t net_port;
uint16_t name_len;
} __attribute__((packed));
typedef struct msg_peer_info_t msg_peer_info;
struct msg_move_t {
uint16_t type;
uint16_t length;
uint32_t seg_nr;
uint32_t column;
} __attribute__((packed));
typedef struct msg_move_t msg_move;
struct msg_move_ack_t {
uint16_t type;
uint16_t length;
uint32_t seg_nr;
} __attribute__((packed));
typedef struct msg_move_ack_t msg_move_ack;
struct game_state_t {
uint16_t current_state;
uint32_t my_latest_move;
uint16_t sec_my;
uint16_t sec_rem_next_excepted;
};
typedef struct game_state_t game_state;
struct game_timer_t {
struct timer* hb_timer;
struct timer* conn_timeout;
struct timer* ack_timer;
unsigned int ack_timeout_ms;
unsigned int hb_timeout_ms;
};
typedef struct game_timer_t game_timers;
struct game_peers_info_t {
struct addrinfo* local;
struct addrinfo* remote;
int start_flag;
int net_fd;
struct game_state_t state;
struct game_timer_t timer;
};
typedef struct game_peers_info_t game_peers_info;
#endif
\ No newline at end of file
......@@ -16,6 +16,7 @@ int parse_args(int argc, char** argv, game_peers_info* peers_info)
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
//hints.ai_family = AF_INET6;
//hints.ai_socktype = SOCK_STREAM;
hints.ai_socktype = SOCK_DGRAM;
//hints.ai_flags = AI_PASSIVE | AI_V4MAPPED;
hints.ai_flags = AI_PASSIVE;
......@@ -24,6 +25,7 @@ int parse_args(int argc, char** argv, game_peers_info* peers_info)
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
//hints.ai_family = AF_INET6;
//hints.ai_socktype = SOCK_STREAM;
hints.ai_socktype = SOCK_DGRAM;
//hints.ai_flags = AI_V4MAPPED;
Getaddrinfo(argv[2], argv[3], &hints, &peers_info->remote);
......
#include "4clib.h"
#include "Socket.h"
#include "cblib.h"
#include <sys/types.h>
#include "game.h"
#ifndef GAMEPEER_H_
#define GAMEPEER_H_
/*
* Message TYPES
*/
#define BUFFER_SIZE (1 << 16)
#define MSG_REG 0
#define MSG_REG_ACK 1
#define MSG_REG_NACK 2
#define MSG_PEER_INFO 3
#define MSG_PEER_INFO_ACK 9
#define MSG_MOVE 4
#define MSG_MOVE_ACK 5
#define MSG_HEARTBEAT 6
#define MSG_HEARTBEAT_ACK 7
#define MSG_UNKNOWN_MSG_TYPE 8
#define LOCAL_START 0
#define REMOTE_START 1
#define LOCAL_PLAYER -1
#define REMOTE_PLAYER 1
//#define STATE_INIT 0
#define STATE_WAIT_FOREIGN_MOVE 1
#define STATE_WAIT_ACK 2
//#define STATE_GOT_FORGEIN_MOVE 2
#define STATE_WAIT_USER_INPUT 3
#define FIRST_SEQ_NUMBER 0
#define TIMEOUT_ACK_MIN_MS 200
#define TIMEOUT_ACK_MAX_MS 20000
#define TIMEOUT_HB_MIN_MS 2000
#define TIMEOUT_HB_MAX_MS 20000
#define DEBUG
/*
* Message STRUCTURES
*/
struct msg_meta_t {
uint16_t type;
uint16_t length;
} __attribute__((packed));
typedef struct msg_meta_t msg_reg_ack;
typedef struct msg_meta_t msg_reg_nack;
typedef struct msg_meta_t msg_peer_info_ack;
typedef struct msg_meta_t msg_unknown_msg_type;
typedef struct msg_meta_t msg_heartbeat;
typedef struct msg_meta_t msg_heartbeat_ack;
struct msg_peer_info_t {
uint16_t type;
uint16_t length;
uint32_t net_addr;
uint16_t net_port;
uint16_t name_len;
} __attribute__((packed));
typedef struct msg_peer_info_t msg_peer_info;
struct msg_move_t {
uint16_t type;
uint16_t length;
uint32_t seg_nr;
uint32_t column;
} __attribute__((packed));
typedef struct msg_move_t msg_move;
struct msg_move_ack_t {
uint16_t type;
uint16_t length;
uint32_t seg_nr;
} __attribute__((packed));
typedef struct msg_move_ack_t msg_move_ack;
struct game_state_t {
uint16_t current_state;
uint32_t my_latest_move;
uint16_t sec_my;
uint16_t sec_rem_next_excepted;
};
typedef struct game_state_t game_state;
struct game_timer_t {
struct timer* hb_timer;
struct timer* conn_timeout;
struct timer* ack_timer;
unsigned int ack_timeout_ms;
unsigned int hb_timeout_ms;
};
typedef struct game_timer_t game_timers;
struct game_peers_info_t {
struct addrinfo* local;
struct addrinfo* remote;
int start_flag;
int net_fd;
struct game_state_t state;
struct game_timer_t timer;
};
typedef struct game_peers_info_t game_peers_info;
/*struct game_state_t
{
uint16_t expected_type_id;
int *(*valid_type_func)(struct game_state_t *cur_state, uint16_t rec_type_id, char *rec_msg, uint16_t rec_msg_len);
int *(*invalid_type_func)(struct game_state_t *cur_state, uint16_t rec_type_id, char *rec_msg, uint16_t rec_msg_len);
struct game_state_t *valid_next_state;
struct game_state_t *invalid_next_state;
};
typedef struct game_state_t game_state;*/
#endif
//int parse_args(int argc, char **argv, game_peers_info *peers_info);
//int process_rec_msg(uint16_t state, uint16_t next_state);
//int process_snd_msg();
int main(int argc, char** argv);
void handle_timer(game_peers_info* peers_info);
void handle_rec(game_peers_info* peers_info);
void handle_stdin(game_peers_info* peers_info);
int init_4gw(game_peers_info* peers_info);
\ No newline at end of file
int init_4gw(game_peers_info* peers_info);
#endif
\ No newline at end of file
#include "gameserver.h"
int main(int argc, char** argv)
{
return 0;
}
\ No newline at end of file
#include "game.h"
#ifndef GAMESERVER_H_
#define GAMESERVER_H_
int main(int argc, char** argv);
#endif
\ No newline at end of file
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