From a4c6d07edc4937087e3f2d0b2bff52cc3980b9e2 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 19 Aug 2010 08:59:36 +0000 Subject: (svn r20553) -Feature: allow rate limiting of incoming commands --- src/network/network_command.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/network/network_command.cpp') diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp index 1bec93c7a..1b1712203 100644 --- a/src/network/network_command.cpp +++ b/src/network/network_command.cpp @@ -17,6 +17,7 @@ #include "network.h" #include "../command_func.h" #include "../company_func.h" +#include "../settings_type.h" /** Table with all the callbacks we'll use for conversion*/ static CommandCallback * const _callback_table[] = { @@ -68,6 +69,7 @@ void CommandQueue::Append(CommandPacket *p) this->last->next = add; } this->last = add; + this->count++; } /** @@ -77,7 +79,10 @@ void CommandQueue::Append(CommandPacket *p) CommandPacket *CommandQueue::Pop() { CommandPacket *ret = this->first; - if (ret != NULL) this->first = this->first->next; + if (ret != NULL) { + this->first = this->first->next; + this->count--; + } return ret; } @@ -97,6 +102,7 @@ void CommandQueue::Free() while ((cp = this->Pop()) != NULL) { free(cp); } + assert(this->count == 0); } /** Local queue of packets waiting for handling. */ @@ -241,8 +247,10 @@ static void DistributeCommandPacket(CommandPacket cp, const NetworkClientSocket */ static void DistributeQueue(CommandQueue *queue, const NetworkClientSocket *owner) { + int to_go = _settings_client.network.commands_per_frame; + CommandPacket *cp; - while ((cp = queue->Pop()) != NULL) { + while (--to_go >= 0 && (cp = queue->Pop()) != NULL) { DistributeCommandPacket(*cp, owner); free(cp); } -- cgit v1.2.3-54-g00ecf