Merge with develop

This commit is contained in:
kervala 2016-05-08 13:42:53 +02:00
parent 43db9313f8
commit bf79b16b5b
6 changed files with 95 additions and 54 deletions

View file

@ -125,7 +125,7 @@ uint8 *CVBDrvInfosD3D::lock (uint begin, uint end, bool readOnly)
} }
else 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);
} }
} }
} }

View file

@ -111,7 +111,7 @@ static CURLcode sslctx_function(CURL * /* curl */, void *sslctx, void * /* parm
{ {
X509_INFO *itmp = sk_X509_INFO_value(info, i); X509_INFO *itmp = sk_X509_INFO_value(info, i);
if (itmp->x509) if (itmp && itmp->x509)
{ {
// add our certificate to this store // add our certificate to this store
if (X509_STORE_add_cert(store, itmp->x509) == 0) 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 // Set POST params
if ((methodWB == "POST ") && (!postParams.empty())) if ((methodWB == "POST") && (!postParams.empty()))
{ {
curl_easy_setopt(_Curl, CURLOPT_POSTFIELDS, postParams.c_str()); 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) 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) 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) 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) 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);
} }
// *************************************************************************** // ***************************************************************************

View file

@ -2792,11 +2792,13 @@ string checkLogin(const string &login, const string &password, const string &cli
string res; string res;
std::string url = ClientCfg.ConfigFile.getVar("StartupHost").asString() + ClientCfg.ConfigFile.getVar("StartupPage").asString();
// don't use login with alt method // don't use login with alt method
if (!login.empty()) if (!login.empty())
{ {
// ask server for salt // 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)"; return "Can't send (error code 60)";
if(pPM->isVerboseLog()) nlinfo("Sent request for password salt"); 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()) if (!login.empty())
{ {
std::string cryptedPassword = CCrypt::crypt(password, Salt); 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)"; return "Can't send (error code 2)";
} }
else else
{ {
// don't send login and password if empty // 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)"; 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 // standard ryzom login sequence
std::string cryptedPassword = CCrypt::crypt(password, Salt); 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)"; return "Can't send (error code 2)";
/* /*
if(!send(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?login="+login+"&password="+password+"&clientApplication="+clientApp)) 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) string selectShard(uint32 shardId, string &cookie, string &addr)
{ {
cookie = addr = ""; cookie.clear();
addr.clear();
if(!HttpClient.connectToLogin()) return "Can't connect (error code 7)"; 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) // send login + crypted password + client app and cp=1 (as crypted password)
std::string cryptedPassword = CCrypt::crypt(LoginPassword, Salt); 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)"; return "Can't send (error code 11)";
string res; string res;

View file

@ -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) 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 std::string path, host;
string path;
// Remove the protocol from the URL
if (url.substr(0, 7) == "http://") if (url.substr(0, 7) == "http://")
path = url.substr(7); path = url.substr(7);
else else
path = url; 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 // Send
if (cookieName.empty() && postParams.empty()) if (cookieName.empty() && postParams.empty())
{ {
return send(methodWB + path + "\r\n", verbose); request += "\r\n";
return send(request, verbose);
} }
else else
{ {
string cookieStr, postStr;
if (!cookieName.empty()) if (!cookieName.empty())
cookieStr = "Cookie: " + cookieName + "=" + cookieValue + "\r\n"; request += "Cookie: " + cookieName + "=" + cookieValue + "\r\n";
if (!postParams.empty()) 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) 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) 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) 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) 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()); nlassert(_Sock.connected());
uint32 size; uint32 size;
res = ""; res.clear();
uint8 buf[1024]; uint8 buf[1024];
@ -179,6 +208,15 @@ bool CHttpClient::receive(string &res, bool verbose)
} }
} }
//nlinfo("all received '%s'", res.c_str()); //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; return true;
} }

View file

@ -336,36 +336,31 @@ class Users{
public static function createPermissions($pvalues) { public static function createPermissions($pvalues) {
try { try {
$values = array('username' => $pvalues[0]); // bind to the shard database (guess so :p)
$dbs = new DBLayer("shard"); $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 // retrieve the user UId
$statement = $db -> executeWithoutParams( "SELECT * FROM domain" ); $values = array('username' => $pvalues[0]);
$rows = $statement -> fetchAll(); $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)); foreach($shardIds as $shardId) { // add default access privileges to the user for each shard
//error_log(print_r($result,true)); $ins_values = array('UId' => $UId, 'DomainId' => $shardId['domain_id'], 'ShardId' => $shardId['ShardId'], 'AccessPrivilege' => $accessPriv);
//error_log(print_r($json,true)); $dbs->insert("permission", $ins_values);
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);
}
} }
catch (PDOException $e) { catch (PDOException $e) {
//oh noooz, the shard is offline! Put it in query queue at ams_lib db! //oh noooz, the shard is offline! Put it in query queue at ams_lib db!

View file

@ -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" ); $dbl = new DBLayer( "lib" );
$sql = "INSERT INTO `settings` (Setting) $sql = "INSERT INTO `settings` (Setting)