mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r21363) -Add: support for limiting the amount of (accepted) incoming data
This commit is contained in:
parent
a0f0f5e2e1
commit
fd752ca2b0
@ -39,7 +39,7 @@ public:
|
|||||||
bool SendPackets(bool closing_down = false);
|
bool SendPackets(bool closing_down = false);
|
||||||
bool IsPacketQueueEmpty();
|
bool IsPacketQueueEmpty();
|
||||||
|
|
||||||
Packet *ReceivePacket();
|
virtual Packet *ReceivePacket();
|
||||||
|
|
||||||
bool CanSendReceive();
|
bool CanSendReceive();
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo
|
|||||||
{
|
{
|
||||||
this->status = STATUS_INACTIVE;
|
this->status = STATUS_INACTIVE;
|
||||||
this->client_id = _network_client_id++;
|
this->client_id = _network_client_id++;
|
||||||
|
this->receive_limit = _settings_client.network.bytes_per_frame_burst;
|
||||||
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
|
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
|
||||||
this->SetInfo(ci);
|
this->SetInfo(ci);
|
||||||
ci->client_playas = COMPANY_INACTIVE_CLIENT;
|
ci->client_playas = COMPANY_INACTIVE_CLIENT;
|
||||||
@ -77,6 +78,19 @@ ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler()
|
|||||||
OrderBackup::ResetUser(this->client_id);
|
OrderBackup::ResetUser(this->client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Packet *ServerNetworkGameSocketHandler::ReceivePacket()
|
||||||
|
{
|
||||||
|
/* Only allow receiving when we have some buffer free; this value
|
||||||
|
* can go negative, but eventually it will become positive again. */
|
||||||
|
if (this->receive_limit <= 0) return NULL;
|
||||||
|
|
||||||
|
/* We can receive a packet, so try that and if needed account for
|
||||||
|
* the amount of received data. */
|
||||||
|
Packet *p = this->NetworkTCPSocketHandler::ReceivePacket();
|
||||||
|
if (p != NULL) this->receive_limit -= p->size;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status)
|
||||||
{
|
{
|
||||||
assert(status != NETWORK_RECV_STATUS_OKAY);
|
assert(status != NETWORK_RECV_STATUS_OKAY);
|
||||||
@ -1540,6 +1554,11 @@ void NetworkServer_Tick(bool send_frame)
|
|||||||
/* Now we are done with the frame, inform the clients that they can
|
/* Now we are done with the frame, inform the clients that they can
|
||||||
* do their frame! */
|
* do their frame! */
|
||||||
FOR_ALL_CLIENT_SOCKETS(cs) {
|
FOR_ALL_CLIENT_SOCKETS(cs) {
|
||||||
|
/* We allow a number of bytes per frame, but only to the burst amount
|
||||||
|
* to be available for packet receiving at any particular time. */
|
||||||
|
cs->receive_limit = min(cs->receive_limit + _settings_client.network.bytes_per_frame,
|
||||||
|
_settings_client.network.bytes_per_frame_burst);
|
||||||
|
|
||||||
/* Check if the speed of the client is what we can expect from a client */
|
/* Check if the speed of the client is what we can expect from a client */
|
||||||
if (cs->status == NetworkClientSocket::STATUS_ACTIVE) {
|
if (cs->status == NetworkClientSocket::STATUS_ACTIVE) {
|
||||||
/* 1 lag-point per day */
|
/* 1 lag-point per day */
|
||||||
|
@ -70,10 +70,12 @@ public:
|
|||||||
uint32 last_token_frame; ///< The last frame we received the right token
|
uint32 last_token_frame; ///< The last frame we received the right token
|
||||||
ClientStatus status; ///< Status of this client
|
ClientStatus status; ///< Status of this client
|
||||||
CommandQueue outgoing_queue; ///< The command-queue awaiting delivery
|
CommandQueue outgoing_queue; ///< The command-queue awaiting delivery
|
||||||
|
int receive_limit; ///< Amount of bytes that we can receive at this moment
|
||||||
|
|
||||||
ServerNetworkGameSocketHandler(SOCKET s);
|
ServerNetworkGameSocketHandler(SOCKET s);
|
||||||
~ServerNetworkGameSocketHandler();
|
~ServerNetworkGameSocketHandler();
|
||||||
|
|
||||||
|
virtual Packet *ReceivePacket();
|
||||||
NetworkRecvStatus CloseConnection(NetworkRecvStatus status);
|
NetworkRecvStatus CloseConnection(NetworkRecvStatus status);
|
||||||
void GetClientName(char *client_name, size_t size) const;
|
void GetClientName(char *client_name, size_t size) const;
|
||||||
|
|
||||||
|
@ -141,6 +141,8 @@ struct NetworkSettings {
|
|||||||
uint8 frame_freq; ///< how often do we send commands to the clients
|
uint8 frame_freq; ///< how often do we send commands to the clients
|
||||||
uint16 commands_per_frame; ///< how many commands may be sent each frame_freq frames?
|
uint16 commands_per_frame; ///< how many commands may be sent each frame_freq frames?
|
||||||
uint16 max_commands_in_queue; ///< how many commands may there be in the incoming queue before dropping the connection?
|
uint16 max_commands_in_queue; ///< how many commands may there be in the incoming queue before dropping the connection?
|
||||||
|
uint16 bytes_per_frame; ///< how many bytes may, over a long period, be received per frame?
|
||||||
|
uint16 bytes_per_frame_burst; ///< how many bytes may, over a short period, be received?
|
||||||
uint16 max_join_time; ///< maximum amount of time, in game ticks, a client may take to join
|
uint16 max_join_time; ///< maximum amount of time, in game ticks, a client may take to join
|
||||||
bool pause_on_join; ///< pause the game when people join
|
bool pause_on_join; ///< pause the game when people join
|
||||||
uint16 server_port; ///< port the server listens on
|
uint16 server_port; ///< port the server listens on
|
||||||
|
@ -633,6 +633,8 @@ const SettingDesc _settings[] = {
|
|||||||
SDTC_VAR(network.frame_freq, SLE_UINT8,C|S,NO, 0, 0, 100, 0, STR_NULL, NULL),
|
SDTC_VAR(network.frame_freq, SLE_UINT8,C|S,NO, 0, 0, 100, 0, STR_NULL, NULL),
|
||||||
SDTC_VAR(network.commands_per_frame, SLE_UINT16, S, NO, 4, 1, 65535, 0, STR_NULL, NULL),
|
SDTC_VAR(network.commands_per_frame, SLE_UINT16, S, NO, 4, 1, 65535, 0, STR_NULL, NULL),
|
||||||
SDTC_VAR(network.max_commands_in_queue,SLE_UINT16, S, NO, 32, 1, 65535, 0, STR_NULL, NULL),
|
SDTC_VAR(network.max_commands_in_queue,SLE_UINT16, S, NO, 32, 1, 65535, 0, STR_NULL, NULL),
|
||||||
|
SDTC_VAR(network.bytes_per_frame, SLE_UINT16, S, NO, 8, 1, 65535, 0, STR_NULL, NULL),
|
||||||
|
SDTC_VAR(network.bytes_per_frame_burst,SLE_UINT16, S, NO, 256, 1, 65535, 0, STR_NULL, NULL),
|
||||||
SDTC_VAR(network.max_join_time, SLE_UINT16, S, NO, 500, 0, 32000, 0, STR_NULL, NULL),
|
SDTC_VAR(network.max_join_time, SLE_UINT16, S, NO, 500, 0, 32000, 0, STR_NULL, NULL),
|
||||||
SDTC_BOOL(network.pause_on_join, S, NO, true, STR_NULL, NULL),
|
SDTC_BOOL(network.pause_on_join, S, NO, true, STR_NULL, NULL),
|
||||||
SDTC_VAR(network.server_port, SLE_UINT16, S, NO,NETWORK_DEFAULT_PORT,0,65535,0,STR_NULL, NULL),
|
SDTC_VAR(network.server_port, SLE_UINT16, S, NO,NETWORK_DEFAULT_PORT,0,65535,0,STR_NULL, NULL),
|
||||||
|
Loading…
Reference in New Issue
Block a user