Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //BBlock
- void CGameContext::ConRegister(IConsole::IResult *pResult, void *pUserData)
- {
- CGameContext *pSelf = (CGameContext *) pUserData;
- CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID];
- if(pPlayer->loggedIn){
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chat","[BBlock]: You are already logged in.");
- }else{
- if (pResult->NumArguments() == 0)
- {
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chat","[BBlock]: /register <username> <password>");
- }else{
- const char *pArg = pResult->GetString(0);
- //get username and password
- std::string username = "notset";
- std::string password = "notset";
- std::string token;
- std::string mystring = pArg;
- int count = 0;
- while(token != mystring){
- count++;
- token = mystring.substr(0,mystring.find_first_of(" "));
- mystring = mystring.substr(mystring.find_first_of(" ") + 1);
- if(count == 1){
- username = token;
- }
- if(count == 2){
- password = token;
- }
- }
- if (!username.compare("notset") | !password.compare("notset") )
- {
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chat","[BBlock]: /register <username> <password>");
- }else{
- //register logic here
- CURL *curl;
- std::string readBuffer;
- curl = curl_easy_init();
- if(curl) {
- std::string url = "http://92.42.46.160/tw/register.php?username=";
- url.append(username);
- url.append("&password=");
- url.append(password);
- curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
- curl_easy_perform(curl);
- curl_easy_cleanup(curl);
- if(readBuffer.find("-1") != std::string::npos){
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chat","[BBlock]: The chosen username is already registered.");
- }
- if(readBuffer.find("0") != std::string::npos){
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chat","[BBlock]: Successfully registered.");
- std::string info = "[BBlock]: You can now login with /login " + username + " " + password;
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chat",info.c_str());
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement