1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/******************************************************************************
* Warmux is a convivial mass murder game.
* Copyright (C) 2001-2011 Warmux Team.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
******************************************************************************/
#ifndef NET_DATA_H
#define NET_DATA_H
#include <netinet/in.h>
#include <string>
#include <time.h>
#include <WSERVER_index_msg.h>
class NetData
{
char* str;
size_t str_size;
size_t msg_size;
int fd;
int ip_address;
time_t ping_time;
bool ping_sent;
size_t bytes_received;
void UpdatePing();
protected:
enum IndexServerMsg msg_id;
// Return false if the client closed the connection
bool ReceiveStr(std::string & full_str);
bool ReceiveInt(int & nbr);
bool SendInt(const int & nbr);
bool SendStr(const std::string & full_str);
size_t BytesReceived() const { return bytes_received; };
public:
bool connected;
NetData();
virtual ~NetData();
const int & GetFD() { return fd; };
const int & GetIP() { return ip_address; };
void Host(const int & client_fd, const unsigned int & ip);
static int GetConnection(const char* host, int port);
bool ConnectTo(const std::string & address, const int & port);
bool Receive();
bool ReceiveData();
virtual bool HandleMsg(enum IndexServerMsg msg_id) = 0;
void CheckState();
};
#endif
|