mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Increase network timeout, small refactors (#22433)
* Refactor consts with kNotion, make static * Increase the no data timeout to 20 seconds, add constant * Fix debug builds * Update changelog.txt
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
- Improved: [#22352] The object selection window now groups relevant object tabs together.
|
||||
- Improved: [#22357] Error messages are now themeable and easier to read.
|
||||
- Improved: [#22361] Add additional colour preset for the Observation Tower.
|
||||
- Improved: [#22433] Increase the network timeout from 7 to 20 seconds, should help slow clients getting disconnected.
|
||||
- Change: [#12292] The ‘Toggle visibility of toolbars’ shortcut is no longer assigned by default.
|
||||
- Change: [#21494] Display pixel density is now taken into account for the initial window scale setting.
|
||||
- Change: [#22230] The plugin/script engine is now initialised off the main thread.
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
constexpr size_t NETWORK_DISCONNECT_REASON_BUFFER_SIZE = 256;
|
||||
constexpr size_t NetworkBufferSize = 1024 * 64; // 64 KiB, maximum packet size.
|
||||
static constexpr size_t kNetworkDisconnectReasonBufSize = 256;
|
||||
static constexpr size_t kNetworkBufferSize = 1024 * 64; // 64 KiB, maximum packet size.
|
||||
# ifndef DEBUG
|
||||
static constexpr size_t kNetworkNoDataTimeout = 20; // Seconds.
|
||||
# endif
|
||||
|
||||
NetworkConnection::NetworkConnection() noexcept
|
||||
{
|
||||
@@ -68,11 +71,11 @@ NetworkReadPacket NetworkConnection::ReadPacket()
|
||||
// NOTE: BytesTransfered includes the header length, this will not underflow.
|
||||
const size_t missingLength = header.Size - (InboundPacket.BytesTransferred - sizeof(header));
|
||||
|
||||
uint8_t buffer[NetworkBufferSize];
|
||||
uint8_t buffer[kNetworkBufferSize];
|
||||
|
||||
if (missingLength > 0)
|
||||
{
|
||||
NetworkReadPacket status = Socket->ReceiveData(buffer, std::min(missingLength, NetworkBufferSize), &bytesRead);
|
||||
NetworkReadPacket status = Socket->ReceiveData(buffer, std::min(missingLength, kNetworkBufferSize), &bytesRead);
|
||||
if (status != NetworkReadPacket::Success)
|
||||
{
|
||||
return status;
|
||||
@@ -179,7 +182,8 @@ void NetworkConnection::ResetLastPacketTime() noexcept
|
||||
bool NetworkConnection::ReceivedPacketRecently() const noexcept
|
||||
{
|
||||
# ifndef DEBUG
|
||||
if (Platform::GetTicks() > _lastPacketTime + 7000)
|
||||
constexpr auto kTimeoutMs = kNetworkNoDataTimeout * 1000;
|
||||
if (Platform::GetTicks() > _lastPacketTime + kTimeoutMs)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -199,8 +203,8 @@ void NetworkConnection::SetLastDisconnectReason(std::string_view src)
|
||||
|
||||
void NetworkConnection::SetLastDisconnectReason(const StringId string_id, void* args)
|
||||
{
|
||||
char buffer[NETWORK_DISCONNECT_REASON_BUFFER_SIZE];
|
||||
OpenRCT2::FormatStringLegacy(buffer, NETWORK_DISCONNECT_REASON_BUFFER_SIZE, string_id, args);
|
||||
char buffer[kNetworkDisconnectReasonBufSize];
|
||||
OpenRCT2::FormatStringLegacy(buffer, kNetworkDisconnectReasonBufSize, string_id, args);
|
||||
SetLastDisconnectReason(buffer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user