doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MsgChannel.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "MsgChannel.h"
33 
34 /*
35 
36 packet header
37 -------------
38 2 bytes id
39 4 bytes outgoing sequence. high bit will be set if this is a fragmented message.
40 2 bytes optional fragment start byte if fragment bit is set.
41 2 bytes optional fragment length if fragment bit is set. if < FRAGMENT_SIZE, this is the last fragment.
42 
43 If the id is -1, the packet should be handled as an out-of-band
44 message instead of as part of the message channel.
45 
46 All fragments will have the same sequence numbers.
47 
48 */
49 
50 
51 #define MAX_PACKETLEN 1400 // max size of a network packet
52 #define FRAGMENT_SIZE (MAX_PACKETLEN - 100)
53 #define FRAGMENT_BIT (1<<31)
54 
55 idCVar net_channelShowPackets( "net_channelShowPackets", "0", CVAR_SYSTEM | CVAR_BOOL, "show all packets" );
56 idCVar net_channelShowDrop( "net_channelShowDrop", "0", CVAR_SYSTEM | CVAR_BOOL, "show dropped packets" );
57 
58 /*
59 ===============
60 idMsgQueue::idMsgQueue
61 ===============
62 */
64  Init( 0 );
65 }
66 
67 /*
68 ===============
69 idMsgQueue::Init
70 ===============
71 */
72 void idMsgQueue::Init( int sequence ) {
73  first = last = sequence;
74  startIndex = endIndex = 0;
75 }
76 
77 /*
78 ===============
79 idMsgQueue::Add
80 ===============
81 */
82 bool idMsgQueue::Add( const byte *data, const int size ) {
83  if ( GetSpaceLeft() < size + 8 ) {
84  return false;
85  }
86  int sequence = last;
87  WriteShort( size );
88  WriteLong( sequence );
89  WriteData( data, size );
90  last++;
91  return true;
92 }
93 
94 /*
95 ===============
96 idMsgQueue::Get
97 ===============
98 */
99 bool idMsgQueue::Get( byte *data, int &size ) {
100  if ( first == last ) {
101  size = 0;
102  return false;
103  }
104  int sequence;
105  size = ReadShort();
106  sequence = ReadLong();
107  ReadData( data, size );
108  assert( sequence == first );
109  first++;
110  return true;
111 }
112 
113 /*
114 ===============
115 idMsgQueue::GetTotalSize
116 ===============
117 */
118 int idMsgQueue::GetTotalSize( void ) const {
119  if ( startIndex <= endIndex ) {
120  return ( endIndex - startIndex );
121  } else {
122  return ( sizeof( buffer ) - startIndex + endIndex );
123  }
124 }
125 
126 /*
127 ===============
128 idMsgQueue::GetSpaceLeft
129 ===============
130 */
131 int idMsgQueue::GetSpaceLeft( void ) const {
132  if ( startIndex <= endIndex ) {
133  return sizeof( buffer ) - ( endIndex - startIndex ) - 1;
134  } else {
135  return ( startIndex - endIndex ) - 1;
136  }
137 }
138 
139 /*
140 ===============
141 idMsgQueue::CopyToBuffer
142 ===============
143 */
144 void idMsgQueue::CopyToBuffer( byte *buf ) const {
145  if ( startIndex <= endIndex ) {
146  memcpy( buf, buffer + startIndex, endIndex - startIndex );
147  } else {
148  memcpy( buf, buffer + startIndex, sizeof( buffer ) - startIndex );
149  memcpy( buf + sizeof( buffer ) - startIndex, buffer, endIndex );
150  }
151 }
152 
153 /*
154 ===============
155 idMsgQueue::WriteByte
156 ===============
157 */
159  buffer[endIndex] = b;
160  endIndex = ( endIndex + 1 ) & ( MAX_MSG_QUEUE_SIZE - 1 );
161 }
162 
163 /*
164 ===============
165 idMsgQueue::ReadByte
166 ===============
167 */
169  byte b = buffer[startIndex];
170  startIndex = ( startIndex + 1 ) & ( MAX_MSG_QUEUE_SIZE - 1 );
171  return b;
172 }
173 
174 /*
175 ===============
176 idMsgQueue::WriteShort
177 ===============
178 */
180  WriteByte( ( s >> 0 ) & 255 );
181  WriteByte( ( s >> 8 ) & 255 );
182 }
183 
184 /*
185 ===============
186 idMsgQueue::ReadShort
187 ===============
188 */
190  return ReadByte() | ( ReadByte() << 8 );
191 }
192 
193 /*
194 ===============
195 idMsgQueue::WriteLong
196 ===============
197 */
199  WriteByte( ( l >> 0 ) & 255 );
200  WriteByte( ( l >> 8 ) & 255 );
201  WriteByte( ( l >> 16 ) & 255 );
202  WriteByte( ( l >> 24 ) & 255 );
203 }
204 
205 /*
206 ===============
207 idMsgQueue::ReadLong
208 ===============
209 */
210 int idMsgQueue::ReadLong( void ) {
211  return ReadByte() | ( ReadByte() << 8 ) | ( ReadByte() << 16 ) | ( ReadByte() << 24 );
212 }
213 
214 /*
215 ===============
216 idMsgQueue::WriteData
217 ===============
218 */
219 void idMsgQueue::WriteData( const byte *data, const int size ) {
220  for ( int i = 0; i < size; i++ ) {
221  WriteByte( data[i] );
222  }
223 }
224 
225 /*
226 ===============
227 idMsgQueue::ReadData
228 ===============
229 */
230 void idMsgQueue::ReadData( byte *data, const int size ) {
231  if ( data ) {
232  for ( int i = 0; i < size; i++ ) {
233  data[i] = ReadByte();
234  }
235  } else {
236  for ( int i = 0; i < size; i++ ) {
237  ReadByte();
238  }
239  }
240 }
241 
242 
243 /*
244 ===============
245 idMsgChannel::idMsgChannel
246 ===============
247 */
249  id = -1;
250 }
251 
252 /*
253 ==============
254 idMsgChannel::Init
255 
256  Opens a channel to a remote system.
257 ==============
258 */
259 void idMsgChannel::Init( const netadr_t adr, const int id ) {
260  this->remoteAddress = adr;
261  this->id = id;
262  this->maxRate = 50000;
264 
265  lastSendTime = 0;
266  lastDataBytes = 0;
267  outgoingRateTime = 0;
268  outgoingRateBytes = 0;
269  incomingRateTime = 0;
270  incomingRateBytes = 0;
272  incomingDroppedPackets = 0.0f;
274  outgoingCompression = 0.0f;
275  incomingCompression = 0.0f;
276  outgoingSequence = 1;
277  incomingSequence = 0;
278  unsentFragments = false;
280  fragmentSequence = 0;
281  fragmentLength = 0;
282  reliableSend.Init( 1 );
283  reliableReceive.Init( 0 );
284 }
285 
286 /*
287 ===============
288 idMsgChannel::Shutdown
289 ================
290 */
292  delete compressor;
293  compressor = NULL;
294 }
295 
296 /*
297 =================
298 idMsgChannel::ResetRate
299 =================
300 */
302  lastSendTime = 0;
303  lastDataBytes = 0;
304  outgoingRateTime = 0;
305  outgoingRateBytes = 0;
306  incomingRateTime = 0;
307  incomingRateBytes = 0;
308 }
309 
310 /*
311 =================
312 idMsgChannel::ReadyToSend
313 =================
314 */
315 bool idMsgChannel::ReadyToSend( const int time ) const {
316  int deltaTime;
317 
318  if ( !maxRate ) {
319  return true;
320  }
321  deltaTime = time - lastSendTime;
322  if ( deltaTime > 1000 ) {
323  return true;
324  }
325  return ( ( lastDataBytes - ( deltaTime * maxRate ) / 1000 ) <= 0 );
326 }
327 
328 /*
329 ===============
330 idMsgChannel::WriteMessageData
331 ================
332 */
334  idBitMsg tmp;
335  byte tmpBuf[MAX_MESSAGE_SIZE];
336 
337  tmp.Init( tmpBuf, sizeof( tmpBuf ) );
338 
339  // write acknowledgement of last received reliable message
341 
342  // write reliable messages
343  reliableSend.CopyToBuffer( tmp.GetData() + tmp.GetSize() );
344  tmp.SetSize( tmp.GetSize() + reliableSend.GetTotalSize() );
345  tmp.WriteShort( 0 );
346 
347  // write data
348  tmp.WriteData( msg.GetData(), msg.GetSize() );
349 
350  // write message size
351  out.WriteShort( tmp.GetSize() );
352 
353  // compress message
354  idFile_BitMsg file( out );
355  compressor->Init( &file, true, 3 );
356  compressor->Write( tmp.GetData(), tmp.GetSize() );
359 }
360 
361 /*
362 ===============
363 idMsgChannel::ReadMessageData
364 ================
365 */
367  int reliableAcknowledge, reliableMessageSize, reliableSequence;
368 
369  // read message size
370  out.SetSize( msg.ReadShort() );
371 
372  // decompress message
373  idFile_BitMsg file( msg );
374  compressor->Init( &file, false, 3 );
375  compressor->Read( out.GetData(), out.GetSize() );
377  out.BeginReading();
378 
379  // read acknowledgement of sent reliable messages
380  reliableAcknowledge = out.ReadLong();
381 
382  // remove acknowledged reliable messages
383  while( reliableSend.GetFirst() <= reliableAcknowledge ) {
384  if ( !reliableSend.Get( NULL, reliableMessageSize ) ) {
385  break;
386  }
387  }
388 
389  // read reliable messages
390  reliableMessageSize = out.ReadShort();
391  while( reliableMessageSize != 0 ) {
392  if ( reliableMessageSize <= 0 || reliableMessageSize > out.GetSize() - out.GetReadCount() ) {
393  common->Printf( "%s: bad reliable message\n", Sys_NetAdrToString( remoteAddress ) );
394  return false;
395  }
396  reliableSequence = out.ReadLong();
397  if ( reliableSequence == reliableReceive.GetLast() + 1 ) {
398  reliableReceive.Add( out.GetData() + out.GetReadCount(), reliableMessageSize );
399  }
400  out.ReadData( NULL, reliableMessageSize );
401  reliableMessageSize = out.ReadShort();
402  }
403 
404  return true;
405 }
406 
407 /*
408 =================
409 idMsgChannel::SendNextFragment
410 
411  Sends one fragment of the current message.
412 =================
413 */
414 void idMsgChannel::SendNextFragment( idPort &port, const int time ) {
415  idBitMsg msg;
416  byte msgBuf[MAX_PACKETLEN];
417  int fragLength;
418 
419  if ( remoteAddress.type == NA_BAD ) {
420  return;
421  }
422 
423  if ( !unsentFragments ) {
424  return;
425  }
426 
427  // write the packet
428  msg.Init( msgBuf, sizeof( msgBuf ) );
429  msg.WriteShort( id );
431 
432  fragLength = FRAGMENT_SIZE;
433  if ( unsentFragmentStart + fragLength > unsentMsg.GetSize() ) {
434  fragLength = unsentMsg.GetSize() - unsentFragmentStart;
435  }
436 
438  msg.WriteShort( fragLength );
439  msg.WriteData( unsentMsg.GetData() + unsentFragmentStart, fragLength );
440 
441  // send the packet
442  port.SendPacket( remoteAddress, msg.GetData(), msg.GetSize() );
443 
444  // update rate control variables
445  UpdateOutgoingRate( time, msg.GetSize() );
446 
448  common->Printf( "%d send %4i : s = %i fragment = %i,%i\n", id, msg.GetSize(), outgoingSequence - 1, unsentFragmentStart, fragLength );
449  }
450 
451  unsentFragmentStart += fragLength;
452 
453  // this exit condition is a little tricky, because a packet
454  // that is exactly the fragment length still needs to send
455  // a second packet of zero length so that the other side
456  // can tell there aren't more to follow
457  if ( unsentFragmentStart == unsentMsg.GetSize() && fragLength != FRAGMENT_SIZE ) {
459  unsentFragments = false;
460  }
461 }
462 
463 /*
464 ===============
465 idMsgChannel::SendMessage
466 
467  Sends a message to a connection, fragmenting if necessary
468  A 0 length will still generate a packet.
469 ================
470 */
471 int idMsgChannel::SendMessage( idPort &port, const int time, const idBitMsg &msg ) {
472  int totalLength;
473 
474  if ( remoteAddress.type == NA_BAD ) {
475  return -1;
476  }
477 
478  if ( unsentFragments ) {
479  common->Error( "idMsgChannel::SendMessage: called with unsent fragments left" );
480  return -1;
481  }
482 
483  totalLength = 4 + reliableSend.GetTotalSize() + 4 + msg.GetSize();
484 
485  if ( totalLength > MAX_MESSAGE_SIZE ) {
486  common->Printf( "idMsgChannel::SendMessage: message too large, length = %i\n", totalLength );
487  return -1;
488  }
489 
490  unsentMsg.Init( unsentBuffer, sizeof( unsentBuffer ) );
492 
493  // fragment large messages
494  if ( totalLength >= FRAGMENT_SIZE ) {
495  unsentFragments = true;
497 
498  // write out the message data
499  WriteMessageData( unsentMsg, msg );
500 
501  // send the first fragment now
502  SendNextFragment( port, time );
503 
504  return outgoingSequence;
505  }
506 
507  // write the header
508  unsentMsg.WriteShort( id );
510 
511  // write out the message data
512  WriteMessageData( unsentMsg, msg );
513 
514  // send the packet
516 
517  // update rate control variables
519 
521  common->Printf( "%d send %4i : s = %i ack = %i\n", id, unsentMsg.GetSize(), outgoingSequence - 1, incomingSequence );
522  }
523 
525 
526  return ( outgoingSequence - 1 );
527 }
528 
529 /*
530 =================
531 idMsgChannel::Process
532 
533  Returns false if the message should not be processed due to being out of order or a fragment.
534 
535  msg must be large enough to hold MAX_MESSAGE_SIZE, because if this is the final
536  fragment of a multi-part message, the entire thing will be copied out.
537 =================
538 */
539 bool idMsgChannel::Process( const netadr_t from, int time, idBitMsg &msg, int &sequence ) {
540  int fragStart, fragLength, dropped;
541  bool fragmented;
542  idBitMsg fragMsg;
543 
544  // the IP port can't be used to differentiate them, because
545  // some address translating routers periodically change UDP
546  // port assignments
547  if ( remoteAddress.port != from.port ) {
548  common->Printf( "idMsgChannel::Process: fixing up a translated port\n" );
549  remoteAddress.port = from.port;
550  }
551 
552  // update incoming rate
553  UpdateIncomingRate( time, msg.GetSize() );
554 
555  // get sequence numbers
556  sequence = msg.ReadLong();
557 
558  // check for fragment information
559  if ( sequence & FRAGMENT_BIT ) {
560  sequence &= ~FRAGMENT_BIT;
561  fragmented = true;
562  } else {
563  fragmented = false;
564  }
565 
566  // read the fragment information
567  if ( fragmented ) {
568  fragStart = msg.ReadShort();
569  fragLength = msg.ReadShort();
570  } else {
571  fragStart = 0; // stop warning message
572  fragLength = 0;
573  }
574 
576  if ( fragmented ) {
577  common->Printf( "%d recv %4i : s = %i fragment = %i,%i\n", id, msg.GetSize(), sequence, fragStart, fragLength );
578  } else {
579  common->Printf( "%d recv %4i : s = %i\n", id, msg.GetSize(), sequence );
580  }
581  }
582 
583  //
584  // discard out of order or duplicated packets
585  //
586  if ( sequence <= incomingSequence ) {
588  common->Printf( "%s: out of order packet %i at %i\n", Sys_NetAdrToString( remoteAddress ), sequence, incomingSequence );
589  }
590  return false;
591  }
592 
593  //
594  // dropped packets don't keep this message from being used
595  //
596  dropped = sequence - (incomingSequence+1);
597  if ( dropped > 0 ) {
599  common->Printf( "%s: dropped %i packets at %i\n", Sys_NetAdrToString( remoteAddress ), dropped, sequence );
600  }
601  UpdatePacketLoss( time, 0, dropped );
602  }
603 
604  //
605  // if the message is fragmented
606  //
607  if ( fragmented ) {
608  // make sure we have the correct sequence number
609  if ( sequence != fragmentSequence ) {
610  fragmentSequence = sequence;
611  fragmentLength = 0;
612  }
613 
614  // if we missed a fragment, dump the message
615  if ( fragStart != fragmentLength ) {
617  common->Printf( "%s: dropped a message fragment at seq %d\n", Sys_NetAdrToString( remoteAddress ), sequence );
618  }
619  // we can still keep the part that we have so far,
620  // so we don't need to clear fragmentLength
621  UpdatePacketLoss( time, 0, 1 );
622  return false;
623  }
624 
625  // copy the fragment to the fragment buffer
626  if ( fragLength < 0 || fragLength > msg.GetRemaingData() || fragmentLength + fragLength > sizeof( fragmentBuffer ) ) {
628  common->Printf( "%s: illegal fragment length\n", Sys_NetAdrToString( remoteAddress ) );
629  }
630  UpdatePacketLoss( time, 0, 1 );
631  return false;
632  }
633 
634  memcpy( fragmentBuffer + fragmentLength, msg.GetData() + msg.GetReadCount(), fragLength );
635 
636  fragmentLength += fragLength;
637 
638  UpdatePacketLoss( time, 1, 0 );
639 
640  // if this wasn't the last fragment, don't process anything
641  if ( fragLength == FRAGMENT_SIZE ) {
642  return false;
643  }
644 
645  } else {
646  memcpy( fragmentBuffer, msg.GetData() + msg.GetReadCount(), msg.GetRemaingData() );
648  UpdatePacketLoss( time, 1, 0 );
649  }
650 
651  fragMsg.Init( fragmentBuffer, fragmentLength );
652  fragMsg.SetSize( fragmentLength );
653  fragMsg.BeginReading();
654 
655  incomingSequence = sequence;
656 
657  // read the message data
658  if ( !ReadMessageData( msg, fragMsg ) ) {
659  return false;
660  }
661 
662  return true;
663 }
664 
665 /*
666 =================
667 idMsgChannel::SendReliableMessage
668 =================
669 */
671  bool result;
672 
674  if ( remoteAddress.type == NA_BAD ) {
675  return false;
676  }
677  result = reliableSend.Add( msg.GetData(), msg.GetSize() );
678  if ( !result ) {
679  common->Warning( "idMsgChannel::SendReliableMessage: overflowed" );
680  return false;
681  }
682  return result;
683 }
684 
685 /*
686 =================
687 idMsgChannel::GetReliableMessage
688 =================
689 */
691  int size;
692  bool result;
693 
694  result = reliableReceive.Get( msg.GetData(), size );
695  msg.SetSize( size );
696  msg.BeginReading();
697  return result;
698 }
699 
700 /*
701 ===============
702 idMsgChannel::ClearReliableMessages
703 ================
704 */
706  reliableSend.Init( 1 );
707  reliableReceive.Init( 0 );
708 }
709 
710 /*
711 =================
712 idMsgChannel::UpdateOutgoingRate
713 =================
714 */
715 void idMsgChannel::UpdateOutgoingRate( const int time, const int size ) {
716  // update the outgoing rate control variables
717  int deltaTime = time - lastSendTime;
718  if ( deltaTime > 1000 ) {
719  lastDataBytes = 0;
720  } else {
721  lastDataBytes -= ( deltaTime * maxRate ) / 1000;
722  if ( lastDataBytes < 0 ) {
723  lastDataBytes = 0;
724  }
725  }
726  lastDataBytes += size;
727  lastSendTime = time;
728 
729  // update outgoing rate variables
730  if ( time - outgoingRateTime > 1000 ) {
731  outgoingRateBytes -= outgoingRateBytes * ( time - outgoingRateTime - 1000 ) / 1000;
732  if ( outgoingRateBytes < 0 ) {
733  outgoingRateBytes = 0;
734  }
735  }
736  outgoingRateTime = time - 1000;
738 }
739 
740 /*
741 =================
742 idMsgChannel::UpdateIncomingRate
743 =================
744 */
745 void idMsgChannel::UpdateIncomingRate( const int time, const int size ) {
746  // update incoming rate variables
747  if ( time - incomingRateTime > 1000 ) {
748  incomingRateBytes -= incomingRateBytes * ( time - incomingRateTime - 1000 ) / 1000;
749  if ( incomingRateBytes < 0 ) {
750  incomingRateBytes = 0;
751  }
752  }
753  incomingRateTime = time - 1000;
755 }
756 
757 /*
758 =================
759 idMsgChannel::UpdatePacketLoss
760 =================
761 */
762 void idMsgChannel::UpdatePacketLoss( const int time, const int numReceived, const int numDropped ) {
763  // update incoming packet loss variables
764  if ( time - incomingPacketLossTime > 5000 ) {
765  float scale = ( time - incomingPacketLossTime - 5000 ) * ( 1.0f / 5000.0f );
767  if ( incomingReceivedPackets < 0.0f ) {
769  }
771  if ( incomingDroppedPackets < 0.0f ) {
772  incomingDroppedPackets = 0.0f;
773  }
774  }
775  incomingPacketLossTime = time - 5000;
776  incomingReceivedPackets += numReceived;
777  incomingDroppedPackets += numDropped;
778 }
779 
780 /*
781 =================
782 idMsgChannel::GetIncomingPacketLoss
783 =================
784 */
786  if ( incomingReceivedPackets == 0.0f && incomingDroppedPackets == 0.0f ) {
787  return 0.0f;
788  }
790 }
static idCompressor * AllocRunLength_ZeroBased(void)
void BeginWriting(void)
Definition: BitMsg.h:265
void WriteData(const byte *data, const int size)
Definition: MsgChannel.cpp:219
virtual int Read(void *outData, int outLength)=0
int GetReadCount(void) const
Definition: BitMsg.h:231
void UpdateIncomingRate(const int time, const int size)
Definition: MsgChannel.cpp:745
int SendMessage(idPort &port, const int time, const idBitMsg &msg)
Definition: MsgChannel.cpp:471
virtual int Write(const void *inData, int inLength)=0
int unsentFragmentStart
Definition: MsgChannel.h:178
assert(prefInfo.fullscreenBtn)
void ReadData(byte *data, const int size)
Definition: MsgChannel.cpp:230
bool Process(const netadr_t from, int time, idBitMsg &msg, int &sequence)
Definition: MsgChannel.cpp:539
netadrtype_t type
Definition: sys_public.h:405
byte ReadByte(void)
Definition: MsgChannel.cpp:168
virtual float GetCompressionRatio(void) const =0
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:4804
float outgoingCompression
Definition: MsgChannel.h:164
int ReadLong(void)
Definition: MsgChannel.cpp:210
int ReadLong(void) const
Definition: BitMsg.h:375
int GetRemaingData(void) const
Definition: BitMsg.h:351
byte unsentBuffer[MAX_MESSAGE_SIZE]
Definition: MsgChannel.h:179
unsigned short port
Definition: sys_public.h:407
int endIndex
Definition: MsgChannel.h:75
int incomingPacketLossTime
Definition: MsgChannel.h:170
int fragmentLength
Definition: MsgChannel.h:184
int outgoingRateTime
Definition: MsgChannel.h:158
bool SendReliableMessage(const idBitMsg &msg)
Definition: MsgChannel.cpp:670
#define FRAGMENT_BIT
Definition: MsgChannel.cpp:53
void Init(const netadr_t adr, const int id)
Definition: MsgChannel.cpp:259
idCompressor * compressor
Definition: MsgChannel.h:151
void WriteShort(int s)
Definition: MsgChannel.cpp:179
byte fragmentBuffer[MAX_MESSAGE_SIZE]
Definition: MsgChannel.h:185
idMsgQueue reliableSend
Definition: MsgChannel.h:188
void SendNextFragment(idPort &port, const int time)
Definition: MsgChannel.cpp:414
int lastSendTime
Definition: MsgChannel.h:154
GLdouble s
Definition: glext.h:2935
int startIndex
Definition: MsgChannel.h:74
idMsgQueue reliableReceive
Definition: MsgChannel.h:189
int i
Definition: process.py:33
Boolean result
netadr_t remoteAddress
Definition: MsgChannel.h:148
void Init(byte *data, int length)
Definition: BitMsg.h:155
int ReadData(void *data, int length) const
Definition: BitMsg.cpp:457
virtual void Init(idFile *f, bool compress, int wordLength)=0
list l
Definition: prepare.py:17
void WriteData(const void *data, int length)
Definition: BitMsg.cpp:210
byte buffer[MAX_MSG_QUEUE_SIZE]
Definition: MsgChannel.h:71
idCVar net_channelShowPackets("net_channelShowPackets","0", CVAR_SYSTEM|CVAR_BOOL,"show all packets")
int fragmentSequence
Definition: MsgChannel.h:183
idBitMsg unsentMsg
Definition: MsgChannel.h:180
void SendPacket(const netadr_t to, const void *data, int size)
Definition: posix_net.cpp:572
void CopyToBuffer(byte *buf) const
Definition: MsgChannel.cpp:144
void Init(int sequence)
Definition: MsgChannel.cpp:72
float incomingDroppedPackets
Definition: MsgChannel.h:169
int GetTotalSize(void) const
Definition: MsgChannel.cpp:118
bool GetReliableMessage(idBitMsg &msg)
Definition: MsgChannel.cpp:690
void WriteLong(int c)
Definition: BitMsg.h:295
idCommon * common
Definition: Common.cpp:206
int incomingSequence
Definition: MsgChannel.h:174
int GetSize(void) const
Definition: BitMsg.h:187
idCVar net_channelShowDrop("net_channelShowDrop","0", CVAR_SYSTEM|CVAR_BOOL,"show dropped packets")
#define NULL
Definition: Lib.h:88
void BeginReading(void) const
Definition: BitMsg.h:346
bool Get(byte *data, int &size)
Definition: MsgChannel.cpp:99
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
GLuint buffer
Definition: glext.h:3108
void ClearReliableMessages(void)
Definition: MsgChannel.cpp:705
bool ReadyToSend(const int time) const
Definition: MsgChannel.cpp:315
void WriteShort(int c)
Definition: BitMsg.h:287
bool unsentFragments
Definition: MsgChannel.h:177
int outgoingRateBytes
Definition: MsgChannel.h:159
void Shutdown(void)
Definition: MsgChannel.cpp:291
void SetSize(int size)
Definition: BitMsg.h:191
int incomingRateBytes
Definition: MsgChannel.h:161
float incomingCompression
Definition: MsgChannel.h:165
virtual void Printf(const char *fmt,...) id_attribute((format(printf
virtual void FinishCompress(void)=0
const char * Sys_NetAdrToString(const netadr_t a)
Definition: posix_net.cpp:187
GLubyte GLubyte b
Definition: glext.h:4662
#define FRAGMENT_SIZE
Definition: MsgChannel.cpp:52
void UpdatePacketLoss(const int time, const int numReceived, const int numDropped)
Definition: MsgChannel.cpp:762
float incomingReceivedPackets
Definition: MsgChannel.h:168
bool ReadMessageData(idBitMsg &out, const idBitMsg &msg)
Definition: MsgChannel.cpp:366
bool GetBool(void) const
Definition: CVarSystem.h:142
#define MAX_MESSAGE_SIZE
Definition: MsgChannel.h:48
#define MAX_PACKETLEN
Definition: MsgChannel.cpp:51
tuple f
Definition: idal.py:89
unsigned char byte
Definition: Lib.h:75
float GetIncomingPacketLoss(void) const
Definition: MsgChannel.cpp:785
GLsizeiptr size
Definition: glext.h:3112
void WriteByte(byte b)
Definition: MsgChannel.cpp:158
bool Add(const byte *data, const int size)
Definition: MsgChannel.cpp:82
byte * GetData(void)
Definition: BitMsg.h:167
int outgoingSequence
Definition: MsgChannel.h:173
int GetFirst(void) const
Definition: MsgChannel.h:66
int ReadShort(void)
Definition: MsgChannel.cpp:189
GLint * first
Definition: glext.h:3036
void ResetRate(void)
Definition: MsgChannel.cpp:301
virtual void Error(const char *fmt,...) id_attribute((format(printf
int lastDataBytes
Definition: MsgChannel.h:155
void WriteLong(int l)
Definition: MsgChannel.cpp:198
int GetSpaceLeft(void) const
Definition: MsgChannel.cpp:131
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
void UpdateOutgoingRate(const int time, const int size)
Definition: MsgChannel.cpp:715
int GetLast(void) const
Definition: MsgChannel.h:67
#define MAX_MSG_QUEUE_SIZE
Definition: MsgChannel.h:53
void WriteMessageData(idBitMsg &out, const idBitMsg &msg)
Definition: MsgChannel.cpp:333
int ReadShort(void) const
Definition: BitMsg.h:367
int incomingRateTime
Definition: MsgChannel.h:160