123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <title>UAS2: E:/uas2/Server/PacketPipe.h Source File</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <link href="doxygen.css" rel="stylesheet" type="text/css"/>
- </head>
- <body>
- <!-- Generated by Doxygen 1.6.2 -->
- <div class="navigation" id="top">
- <div class="tabs">
- <ul>
- <li><a href="main.html"><span>Main Page</span></a></li>
- <li><a href="annotated.html"><span>Classes</span></a></li>
- <li class="current"><a href="files.html"><span>Files</span></a></li>
- </ul>
- </div>
- <div class="tabs">
- <ul>
- <li><a href="files.html"><span>File List</span></a></li>
- <li><a href="globals.html"><span>File Members</span></a></li>
- </ul>
- </div>
- <h1>E:/uas2/Server/PacketPipe.h</h1><a href="_packet_pipe_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
- <a name="l00002"></a>00002 <span class="comment">* This file is part of UAS2.</span>
- <a name="l00003"></a>00003 <span class="comment">*</span>
- <a name="l00004"></a>00004 <span class="comment">* UAS2 is free software; you can redistribute it and/or modify</span>
- <a name="l00005"></a>00005 <span class="comment">* it under the terms of the GNU General Public License as published by</span>
- <a name="l00006"></a>00006 <span class="comment">* the Free Software Foundation; either version 2 of the License, or</span>
- <a name="l00007"></a>00007 <span class="comment">* (at your option) any later version.</span>
- <a name="l00008"></a>00008 <span class="comment">*</span>
- <a name="l00009"></a>00009 <span class="comment">* UAS2 is distributed in the hope that it will be useful,</span>
- <a name="l00010"></a>00010 <span class="comment">* but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
- <a name="l00011"></a>00011 <span class="comment">* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
- <a name="l00012"></a>00012 <span class="comment">* GNU General Public License for more details.</span>
- <a name="l00013"></a>00013 <span class="comment"></span>
- <a name="l00014"></a>00014 <span class="comment">* You should have received a copy of the GNU General Public License</span>
- <a name="l00015"></a>00015 <span class="comment">* along with UASv1; if not, write to the Free Software</span>
- <a name="l00016"></a>00016 <span class="comment">* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
- <a name="l00017"></a>00017 <span class="comment">*/</span>
- <a name="l00018"></a>00018
- <a name="l00023"></a>00023 <span class="preprocessor">#ifndef __PACKETPIPE_H</span>
- <a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#define __PACKETPIPE_H</span>
- <a name="l00025"></a>00025 <span class="preprocessor"></span>
- <a name="l00026"></a>00026 <span class="preprocessor">#include <list></span>
- <a name="l00027"></a>00027
- <a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="_message_8h.html">Message.h</a>"</span>
- <a name="l00029"></a>00029 <span class="preprocessor">#include "CRC_Module.h"</span>
- <a name="l00030"></a>00030
- <a name="l00031"></a>00031
- <a name="l00032"></a><a class="code" href="structc_fragment.html">00032</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structc_fragment.html">cFragment</a> {
- <a name="l00033"></a>00033 BYTE m_pbData[MAX_PACKET_SIZE];
- <a name="l00034"></a>00034 WORD m_wSize;
- <a name="l00035"></a>00035 DWORD m_dwSeed;
- <a name="l00036"></a>00036
- <a name="l00037"></a>00037 <a class="code" href="structc_fragment.html">cFragment</a>( BYTE *pbData, WORD wSize )
- <a name="l00038"></a>00038 : m_wSize( wSize + 36 )
- <a name="l00039"></a>00039 {
- <a name="l00040"></a>00040 CopyMemory( &m_pbData[36], pbData, wSize );
- <a name="l00041"></a>00041 }
- <a name="l00042"></a>00042
- <a name="l00043"></a>00043 <a class="code" href="structc_fragment.html">cFragment</a>( )
- <a name="l00044"></a>00044 : m_wSize( 0 )
- <a name="l00045"></a>00045 {
- <a name="l00046"></a>00046 }
- <a name="l00047"></a>00047
- <a name="l00048"></a>00048 ~<a class="code" href="structc_fragment.html">cFragment</a>( ) {}
- <a name="l00049"></a>00049
- <a name="l00050"></a>00050 } <a class="code" href="structc_fragment.html">cFragment</a>;
- <a name="l00051"></a>00051
- <a name="l00052"></a><a class="code" href="structc_ignore_request.html">00052</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structc_ignore_request.html">cIgnoreRequest</a>
- <a name="l00053"></a>00053 {
- <a name="l00054"></a>00054 DWORD m_dwZero; <span class="comment">//Sequence - Numeric identifier for the order in which this packet should be processed.</span>
- <a name="l00055"></a>00055 DWORD m_dwEight; <span class="comment">//Flags - Bitmask identifying what data follows the header.</span>
- <a name="l00056"></a>00056 DWORD m_dwCRC; <span class="comment">// CRC - Cyclic redundancy checksum verifying all data is authentic and undamaged.</span>
- <a name="l00057"></a>00057 DWORD m_dwNum; <span class="comment">// ?</span>
- <a name="l00058"></a>00058 WORD m_wUnk1; <span class="comment">// Server Logical ID - Recipient identifier (index < 400) distinguishing the connection host.</span>
- <a name="l00059"></a>00059 WORD m_wUnk2; <span class="comment">// Time - Half-seconds since connection establishment that you received a packet.</span>
- <a name="l00060"></a>00060 WORD m_wSize; <span class="comment">// Size - Number of bytes following the header.</span>
- <a name="l00061"></a>00061 WORD m_wTable; <span class="comment">// Table - Unknown. Might involve CRC. Should match for sent/received headers.</span>
- <a name="l00062"></a>00062
- <a name="l00063"></a>00063 <a class="code" href="structc_ignore_request.html">cIgnoreRequest</a>( )
- <a name="l00064"></a>00064 {
- <a name="l00065"></a>00065 m_dwZero = 0;
- <a name="l00066"></a>00066 m_dwEight = 8;
- <a name="l00067"></a>00067 m_wSize = 8;
- <a name="l00068"></a>00068 m_wTable = 2;
- <a name="l00069"></a>00069 }
- <a name="l00070"></a>00070 } <a class="code" href="structc_ignore_request.html">cIgnoreRequest</a>;
- <a name="l00071"></a>00071
- <a name="l00072"></a>00072 <span class="keyword">template</span>< <span class="keyword">class</span> _Type >
- <a name="l00073"></a><a class="code" href="classc_packet_pipe.html">00073</a> <span class="keyword">class </span><a class="code" href="classc_packet_pipe.html">cPacketPipe</a> : <span class="keyword">public</span> _Type
- <a name="l00074"></a>00074 {
- <a name="l00075"></a>00075 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classc_client.html">cClient</a>;
- <a name="l00076"></a>00076 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classc_master_server.html">cMasterServer</a>;
- <a name="l00077"></a>00077
- <a name="l00078"></a>00078 <span class="keyword">public</span>:
- <a name="l00079"></a>00079 <a class="code" href="classc_packet_pipe.html">cPacketPipe</a> ( ) {}
- <a name="l00080"></a>00080 ~<a class="code" href="classc_packet_pipe.html">cPacketPipe</a>( )
- <a name="l00081"></a>00081 {
- <a name="l00082"></a>00082 <span class="keywordflow">while</span> ( !m_lstQueuedPackets.empty( ) )
- <a name="l00083"></a>00083 {
- <a name="l00084"></a>00084 SAFEDELETE( m_lstQueuedPackets.front( ) )
- <a name="l00085"></a>00085 m_lstQueuedPackets.pop_front( );
- <a name="l00086"></a>00086 }
- <a name="l00087"></a>00087
- <a name="l00088"></a>00088 <span class="keywordflow">while</span> ( !m_lstSentPackets.empty( ) )
- <a name="l00089"></a>00089 {
- <a name="l00090"></a>00090 SAFEDELETE( m_lstSentPackets.front( ) )
- <a name="l00091"></a>00091 m_lstSentPackets.pop_front( );
- <a name="l00092"></a>00092 }
- <a name="l00093"></a>00093 }
- <a name="l00094"></a>00094
- <a name="l00098"></a><a class="code" href="classc_packet_pipe.html#ad18463cab7b852778c31af9ba34bc9da">00098</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classc_packet_pipe.html#ad18463cab7b852778c31af9ba34bc9da">Initialize</a>( )
- <a name="l00099"></a>00099 {
- <a name="l00100"></a>00100 m_dwSendSequence = 1;
- <a name="l00101"></a>00101 m_dwRecvSequence = 1;
- <a name="l00102"></a>00102 m_dwMsgID = 1;
- <a name="l00103"></a>00103 m_wTime = 12;
- <a name="l00104"></a>00104 m_pdwSendCRC = m_lpdwSendCRC;
- <a name="l00105"></a>00105 m_pdwRecvCRC = m_lpdwRecvCRC;
- <a name="l00106"></a>00106
- <a name="l00107"></a>00107 ResetCRCs( );
- <a name="l00108"></a>00108 }
- <a name="l00112"></a><a class="code" href="classc_packet_pipe.html#a36664145f29d7cbf473eb158f53182d5">00112</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classc_packet_pipe.html#a36664145f29d7cbf473eb158f53182d5">Reset</a>( )
- <a name="l00113"></a>00113 {
- <a name="l00114"></a>00114 m_dwSendSequence = 1;
- <a name="l00115"></a>00115 m_dwRecvSequence = 1;
- <a name="l00116"></a>00116 m_dwMsgID = 1;
- <a name="l00117"></a>00117 m_wTime = 12;
- <a name="l00118"></a>00118
- <a name="l00119"></a>00119 ResetCRCs( );
- <a name="l00120"></a>00120 }
- <a name="l00121"></a>00121
- <a name="l00122"></a>00122 <span class="keyword">inline</span> <span class="keywordtype">void</span> SetSendSequence( DWORD dwSendSequence )
- <a name="l00123"></a>00123 {
- <a name="l00124"></a>00124 m_dwSendSequence = dwSendSequence;
- <a name="l00125"></a>00125 }
- <a name="l00126"></a>00126
- <a name="l00135"></a><a class="code" href="classc_packet_pipe.html#a3cdc52a487c7feaa855363c5ebb0f174">00135</a> <span class="keyword">static</span> <span class="keyword">inline</span> DWORD <a class="code" href="classc_packet_pipe.html#a3cdc52a487c7feaa855363c5ebb0f174">CalcCRC</a>( BYTE *pbSendBuffer, <span class="keywordtype">int</span> iSize )
- <a name="l00136"></a>00136 {
- <a name="l00137"></a>00137 DWORD dwCrc1, dwCrc2, *pdwCrc;
- <a name="l00138"></a>00138
- <a name="l00139"></a>00139 pdwCrc = (DWORD *)&pbSendBuffer[8];
- <a name="l00140"></a>00140 *pdwCrc = 0xBADD70DD;
- <a name="l00141"></a>00141 dwCrc1 = GetMagicNumber( &pbSendBuffer[0x00], 0x14, TRUE );
- <a name="l00142"></a>00142 dwCrc2 = GetMagicNumber( &pbSendBuffer[0x14], iSize, FALSE );
- <a name="l00143"></a>00143 *pdwCrc = dwCrc1 + dwCrc2;
- <a name="l00144"></a>00144
- <a name="l00145"></a>00145 <span class="keywordflow">return</span> (dwCrc1 + dwCrc2);
- <a name="l00146"></a>00146 }
- <a name="l00147"></a>00147
- <a name="l00148"></a>00148 <span class="keyword">private</span>:
- <a name="l00156"></a>00156 <span class="keywordtype">void</span> AddPacket( BYTE *pbData, WORD wSize, WORD wGroup )
- <a name="l00157"></a>00157 {
- <a name="l00158"></a>00158 <span class="keywordflow">if</span> ( !wSize || !pbData )
- <a name="l00159"></a>00159 return ;
- <a name="l00160"></a>00160
- <a name="l00161"></a>00161 WORD wDataSize;
- <a name="l00162"></a>00162 <a class="code" href="structc_fragment.html">cFragment</a> *pcFragment;
- <a name="l00163"></a>00163
- <a name="l00164"></a>00164 <span class="keywordflow">if</span> ( FindSpaceInQueue( pbData, wSize, wGroup ) )
- <a name="l00165"></a>00165 return ;
- <a name="l00166"></a>00166
- <a name="l00167"></a>00167 WORD wSizeLeft = wSize;
- <a name="l00168"></a>00168 WORD wFragmentCount = wSize / MAX_DATA_SIZE;
- <a name="l00169"></a>00169 WORD wFragmentIndex = 0;
- <a name="l00170"></a>00170 BYTE *pbCurData = pbData;
- <a name="l00171"></a>00171
- <a name="l00172"></a>00172 <span class="keywordflow">if</span> ( wSize % MAX_DATA_SIZE )
- <a name="l00173"></a>00173 ++wFragmentCount;
- <a name="l00174"></a>00174
- <a name="l00175"></a>00175 wDataSize = wSizeLeft > MAX_DATA_SIZE ? MAX_DATA_SIZE : wSizeLeft;
- <a name="l00176"></a>00176 pcFragment = <span class="keyword">new</span> <a class="code" href="structc_fragment.html">cFragment</a>( pbCurData, wDataSize );
- <a name="l00177"></a>00177
- <a name="l00178"></a>00178 <span class="keywordflow">for</span> ( ; wFragmentIndex < wFragmentCount; ++wFragmentIndex )
- <a name="l00179"></a>00179 {
- <a name="l00180"></a>00180 AddFragmentHeader( pcFragment->m_pbData + <span class="keyword">sizeof</span>( <a class="code" href="structc_transport_header.html">cTransportHeader</a> ), wDataSize, wFragmentIndex, wFragmentCount, wGroup );
- <a name="l00181"></a>00181
- <a name="l00182"></a>00182 pbCurData = pbCurData + wDataSize;
- <a name="l00183"></a>00183 wSizeLeft -= wDataSize;
- <a name="l00184"></a>00184 wDataSize = wSizeLeft > MAX_DATA_SIZE ? MAX_DATA_SIZE : wSizeLeft;
- <a name="l00185"></a>00185
- <a name="l00186"></a>00186 m_lstQueuedPackets.push_back( pcFragment );
- <a name="l00187"></a>00187
- <a name="l00188"></a>00188 <span class="keywordflow">if</span> ( wDataSize )
- <a name="l00189"></a>00189 pcFragment = <span class="keyword">new</span> <a class="code" href="structc_fragment.html">cFragment</a>( pbCurData, wDataSize );
- <a name="l00190"></a>00190 }
- <a name="l00191"></a>00191
- <a name="l00192"></a>00192 ++m_dwMsgID;
- <a name="l00193"></a>00193
- <a name="l00194"></a>00194 }
- <a name="l00200"></a>00200 <span class="keywordtype">void</span> SendQueuedPackets( SOCKADDR_IN& saSockAddr )
- <a name="l00201"></a>00201 {
- <a name="l00202"></a>00202 <a class="code" href="structc_transport_header.html">cTransportHeader</a> *pcTH;
- <a name="l00203"></a>00203 <a class="code" href="structc_fragment.html">cFragment</a> *pcFragment;
- <a name="l00204"></a>00204
- <a name="l00205"></a>00205 <span class="keywordflow">while</span> ( !m_lstQueuedPackets.empty( ) )
- <a name="l00206"></a>00206 {
- <a name="l00207"></a>00207 pcFragment = m_lstQueuedPackets.front( );
- <a name="l00208"></a>00208
- <a name="l00209"></a>00209 pcTH = <span class="keyword">reinterpret_cast<</span> <a class="code" href="structc_transport_header.html">cTransportHeader</a> * <span class="keyword">></span>( pcFragment->m_pbData );
- <a name="l00210"></a>00210
- <a name="l00211"></a>00211 pcTH->m_dwSequence = ++m_dwSendSequence;
- <a name="l00212"></a>00212 pcTH-><a class="code" href="structc_transport_header.html#a1e7fd0349092e3c2799f574e53414adf" title="0x00 - 0x03">m_dwFlags</a> = 0x0200;
- <a name="l00213"></a>00213 pcTH-><a class="code" href="structc_transport_header.html#a34986761fe175921ab35db53d6ab8b6c" title="0x08 - 0x0B">m_wLogicalID</a> = m_wLogicalID;
- <a name="l00214"></a>00214 pcTH-><a class="code" href="structc_transport_header.html#a426e0c7926a43c41738c97192747943a" title="0x0C - 0x0D">m_wTime</a> = m_wTime;
- <a name="l00215"></a>00215 pcTH-><a class="code" href="structc_transport_header.html#ab2da7be7e3a7c2ef02e78a81a959878b" title="0x0E - 0x0F">m_wTotalSize</a> = pcFragment->m_wSize - <span class="keyword">sizeof</span>( <a class="code" href="structc_transport_header.html">cTransportHeader</a> );
- <a name="l00216"></a>00216 pcTH-><a class="code" href="structc_transport_header.html#ae9f095331be7ab4be89b7b40be43670c" title="0x10 - 0x11">m_wTable</a> = 0x0000;
- <a name="l00217"></a>00217
- <a name="l00218"></a>00218 DWORD dwNewCRC, dwXorVal;
- <a name="l00219"></a>00219 <span class="comment">//dwNewCRC = Calc200_CRC( pcFragment->m_pbData );</span>
- <a name="l00220"></a>00220 <span class="comment">//</span>
- <a name="l00221"></a>00221 dwNewCRC = GetMagicNumber(pcFragment->m_pbData + <span class="keyword">sizeof</span>(<a class="code" href="structc_transport_header.html">cTransportHeader</a>),pcTH-><a class="code" href="structc_transport_header.html#ab2da7be7e3a7c2ef02e78a81a959878b" title="0x0E - 0x0F">m_wTotalSize</a>,1);
- <a name="l00222"></a>00222 <span class="comment">//</span>
- <a name="l00223"></a>00223 dwXorVal = GetSendXORVal( m_pdwSendCRC );
- <a name="l00224"></a>00224 dwNewCRC ^= dwXorVal;
- <a name="l00225"></a>00225 <span class="comment">// </span>
- <a name="l00226"></a>00226 pcTH-><a class="code" href="structc_transport_header.html#a3fc84ee42f26204b137d4df1c65bf1c3" title="0x04 - 0x07">m_dwCRC</a> = 0xBADD70DD;
- <a name="l00227"></a>00227 <span class="comment">//</span>
- <a name="l00228"></a>00228 <span class="comment">//dwNewCRC += CalcTransportCRC( (DWORD *)pcFragment->m_pbData );</span>
- <a name="l00229"></a>00229
- <a name="l00230"></a>00230 dwNewCRC += GetMagicNumber(pcFragment->m_pbData, <span class="keyword">sizeof</span>(<a class="code" href="structc_transport_header.html">cTransportHeader</a>),1);
- <a name="l00231"></a>00231 <span class="comment">//</span>
- <a name="l00232"></a>00232 pcTH-><a class="code" href="structc_transport_header.html#a3fc84ee42f26204b137d4df1c65bf1c3" title="0x04 - 0x07">m_dwCRC</a> = dwNewCRC;
- <a name="l00233"></a>00233
- <a name="l00234"></a>00234 sendto( m_Socket, (<span class="keywordtype">char</span> *)pcFragment->m_pbData, pcFragment->m_wSize, NULL, (sockaddr *)&saSockAddr, <span class="keyword">sizeof</span>( SOCKADDR ) );
- <a name="l00235"></a>00235
- <a name="l00236"></a>00236 pcFragment->m_dwSeed = dwXorVal;
- <a name="l00237"></a>00237
- <a name="l00238"></a>00238 m_lstSentPackets.push_back( pcFragment );
- <a name="l00239"></a>00239 m_lstQueuedPackets.pop_front( );
- <a name="l00240"></a>00240 }
- <a name="l00241"></a>00241 }
- <a name="l00249"></a>00249 <span class="keyword">static</span> <span class="keyword">inline</span> DWORD Calc200_CRC( BYTE *pbPacket )
- <a name="l00250"></a>00250 {
- <a name="l00251"></a>00251 BYTE *pbPacketEnd = pbPacket + <span class="keyword">reinterpret_cast<</span> <a class="code" href="structc_transport_header.html">cTransportHeader</a> * <span class="keyword">></span> ( pbPacket )->m_wTotalSize + <span class="keyword">sizeof</span> ( <a class="code" href="structc_transport_header.html">cTransportHeader</a> );
- <a name="l00252"></a>00252 DWORD dwCrc = 0;
- <a name="l00253"></a>00253
- <a name="l00254"></a>00254 <span class="keywordflow">for</span> ( BYTE *pbFragment = pbPacket + <span class="keyword">sizeof</span> ( <a class="code" href="structc_transport_header.html">cTransportHeader</a> ); pbFragment < pbPacketEnd; )
- <a name="l00255"></a>00255 {
- <a name="l00256"></a>00256 WORD wLength = <span class="keyword">reinterpret_cast<</span> <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> * <span class="keyword">></span> ( pbFragment )->m_wFragmentLength;
- <a name="l00257"></a>00257
- <a name="l00258"></a>00258 dwCrc += GetMagicNumber ( pbFragment, <span class="keyword">sizeof</span> ( <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> ), 1 ) + GetMagicNumber ( pbFragment + <span class="keyword">sizeof</span> ( <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> ), wLength - <span class="keyword">sizeof</span> ( <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> ), TRUE );
- <a name="l00259"></a>00259 pbFragment += wLength;
- <a name="l00260"></a>00260 }
- <a name="l00261"></a>00261
- <a name="l00262"></a>00262 <span class="keywordflow">return</span> dwCrc;
- <a name="l00263"></a>00263 }
- <a name="l00271"></a>00271 <span class="keyword">static</span> <span class="keyword">inline</span> DWORD CalcTransportCRC( DWORD *pdwWoot )
- <a name="l00272"></a>00272 {
- <a name="l00273"></a>00273 DWORD dwOrg = pdwWoot[2];
- <a name="l00274"></a>00274 DWORD dwCrc = 0;
- <a name="l00275"></a>00275
- <a name="l00276"></a>00276 pdwWoot[2] = 0xBADD70DD;
- <a name="l00277"></a>00277 dwCrc += GetMagicNumber( (BYTE *)pdwWoot, 20, TRUE );
- <a name="l00278"></a>00278 pdwWoot[2] = dwOrg;
- <a name="l00279"></a>00279
- <a name="l00280"></a>00280 <span class="keywordflow">return</span> dwCrc;
- <a name="l00281"></a>00281 }
- <a name="l00291"></a>00291 <span class="keyword">static</span> DWORD GetMagicNumber( BYTE *pbBuf, WORD wSize, BOOL fIncludeSize )
- <a name="l00292"></a>00292 {
- <a name="l00293"></a>00293 DWORD dwCS = 0;
- <a name="l00294"></a>00294 <span class="keywordtype">int</span> i;
- <a name="l00295"></a>00295
- <a name="l00296"></a>00296 <span class="keywordflow">if</span> ( fIncludeSize )
- <a name="l00297"></a>00297 dwCS += wSize << 16;
- <a name="l00298"></a>00298
- <a name="l00299"></a>00299 <span class="comment">// sum up the DWORDs:</span>
- <a name="l00300"></a>00300 <span class="keywordflow">for</span> (i = 0; i < (wSize >> 2); ++i )
- <a name="l00301"></a>00301 dwCS += ((DWORD *)pbBuf)[i];
- <a name="l00302"></a>00302
- <a name="l00303"></a>00303 <span class="comment">// now any remaining bytes are summed in reverse endian</span>
- <a name="l00304"></a>00304 <span class="keywordtype">int</span> iShift = 3;
- <a name="l00305"></a>00305 <span class="keywordflow">for</span> ( i = (i << 2); i < wSize; ++i )
- <a name="l00306"></a>00306 {
- <a name="l00307"></a>00307 dwCS += pbBuf[i] << (iShift * 8);
- <a name="l00308"></a>00308 --iShift;
- <a name="l00309"></a>00309 }
- <a name="l00310"></a>00310
- <a name="l00311"></a>00311 <span class="keywordflow">return</span> dwCS;
- <a name="l00312"></a>00312 }
- <a name="l00318"></a>00318 <span class="keywordtype">void</span> ReturnPing( SOCKADDR_IN& saSockAddr )
- <a name="l00319"></a>00319 {
- <a name="l00320"></a>00320 <span class="keywordtype">char</span> szSendBuffer[0x40];
- <a name="l00321"></a>00321
- <a name="l00322"></a>00322 DWORD *last = (DWORD *)&szSendBuffer[0x14];
- <a name="l00323"></a>00323
- <a name="l00324"></a>00324 <a class="code" href="structc_transport_header.html">cTransportHeader</a> *pcTH;
- <a name="l00325"></a>00325 pcTH = <span class="keyword">reinterpret_cast<</span> <a class="code" href="structc_transport_header.html">cTransportHeader</a> * <span class="keyword">></span>( szSendBuffer );
- <a name="l00326"></a>00326 pcTH->m_dwSequence = m_dwSendSequence;
- <a name="l00327"></a>00327 pcTH-><a class="code" href="structc_transport_header.html#a1e7fd0349092e3c2799f574e53414adf" title="0x00 - 0x03">m_dwFlags</a> = 0x00000004;
- <a name="l00328"></a>00328 pcTH-><a class="code" href="structc_transport_header.html#a34986761fe175921ab35db53d6ab8b6c" title="0x08 - 0x0B">m_wLogicalID</a> = m_wLogicalID;
- <a name="l00329"></a>00329 pcTH-><a class="code" href="structc_transport_header.html#a426e0c7926a43c41738c97192747943a" title="0x0C - 0x0D">m_wTime</a> = m_wTime;
- <a name="l00330"></a>00330 pcTH-><a class="code" href="structc_transport_header.html#ab2da7be7e3a7c2ef02e78a81a959878b" title="0x0E - 0x0F">m_wTotalSize</a> = 4;
- <a name="l00331"></a>00331 pcTH-><a class="code" href="structc_transport_header.html#ae9f095331be7ab4be89b7b40be43670c" title="0x10 - 0x11">m_wTable</a> = 0;
- <a name="l00332"></a>00332
- <a name="l00333"></a>00333 *last = m_dwRecvSequence;
- <a name="l00334"></a>00334
- <a name="l00335"></a>00335 <a class="code" href="classc_packet_pipe.html#a3cdc52a487c7feaa855363c5ebb0f174">CalcCRC</a>( (BYTE *)szSendBuffer, 4 );
- <a name="l00336"></a>00336 sendto( m_Socket, (<span class="keywordtype">char</span> *)szSendBuffer, 24, NULL, (SOCKADDR *)&saSockAddr, <span class="keyword">sizeof</span>( SOCKADDR ) );
- <a name="l00337"></a>00337 }
- <a name="l00344"></a>00344 <span class="keyword">inline</span> <span class="keywordtype">void</span> AddPacket( <a class="code" href="classc_message.html">cMessage</a>& cmPacket, WORD wGroup )
- <a name="l00345"></a>00345 {
- <a name="l00346"></a>00346 WORD wSize = cmPacket.getSize( );
- <a name="l00347"></a>00347
- <a name="l00348"></a>00348 BYTE *pbData = <span class="keyword">new</span> BYTE[wSize];
- <a name="l00349"></a>00349 cmPacket.getData( 0, wSize, pbData );
- <a name="l00350"></a>00350
- <a name="l00351"></a>00351 AddPacket( pbData, wSize, wGroup );
- <a name="l00352"></a>00352
- <a name="l00353"></a>00353 SAFEDELETE_ARRAY( pbData )
- <a name="l00354"></a>00354 }
- <a name="l00362"></a>00362 BOOL FindSpaceInQueue( BYTE *pbData, WORD wSize, WORD wGroup )
- <a name="l00363"></a>00363 {
- <a name="l00364"></a>00364 <a class="code" href="structc_fragment.html">cFragment</a> *pcFragment;
- <a name="l00365"></a>00365
- <a name="l00366"></a>00366 std::list< cFragment * >::iterator itFragment = m_lstQueuedPackets.begin( );
- <a name="l00367"></a>00367 <span class="keywordflow">for</span> ( ; itFragment != m_lstQueuedPackets.end( ); ++itFragment )
- <a name="l00368"></a>00368 {
- <a name="l00369"></a>00369 pcFragment = *itFragment;
- <a name="l00370"></a>00370
- <a name="l00371"></a>00371 <span class="keywordflow">if</span> ( pcFragment->m_wSize + wSize + <span class="keyword">sizeof</span>( <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> ) <= MAX_PACKET_SIZE )
- <a name="l00372"></a>00372 {
- <a name="l00373"></a>00373 CopyMemory( &pcFragment->m_pbData[pcFragment->m_wSize + <span class="keyword">sizeof</span>( <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> )], pbData, wSize );
- <a name="l00374"></a>00374 AddFragmentHeader( &pcFragment->m_pbData[pcFragment->m_wSize], wSize, 0, 1, wGroup );
- <a name="l00375"></a>00375 pcFragment->m_wSize += wSize + <span class="keyword">sizeof</span>( <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> );
- <a name="l00376"></a>00376 <span class="keywordflow">return</span> TRUE;
- <a name="l00377"></a>00377 }
- <a name="l00378"></a>00378 }
- <a name="l00379"></a>00379 <span class="keywordflow">return</span> FALSE;
- <a name="l00380"></a>00380 }
- <a name="l00390"></a>00390 <span class="keyword">inline</span> <span class="keywordtype">void</span> AddFragmentHeader( BYTE *pbStart, WORD wSize, WORD wFragmentIndex, WORD wFragmentCount, WORD wGroup )
- <a name="l00391"></a>00391 {
- <a name="l00392"></a>00392 <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> *pcFH = <span class="keyword">reinterpret_cast<</span> <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> * <span class="keyword">></span>( pbStart );
- <a name="l00393"></a>00393
- <a name="l00394"></a>00394 pcFH->m_dwSequence = m_dwMsgID;
- <a name="l00395"></a>00395 pcFH-><a class="code" href="structc_fragment_header.html#a135cf18e703c3e3aad60ee878ebfb96a" title="Sequence/ID - Identifier used to match fragmented messages together.">m_dwObjectID</a> = 0x80000000;
- <a name="l00396"></a>00396 pcFH-><a class="code" href="structc_fragment_header.html#aade0c3196e48cadebde96aa151656c25" title="Size - Number of bytes in this fragment, including the fragment header.">m_wFragmentIndex</a> = wFragmentIndex;
- <a name="l00397"></a>00397 pcFH-><a class="code" href="structc_fragment_header.html#ae1372b0c5d1092f0d74bbd86fac84c75" title="Count - The number of fragments required to complete this message.">m_wFragmentLength</a> = wSize + <span class="keyword">sizeof</span>( <a class="code" href="structc_fragment_header.html">cFragmentHeader</a> );
- <a name="l00398"></a>00398 pcFH-><a class="code" href="structc_fragment_header.html#a1e72c82f16409aa82424b161138fcf3c" title="Flags - Bitmask with an unknown purpose. Always 0x80000000?">m_wFragmentCount</a> = wFragmentCount;
- <a name="l00399"></a>00399 pcFH-><a class="code" href="structc_fragment_header.html#a3eaaeee7566155555b4b0d093be1e78f" title="Index - Fragment index. Used to order the message data from the fragment.">m_wFragmentGroup</a> = wGroup;
- <a name="l00400"></a>00400 }
- <a name="l00408"></a>00408 <span class="keywordtype">void</span> ProcessLostPackets( DWORD dwNumLostPackets, DWORD *pdwMissingPackets, SOCKADDR_IN& saSockAddr )
- <a name="l00409"></a>00409 {
- <a name="l00410"></a>00410
- <a name="l00411"></a>00411 DWORD dwNumIgnored = 0;
- <a name="l00412"></a>00412
- <a name="l00413"></a>00413 std::vector< DWORD > vIgnoreList;
- <a name="l00414"></a>00414 vIgnoreList.reserve( dwNumLostPackets );
- <a name="l00415"></a>00415
- <a name="l00416"></a>00416 <a class="code" href="structc_fragment.html">cFragment</a> *pcFragment;
- <a name="l00417"></a>00417
- <a name="l00418"></a>00418 <span class="keywordflow">for</span> ( DWORD dwCurrentPacket = 0; dwCurrentPacket < dwNumLostPackets; ++dwCurrentPacket )
- <a name="l00419"></a>00419 {
- <a name="l00420"></a>00420 std::list< cFragment * >::iterator itFragment = m_lstSentPackets.begin( );
- <a name="l00421"></a>00421 <span class="keywordflow">for</span> ( ; itFragment != m_lstSentPackets.end( ); ++itFragment )
- <a name="l00422"></a>00422 {
- <a name="l00423"></a>00423 pcFragment = *itFragment;
- <a name="l00424"></a>00424 <span class="keywordflow">if</span> ( *((DWORD *)pcFragment->m_pbData) == pdwMissingPackets[dwCurrentPacket] )
- <a name="l00425"></a>00425 <span class="keywordflow">break</span>;
- <a name="l00426"></a>00426 }
- <a name="l00427"></a>00427
- <a name="l00428"></a>00428 <span class="keywordflow">if</span> ( itFragment != m_lstSentPackets.end( ) )
- <a name="l00429"></a>00429 {
- <a name="l00430"></a>00430 <a class="code" href="structc_transport_header.html">cTransportHeader</a> *pcTH = <span class="keyword">reinterpret_cast<</span> <a class="code" href="structc_transport_header.html">cTransportHeader</a> * <span class="keyword">></span>( pcFragment->m_pbData );
- <a name="l00431"></a>00431
- <a name="l00432"></a>00432 pcTH-><a class="code" href="structc_transport_header.html#a1e7fd0349092e3c2799f574e53414adf" title="0x00 - 0x03">m_dwFlags</a> = 0x00000201;
- <a name="l00433"></a>00433 pcTH-><a class="code" href="structc_transport_header.html#a426e0c7926a43c41738c97192747943a" title="0x0C - 0x0D">m_wTime</a> = m_wTime;
- <a name="l00434"></a>00434
- <a name="l00435"></a>00435 DWORD dwNewCRC;
- <a name="l00436"></a>00436 dwNewCRC = Calc200_CRC( pcFragment->m_pbData );
- <a name="l00437"></a>00437 dwNewCRC ^= pcFragment->m_dwSeed;
- <a name="l00438"></a>00438 dwNewCRC += CalcTransportCRC( (DWORD *)pcFragment->m_pbData );
- <a name="l00439"></a>00439
- <a name="l00440"></a>00440 pcTH-><a class="code" href="structc_transport_header.html#a3fc84ee42f26204b137d4df1c65bf1c3" title="0x04 - 0x07">m_dwCRC</a> = dwNewCRC;
- <a name="l00441"></a>00441
- <a name="l00442"></a>00442 sendto( m_Socket, (<span class="keywordtype">char</span> *)pcFragment->m_pbData, pcFragment->m_wSize, NULL, (SOCKADDR *)&saSockAddr, <span class="keyword">sizeof</span>( SOCKADDR ) );
- <a name="l00443"></a>00443 }
- <a name="l00444"></a>00444 <span class="keywordflow">else</span>
- <a name="l00445"></a>00445 {
- <a name="l00446"></a>00446 vIgnoreList.push_back( pdwMissingPackets[dwCurrentPacket] );
- <a name="l00447"></a>00447 ++dwNumIgnored;
- <a name="l00448"></a>00448 }
- <a name="l00449"></a>00449 }
- <a name="l00450"></a>00450
- <a name="l00451"></a>00451 <span class="keywordflow">if</span> ( !vIgnoreList.empty( ) )
- <a name="l00452"></a>00452 {
- <a name="l00453"></a>00453 BYTE pbSendBuffer[0x1E4];
- <a name="l00454"></a>00454
- <a name="l00455"></a>00455 <a class="code" href="structc_ignore_request.html">cIgnoreRequest</a> irOut;
- <a name="l00456"></a>00456 irOut.m_dwNum = dwNumIgnored;
- <a name="l00457"></a>00457 irOut.m_wUnk1 = m_wLogicalID;
- <a name="l00458"></a>00458 irOut.m_wUnk2 = m_wTime;
- <a name="l00459"></a>00459 irOut.m_wSize = 4 + dwNumIgnored * 4;
- <a name="l00460"></a>00460
- <a name="l00461"></a>00461 CopyMemory( pbSendBuffer, &irOut, <span class="keyword">sizeof</span>( <a class="code" href="structc_ignore_request.html">cIgnoreRequest</a> ) );
- <a name="l00462"></a>00462
- <a name="l00463"></a>00463 std::vector< DWORD >::iterator itIgnore = vIgnoreList.begin( );
- <a name="l00464"></a>00464 <span class="keywordflow">for</span> ( DWORD dwCount = 0; itIgnore != vIgnoreList.end( ); ++itIgnore, ++dwCount )
- <a name="l00465"></a>00465 CopyMemory( pbSendBuffer + <span class="keyword">sizeof</span>( irOut ) + dwCount * 4, &itIgnore, <span class="keyword">sizeof</span>( DWORD ) );
- <a name="l00466"></a>00466
- <a name="l00467"></a>00467 irOut.m_dwCRC = <a class="code" href="classc_packet_pipe.html#a3cdc52a487c7feaa855363c5ebb0f174">CalcCRC</a>( pbSendBuffer, 4 + dwNumIgnored * 4 );
- <a name="l00468"></a>00468
- <a name="l00469"></a>00469 sendto( m_Socket, (<span class="keywordtype">char</span>*)pbSendBuffer, <span class="keyword">sizeof</span>( irOut ) + dwNumIgnored * 4, NULL, (SOCKADDR *)&saSockAddr, <span class="keyword">sizeof</span>( SOCKADDR ) );
- <a name="l00470"></a>00470
- <a name="l00471"></a>00471 vIgnoreList.clear( );
- <a name="l00472"></a>00472 }
- <a name="l00473"></a>00473
- <a name="l00474"></a>00474 }
- <a name="l00480"></a>00480 <span class="keyword">inline</span> <span class="keywordtype">void</span> ClearSentPackets( DWORD dwLastGoodSeq )
- <a name="l00481"></a>00481 {
- <a name="l00482"></a>00482 <a class="code" href="structc_fragment.html">cFragment</a> *pcFragment;
- <a name="l00483"></a>00483
- <a name="l00484"></a>00484 <span class="keywordflow">while</span> ( !m_lstSentPackets.empty( ) )
- <a name="l00485"></a>00485 {
- <a name="l00486"></a>00486 pcFragment = m_lstSentPackets.front( );
- <a name="l00487"></a>00487
- <a name="l00488"></a>00488 <span class="keywordflow">if</span> ( *((DWORD *)pcFragment->m_pbData) > dwLastGoodSeq )
- <a name="l00489"></a>00489 <span class="keywordflow">break</span>;
- <a name="l00490"></a>00490 <span class="keywordflow">else</span>
- <a name="l00491"></a>00491 {
- <a name="l00492"></a>00492 m_lstSentPackets.pop_front( );
- <a name="l00493"></a>00493 SAFEDELETE( pcFragment )
- <a name="l00494"></a>00494 }
- <a name="l00495"></a>00495 }
- <a name="l00496"></a>00496 }
- <a name="l00497"></a>00497 <span class="keyword">inline</span> <span class="keywordtype">void</span> ResetCRCs( )
- <a name="l00498"></a>00498 {
- <a name="l00499"></a>00499 GenerateCRCs( m_dwSendCRCSeed, m_dwRecvCRCSeed, m_pdwSendCRC, m_pdwRecvCRC );
- <a name="l00500"></a>00500 }
- <a name="l00501"></a>00501
- <a name="l00502"></a>00502 DWORD m_lpdwSendCRC[3];
- <a name="l00503"></a>00503 DWORD m_lpdwRecvCRC[3];
- <a name="l00504"></a>00504 DWORD *m_pdwSendCRC;
- <a name="l00505"></a>00505 DWORD *m_pdwRecvCRC;
- <a name="l00506"></a>00506 DWORD m_dwSendSequence;
- <a name="l00507"></a>00507 DWORD m_dwRecvSequence;
- <a name="l00508"></a>00508 DWORD m_dwMsgID;
- <a name="l00509"></a>00509 WORD m_wTime;
- <a name="l00510"></a>00510 <span class="comment">//SOCKADDR_IN m_saSockAddr;</span>
- <a name="l00511"></a>00511
- <a name="l00512"></a>00512 std::list< cFragment * > m_lstQueuedPackets;
- <a name="l00513"></a>00513 std::list< cFragment * > m_lstSentPackets;
- <a name="l00514"></a>00514 };
- <a name="l00515"></a>00515
- <a name="l00516"></a>00516 <span class="preprocessor">#endif // #ifndef __PACKETPIPE_H</span>
- </pre></div></div>
- <hr size="1"/><address style="text-align: right;"><small>Generated by
- <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
- </body>
- </html>
|