From 1e0283d38ca59b71df1565993f4c33c62cfc6d08 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 8 May 2016 13:22:32 +0200 Subject: [PATCH 1/7] Fixed: Use %p to display pointer --HG-- branch : develop --- code/nel/src/3d/driver/direct3d/driver_direct3d_vertex.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } } } From 1ff64c71d45d2333ad4cdffa4d0e9b29218132be Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 8 May 2016 13:28:25 +0200 Subject: [PATCH 2/7] Fixed: Some problems with AMS, patches by depyraken (thanks a lot!) --HG-- branch : develop --- code/web/private_php/ams/autoload/users.php | 49 +++++++++---------- .../Domain_Management/Domain_Management.php | 2 +- 2 files changed, 23 insertions(+), 28 deletions(-) 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) From 8fb8cfb218841cfc64bc0c695c3f536dbacf6445 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 8 May 2016 13:31:08 +0200 Subject: [PATCH 3/7] Changed: Specify host too for login HTTP requests --HG-- branch : develop --- code/ryzom/client/src/login.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/code/ryzom/client/src/login.cpp b/code/ryzom/client/src/login.cpp index 987e50dd2..081d31a9d 100644 --- a/code/ryzom/client/src/login.cpp +++ b/code/ryzom/client/src/login.cpp @@ -2719,8 +2719,10 @@ 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(); + // 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"); @@ -2760,7 +2762,8 @@ string checkLogin(const string &login, const string &password, const string &cli { // R2 login sequence 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)) + + if(!HttpClient.sendGet(url + "?cmd=login&login=" + login + "&password=" + cryptedPassword + "&clientApplication=" + clientApp + "&cp=1" + "&lg=" + ClientCfg.LanguageCode)) return "Can't send (error code 2)"; // the response should contains the result code and the cookie value @@ -2839,7 +2842,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)) @@ -2944,7 +2948,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; From 8099537d02f8ea649232b6e010c8cfc75bb7718f Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 8 May 2016 13:31:54 +0200 Subject: [PATCH 4/7] Changed: Minor changes --HG-- branch : develop --- code/ryzom/client/src/login.cpp | 3 ++- code/ryzom/common/src/game_share/http_client.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/code/ryzom/client/src/login.cpp b/code/ryzom/client/src/login.cpp index 081d31a9d..b8ac576d0 100644 --- a/code/ryzom/client/src/login.cpp +++ b/code/ryzom/client/src/login.cpp @@ -2938,7 +2938,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)"; diff --git a/code/ryzom/common/src/game_share/http_client.cpp b/code/ryzom/common/src/game_share/http_client.cpp index d9add4692..0c77fcb1a 100644 --- a/code/ryzom/common/src/game_share/http_client.cpp +++ b/code/ryzom/common/src/game_share/http_client.cpp @@ -152,7 +152,7 @@ bool CHttpClient::receive(string &res, bool verbose) nlassert(_Sock.connected()); uint32 size; - res = ""; + res.clear(); uint8 buf[1024]; From a0916ca14aea192194a8904d0f7f5c6722debe6c Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 8 May 2016 13:33:21 +0200 Subject: [PATCH 5/7] Changed: Useless to put a space after method name (if needed, we'll add ourself later) --HG-- branch : develop --- code/ryzom/client/src/http_client_curl.cpp | 10 +++++----- code/ryzom/common/src/game_share/http_client.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/ryzom/client/src/http_client_curl.cpp b/code/ryzom/client/src/http_client_curl.cpp index 92bf3e957..8ca82b9ad 100644 --- a/code/ryzom/client/src/http_client_curl.cpp +++ b/code/ryzom/client/src/http_client_curl.cpp @@ -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/common/src/game_share/http_client.cpp b/code/ryzom/common/src/game_share/http_client.cpp index 0c77fcb1a..c48087037 100644 --- a/code/ryzom/common/src/game_share/http_client.cpp +++ b/code/ryzom/common/src/game_share/http_client.cpp @@ -125,25 +125,25 @@ bool CHttpClient::sendRequest(const std::string& methodWB, const std::string &ur // *************************************************************************** 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); } // *************************************************************************** From c95bd7fabae0397a17134714ebbdf14246c7218e Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 8 May 2016 13:33:38 +0200 Subject: [PATCH 6/7] Changed: Check for NULL X509_INFO --HG-- branch : develop --- code/ryzom/client/src/http_client_curl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/client/src/http_client_curl.cpp b/code/ryzom/client/src/http_client_curl.cpp index 8ca82b9ad..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) From b932c31546c0845c009ba445e24fcac55e7913ab Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 8 May 2016 13:39:17 +0200 Subject: [PATCH 7/7] Fixed: Use correct formatted HTTP 1.1 query, previous one was blocked by some security software (a big thanks to Vojtech Vobr from AVG Technologies for his investigation to help us to fix this issue) --HG-- branch : develop --- .../common/src/game_share/http_client.cpp | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/code/ryzom/common/src/game_share/http_client.cpp b/code/ryzom/common/src/game_share/http_client.cpp index c48087037..78fd02797 100644 --- a/code/ryzom/common/src/game_share/http_client.cpp +++ b/code/ryzom/common/src/game_share/http_client.cpp @@ -98,27 +98,56 @@ 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); } } @@ -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; }