diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_vertex.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_vertex.cpp index ad5bb04b9..2b7fa8fa9 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d_vertex.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d_vertex.cpp @@ -125,7 +125,7 @@ uint8 *CVBDrvInfosD3D::lock (uint begin, uint end, bool readOnly) } else { - nlinfo("Buffer %s at %x is Locked", (*it)->VertexBufferPtr->getName().c_str(), (int) *it); + nlinfo("Buffer %s at %p is Locked", (*it)->VertexBufferPtr->getName().c_str(), *it); } } } diff --git a/code/ryzom/client/src/http_client_curl.cpp b/code/ryzom/client/src/http_client_curl.cpp index 92bf3e957..322223f94 100644 --- a/code/ryzom/client/src/http_client_curl.cpp +++ b/code/ryzom/client/src/http_client_curl.cpp @@ -111,7 +111,7 @@ static CURLcode sslctx_function(CURL * /* curl */, void *sslctx, void * /* parm { X509_INFO *itmp = sk_X509_INFO_value(info, i); - if (itmp->x509) + if (itmp && itmp->x509) { // add our certificate to this store if (X509_STORE_add_cert(store, itmp->x509) == 0) @@ -189,7 +189,7 @@ bool CCurlHttpClient::sendRequest(const std::string& methodWB, const std::string } // Set POST params - if ((methodWB == "POST ") && (!postParams.empty())) + if ((methodWB == "POST") && (!postParams.empty())) { curl_easy_setopt(_Curl, CURLOPT_POSTFIELDS, postParams.c_str()); } @@ -235,25 +235,25 @@ void CCurlHttpClient::pushReceivedData(uint8 *buffer, uint size) // *************************************************************************** bool CCurlHttpClient::sendGet(const string &url, const string& params, bool verbose) { - return sendRequest("GET ", url + (params.empty() ? "" : ("?" + params)), string(), string(), string(), verbose); + return sendRequest("GET", url + (params.empty() ? "" : ("?" + params)), string(), string(), string(), verbose); } // *************************************************************************** bool CCurlHttpClient::sendGetWithCookie(const string &url, const string &name, const string &value, const string& params, bool verbose) { - return sendRequest("GET ", url + (params.empty() ? "" : ("?" + params)), name, value, string(), verbose); + return sendRequest("GET", url + (params.empty() ? "" : ("?" + params)), name, value, string(), verbose); } // *************************************************************************** bool CCurlHttpClient::sendPost(const string &url, const string& params, bool verbose) { - return sendRequest("POST ", url, string(), string(), params, verbose); + return sendRequest("POST", url, string(), string(), params, verbose); } // *************************************************************************** bool CCurlHttpClient::sendPostWithCookie(const string &url, const string &name, const string &value, const string& params, bool verbose) { - return sendRequest("POST ", url, name, value, params, verbose); + return sendRequest("POST", url, name, value, params, verbose); } // *************************************************************************** diff --git a/code/ryzom/client/src/login.cpp b/code/ryzom/client/src/login.cpp index 4667912f4..52e09afc3 100644 --- a/code/ryzom/client/src/login.cpp +++ b/code/ryzom/client/src/login.cpp @@ -2792,11 +2792,13 @@ string checkLogin(const string &login, const string &password, const string &cli string res; + std::string url = ClientCfg.ConfigFile.getVar("StartupHost").asString() + ClientCfg.ConfigFile.getVar("StartupPage").asString(); + // don't use login with alt method if (!login.empty()) { // ask server for salt - if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=ask&login="+login+"&lg="+ClientCfg.LanguageCode, "", pPM->isVerboseLog())) + if(!HttpClient.sendGet(url + "?cmd=ask&login=" + login + "&lg=" + ClientCfg.LanguageCode, "", pPM->isVerboseLog())) return "Can't send (error code 60)"; if(pPM->isVerboseLog()) nlinfo("Sent request for password salt"); @@ -2840,13 +2842,14 @@ string checkLogin(const string &login, const string &password, const string &cli if (!login.empty()) { std::string cryptedPassword = CCrypt::crypt(password, Salt); - if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=login&login="+login+"&password="+cryptedPassword+"&clientApplication="+clientApp+"&cp=1"+"&lg="+ClientCfg.LanguageCode+customParameters)) + + if(!HttpClient.sendGet(url + "?cmd=login&login=" + login + "&password=" + cryptedPassword + "&clientApplication=" + clientApp + "&cp=1" + "&lg=" + ClientCfg.LanguageCode + customParameters)) return "Can't send (error code 2)"; } else { // don't send login and password if empty - if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=login&clientApplication="+clientApp+"&cp=1"+"&lg="+ClientCfg.LanguageCode+customParameters)) + if(!HttpClient.sendGet(url + "?cmd=login&clientApplication=" + clientApp + "&cp=1" + "&lg=" + ClientCfg.LanguageCode + customParameters)) return "Can't send (error code 2)"; } @@ -2926,7 +2929,8 @@ string checkLogin(const string &login, const string &password, const string &cli { // standard ryzom login sequence std::string cryptedPassword = CCrypt::crypt(password, Salt); - if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?login="+login+"&password="+cryptedPassword+"&clientApplication="+clientApp+"&cp=1")) + + if(!HttpClient.sendGet(url + "?login=" + login + "&password=" + cryptedPassword + "&clientApplication=" + clientApp + "&cp=1")) return "Can't send (error code 2)"; /* if(!send(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?login="+login+"&password="+password+"&clientApplication="+clientApp)) @@ -3021,7 +3025,8 @@ string checkLogin(const string &login, const string &password, const string &cli // *************************************************************************** string selectShard(uint32 shardId, string &cookie, string &addr) { - cookie = addr = ""; + cookie.clear(); + addr.clear(); if(!HttpClient.connectToLogin()) return "Can't connect (error code 7)"; @@ -3031,7 +3036,10 @@ string selectShard(uint32 shardId, string &cookie, string &addr) // send login + crypted password + client app and cp=1 (as crypted password) std::string cryptedPassword = CCrypt::crypt(LoginPassword, Salt); - if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=login&shardid="+toString(shardId)+"&login="+LoginLogin+"&password="+cryptedPassword+"&clientApplication="+ClientApp+"&cp=1")) + + std::string url = ClientCfg.ConfigFile.getVar("StartupHost").asString() + ClientCfg.ConfigFile.getVar("StartupPage").asString(); + + if(!HttpClient.sendGet(url + "?cmd=login&shardid=" + toString(shardId) + "&login=" + LoginLogin + "&password=" + cryptedPassword + "&clientApplication=" + ClientApp + "&cp=1")) return "Can't send (error code 11)"; string res; diff --git a/code/ryzom/common/src/game_share/http_client.cpp b/code/ryzom/common/src/game_share/http_client.cpp index d9add4692..78fd02797 100644 --- a/code/ryzom/common/src/game_share/http_client.cpp +++ b/code/ryzom/common/src/game_share/http_client.cpp @@ -98,52 +98,81 @@ bool CHttpClient::send(const std::string& buffer, bool verbose) // *************************************************************************** bool CHttpClient::sendRequest(const std::string& methodWB, const std::string &url, const std::string &cookieName, const std::string &cookieValue, const std::string& postParams, bool verbose) { - // Remove the host from the URL - string path; + std::string path, host; + + // Remove the protocol from the URL if (url.substr(0, 7) == "http://") path = url.substr(7); else path = url; - path = path.substr(path.find( "/" )); + + std::string::size_type pos = path.find("/"); + + // Remove the host from the URL + if (pos != std::string::npos) + { + host = path.substr(0, pos); + path = path.substr(pos); + } + else + { + host = path; + path.clear(); + } + + // build HTTP request + std::string request; + request += methodWB + " " + path + " HTTP/1.1\r\n"; + request += "Host: " + host + "\r\n"; // Send if (cookieName.empty() && postParams.empty()) { - return send(methodWB + path + "\r\n", verbose); + request += "\r\n"; + + return send(request, verbose); } else { - string cookieStr, postStr; if (!cookieName.empty()) - cookieStr = "Cookie: " + cookieName + "=" + cookieValue + "\r\n"; + request += "Cookie: " + cookieName + "=" + cookieValue + "\r\n"; + if (!postParams.empty()) - postStr = "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: " + toString(postParams.size()) + "\r\n\r\n" + postParams; - return send(methodWB + path + " HTTP/1.0\r\n" + cookieStr + postStr + "\r\n", verbose); + { + request += "Content-Type: application/x-www-form-urlencoded\r\n"; + request += "Content-Length: " + toString(postParams.size()) + "\r\n"; + request += "\r\n"; + request += postParams; + } + + request += "\r\n"; + + return send(request, verbose); } } // *************************************************************************** bool CHttpClient::sendGet(const string &url, const string& params, bool verbose) { - return sendRequest("GET ", url + (params.empty() ? "" : ("?" + params)), string(), string(), string(), verbose); + return sendRequest("GET", url + (params.empty() ? "" : ("?" + params)), string(), string(), string(), verbose); } // *************************************************************************** bool CHttpClient::sendGetWithCookie(const string &url, const string &name, const string &value, const string& params, bool verbose) { - return sendRequest("GET ", url + (params.empty() ? "" : ("?" + params)), name, value, string(), verbose); + return sendRequest("GET", url + (params.empty() ? "" : ("?" + params)), name, value, string(), verbose); } // *************************************************************************** bool CHttpClient::sendPost(const string &url, const string& params, bool verbose) { - return sendRequest("POST ", url, string(), string(), params, verbose); + return sendRequest("POST", url, string(), string(), params, verbose); } // *************************************************************************** bool CHttpClient::sendPostWithCookie(const string &url, const string &name, const string &value, const string& params, bool verbose) { - return sendRequest("POST ", url, name, value, params, verbose); + return sendRequest("POST", url, name, value, params, verbose); } // *************************************************************************** @@ -152,7 +181,7 @@ bool CHttpClient::receive(string &res, bool verbose) nlassert(_Sock.connected()); uint32 size; - res = ""; + res.clear(); uint8 buf[1024]; @@ -179,6 +208,15 @@ bool CHttpClient::receive(string &res, bool verbose) } } //nlinfo("all received '%s'", res.c_str()); + + // only keep content (delimited by two \r\n) and discard server headers + std::string::size_type pos = res.find("\r\n\r\n"); + + if (pos != std::string::npos) + { + res = res.substr(pos + 4); + } + return true; } diff --git a/code/web/private_php/ams/autoload/users.php b/code/web/private_php/ams/autoload/users.php index 5b3bfaa2d..81bc0599f 100644 --- a/code/web/private_php/ams/autoload/users.php +++ b/code/web/private_php/ams/autoload/users.php @@ -336,36 +336,31 @@ class Users{ public static function createPermissions($pvalues) { try { - $values = array('username' => $pvalues[0]); + // bind to the shard database (guess so :p) $dbs = new DBLayer("shard"); - $sth = $dbs->selectWithParameter("UId", "user", $values, "Login= :username"); - $result = $sth->fetchAll(); - $dbl = new DBLayer("lib"); - - $UId = $result['0']['UId']; - - $statement = $dbl->execute("SELECT * FROM `settings` WHERE `Setting` = :setting", Array('setting' => 'Domain_Auto_Add')); - $json = $statement->fetch(); - $json = json_decode($json['Value'],true); - - $db = new DBLayer( 'shard' ); - // get all domains - $statement = $db -> executeWithoutParams( "SELECT * FROM domain" ); - $rows = $statement -> fetchAll(); + // retrieve the user UId + $values = array('username' => $pvalues[0]); + $statement = $dbs->selectWithParameter("UId", "user", $values, "Login= :username"); + $result = $statement->fetchAll(); + $UId = $result['0']['UId']; + + // retrieve the default access privileges (don't understand what exactly is done) + $dbl = new DBLayer("lib"); + $statement = $dbl->execute("SELECT Value FROM `settings` WHERE `Setting` = :setting", Array('setting' => 'Domain_Auto_Add')); + //$statement = $dbl->execute("SELECT * FROM `settings` WHERE `Setting` = :setting", Array('setting' => 'Domain_Auto_Add')); + $json = $statement->fetch(); + $accessPriv = $json['Value']; + //$accessPriv = json_decode($json['Value'],true); + + // get all shardIds and domain_ids + $statement = $dbs -> executeWithoutParams( "SELECT ShardId, domain_id FROM shard" ); + $shardIds = $statement -> fetchAll(); - //error_log(print_r($rows,true)); - //error_log(print_r($result,true)); - //error_log(print_r($json,true)); - if ($json) foreach ($json as $key => $value) { - //error_log(print_r($key,true)); - //error_log(print_r($value,true)); - - $ins_values = array('UId' => $UId, 'DomainId' => $key, 'AccessPrivilege' => $value['1']); - error_log(print_r($ins_values,true)); - $dbs = new DBLayer("shard"); - $dbs->insert("permission", $ins_values); - } + foreach($shardIds as $shardId) { // add default access privileges to the user for each shard + $ins_values = array('UId' => $UId, 'DomainId' => $shardId['domain_id'], 'ShardId' => $shardId['ShardId'], 'AccessPrivilege' => $accessPriv); + $dbs->insert("permission", $ins_values); + } } catch (PDOException $e) { //oh noooz, the shard is offline! Put it in query queue at ams_lib db! diff --git a/code/web/private_php/ams/plugins/Domain_Management/Domain_Management.php b/code/web/private_php/ams/plugins/Domain_Management/Domain_Management.php index a99ac5551..5362eef6b 100644 --- a/code/web/private_php/ams/plugins/Domain_Management/Domain_Management.php +++ b/code/web/private_php/ams/plugins/Domain_Management/Domain_Management.php @@ -156,7 +156,7 @@ function domain_management_hook_return_global() } -function api_key_management_hook_activate() +function domain_management_hook_activate() { $dbl = new DBLayer( "lib" ); $sql = "INSERT INTO `settings` (Setting)