Commit 1c39ffd6 authored by Simon Wüllhorst's avatar Simon Wüllhorst

Updated parse_args():

It now can handle both: direct client connection or parsing informations about an foreign gameserver
parent 1323d0cc
#include "Socket.h"
#include "cblib.h"
#include <sys/param.h>
#include <sys/types.h>
#ifndef GAME_H_
......
#include "gamepeer.h"
static char buf[BUFFER_SIZE];
int parse_args(int argc, char** argv, game_peers_info* peers_info)
int parse_remote_client(int argc, char** argv, game_peers_info* peers_info)
{
struct addrinfo hints;
if (argc != 5) {
printf("Wrong amount of parameters. Propper usage:\n ./%s LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT START_FLAG\n", argv[0]);
return -1;
}
peers_info->start_flag = atoi(argv[4]);
peers_info->start_flag = atoi(argv[5]);
if (peers_info->start_flag != REMOTE_START && peers_info->start_flag != LOCAL_START) {
printf("Wrong value for START_FLAG.\n");
return -1;
......@@ -18,19 +16,49 @@ int parse_args(int argc, char** argv, game_peers_info* peers_info)
//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;
Getaddrinfo(NULL, argv[1], &hints, &peers_info->local);
//hints.ai_flags = AI_V4MAPPED;
Getaddrinfo(argv[3], argv[4], &hints, &peers_info->remote);
return 0;
}
int parse_remote_server(int argc, char** argv, game_peers_info* peers_info)
{
printf("ERR: Server-Modus not implemented, yet.\n");
return -1;
}
int parse_args(int argc, char** argv, game_peers_info* peers_info)
{
char fmt_string[] = "Wrong amount of parameters. Propper usage:\n %s LOCAL_PORT {(-c REMOTE_CLIENT_ADDRESS REMOTE_CLIENT_PORT) | (-s REMOTE_SERVER_ADDRESS REMOTE_SERVER_PORT)}\n";
struct addrinfo hints;
if (argc < 5) {
printf(fmt_string, argv[0]);
return -1;
}
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);
//hints.ai_flags = AI_PASSIVE | AI_V4MAPPED;
hints.ai_flags = AI_PASSIVE;
Getaddrinfo(NULL, argv[1], &hints, &peers_info->local);
return 0;
if (argv[2][1] == 'c') {
if (argc != 6) {
printf(fmt_string, argv[0]);
return -1;
}
return parse_remote_client(argc, argv, peers_info);
} else if (argv[2][1] == 's') {
if (argc != 5) {
printf(fmt_string, argv[0]);
return -1;
}
return parse_remote_server(argc, argv, peers_info);
} else {
printf("Unknown type flag, use -c or -s.\n");
return -1;
}
}
void finalize(game_peers_info* peers_info, int exit_code, char* last_message)
......
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