int UserAuth::sendUserEvent(std::string user_token, std::string type, std::string arg1, std::string arg2) { STACKLOG; // Only contact the master server if we are allowed to do so if(trustlevel<=1) return 0; char url[1024]; sprintf(url, "%s/userevent/?v=0&sh=%s&h=%s&t=%s&a1=%s&a2=%s", REPO_URLPREFIX, challenge.c_str(), user_token.c_str(), type.c_str(), arg1.c_str(), arg2.c_str()); HttpMsg resp; if (HTTPGET(url, resp) < 0) return -1; std::string body = resp.getBody(); Logger::log(LOG_DEBUG,"UserEvent reply: " + body); return (body!="ok"); }
int UserAuth::resolve(std::string user_token, UTFString &user_nick, int clientid) { STACKLOG; // There's alot of other info in the user token variable, but we don't need it here. // We only need the first 40 characters = the actual (encoded) token. user_token = user_token.substr(0,40); //check cache first if(cache.find(user_token) != cache.end()) { // cache hit! user_nick = cache[user_token].second; return cache[user_token].first; } // initialize the authlevel on none = normal user int authlevel = AUTH_NONE; // Only contact the master-server if we're allowed to do so if(trustlevel>1) { std::string msg = ""; UTFString resultNick = L""; // not found in cache or local_auth, get auth from masterserver char url[2048]; sprintf(url, "%s/authuser_utf8/?c=%s&t=%s&u=%s", REPO_URLPREFIX, challenge.c_str(), user_token.c_str(), user_nick.asUTF8_c_str()); Logger::log(LOG_DEBUG, "UserAuth query to server: " + std::string(url)); HttpMsg resp; if (HTTPGET(url, resp) < 0) { Logger::log(LOG_ERROR, "UserAuth resolve query result empty"); return AUTH_NONE; } std::string body = resp.getBody(); Logger::log(LOG_DEBUG,"UserAuth reply: " + body); std::vector<std::string> args; strict_tokenize(body, args, "\t"); if(args.size() < 2) { Logger::log(LOG_INFO,"UserAuth: invalid return value from server: " + body); return AUTH_NONE; } authlevel = atoi(args[0].c_str()); resultNick = tryConvertUTF(args[1].c_str()); if(args.size() > 2) msg = args[2]; // debug output the auth status UTFString authst; if(authlevel & AUTH_NONE) authst = authst + "N"; if(authlevel & AUTH_ADMIN) authst = authst + "A"; if(authlevel & AUTH_MOD) authst = authst + "M"; if(authlevel & AUTH_RANKED) authst = authst + "R"; if(authlevel & AUTH_BOT) authst = authst + "B"; if(authst.empty()) authst = "(none)"; Logger::log(LOG_DEBUG, UTFString("User Auth Result: ") + authst + " / " + (resultNick) + " / " + tryConvertUTF(msg.c_str())); if(resultNick == L"error" || resultNick == L"reserved" || resultNick == L"notranked") { resultNick = widen(getNewPlayernameByID(clientid)); Logger::log(LOG_DEBUG, UTFString("got new random name for player: ") + resultNick); authlevel = AUTH_NONE; } // returned name valid, use it user_nick = resultNick; } //then check for overrides in the authorizations file (server admins, etc) if(local_auth.find(user_token) != local_auth.end()) { // local auth hit! // the stored nickname can be empty if no nickname is specified. if(!local_auth[user_token].second.empty()) user_nick = local_auth[user_token].second; authlevel |= local_auth[user_token].first; } // cache result if ranked or higher if(authlevel > AUTH_NONE) { user_auth_pair_t p; p.first = authlevel; p.second = user_nick; Logger::log(LOG_DEBUG, "adding entry to remote auth cache, size: %d", cache.size()); cache[user_token] = p; } return authlevel; }
int UserAuth::resolve(std::string user_token, std::string &user_nick) { STACKLOG; // There's alot of other info in the user token variable, but we don't need it here. // We only need the first 40 characters = the actual (encoded) token. user_token = user_token.substr(0,40); //check cache first if(cache.find(user_token) != cache.end()) { // cache hit! user_nick = cache[user_token].second; return cache[user_token].first; } // initialize the authlevel on none = normal user int authlevel = AUTH_NONE; // Only contact the master-server if we're allowed to do so if(trustlevel>1) { // not found in cache or local_auth, get auth from masterserver char url[1024]; sprintf(url, "%s/authuser/?c=%s&t=%s", REPO_URLPREFIX, challenge.c_str(), user_token.c_str()); HttpMsg resp; if (HTTPGET(url, resp) < 0) return -1; std::string body = resp.getBody(); Logger::log(LOG_DEBUG,"UserAuth reply: " + body); std::vector<std::string> args; strict_tokenize(body, args, "\t"); if(args.size() != 2) { Logger::log(LOG_INFO,"UserAuth: invalid return value from server: " + body); return AUTH_NONE; } authlevel = atoi(args[0].c_str()); user_nick = args[1]; } //then check for overrides in the authorizations file (server admins, etc) if(local_auth.find(user_token) != local_auth.end()) { // local auth hit! // the stored nickname can be empty if no nickname is specified. if(!local_auth[user_token].second.empty()) user_nick = local_auth[user_token].second; authlevel |= local_auth[user_token].first; } // debug output the auth status char authst[10] = ""; if(authlevel & AUTH_ADMIN) strcat(authst, "A"); if(authlevel & AUTH_MOD) strcat(authst, "M"); if(authlevel & AUTH_RANKED) strcat(authst, "R"); if(authlevel & AUTH_BOT) strcat(authst, "B"); if(authlevel != AUTH_NONE) Logger::log(LOG_INFO,"User Auth Flags: " + std::string(authst)); // cache result std::pair< int, std::string > p; p.first = authlevel; p.second = user_nick; Logger::log(LOG_DEBUG, "adding entry to remote auth cache, size: %d", cache.size()); cache[user_token] = p; return authlevel; }