netInterface.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "sim/netConnection.h"
  24. #include "sim/netInterface.h"
  25. #include "core/stream/bitStream.h"
  26. #include "math/mRandom.h"
  27. #include "core/util/journal/journal.h"
  28. #include "console/engineAPI.h"
  29. #ifdef GGC_PLUGIN
  30. #include "GGCNatTunnel.h"
  31. extern void HandleGGCPacket(NetAddress* addr, unsigned char* data, U32 dataSize);
  32. #endif
  33. NetInterface *GNet = NULL;
  34. NetInterface::NetInterface()
  35. {
  36. AssertFatal(GNet == NULL, "ERROR: Multiple net interfaces declared.");
  37. GNet = this;
  38. mLastTimeoutCheckTime = 0;
  39. mAllowConnections = false;
  40. }
  41. void NetInterface::initRandomData()
  42. {
  43. mRandomDataInitialized = true;
  44. U32 seed = Platform::getRealMilliseconds();
  45. if(Journal::IsPlaying())
  46. Journal::Read(&seed);
  47. else if(Journal::IsRecording())
  48. Journal::Write(seed);
  49. MRandomR250 myRandom(seed);
  50. for(U32 i = 0; i < 12; i++)
  51. mRandomHashData[i] = myRandom.randI();
  52. }
  53. void NetInterface::addPendingConnection(NetConnection *connection)
  54. {
  55. Con::printf("Adding a pending connection");
  56. mPendingConnections.push_back(connection);
  57. }
  58. void NetInterface::removePendingConnection(NetConnection *connection)
  59. {
  60. for(U32 i = 0; i < mPendingConnections.size(); i++)
  61. if(mPendingConnections[i] == connection)
  62. mPendingConnections.erase(i);
  63. }
  64. NetConnection *NetInterface::findPendingConnection(const NetAddress *address, U32 connectSequence)
  65. {
  66. for(U32 i = 0; i < mPendingConnections.size(); i++)
  67. if(Net::compareAddresses(address, mPendingConnections[i]->getNetAddress()) &&
  68. connectSequence == mPendingConnections[i]->getSequence())
  69. return mPendingConnections[i];
  70. return NULL;
  71. }
  72. void NetInterface::processPacketReceiveEvent(NetAddress srcAddress, RawData packetData)
  73. {
  74. U32 dataSize = packetData.size;
  75. BitStream pStream(packetData.data, dataSize);
  76. // Determine what to do with this packet:
  77. if(packetData.data[0] & 0x01) // it's a protocol packet...
  78. {
  79. // if the LSB of the first byte is set, it's a game data packet
  80. // so pass it to the appropriate connection.
  81. // lookup the connection in the addressTable
  82. NetConnection *conn = NetConnection::lookup(&srcAddress);
  83. if(conn)
  84. conn->processRawPacket(&pStream);
  85. }
  86. else
  87. {
  88. // Otherwise, it's either a game info packet or a
  89. // connection handshake packet.
  90. U8 packetType;
  91. pStream.read(&packetType);
  92. NetAddress *addr = &srcAddress;
  93. if(packetType <= GameHeartbeat || packetType == MasterServerExtendedListResponse)
  94. handleInfoPacket(addr, packetType, &pStream);
  95. #ifdef GGC_PLUGIN
  96. else if (packetType == GGCPacket)
  97. {
  98. HandleGGCPacket(addr, (U8*)packetData.data, dataSize);
  99. }
  100. #endif
  101. else
  102. {
  103. // check if there's a connection already:
  104. switch(packetType)
  105. {
  106. case ConnectChallengeRequest:
  107. handleConnectChallengeRequest(addr, &pStream);
  108. break;
  109. case ConnectRequest:
  110. handleConnectRequest(addr, &pStream);
  111. break;
  112. case ConnectChallengeResponse:
  113. handleConnectChallengeResponse(addr, &pStream);
  114. break;
  115. case ConnectAccept:
  116. handleConnectAccept(addr, &pStream);
  117. break;
  118. case Disconnect:
  119. handleDisconnect(addr, &pStream);
  120. break;
  121. case ConnectReject:
  122. handleConnectReject(addr, &pStream);
  123. break;
  124. }
  125. }
  126. }
  127. }
  128. //-----------------------------------------------------------------------------
  129. //-----------------------------------------------------------------------------
  130. // Connection handshaking basic overview:
  131. // The torque engine does a two phase connect handshake to
  132. // prevent a spoofed source address Denial-of-Service (DOS) attack
  133. //
  134. // Basically, the initiator of a connection (client) sends a
  135. // Connect Challenge Request packet to the server to initiate the connection
  136. // The server then hashes the source address of the client request
  137. // with some random magic server data to come up with a 16-byte key that
  138. // the client can then use to gain entry to the server.
  139. // This way there are no partially active connection records on the
  140. // server at all.
  141. //
  142. // The client then sends a Connect Request packet to the server,
  143. // including any game specific data necessary to start a connection (a
  144. // server password, for instance), along with the key the server sent
  145. // on the Connect Challenge Response packet.
  146. //
  147. // The server, on receipt of the Connect Request, compares the
  148. // entry key with a computed key, makes sure it can create the requested
  149. // NetConnection subclass, and then passes all processing on to the connection
  150. // instance.
  151. //
  152. // If the subclass reads and accepts he connect request successfully, the
  153. // server sends a Connect Accept packet - otherwise the connection
  154. // is rejected with the sendConnectReject function
  155. //-----------------------------------------------------------------------------
  156. //-----------------------------------------------------------------------------
  157. void NetInterface::sendConnectChallengeRequest(NetConnection *conn)
  158. {
  159. Con::printf("Sending Connect challenge Request");
  160. BitStream *out = BitStream::getPacketStream();
  161. out->write(U8(ConnectChallengeRequest));
  162. out->write(conn->getSequence());
  163. conn->mConnectSendCount++;
  164. conn->mConnectLastSendTime = Platform::getVirtualMilliseconds();
  165. BitStream::sendPacketStream(conn->getNetAddress());
  166. }
  167. void NetInterface::handleConnectChallengeRequest(const NetAddress *addr, BitStream *stream)
  168. {
  169. char buf[256];
  170. Net::addressToString(addr, buf);
  171. Con::printf("Got Connect challenge Request from %s", buf);
  172. if(!mAllowConnections)
  173. return;
  174. U32 connectSequence;
  175. stream->read(&connectSequence);
  176. if(!mRandomDataInitialized)
  177. initRandomData();
  178. U32 addressDigest[4];
  179. computeNetMD5(addr, connectSequence, addressDigest);
  180. BitStream *out = BitStream::getPacketStream();
  181. out->write(U8(ConnectChallengeResponse));
  182. out->write(connectSequence);
  183. out->write(addressDigest[0]);
  184. out->write(addressDigest[1]);
  185. out->write(addressDigest[2]);
  186. out->write(addressDigest[3]);
  187. BitStream::sendPacketStream(addr);
  188. }
  189. //-----------------------------------------------------------------------------
  190. void NetInterface::handleConnectChallengeResponse(const NetAddress *address, BitStream *stream)
  191. {
  192. Con::printf("Got Connect challenge Response");
  193. U32 connectSequence;
  194. stream->read(&connectSequence);
  195. NetConnection *conn = findPendingConnection(address, connectSequence);
  196. if(!conn || conn->getConnectionState() != NetConnection::AwaitingChallengeResponse)
  197. return;
  198. U32 addressDigest[4];
  199. stream->read(&addressDigest[0]);
  200. stream->read(&addressDigest[1]);
  201. stream->read(&addressDigest[2]);
  202. stream->read(&addressDigest[3]);
  203. conn->setAddressDigest(addressDigest);
  204. conn->setConnectionState(NetConnection::AwaitingConnectResponse);
  205. conn->mConnectSendCount = 0;
  206. Con::printf("Sending Connect Request");
  207. sendConnectRequest(conn);
  208. }
  209. //-----------------------------------------------------------------------------
  210. void NetInterface::sendConnectRequest(NetConnection *conn)
  211. {
  212. BitStream *out = BitStream::getPacketStream();
  213. out->write(U8(ConnectRequest));
  214. out->write(conn->getSequence());
  215. U32 addressDigest[4];
  216. conn->getAddressDigest(addressDigest);
  217. out->write(addressDigest[0]);
  218. out->write(addressDigest[1]);
  219. out->write(addressDigest[2]);
  220. out->write(addressDigest[3]);
  221. out->writeString(conn->getClassName());
  222. conn->writeConnectRequest(out);
  223. conn->mConnectSendCount++;
  224. conn->mConnectLastSendTime = Platform::getVirtualMilliseconds();
  225. BitStream::sendPacketStream(conn->getNetAddress());
  226. }
  227. //-----------------------------------------------------------------------------
  228. void NetInterface::handleConnectRequest(const NetAddress *address, BitStream *stream)
  229. {
  230. if(!mAllowConnections)
  231. return;
  232. Con::printf("Got Connect Request");
  233. U32 connectSequence;
  234. stream->read(&connectSequence);
  235. // see if the connection is in the main connection table:
  236. NetConnection *connect = NetConnection::lookup(address);
  237. if(connect && connect->getSequence() == connectSequence)
  238. {
  239. sendConnectAccept(connect);
  240. return;
  241. }
  242. U32 addressDigest[4];
  243. U32 computedAddressDigest[4];
  244. stream->read(&addressDigest[0]);
  245. stream->read(&addressDigest[1]);
  246. stream->read(&addressDigest[2]);
  247. stream->read(&addressDigest[3]);
  248. computeNetMD5(address, connectSequence, computedAddressDigest);
  249. if(addressDigest[0] != computedAddressDigest[0] ||
  250. addressDigest[1] != computedAddressDigest[1] ||
  251. addressDigest[2] != computedAddressDigest[2] ||
  252. addressDigest[3] != computedAddressDigest[3])
  253. return; // bogus connection attempt
  254. if(connect)
  255. {
  256. if(connect->getSequence() > connectSequence)
  257. return; // the existing connection should be kept - the incoming request is stale.
  258. else
  259. connect->deleteObject(); // disconnect this one, and allow the new one to be created.
  260. }
  261. char connectionClass[255];
  262. stream->readString(connectionClass);
  263. ConsoleObject *co = ConsoleObject::create(connectionClass);
  264. NetConnection *conn = dynamic_cast<NetConnection *>(co);
  265. if(!conn || !conn->canRemoteCreate())
  266. {
  267. delete co;
  268. return;
  269. }
  270. conn->registerObject();
  271. conn->setNetAddress(address);
  272. conn->setNetworkConnection(true);
  273. conn->setSequence(connectSequence);
  274. const char *errorString = NULL;
  275. if(!conn->readConnectRequest(stream, &errorString))
  276. {
  277. sendConnectReject(conn, errorString);
  278. conn->deleteObject();
  279. return;
  280. }
  281. conn->setNetworkConnection(true);
  282. conn->onConnectionEstablished(false);
  283. conn->setEstablished();
  284. conn->setConnectSequence(connectSequence);
  285. sendConnectAccept(conn);
  286. }
  287. //-----------------------------------------------------------------------------
  288. void NetInterface::sendConnectAccept(NetConnection *conn)
  289. {
  290. BitStream *out = BitStream::getPacketStream();
  291. out->write(U8(ConnectAccept));
  292. out->write(conn->getSequence());
  293. conn->writeConnectAccept(out);
  294. BitStream::sendPacketStream(conn->getNetAddress());
  295. }
  296. void NetInterface::handleConnectAccept(const NetAddress *address, BitStream *stream)
  297. {
  298. U32 connectSequence;
  299. stream->read(&connectSequence);
  300. NetConnection *conn = findPendingConnection(address, connectSequence);
  301. if(!conn || conn->getConnectionState() != NetConnection::AwaitingConnectResponse)
  302. return;
  303. const char *errorString = NULL;
  304. if(!conn->readConnectAccept(stream, &errorString))
  305. {
  306. conn->handleStartupError(errorString);
  307. removePendingConnection(conn);
  308. conn->deleteObject();
  309. return;
  310. }
  311. removePendingConnection(conn); // remove from the pending connection list
  312. conn->setNetworkConnection(true);
  313. conn->onConnectionEstablished(true); // notify the connection that it has been established
  314. conn->setEstablished(); // installs the connection in the connection table, and causes pings/timeouts to happen
  315. conn->setConnectSequence(connectSequence);
  316. }
  317. void NetInterface::sendConnectReject(NetConnection *conn, const char *reason)
  318. {
  319. if(!reason)
  320. return; // if the stream is NULL, we reject silently
  321. BitStream *out = BitStream::getPacketStream();
  322. out->write(U8(ConnectReject));
  323. out->write(conn->getSequence());
  324. out->writeString(reason);
  325. BitStream::sendPacketStream(conn->getNetAddress());
  326. }
  327. void NetInterface::handleConnectReject(const NetAddress *address, BitStream *stream)
  328. {
  329. U32 connectSequence;
  330. stream->read(&connectSequence);
  331. NetConnection *conn = findPendingConnection(address, connectSequence);
  332. if(!conn || (conn->getConnectionState() != NetConnection::AwaitingChallengeResponse &&
  333. conn->getConnectionState() != NetConnection::AwaitingConnectResponse))
  334. return;
  335. removePendingConnection(conn);
  336. char reason[256];
  337. stream->readString(reason);
  338. conn->onConnectionRejected(reason);
  339. conn->deleteObject();
  340. }
  341. void NetInterface::handleDisconnect(const NetAddress *address, BitStream *stream)
  342. {
  343. NetConnection *conn = NetConnection::lookup(address);
  344. if(!conn)
  345. return;
  346. U32 connectSequence;
  347. char reason[256];
  348. stream->read(&connectSequence);
  349. stream->readString(reason);
  350. if(conn->getSequence() != connectSequence)
  351. return;
  352. conn->onDisconnect(reason);
  353. conn->deleteObject();
  354. }
  355. void NetInterface::handleInfoPacket(const NetAddress *address, U8 packetType, BitStream *stream)
  356. {
  357. }
  358. void NetInterface::processClient()
  359. {
  360. NetObject::collapseDirtyList(); // collapse all the mask bits...
  361. for(NetConnection *walk = NetConnection::getConnectionList();
  362. walk; walk = walk->getNext())
  363. {
  364. if(walk->isConnectionToServer() && (walk->isLocalConnection() || walk->isNetworkConnection()))
  365. walk->checkPacketSend(false);
  366. }
  367. }
  368. void NetInterface::processServer()
  369. {
  370. NetObject::collapseDirtyList(); // collapse all the mask bits...
  371. for(NetConnection *walk = NetConnection::getConnectionList();
  372. walk; walk = walk->getNext())
  373. {
  374. if(!walk->isConnectionToServer() && (walk->isLocalConnection() || walk->isNetworkConnection()))
  375. walk->checkPacketSend(false);
  376. }
  377. }
  378. void NetInterface::startConnection(NetConnection *conn)
  379. {
  380. addPendingConnection(conn);
  381. conn->mConnectionSendCount = 0;
  382. conn->setConnectSequence(Platform::getVirtualMilliseconds());
  383. conn->setConnectionState(NetConnection::AwaitingChallengeResponse);
  384. // This is a the client side of the connection, so set the connection to
  385. // server flag. We need to set this early so that if the connection times
  386. // out, its onRemove() will handle the cleanup properly.
  387. conn->setIsConnectionToServer();
  388. // Everything set, so send off the request.
  389. sendConnectChallengeRequest(conn);
  390. }
  391. void NetInterface::sendDisconnectPacket(NetConnection *conn, const char *reason)
  392. {
  393. Con::printf("Issuing Disconnect packet.");
  394. // send a disconnect packet...
  395. U32 connectSequence = conn->getSequence();
  396. BitStream *out = BitStream::getPacketStream();
  397. out->write(U8(Disconnect));
  398. out->write(connectSequence);
  399. out->writeString(reason);
  400. BitStream::sendPacketStream(conn->getNetAddress());
  401. }
  402. void NetInterface::checkTimeouts()
  403. {
  404. U32 time = Platform::getVirtualMilliseconds();
  405. if(time > mLastTimeoutCheckTime + TimeoutCheckInterval)
  406. {
  407. for(U32 i = 0; i < mPendingConnections.size();)
  408. {
  409. NetConnection *pending = mPendingConnections[i];
  410. if(pending->getConnectionState() == NetConnection::AwaitingChallengeResponse &&
  411. time > pending->mConnectLastSendTime + ChallengeRetryTime)
  412. {
  413. if(pending->mConnectSendCount > ChallengeRetryCount)
  414. {
  415. pending->onConnectTimedOut();
  416. removePendingConnection(pending);
  417. pending->deleteObject();
  418. continue;
  419. }
  420. else
  421. sendConnectChallengeRequest(pending);
  422. }
  423. else if(pending->getConnectionState() == NetConnection::AwaitingConnectResponse &&
  424. time > pending->mConnectLastSendTime + ConnectRetryTime)
  425. {
  426. if(pending->mConnectSendCount > ConnectRetryCount)
  427. {
  428. pending->onConnectTimedOut();
  429. removePendingConnection(pending);
  430. pending->deleteObject();
  431. continue;
  432. }
  433. else
  434. sendConnectRequest(pending);
  435. }
  436. i++;
  437. }
  438. mLastTimeoutCheckTime = time;
  439. NetConnection *walk = NetConnection::getConnectionList();
  440. while(walk)
  441. {
  442. NetConnection *next = walk->getNext();
  443. if(walk->checkTimeout(time))
  444. {
  445. // this baddie timed out
  446. walk->onTimedOut();
  447. walk->deleteObject();
  448. }
  449. walk = next;
  450. }
  451. }
  452. }
  453. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  454. #define F2(x, y, z) F1(z, x, y)
  455. #define F3(x, y, z) (x ^ y ^ z)
  456. #define F4(x, y, z) (y ^ (x | ~z))
  457. inline U32 rotlFixed(U32 x, U32 y)
  458. {
  459. return (x >> y) | (x << (32 - y));
  460. }
  461. #define MD5STEP(f, w, x, y, z, data, s) w = rotlFixed(w + f(x, y, z) + data, s) + x
  462. void NetInterface::computeNetMD5(const NetAddress *address, U32 connectSequence, U32 digest[4])
  463. {
  464. digest[0] = 0x67452301L;
  465. digest[1] = 0xefcdab89L;
  466. digest[2] = 0x98badcfeL;
  467. digest[3] = 0x10325476L;
  468. U32 a, b, c, d;
  469. a=digest[0];
  470. b=digest[1];
  471. c=digest[2];
  472. d=digest[3];
  473. U32 in[16];
  474. in[0] = address->type;
  475. in[1] = address->getHash();
  476. in[2] = address->port;
  477. in[3] = connectSequence;
  478. for(U32 i = 0; i < 12; i++)
  479. in[i + 4] = mRandomHashData[i];
  480. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  481. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  482. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  483. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  484. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  485. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  486. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  487. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  488. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  489. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  490. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  491. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  492. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  493. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  494. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  495. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  496. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  497. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  498. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  499. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  500. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  501. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  502. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  503. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  504. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  505. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  506. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  507. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  508. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  509. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  510. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  511. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  512. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  513. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  514. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  515. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  516. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  517. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  518. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  519. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  520. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  521. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  522. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  523. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  524. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  525. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  526. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  527. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  528. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  529. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  530. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  531. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  532. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  533. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  534. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  535. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  536. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  537. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  538. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  539. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  540. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  541. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  542. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  543. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  544. digest[0]+=a;
  545. digest[1]+=b;
  546. digest[2]+=c;
  547. digest[3]+=d;
  548. }
  549. ConsoleFunctionGroupBegin(NetInterface, "Global control functions for the netInterfaces.");
  550. DefineConsoleFunction( allowConnections, void, ( bool allow ), , "allowConnections(bool allow)"
  551. "@brief Sets whether or not the global NetInterface allows connections from remote hosts.\n\n"
  552. "@param allow Set to true to allow remote connections.\n"
  553. "@ingroup Networking\n")
  554. {
  555. GNet->setAllowsConnections(allow);
  556. }
  557. ConsoleFunctionGroupEnd(NetInterface);