summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-07 18:23:14 +0000
committerrubidium <rubidium@openttd.org>2009-04-07 18:23:14 +0000
commit22d93068890b758ac7d54256fdc24e0c3169504e (patch)
treede0bc2023bce888ef3480f009231e3c8bb85eebb /src
parent3fdb8a62c4867e14417ac92119c3acb0c3fd2d5a (diff)
downloadopenttd-22d93068890b758ac7d54256fdc24e0c3169504e.tar.xz
(svn r15967) -Codechange: do not access NetworkSocketHandler::has_quit directly
Diffstat (limited to 'src')
-rw-r--r--src/network/core/core.h10
-rw-r--r--src/network/core/tcp.cpp2
-rw-r--r--src/network/core/udp.cpp4
-rw-r--r--src/network/network.cpp6
-rw-r--r--src/network/network_client.cpp12
-rw-r--r--src/network/network_content.cpp2
-rw-r--r--src/network/network_server.cpp28
7 files changed, 34 insertions, 30 deletions
diff --git a/src/network/core/core.h b/src/network/core/core.h
index c1605d46d..bc348255d 100644
--- a/src/network/core/core.h
+++ b/src/network/core/core.h
@@ -36,10 +36,9 @@ struct Packet;
* SocketHandler for all network sockets in OpenTTD.
*/
class NetworkSocketHandler {
-public:
- /* TODO: make socket & has_quit protected once the TCP stuff
- *is in a real class too */
bool has_quit; ///< Whether the current client has quit/send a bad packet
+public:
+ /* TODO: make socket protected once the TCP stuff is in a real class too */
SOCKET sock; ///< The socket currently connected to
public:
/** Create a new unbound socket */
@@ -72,6 +71,11 @@ public:
*/
bool HasClientQuit() const { return this->has_quit; }
+ /**
+ * Reopen the socket so we can send/receive stuff again.
+ */
+ void Reopen() { this->has_quit = false; }
+
void Send_GRFIdentifier(Packet *p, const GRFIdentifier *grf);
void Recv_GRFIdentifier(Packet *p, GRFIdentifier *grf);
void Send_CompanyInformation(Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats);
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index 963257847..1ed8b618c 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -29,7 +29,7 @@ NetworkTCPSocketHandler::~NetworkTCPSocketHandler()
NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection()
{
this->writable = false;
- this->has_quit = true;
+ NetworkSocketHandler::CloseConnection();
/* Free all pending and partially received packets */
while (this->packet_queue != NULL) {
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index b2bc7b220..df5a68cb5 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -54,7 +54,7 @@ void NetworkUDPSocketHandler::Close()
NetworkRecvStatus NetworkUDPSocketHandler::CloseConnection()
{
- this->has_quit = true;
+ NetworkSocketHandler::CloseConnection();
return NETWORK_RECV_STATUS_OKAY;
}
@@ -264,7 +264,7 @@ void NetworkUDPSocketHandler::HandleUDPPacket(Packet *p, NetworkAddress *client_
PacketUDPType type;
/* New packet == new client, which has not quit yet */
- this->has_quit = false;
+ this->Reopen();
type = (PacketUDPType)p->Recv_uint8();
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 5cc15bf69..0e241f1a6 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -274,7 +274,7 @@ static void NetworkClientError(NetworkRecvStatus res, NetworkClientSocket *cs)
/* We just want to close the connection.. */
if (res == NETWORK_RECV_STATUS_CLOSE_QUERY) {
- cs->has_quit = true;
+ cs->CloseConnection();
NetworkCloseClient(cs);
_networking = false;
@@ -434,7 +434,7 @@ void NetworkCloseClient(NetworkClientSocket *cs)
DEBUG(net, 1, "Closed client connection %d", cs->client_id);
- if (!cs->has_quit && _network_server && cs->status > STATUS_INACTIVE) {
+ if (!cs->HasClientQuit() && _network_server && cs->status > STATUS_INACTIVE) {
/* We did not receive a leave message from this client... */
char client_name[NETWORK_CLIENT_NAME_LENGTH];
NetworkClientSocket *new_cs;
@@ -844,7 +844,7 @@ static bool NetworkReceive()
NetworkRecvStatus res;
/* The client already was quiting! */
- if (cs->has_quit) return false;
+ if (cs->HasClientQuit()) return false;
res = NetworkClient_ReadPackets(cs);
if (res != NETWORK_RECV_STATUS_OKAY) {
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index e50543111..2f5a040a0 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -359,7 +359,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
{
byte company_info_version = p->Recv_uint8();
- if (!MY_CLIENT->has_quit && company_info_version == NETWORK_COMPANY_INFO_VERSION) {
+ if (!MY_CLIENT->HasClientQuit() && company_info_version == NETWORK_COMPANY_INFO_VERSION) {
/* We have received all data... (there are no more packets coming) */
if (!p->Recv_bool()) return NETWORK_RECV_STATUS_CLOSE_QUERY;
@@ -403,7 +403,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
p->Recv_string(name, sizeof(name));
- if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
+ if (MY_CLIENT->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
/* Do we receive a change of data? Most likely we changed playas */
if (client_id == _network_own_client_id) _network_playas = playas;
@@ -513,7 +513,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD)
/* Initialize the password hash salting variables. */
_password_game_seed = p->Recv_uint32();
p->Recv_string(_password_server_unique_id, sizeof(_password_server_unique_id));
- if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ if (MY_CLIENT->HasClientQuit()) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
case NETWORK_GAME_PASSWORD:
ShowNetworkNeedPassword(type);
@@ -557,7 +557,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
maptype = p->Recv_uint8();
- if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
+ if (MY_CLIENT->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
/* First packet, init some stuff */
if (maptype == MAP_PACKET_START) {
@@ -577,7 +577,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
* do a division by zero. When the connection is lost, we just return
* that. If kbytes_total is 0, the packet must be malformed as a
* savegame less than 1 kilobyte is practically impossible. */
- if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
+ if (MY_CLIENT->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
if (_network_join_bytes_total == 0) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
_network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING;
@@ -938,7 +938,7 @@ NetworkRecvStatus NetworkClient_ReadPackets(NetworkClientSocket *cs)
while (res == NETWORK_RECV_STATUS_OKAY && (p = cs->Recv_Packet(&res)) != NULL) {
byte type = p->Recv_uint8();
- if (type < PACKET_END && _network_client_packet[type] != NULL && !MY_CLIENT->has_quit) {
+ if (type < PACKET_END && _network_client_packet[type] != NULL && !MY_CLIENT->HasClientQuit()) {
res = _network_client_packet[type](p);
} else {
res = NETWORK_RECV_STATUS_MALFORMED_PACKET;
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index ea33691b2..3b94c34b4 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -457,7 +457,7 @@ public:
assert(_network_content_client.sock == INVALID_SOCKET);
_network_content_client.isConnecting = false;
_network_content_client.sock = s;
- _network_content_client.has_quit = false;
+ _network_content_client.Reopen();
_network_content_client.OnConnect(true);
}
};
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index f4de01a5c..bd0b161c7 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -166,7 +166,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientSocket *cs, Netw
DEBUG(net, 1, "Client %d made an error and has been disconnected. Reason: '%s'", cs->client_id, str);
}
- cs->has_quit = true;
+ cs->CloseConnection();
/* Make sure the data get's there before we close the connection */
cs->Send_Packets();
@@ -668,7 +668,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
client_lang = (NetworkLanguage)p->Recv_uint8();
p->Recv_string(unique_id, sizeof(unique_id));
- if (cs->has_quit) return;
+ if (cs->HasClientQuit()) return;
/* join another company does not affect these values */
switch (playas) {
@@ -769,7 +769,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP)
/* The client was never joined.. so this is impossible, right?
* Ignore the packet, give the client a warning, and close his connection */
- if (cs->status < STATUS_AUTH || cs->has_quit) {
+ if (cs->status < STATUS_AUTH || cs->HasClientQuit()) {
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED);
return;
}
@@ -791,7 +791,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP)
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)
{
/* Client has the map, now start syncing */
- if (cs->status == STATUS_DONE_MAP && !cs->has_quit) {
+ if (cs->status == STATUS_DONE_MAP && !cs->HasClientQuit()) {
char client_name[NETWORK_CLIENT_NAME_LENGTH];
NetworkClientSocket *new_cs;
@@ -846,7 +846,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
/* The client was never joined.. so this is impossible, right?
* Ignore the packet, give the client a warning, and close his connection */
- if (cs->status < STATUS_DONE_MAP || cs->has_quit) {
+ if (cs->status < STATUS_DONE_MAP || cs->HasClientQuit()) {
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
return;
}
@@ -854,7 +854,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
CommandPacket cp;
const char *err = cs->Recv_Command(p, &cp);
- if (cs->has_quit) return;
+ if (cs->HasClientQuit()) return;
NetworkClientInfo *ci = cs->GetInfo();
@@ -946,8 +946,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
NetworkErrorCode errorno = (NetworkErrorCode)p->Recv_uint8();
/* The client was never joined.. thank the client for the packet, but ignore it */
- if (cs->status < STATUS_DONE_MAP || cs->has_quit) {
- cs->has_quit = true;
+ if (cs->status < STATUS_DONE_MAP || cs->HasClientQuit()) {
+ cs->CloseConnection();
return;
}
@@ -966,7 +966,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
}
}
- cs->has_quit = true;
+ cs->CloseConnection();
}
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
@@ -977,8 +977,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
char client_name[NETWORK_CLIENT_NAME_LENGTH];
/* The client was never joined.. thank the client for the packet, but ignore it */
- if (cs->status < STATUS_DONE_MAP || cs->has_quit) {
- cs->has_quit = true;
+ if (cs->status < STATUS_DONE_MAP || cs->HasClientQuit()) {
+ cs->CloseConnection();
return;
}
@@ -992,7 +992,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
}
}
- cs->has_quit = true;
+ cs->CloseConnection();
}
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
@@ -1194,7 +1194,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
p->Recv_string(client_name, sizeof(client_name));
ci = cs->GetInfo();
- if (cs->has_quit) return;
+ if (cs->HasClientQuit()) return;
if (ci != NULL) {
/* Display change */
@@ -1552,7 +1552,7 @@ bool NetworkServer_ReadPackets(NetworkClientSocket *cs)
NetworkRecvStatus res;
while ((p = cs->Recv_Packet(&res)) != NULL) {
byte type = p->Recv_uint8();
- if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->has_quit) {
+ if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->HasClientQuit()) {
_network_server_packet[type](cs, p);
} else {
DEBUG(net, 0, "[server] received invalid packet type %d", type);