2015-01-02 13:55:23 +00:00
|
|
|
#ifndef _TTRTS_NET_H_
|
|
|
|
#define _TTRTS_NET_H_
|
|
|
|
|
2015-01-02 19:51:14 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <game.h>
|
|
|
|
#include <formatters.h>
|
|
|
|
|
2015-01-02 15:13:05 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-01-03 22:30:52 +00:00
|
|
|
#include <iostream>
|
2015-01-02 15:13:05 +00:00
|
|
|
|
2015-01-03 20:04:31 +00:00
|
|
|
#define TTRTS_HANDSHAKE_FORMAT "player %u name %s"
|
|
|
|
|
2015-01-02 19:51:14 +00:00
|
|
|
// Struct for net client info
|
|
|
|
struct ClientInfo
|
|
|
|
{
|
|
|
|
sockaddr_in cli_addr;
|
|
|
|
int clientsockfd;
|
|
|
|
player_t player;
|
|
|
|
};
|
|
|
|
|
|
|
|
int WaitForOrdersFromClient(const ClientInfo info, std::mutex &mut, CTTRTSGame &game);
|
|
|
|
|
|
|
|
void GetOrdersFromClients(std::vector<ClientInfo> &myClients, CTTRTSGame &game, std::mutex &gameMutex);
|
|
|
|
|
|
|
|
void SendGameInfoToClients(std::vector<ClientInfo> &myClients, const CTTRTSGame &game, std::mutex &gameMutex);
|
|
|
|
|
2015-01-03 22:30:52 +00:00
|
|
|
inline void fatal_error(const char *msg)
|
|
|
|
{
|
|
|
|
std::cerr<<msg<<std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void fatal_perror(const char *msg)
|
2015-01-02 15:13:05 +00:00
|
|
|
{
|
|
|
|
perror(msg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-01-02 13:55:23 +00:00
|
|
|
#endif
|