#include <udp_sim_sock.h>
Notes: InLag must be >0 to use the InPacketLoss variable
Nevrax France
Definition at line 49 of file udp_sim_sock.h.
Public Member Functions | |
| void | close () |
| void | connect (const CInetAddress &addr) |
| bool | connected () |
| CUdpSimSock (bool logging=true) | |
| bool | dataAvailable () |
| const CInetAddress & | localAddr () const |
| bool | receive (uint8 *buffer, uint32 &len, bool throw_exception=true) |
| CSock::TSockResult | send (const uint8 *buffer, uint32 &len, bool throw_exception=true) |
| void | sendTo (const uint8 *buffer, uint32 &len, const CInetAddress &addr) |
Static Public Member Functions | |
| void | setSimValues (NLMISC::CConfigFile &cf) |
Data Fields | |
| CUdpSock | UdpSock |
Private Member Functions | |
| void | sendUDP (const uint8 *buffer, uint32 &len, const CInetAddress *addr=NULL) |
| void | sendUDPNow (const uint8 *buffer, uint32 len, const CInetAddress *addr=NULL) |
| void | updateBufferizedPackets () |
Static Private Attributes | |
| uint32 | _InLag = 0 |
| uint8 | _InPacketLoss = 0 |
| uint32 | _OutLag = 0 |
| uint8 | _OutPacketDisordering = 0 |
| uint8 | _OutPacketDuplication = 0 |
| uint8 | _OutPacketLoss = 0 |
Friends | |
| void | cbSimVar (NLMISC::CConfigFile::CVar &var) |
|
|
Definition at line 53 of file udp_sim_sock.h. References UdpSock.
00053 : UdpSock(logging) { } |
|
|
Definition at line 231 of file udp_sim_sock.cpp. References NLNET::CSock::close(), and UdpSock.
00232 {
00233 UdpSock.close ();
00234 }
|
|
|
Definition at line 226 of file udp_sim_sock.cpp. References addr, NLNET::CSock::connect(), and UdpSock. Referenced by NLNET::CLoginClient::connectToShard().
00227 {
00228 UdpSock.connect (addr);
00229 }
|
|
|
Definition at line 306 of file udp_sim_sock.cpp. References NLNET::CSock::connected(), and UdpSock. Referenced by NLNET::CLoginClient::connectToShard().
00307 {
00308 return UdpSock.connected ();
00309 }
|
|
|
Definition at line 238 of file udp_sim_sock.cpp. References _InLag, _InPacketLoss, addr, buffer, NLNET::BufferizedInPackets, NLNET::CSock::dataAvailable(), len, NLNET::CUdpSock::receivedFrom(), NLMISC::TTime, UdpSock, uint, and updateBufferizedPackets().
00239 {
00240 updateBufferizedPackets ();
00241
00242 if (_InLag > 0)
00243 {
00244 while (UdpSock.dataAvailable ())
00245 {
00246 CInetAddress addr;
00247 uint len = 10000;
00248 UdpSock.receivedFrom (buffer, len, addr);
00249
00250 if ((float)rand()/(float)(RAND_MAX)*100.0f >= _InPacketLoss)
00251 {
00252 CBufferizedOutPacket *bp = new CBufferizedOutPacket (&UdpSock, buffer, len, _InLag, &addr);
00253 BufferizedInPackets.push (bp);
00254 }
00255 }
00256
00257 TTime ct = CTime::getLocalTime ();
00258 if (!BufferizedInPackets.empty() && BufferizedInPackets.front ()->Time <= ct)
00259 return true;
00260 else
00261 return false;
00262 }
00263 else
00264 {
00265 return UdpSock.dataAvailable ();
00266 }
00267 }
|
|
|
Definition at line 66 of file udp_sim_sock.h. References NLNET::CSock::localAddr(), and UdpSock.
00066 { return UdpSock.localAddr(); }
|
|
||||||||||||||||
|
Definition at line 269 of file udp_sim_sock.cpp. References _InLag, buffer, NLNET::BufferizedInPackets, len, min, NLNET::CBufferizedOutPacket::Packet, NLNET::CBufferizedOutPacket::PacketSize, NLNET::CUdpSock::receive(), s, UdpSock, uint32, and uint8.
00270 {
00271 if (_InLag> 0)
00272 {
00273 if (BufferizedInPackets.empty())
00274 {
00275 if (throw_exception)
00276 throw Exception ("no data available");
00277 return false;
00278 }
00279
00280 CBufferizedOutPacket *bp = BufferizedInPackets.front ();
00281 uint32 s = min (len, bp->PacketSize);
00282 memcpy (buffer, bp->Packet, s);
00283 len = s;
00284
00285 delete bp;
00286 BufferizedInPackets.pop ();
00287 return true;
00288 }
00289 else
00290 {
00291 return UdpSock.receive(buffer, len, throw_exception);
00292 }
00293 }
|
|
||||||||||||||||
|
Definition at line 295 of file udp_sim_sock.cpp. References buffer, len, sendUDP(), uint32, and uint8.
00296 {
00297 sendUDP (buffer, len);
00298 return CSock::Ok;
00299 }
|
|
||||||||||||||||
|
Definition at line 301 of file udp_sim_sock.cpp. References addr, buffer, len, sendUDP(), uint32, and uint8.
00302 {
00303 sendUDP (buffer, len, &addr);
00304 }
|
|
||||||||||||||||
|
Definition at line 115 of file udp_sim_sock.cpp. References _OutLag, _OutPacketDisordering, _OutPacketDuplication, _OutPacketLoss, addr, buffer, NLNET::BufferizedOutPackets, len, nlassert, sendUDPNow(), sint32, t, NLNET::CBufferizedOutPacket::Time, NLMISC::TTime, UdpSock, uint32, and uint8. Referenced by send(), and sendTo().
00116 {
00117 nlassert (buffer != NULL);
00118 nlassert (len > 0);
00119
00120 if ((float)rand()/(float)(RAND_MAX)*100.0f >= _OutPacketLoss)
00121 {
00122 sint32 lag = _OutLag /*+ (rand()%40) - 20*/;// void disordering
00123
00124 if (lag > 100)
00125 {
00126 // send the packet later
00127
00128 CBufferizedOutPacket *bp = new CBufferizedOutPacket (&UdpSock, buffer, len, lag, addr);
00129
00130 // duplicate the packet
00131 if ((float)rand()/(float)(RAND_MAX)*100.0f < _OutPacketDisordering && BufferizedOutPackets.size() > 0)
00132 {
00133 CBufferizedOutPacket *bp2 = BufferizedOutPackets.back();
00134
00135 // exange the time
00136 TTime t = bp->Time;
00137 bp->Time = bp2->Time;
00138 bp2->Time = t;
00139
00140 // exange packet in the buffer
00141 BufferizedOutPackets.back() = bp;
00142 bp = bp2;
00143 }
00144
00145 BufferizedOutPackets.push (bp);
00146
00147 // duplicate the packet
00148 if ((float)rand()/(float)(RAND_MAX)*100.0f < _OutPacketDuplication)
00149 {
00150 CBufferizedOutPacket *bp = new CBufferizedOutPacket (&UdpSock, buffer, len, lag, addr);
00151 BufferizedOutPackets.push (bp);
00152 }
00153 }
00154 else
00155 {
00156 // send the packet NOW
00157
00158 sendUDPNow (buffer, len, addr);
00159
00160 // duplicate the packet
00161 if ((float)rand()/(float)(RAND_MAX)*100.0f < _OutPacketDuplication)
00162 {
00163 sendUDPNow (buffer, len, addr);
00164 }
00165 }
00166 }
00167 }
|
|
||||||||||||||||
|
Definition at line 107 of file udp_sim_sock.cpp. References addr, buffer, len, NLNET::CSock::send(), NLNET::CUdpSock::sendTo(), UdpSock, uint32, and uint8. Referenced by sendUDP(), and updateBufferizedPackets().
|
|
|
Definition at line 202 of file udp_sim_sock.cpp. References cbSimVar, NLNET::cbSimVar(), NLMISC::CConfigFile::getVar(), nlwarning, and NLMISC::CConfigFile::setCallback().
00203 {
00204 cf.setCallback ("SimInLag", cbSimVar);
00205 cf.setCallback ("SimInPacketLost", cbSimVar);
00206 cf.setCallback ("SimOutLag", cbSimVar);
00207 cf.setCallback ("SimOutPacketLost", cbSimVar);
00208 cf.setCallback ("SimOutPacketDuplication", cbSimVar);
00209 cf.setCallback ("SimOutPacketDisordering", cbSimVar);
00210
00211 try
00212 {
00213 cbSimVar (cf.getVar("SimInLag"));
00214 cbSimVar (cf.getVar("SimInPacketLost"));
00215 cbSimVar (cf.getVar("SimOutLag"));
00216 cbSimVar (cf.getVar("SimOutPacketLost"));
00217 cbSimVar (cf.getVar("SimOutPacketDuplication"));
00218 cbSimVar (cf.getVar("SimOutPacketDisordering"));
00219 }
00220 catch (Exception &e)
00221 {
00222 nlwarning ("LNETL0: Problem during getting Sim values from config file: %s", e.what());
00223 }
00224 }
|
|
|
Definition at line 171 of file udp_sim_sock.cpp. References NLNET::CBufferizedOutPacket::Addr, NLNET::BufferizedOutPackets, NLNET::CBufferizedOutPacket::Packet, NLNET::CBufferizedOutPacket::PacketSize, sendUDPNow(), NLNET::CBufferizedOutPacket::Time, and NLMISC::TTime. Referenced by dataAvailable().
00172 {
00173 TTime ct = CTime::getLocalTime ();
00174 while (!BufferizedOutPackets.empty())
00175 {
00176 CBufferizedOutPacket *bp = BufferizedOutPackets.front ();
00177 if (bp->Time <= ct)
00178 {
00179 // time to send the message
00180 sendUDPNow (bp->Packet, bp->PacketSize, bp->Addr);
00181 delete bp;
00182 BufferizedOutPackets.pop ();
00183 }
00184 else
00185 {
00186 break;
00187 }
00188 }
00189 }
|
|
|
Definition at line 191 of file udp_sim_sock.cpp. Referenced by setSimValues().
00192 {
00193 if (var.Name == "SimInLag") CUdpSimSock::_InLag = var.asInt ();
00194 else if (var.Name == "SimInPacketLost") CUdpSimSock::_InPacketLoss = var.asInt ();
00195 else if (var.Name == "SimOutLag") CUdpSimSock::_OutLag = var.asInt ();
00196 else if (var.Name == "SimOutPacketLost") CUdpSimSock::_OutPacketLoss = var.asInt ();
00197 else if (var.Name == "SimOutPacketDuplication") CUdpSimSock::_OutPacketDuplication = var.asInt ();
00198 else if (var.Name == "SimOutPacketDisordering") CUdpSimSock::_OutPacketDisordering = var.asInt ();
00199 else nlstop;
00200 }
|
|
|
Definition at line 95 of file udp_sim_sock.cpp. Referenced by dataAvailable(), and receive(). |
|
|
Definition at line 96 of file udp_sim_sock.cpp. Referenced by dataAvailable(). |
|
|
Definition at line 98 of file udp_sim_sock.cpp. Referenced by sendUDP(). |
|
|
Definition at line 101 of file udp_sim_sock.cpp. Referenced by sendUDP(). |
|
|
Definition at line 100 of file udp_sim_sock.cpp. Referenced by sendUDP(). |
|
|
Definition at line 99 of file udp_sim_sock.cpp. Referenced by sendUDP(). |
|
|
Definition at line 69 of file udp_sim_sock.h. Referenced by close(), connect(), connected(), CUdpSimSock(), dataAvailable(), localAddr(), receive(), sendUDP(), and sendUDPNow(). |
1.3.6