Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

"Fixed" player authentication

  • Loading branch information...
commit 5fa90c7b07fe065f845c32b3579a7ae2949a4e6e 1 parent 0b78073
Marko Viitanen fador authored

Showing 2 changed files with 73 additions and 0 deletions. Show diff stats Hide diff stats

  1. +3 0  files/config.cfg
  2. +70 0 src/packets.cpp
3  files/config.cfg
@@ -14,6 +14,9 @@ system.server_name = "Mineserver testserver";
14 14 # Validate usernames against minecraft.net?
15 15 system.user_validation = false;
16 16
  17 +# Allow connecting when auth is down
  18 +system.allow_connect_on_auth_timeout = false;
  19 +
17 20 # Disclose Software Version
18 21 system.show_version = true;
19 22
70 src/packets.cpp
@@ -345,6 +345,76 @@ int PacketHandler::login_request(User* user)
345 345 return PACKET_OK;
346 346 }
347 347
  348 +
  349 +
  350 + // Check if we're to do user validation
  351 + if(Mineserver::get()->config()->bData("system.user_validation") == true)
  352 + {
  353 + std::string url = "/game/checkserver.jsp?user=" + player + "&serverId=" + hash(player);
  354 + LOG(INFO, "Packets","Validating " + player + " against minecraft.net: ");
  355 +
  356 + std::string http_request ="GET " + url + " HTTP/1.1\r\n"
  357 + +"Host: www.minecraft.net\r\n"
  358 + +"Connection: close\r\n\r\n";
  359 +
  360 + int fd=socket_connect((char*)"50.16.200.224", 80);
  361 + if(fd)
  362 + {
  363 + #ifdef WIN32
  364 + send(fd, http_request.c_str(), http_request.length(),NULL);
  365 + #else
  366 + write(fd, http_request.c_str(), http_request.length());
  367 + #endif
  368 +
  369 + #define BUFFER_SIZE 1024
  370 + char *buffer = new char[BUFFER_SIZE];
  371 + std::string stringbuffer;
  372 +
  373 + #ifdef WIN32
  374 + while(int received=recv(fd, buffer, BUFFER_SIZE - 1, NULL) != 0)
  375 + {
  376 + #else
  377 + while(read(fd, buffer, BUFFER_SIZE - 1) != 0)
  378 + {
  379 + #endif
  380 + stringbuffer+=std::string(buffer);
  381 + }
  382 + delete [] buffer;
  383 + #ifdef WIN32
  384 + closesocket(fd);
  385 + #else
  386 + close(fd);
  387 + #endif
  388 +
  389 + bool allow_access = false;
  390 + //No response data, timeout
  391 + if(stringbuffer.size() == 0 && Mineserver::get()->config()->bData("system.allow_connect_on_auth_timeout"))
  392 + {
  393 + LOG(INFO, "Packets"," Auth skipped on timeout ");
  394 + allow_access = true;
  395 + }
  396 +
  397 + if(allow_access || (stringbuffer.size()>=3 && stringbuffer.find("\r\n\r\nYES",0) != std::string::npos))
  398 + {
  399 + LOG(INFO, "Packets"," Verified!");
  400 + user->sendLoginInfo();
  401 + }
  402 + else
  403 + {
  404 + LOG(INFO, "Packets"," Failed" + stringbuffer.substr(stringbuffer.size()-3));
  405 + user->kick("Failed to verify username!");
  406 + }
  407 + }
  408 + else
  409 + {
  410 + LOG(INFO, "Packets"," Failed");
  411 + user->kick("Failed to verify username!");
  412 + }
  413 +
  414 + return PACKET_OK;
  415 + }
  416 +
  417 +
348 418 char* kickMessage = NULL;
349 419 if ((static_cast<Hook2<bool, const char*, char**>*>(Mineserver::get()->plugin()->getHook("PlayerLoginPre")))->doUntilFalse(player.c_str(), &kickMessage))
350 420 {

0 comments on commit 5fa90c7

Please sign in to comment.
Something went wrong with that request. Please try again.