Advertisement
Guest User

Untitled

a guest
May 28th, 2012
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. RakNet::TCPInterface   *tcp;
  4. RakNet::HTTPConnection *httpConnection;
  5.  
  6. std::string tHTTPSaddress = "login.server.net";
  7. std::string tPath = "/";
  8. std::string tData = "?user=myusername&password=mypassword&version=3";
  9. std::string tContentType = "application/x-www-form-urlencoded";
  10.  
  11. bool Init()
  12. {
  13.     tcp = RakNet::OP_NEW<RakNet::TCPInterface>(__FILE__, __LINE__);
  14.     tcp->Start(0, 64);
  15.  
  16.     httpConnection = RakNet::OP_NEW<RakNet::HTTPConnection>(__FILE__, __LINE__);
  17.  
  18.     httpConnection->Init(tcp, tHTTPSaddress.c_str());
  19.  
  20.     return true;
  21. }
  22.  
  23. bool Update()
  24. {
  25.     httpConnection->Update();
  26.  
  27.     if (RakNet::Packet *packet = tcp->Receive()) {
  28.         httpConnection->ProcessTCPPacket(packet);
  29.         tcp->DeallocatePacket(packet);
  30.     }
  31.    
  32.     RakSleep(500);
  33.  
  34.     if (httpConnection->IsBusy()) return true;
  35.  
  36.     httpConnection->Post(tPath.c_str(),tData.c_str(), tContentType.c_str());
  37.  
  38.     RakNet::RakString data = httpConnection->Read();
  39.     httpConnection->HasBadResponse(NULL, &data);
  40.  
  41.     std::cout << data.C_String() << std::endl;
  42.  
  43.     if (data.IsEmpty()) return true;
  44.  
  45.     return false;
  46. }
  47.  
  48. void Draw()
  49. {
  50.     std::string state;
  51.  
  52.     switch (httpConnection->GetState()) {
  53.         case 0: state = "Waiting";       break;
  54.         case 1: state = "Disconnecting"; break;
  55.         case 2: state = "Connecting";    break;
  56.         case 3: state = "Connected";     break;
  57.         case 4: state = "Processing";    break;
  58.     }
  59.  
  60.     std::cout << (std::string)state<< std::endl;;
  61. }
  62.  
  63. void Shut() {}
  64.  
  65. int main (int argc, char ** argv)
  66. {
  67.     Init();
  68.     while (Update())
  69.     {
  70.         Draw();
  71.     }
  72.     Shut();
  73.  
  74.     system("pause");
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement