Guest User

Untitled

a guest
Jan 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. // [0] - protocol type
  2. // [1...4] - packet number
  3. // [5...512] - email(254 symbols in UTF-8)
  4. // [513...514] - email length
  5. // [515...578] - password(32 symbols in UTF-8)
  6. // [579] - password length
  7.  
  8. ...
  9.  
  10. const std::wstring email = L"player@gmail.com";
  11. const std::wstring password = L"difficult_password";
  12.  
  13. std::unique_ptr<Protocol::LoginPacket> packetToServer = std::make_unique<Protocol::LoginPacket>();
  14. packetToServer->setPacketNumber(mPacketNumber++);
  15. packetToServer->setEmailSize((std::int16_t) email.size());
  16. packetToServer->setPasswordSize((std::int8_t) password.size());
  17. packetToServer->setEmail(email.data());
  18. packetToServer->setPassword(password.data());
  19. mConnection.sendBuffer(packetToServer->toBuffer(), sizeof(Protocol::LoginPacket));
  20.  
  21. ...
  22.  
  23. ...
  24.  
  25. private final static byte POSITION_EMAIL = 5; // index
  26. private final static short SIZE_EMAIL = 254 * Primitives.CHAR_SIZE; // bytes
  27. private final static short POSITION_OF_SIZE_EMAIL = 513; // index
  28. private final static byte SIZE_OF_EMAIL_SIZE = Primitives.SHORT_SIZE; // bytes
  29.  
  30. ...
  31.  
  32. public String getEmail(){
  33. return new String(buffer, POSITION_EMAIL, ByteBuffer.wrap(buffer, POSITION_OF_SIZE_EMAIL, SIZE_OF_EMAIL_SIZE).getShort() * Primitives.CHAR_SIZE);
  34. }
  35.  
  36. ...
  37.  
  38. if ("player@gmail.com".equals(protocol.getPassword())) {
  39. ...
  40. }
Add Comment
Please, Sign In to add comment