Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. void ProtocolGame::onRecvFirstMessage(NetworkMessage& msg)
  2. {
  3.     if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
  4.         disconnect();
  5.         return;
  6.     }
  7.  
  8.     OperatingSystem_t operatingSystem = static_cast<OperatingSystem_t>(msg.get<uint16_t>());
  9.     version = msg.get<uint16_t>();
  10.  
  11.     msg.skipBytes(7); // U32 client version, U8 client type, U16 dat revision
  12.  
  13.     if (!Protocol::RSA_decrypt(msg)) {
  14.         disconnect();
  15.         return;
  16.     }
  17.  
  18.     uint32_t key[4];
  19.     key[0] = msg.get<uint32_t>();
  20.     key[1] = msg.get<uint32_t>();
  21.     key[2] = msg.get<uint32_t>();
  22.     key[3] = msg.get<uint32_t>();
  23.     enableXTEAEncryption();
  24.     setXTEAKey(key);
  25.  
  26.     if (operatingSystem >= CLIENTOS_OTCLIENT_LINUX) {
  27.         NetworkMessage opcodeMessage;
  28.         opcodeMessage.addByte(0x32);
  29.         opcodeMessage.addByte(0x00);
  30.         opcodeMessage.add<uint16_t>(0x00);
  31.         writeToOutputBuffer(opcodeMessage);
  32.     }
  33.  
  34.     msg.skipBytes(1); // gamemaster flag
  35.  
  36.     std::string sessionKey = msg.getString();
  37.  
  38.     auto sessionArgs = explodeString(sessionKey, "\n", 4);
  39.     if (sessionArgs.size() != 4) {
  40.         disconnect();
  41.         return;
  42.     }
  43.  
  44.     std::string& accountName = sessionArgs[0];
  45.     std::string& password = sessionArgs[1];
  46.     std::string& token = sessionArgs[2];
  47.     uint32_t tokenTime = strtoul(sessionArgs[3].c_str(), NULL, 10);
  48.  
  49.     if (accountName.empty()) {
  50.         disconnectClient("You must enter your account name.");
  51.         return;
  52.     }
  53.  
  54.     std::string characterName = msg.getString();
  55.  
  56.     uint32_t timeStamp = msg.get<uint32_t>();
  57.     uint8_t randNumber = msg.getByte();
  58.     if (challengeTimestamp != timeStamp || challengeRandom != randNumber) {
  59.         disconnect();
  60.         return;
  61.     }
  62.  
  63.     if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
  64.         std::ostringstream ss;
  65.         ss << "Only clients with protocol " << CLIENT_VERSION_STR << " allowed!";
  66.         disconnectClient(ss.str());
  67.         return;
  68.     }
  69.  
  70.     if (g_game.getGameState() == GAME_STATE_STARTUP) {
  71.         disconnectClient("Gameworld is starting up. Please wait.");
  72.         return;
  73.     }
  74.  
  75.     if (g_game.getGameState() == GAME_STATE_MAINTAIN) {
  76.         disconnectClient("Gameworld is under maintenance. Please re-connect in a while.");
  77.         return;
  78.     }
  79.  
  80.     BanInfo banInfo;
  81.     if (IOBan::isIpBanned(getIP(), banInfo)) {
  82.         if (banInfo.reason.empty()) {
  83.             banInfo.reason = "(none)";
  84.         }
  85.  
  86.         std::ostringstream ss;
  87.         ss << "Your IP has been banned until " << formatDateShort(banInfo.expiresAt) << " by " << banInfo.bannedBy << ".\n\nReason specified:\n" << banInfo.reason;
  88.         disconnectClient(ss.str());
  89.         return;
  90.     }
  91.  
  92.     uint32_t accountId = IOLoginData::gameworldAuthentication(accountName, password, characterName, token, tokenTime);
  93.     if (accountId == 0) {
  94.         disconnectClient("Account name or password is not correct.");
  95.         return;
  96.     }
  97.  
  98.     g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::login, getThis(), characterName, accountId, operatingSystem)));
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement