netInterface.cpp 22 KB

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