Cosmetic changes, added some convenience functions.
This commit is contained in:
@@ -35,8 +35,8 @@
|
||||
|
||||
NetworkManager::NetworkManager()
|
||||
{
|
||||
m_public_address.ip = 0;
|
||||
m_public_address.port = 0;
|
||||
m_public_address.m_ip = 0;
|
||||
m_public_address.m_port = 0;
|
||||
m_localhost = NULL;
|
||||
m_game_setup = NULL;
|
||||
}
|
||||
|
||||
@@ -125,8 +125,7 @@ void ClientLobbyRoomProtocol::voteLaps(uint8_t laps, uint8_t track_nb)
|
||||
void ClientLobbyRoomProtocol::leave()
|
||||
{
|
||||
m_server->disconnect();
|
||||
m_server_address.ip = 0;
|
||||
m_server_address.port = 0;
|
||||
m_server_address.clear();
|
||||
} // leave
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -59,12 +59,10 @@ bool ConnectToPeer::notifyEventAsynchronous(Event* event)
|
||||
|
||||
void ConnectToPeer::setup()
|
||||
{
|
||||
m_state = NONE;
|
||||
m_public_address.ip = 0;
|
||||
m_public_address.port = 0;
|
||||
m_peer_address.ip = 0;
|
||||
m_peer_address.port = 0;
|
||||
m_current_protocol_id = 0;
|
||||
m_state = NONE;
|
||||
m_public_address.clear();
|
||||
m_peer_address.clear();
|
||||
m_current_protocol_id = 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -83,22 +81,22 @@ void ConnectToPeer::asynchronousUpdate()
|
||||
if (m_listener->getProtocolState(m_current_protocol_id)
|
||||
== PROTOCOL_STATE_TERMINATED) // we know the peer address
|
||||
{
|
||||
if (m_peer_address.ip != 0 && m_peer_address.port != 0)
|
||||
if (m_peer_address.m_ip != 0 && m_peer_address.m_port != 0)
|
||||
{
|
||||
// we're in the same lan (same public ip address) !!
|
||||
if (m_peer_address.ip == NetworkManager::getInstance()->getPublicAddress().ip)
|
||||
if (m_peer_address.m_ip == NetworkManager::getInstance()->getPublicAddress().m_ip)
|
||||
{
|
||||
// just send a broadcast packet with the string aloha_stk inside, the client will know our ip address and will connect
|
||||
STKHost* host = NetworkManager::getInstance()->getHost();
|
||||
TransportAddress broadcast_address;
|
||||
broadcast_address.ip = -1; // 255.255.255.255
|
||||
broadcast_address.port = m_peer_address.port; // 0b10101100000101101101111111111111; // for test
|
||||
broadcast_address.m_ip = -1; // 255.255.255.255
|
||||
broadcast_address.m_port = m_peer_address.m_port; // 0b10101100000101101101111111111111; // for test
|
||||
char data[] = "aloha_stk\0";
|
||||
host->sendRawPacket((uint8_t*)(data), 10, broadcast_address);
|
||||
Log::info("ConnectToPeer", "Broadcast aloha sent.");
|
||||
StkTime::sleep(1);
|
||||
broadcast_address.ip = 0x7f000001; // 127.0.0.1 (localhost)
|
||||
broadcast_address.port = m_peer_address.port;
|
||||
broadcast_address.m_ip = 0x7f000001; // 127.0.0.1 (localhost)
|
||||
broadcast_address.m_port = m_peer_address.m_port;
|
||||
host->sendRawPacket((uint8_t*)(data), 10, broadcast_address);
|
||||
Log::info("ConnectToPeer", "Broadcast aloha to self.");
|
||||
}
|
||||
|
||||
@@ -82,10 +82,8 @@ void ConnectToServer::setup()
|
||||
{
|
||||
Log::info("ConnectToServer", "SETUPP");
|
||||
m_state = NONE;
|
||||
m_public_address.ip = 0;
|
||||
m_public_address.port = 0;
|
||||
m_server_address.ip = 0;
|
||||
m_server_address.port = 0;
|
||||
m_public_address.clear();
|
||||
m_server_address.clear();
|
||||
m_current_protocol_id = 0;
|
||||
}
|
||||
|
||||
@@ -139,7 +137,7 @@ void ConnectToServer::asynchronousUpdate()
|
||||
== PROTOCOL_STATE_TERMINATED) // we know the server address
|
||||
{
|
||||
Log::info("ConnectToServer", "Server's address known");
|
||||
if (m_server_address.ip == m_public_address.ip) // we're in the same lan (same public ip address) !!
|
||||
if (m_server_address.m_ip == m_public_address.m_ip) // we're in the same lan (same public ip address) !!
|
||||
Log::info("ConnectToServer", "Server appears to be in the same LAN.");
|
||||
m_state = REQUESTING_CONNECTION;
|
||||
m_current_protocol_id = m_listener->requestStart(new RequestConnection(m_server_id));
|
||||
@@ -150,14 +148,15 @@ void ConnectToServer::asynchronousUpdate()
|
||||
== PROTOCOL_STATE_TERMINATED) // server knows we wanna connect
|
||||
{
|
||||
Log::info("ConnectToServer", "Connection request made");
|
||||
if (m_server_address.ip == 0 || m_server_address.port == 0)
|
||||
if (m_server_address.m_ip == 0 || m_server_address.m_port == 0)
|
||||
{ // server data not correct, hide address and stop
|
||||
m_state = HIDING_ADDRESS;
|
||||
Log::error("ConnectToServer", "Server address is " ADDRESS_FORMAT, ADDRESS_ARGS(m_server_address.ip, m_server_address.port));
|
||||
Log::error("ConnectToServer", "Server address is %s",
|
||||
m_server_address.toString().c_str());
|
||||
m_current_protocol_id = m_listener->requestStart(new HidePublicAddress());
|
||||
return;
|
||||
}
|
||||
if (m_server_address.ip == m_public_address.ip) // we're in the same lan (same public ip address) !!
|
||||
if (m_server_address.m_ip == m_public_address.m_ip) // we're in the same lan (same public ip address) !!
|
||||
{
|
||||
// just send a broadcast packet, the client will know our ip address and will connect
|
||||
STKHost* host = NetworkManager::getInstance()->getHost();
|
||||
@@ -165,8 +164,8 @@ void ConnectToServer::asynchronousUpdate()
|
||||
TransportAddress sender;
|
||||
|
||||
TransportAddress broadcast_address;
|
||||
broadcast_address.ip = -1; // 255.255.255.255
|
||||
broadcast_address.port = 7321; // 0b10101100000101101101111111111111; // for test
|
||||
broadcast_address.m_ip = -1; // 255.255.255.255
|
||||
broadcast_address.m_port = 7321; // 0b10101100000101101101111111111111; // for test
|
||||
char data2[] = "aloha_stk\0";
|
||||
host->sendRawPacket((uint8_t*)(data2), 10, broadcast_address);
|
||||
|
||||
@@ -177,7 +176,8 @@ void ConnectToServer::asynchronousUpdate()
|
||||
const char data[] = "aloha_stk\0";
|
||||
if (strcmp(data, (char*)(received_data)) == 0)
|
||||
{
|
||||
Log::info("ConnectToServer", "LAN Server found : %u:%u", sender.ip, sender.port);
|
||||
Log::info("ConnectToServer", "LAN Server found : %s",
|
||||
sender.toString());
|
||||
#ifndef WIN32
|
||||
// just check if the ip is ours : if so, then just use localhost (127.0.0.1)
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
@@ -219,9 +219,9 @@ void ConnectToServer::asynchronousUpdate()
|
||||
for(unsigned int i=0; i<table->dwNumEntries; i++)
|
||||
{
|
||||
unsigned int ip = ntohl(table->table[i].dwAddr);
|
||||
if(sender.ip == ip) // this interface is ours
|
||||
if(sender.m_ip == ip) // this interface is ours
|
||||
{
|
||||
sender.ip = 0x7f000001; // 127.0.0.1
|
||||
sender.m_ip = 0x7f000001; // 127.0.0.1
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,8 @@ void ConnectToServer::asynchronousUpdate()
|
||||
{
|
||||
timer = StkTime::getRealTime();
|
||||
NetworkManager::getInstance()->connect(m_server_address);
|
||||
Log::info("ConnectToServer", "Trying to connect to %u:%u", m_server_address.ip, m_server_address.port);
|
||||
Log::info("ConnectToServer", "Trying to connect to %s",
|
||||
m_server_address.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ void GetPeerAddress::asynchronousUpdate()
|
||||
if (rec_success == "yes")
|
||||
{
|
||||
TransportAddress* addr = static_cast<TransportAddress*>(m_callback_object);
|
||||
result->get("ip", &addr->ip);
|
||||
result->get("ip", &addr->m_ip);
|
||||
|
||||
if (addr->ip == NetworkManager::getInstance()->getPublicAddress().ip)
|
||||
result->get("private_port", &addr->port);
|
||||
if (addr->m_ip == NetworkManager::getInstance()->getPublicAddress().m_ip)
|
||||
result->get("private_port", &addr->m_port);
|
||||
else
|
||||
result->get("port", &addr->port);
|
||||
result->get("port", &addr->m_port);
|
||||
|
||||
Log::debug("GetPeerAddress", "Address gotten successfully.");
|
||||
}
|
||||
|
||||
@@ -156,8 +156,7 @@ std::string GetPublicAddress::parseStunResponse()
|
||||
|
||||
|
||||
// Those are the port and the address to be detected
|
||||
uint16_t port;
|
||||
uint32_t address;
|
||||
TransportAddress address;
|
||||
int pos = 20;
|
||||
while (true)
|
||||
{
|
||||
@@ -167,8 +166,8 @@ std::string GetPublicAddress::parseStunResponse()
|
||||
{
|
||||
assert(size == 8);
|
||||
assert(datas.getUInt8(pos+5) == 0x01); // Family IPv4 only
|
||||
port = datas.getUInt16(pos + 6);
|
||||
address = datas.getUInt32(pos + 8);
|
||||
address.m_port = datas.getUInt16(pos + 6);
|
||||
address.m_ip = datas.getUInt32(pos + 8);
|
||||
break;
|
||||
} // type = 0 or 1
|
||||
pos += 4 + size;
|
||||
@@ -180,11 +179,10 @@ std::string GetPublicAddress::parseStunResponse()
|
||||
} // while true
|
||||
|
||||
// finished parsing, we know our public transport address
|
||||
Log::debug("GetPublicAddress", "The public address has been found: %i.%i.%i.%i:%i",
|
||||
address>>24&0xff, address>>16&0xff, address>>8&0xff, address&0xff, port);
|
||||
Log::debug("GetPublicAddress", "The public address has been found: %s",
|
||||
address.toString().c_str());
|
||||
TransportAddress* addr = static_cast<TransportAddress*>(m_callback_object);
|
||||
addr->ip = address;
|
||||
addr->port = port;
|
||||
*addr = address;
|
||||
|
||||
// The address and the port are known, so the connection can be closed
|
||||
m_state = EXITING;
|
||||
|
||||
@@ -59,10 +59,11 @@ void QuickJoinProtocol::asynchronousUpdate()
|
||||
{
|
||||
if(rec_success == "yes")
|
||||
{
|
||||
result->get("ip", &res->ip);
|
||||
result->get("port", &res->port);
|
||||
result->get("ip", &res->m_ip);
|
||||
result->get("port", &res->m_port);
|
||||
result->get("hostid", m_server_id);
|
||||
Log::info("QuickJoinProtocol", "Quick joining %d:%d (server#%d).", res->ip, res->port, *m_server_id);
|
||||
Log::info("QuickJoinProtocol", "Quick joining %s (server#%d).",
|
||||
res->toString(), *m_server_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -53,8 +53,7 @@ void ServerLobbyRoomProtocol::setup()
|
||||
m_setup->getRaceConfig()->setPlayerCount(16); //FIXME : this has to be moved to when logging into the server
|
||||
m_next_id = 0;
|
||||
m_state = NONE;
|
||||
m_public_address.ip = 0;
|
||||
m_public_address.port = 0;
|
||||
m_public_address.clear();
|
||||
m_selection_enabled = false;
|
||||
m_in_race = false;
|
||||
Log::info("ServerLobbyRoomProtocol", "Starting the protocol.");
|
||||
@@ -185,8 +184,8 @@ void ServerLobbyRoomProtocol::checkIncomingConnectionRequests()
|
||||
Online::XMLRequest* request = new Online::XMLRequest();
|
||||
PlayerManager::setUserDetails(request, "poll-connection-requests", Online::API::SERVER_PATH);
|
||||
|
||||
request->addParameter("address", addr.ip);
|
||||
request->addParameter("port", addr.port);
|
||||
request->addParameter("address", addr.m_ip);
|
||||
request->addParameter("port", addr.m_port);
|
||||
|
||||
request->executeNow();
|
||||
assert(request->isDone());
|
||||
|
||||
@@ -45,11 +45,11 @@ void ShowPublicAddress::asynchronousUpdate()
|
||||
m_request = new Online::XMLRequest();
|
||||
PlayerManager::setUserDetails(m_request, "set", Online::API::SERVER_PATH);
|
||||
|
||||
m_request->addParameter("address", addr.ip);
|
||||
m_request->addParameter("port", addr.port);
|
||||
m_request->addParameter("address", addr.m_ip);
|
||||
m_request->addParameter("port", addr.m_port);
|
||||
m_request->addParameter("private_port", NetworkManager::getInstance()->getHost()->getPort());
|
||||
|
||||
Log::info("ShowPublicAddress", "Showing addr %u and port %d", addr.ip, addr.port);
|
||||
Log::info("ShowPublicAddress", "Showing addr %s", addr.toString().c_str());
|
||||
|
||||
Online::RequestManager::get()->addRequest(m_request);
|
||||
m_state = REQUEST_PENDING;
|
||||
|
||||
@@ -44,12 +44,12 @@ void StartServer::asynchronousUpdate()
|
||||
m_request = new Online::XMLRequest();
|
||||
PlayerManager::setUserDetails(m_request, "start", Online::API::SERVER_PATH);
|
||||
|
||||
m_request->addParameter("address", addr.ip);
|
||||
m_request->addParameter("port", addr.port);
|
||||
m_request->addParameter("address", addr.m_ip);
|
||||
m_request->addParameter("port", addr.m_port);
|
||||
m_request->addParameter("private_port", NetworkManager::getInstance()->getHost()->getPort());
|
||||
m_request->addParameter("max_players", UserConfigParams::m_server_max_players);
|
||||
|
||||
Log::info("ShowPublicAddress", "Showing addr %u and port %d", addr.ip, addr.port);
|
||||
Log::info("ShowPublicAddress", "Showing addr %s", addr.toString().c_str());
|
||||
|
||||
Online::RequestManager::get()->addRequest(m_request);
|
||||
m_state = REQUEST_PENDING;
|
||||
|
||||
@@ -49,10 +49,10 @@ void StopServer::asynchronousUpdate()
|
||||
m_request = new Online::XMLRequest();
|
||||
PlayerManager::setUserDetails(m_request, "stop", Online::API::SERVER_PATH);
|
||||
|
||||
m_request->addParameter("address", addr.ip);
|
||||
m_request->addParameter("port", addr.port);
|
||||
m_request->addParameter("address", addr.m_ip);
|
||||
m_request->addParameter("port", addr.m_port);
|
||||
|
||||
Log::info("StopServer", "address %u, port %d", addr.ip, addr.port);
|
||||
Log::info("StopServer", "address %s", addr.toString().c_str());
|
||||
|
||||
Online::RequestManager::get()->addRequest(m_request);
|
||||
m_state = REQUEST_PENDING;
|
||||
|
||||
@@ -208,13 +208,13 @@ void STKHost::sendRawPacket(uint8_t* data, int length, TransportAddress dst)
|
||||
memset(&to,0,to_len);
|
||||
|
||||
to.sin_family = AF_INET;
|
||||
to.sin_port = htons(dst.port);
|
||||
to.sin_addr.s_addr = htonl(dst.ip);
|
||||
to.sin_port = htons(dst.m_port);
|
||||
to.sin_addr.s_addr = htonl(dst.m_ip);
|
||||
|
||||
sendto(m_host->socket, (char*)data, length, 0,(sockaddr*)&to, to_len);
|
||||
Log::verbose("STKHost", "Raw packet sent to %i.%i.%i.%i:%u", ((dst.ip>>24)&0xff)
|
||||
, ((dst.ip>>16)&0xff), ((dst.ip>>8)&0xff), ((dst.ip>>0)&0xff), dst.port);
|
||||
STKHost::logPacket(NetworkString(std::string((char*)(data), length)), false);
|
||||
Log::verbose("STKHost", "Raw packet sent to %s", dst.toString().c_str());
|
||||
STKHost::logPacket(NetworkString(std::string((char*)(data), length)),
|
||||
false);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -265,8 +265,8 @@ uint8_t* STKHost::receiveRawPacket(TransportAddress* sender)
|
||||
Log::error("STKHost", "Problem with the socket. Please contact the dev team.");
|
||||
}
|
||||
// we received the data
|
||||
sender->ip = ntohl((uint32_t)(addr.sin_addr.s_addr));
|
||||
sender->port = ntohs(addr.sin_port);
|
||||
sender->m_ip = ntohl((uint32_t)(addr.sin_addr.s_addr));
|
||||
sender->m_port = ntohs(addr.sin_port);
|
||||
|
||||
if (addr.sin_family == AF_INET)
|
||||
{
|
||||
@@ -294,7 +294,7 @@ uint8_t* STKHost::receiveRawPacket(TransportAddress sender, int max_tries)
|
||||
|
||||
int i = 0;
|
||||
// wait to receive the message because enet sockets are non-blocking
|
||||
while(len < 0 || addr.sin_addr.s_addr == sender.ip)
|
||||
while(len < 0 || addr.sin_addr.s_addr == sender.m_ip)
|
||||
{
|
||||
i++;
|
||||
if (len>=0)
|
||||
@@ -339,8 +339,8 @@ bool STKHost::peerExists(TransportAddress peer)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_host->peerCount; i++)
|
||||
{
|
||||
if (m_host->peers[i].address.host == ntohl(peer.ip) &&
|
||||
m_host->peers[i].address.port == peer.port)
|
||||
if (m_host->peers[i].address.host == ntohl(peer.m_ip) &&
|
||||
m_host->peers[i].address.port == peer.m_port)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -354,8 +354,7 @@ bool STKHost::isConnectedTo(TransportAddress peer)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_host->peerCount; i++)
|
||||
{
|
||||
if (m_host->peers[i].address.host == ntohl(peer.ip) &&
|
||||
m_host->peers[i].address.port == peer.port &&
|
||||
if (peer == m_host->peers[i].address &&
|
||||
m_host->peers[i].state == ENET_PEER_STATE_CONNECTED)
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -67,11 +67,11 @@ bool STKPeer::connectToHost(STKHost* localhost, TransportAddress host,
|
||||
{
|
||||
ENetAddress address;
|
||||
address.host =
|
||||
((host.ip & 0xff000000) >> 24)
|
||||
+ ((host.ip & 0x00ff0000) >> 8)
|
||||
+ ((host.ip & 0x0000ff00) << 8)
|
||||
+ ((host.ip & 0x000000ff) << 24); // because ENet wants little endian
|
||||
address.port = host.port;
|
||||
((host.m_ip & 0xff000000) >> 24)
|
||||
+ ((host.m_ip & 0x00ff0000) >> 8)
|
||||
+ ((host.m_ip & 0x0000ff00) << 8)
|
||||
+ ((host.m_ip & 0x000000ff) << 24); // because ENet wants little endian
|
||||
address.port = host.m_port;
|
||||
|
||||
ENetPeer* peer = enet_host_connect(localhost->m_host, &address, 2, 0);
|
||||
if (peer == NULL)
|
||||
@@ -79,10 +79,10 @@ bool STKPeer::connectToHost(STKHost* localhost, TransportAddress host,
|
||||
Log::error("STKPeer", "Could not try to connect to server.\n");
|
||||
return false;
|
||||
}
|
||||
Log::verbose("STKPeer", "Connecting to %i.%i.%i.%i:%i.\nENetPeer address "
|
||||
"is %p", (peer->address.host>>0)&0xff,
|
||||
(peer->address.host>>8)&0xff,(peer->address.host>>16)&0xff,
|
||||
(peer->address.host>>24)&0xff,peer->address.port, peer);
|
||||
TransportAddress a;
|
||||
a.m_ip = peer->address.host;
|
||||
a.m_port = peer->address.port;
|
||||
Log::verbose("STKPeer", "Connecting to %s", a.toString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -97,10 +97,13 @@ void STKPeer::disconnect()
|
||||
|
||||
void STKPeer::sendPacket(NetworkString const& data, bool reliable)
|
||||
{
|
||||
Log::verbose("STKPeer", "sending packet of size %d to %i.%i.%i.%i:%i",
|
||||
data.size(), (m_peer->address.host>>0)&0xff,
|
||||
(m_peer->address.host>>8)&0xff,(m_peer->address.host>>16)&0xff,
|
||||
(m_peer->address.host>>24)&0xff,m_peer->address.port);
|
||||
TransportAddress a;
|
||||
a.m_ip = m_peer->address.host;
|
||||
a.m_port = m_peer->address.port;
|
||||
|
||||
Log::verbose("STKPeer", "sending packet of size %d to %s",
|
||||
a.toString().c_str());
|
||||
|
||||
ENetPacket* packet = enet_packet_create(data.getBytes(), data.size() + 1,
|
||||
(reliable ? ENET_PACKET_FLAG_RELIABLE : ENET_PACKET_FLAG_UNSEQUENCED));
|
||||
/* to debug the packet output
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
#ifndef TYPES_HPP
|
||||
#define TYPES_HPP
|
||||
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
#include "enet/enet.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
/*! functions to write easily addresses in logs. */
|
||||
#define ADDRESS_FORMAT "%d.%d.%d.%d:%d"
|
||||
#define ADDRESS_ARGS(ip,port) ((ip>>24)&0xff),((ip>>16)&0xff),((ip>>8)&0xff),((ip>>0)&0xff),port
|
||||
|
||||
// ============================================================================
|
||||
/*! \class CallbackObject
|
||||
* \brief Class that must be inherited to pass objects to protocols.
|
||||
*/
|
||||
@@ -39,29 +39,67 @@ class CallbackObject
|
||||
CallbackObject() {}
|
||||
~CallbackObject() {}
|
||||
|
||||
};
|
||||
}; // CallbackObject
|
||||
|
||||
// ============================================================================
|
||||
/*! \class TransportAddress
|
||||
* \brief Describes a transport-layer address.
|
||||
* For IP networks, a transport address is the couple ip:port.
|
||||
*/
|
||||
class TransportAddress : public CallbackObject
|
||||
{
|
||||
public:
|
||||
TransportAddress(uint32_t p_ip = 0, uint16_t p_port = 0)
|
||||
{ ip = p_ip; port = p_port; }
|
||||
public:
|
||||
uint32_t m_ip; //!< The IPv4 address
|
||||
uint16_t m_port; //!< The port number
|
||||
|
||||
/** Constructor. */
|
||||
TransportAddress(uint32_t ip = 0, uint16_t port = 0)
|
||||
{
|
||||
m_ip = ip;
|
||||
m_port = port;
|
||||
} // TransportAddress
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
~TransportAddress() {}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Resets ip and port to 0. */
|
||||
void clear()
|
||||
{
|
||||
m_ip = 0;
|
||||
m_port = 0;
|
||||
} // clear
|
||||
// ------------------------------------------------------------------------
|
||||
/** Compares if ip address and port are identical. */
|
||||
bool operator==(const TransportAddress& other) const
|
||||
{ return other.ip == ip && other.port == port; }
|
||||
{
|
||||
return other.m_ip == m_ip && other.m_port == m_port;
|
||||
} // operator==
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
bool operator==(const ENetAddress& other)
|
||||
{
|
||||
return other.host == ntohl(m_ip) && other.port == m_port;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Compares if ip address or port are different. */
|
||||
bool operator!=(const TransportAddress& other) const
|
||||
{ return other.ip != ip || other.port != port; }
|
||||
|
||||
uint32_t ip; //!< The IPv4 address
|
||||
uint16_t port; //!< The port number
|
||||
};
|
||||
{
|
||||
return other.m_ip != m_ip || other.m_port != m_port;
|
||||
} // operator!=
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns a std::string representing the ip address and port in human
|
||||
* readable format. */
|
||||
std::string toString() const
|
||||
{
|
||||
return
|
||||
StringUtils::insertValues("%d.%d.%d.%d:%d",
|
||||
((m_ip >> 24) & 0xff), ((m_ip >> 16) & 0xff),
|
||||
((m_ip >> 8) & 0xff), ((m_ip >> 0) & 0xff),
|
||||
m_port );
|
||||
} // toString
|
||||
}; // TransportAddress
|
||||
|
||||
// ============================================================================
|
||||
/*! \class PlayerLogin
|
||||
* \brief Contains the information needed to authenticate a user.
|
||||
*/
|
||||
@@ -73,7 +111,7 @@ class PlayerLogin : public CallbackObject
|
||||
|
||||
std::string username; //!< Username of the player
|
||||
std::string password; //!< Password of the player
|
||||
};
|
||||
}; // class PlayerLogin
|
||||
|
||||
|
||||
#endif // TYPES_HPP
|
||||
|
||||
Reference in New Issue
Block a user