Change ClientApplication to DomainId in permission table

This commit is contained in:
kaetemi 2014-09-07 08:53:10 +02:00
parent f704285e3b
commit ac1f3a7b85
14 changed files with 286 additions and 343 deletions

View file

@ -28,9 +28,7 @@
#ifndef <xsl:value-of select="@header_tag"/>
#define <xsl:value-of select="@header_tag"/>
#include "nel/misc/types_nl.h"
#ifdef NL_COMP_VC8
#include &lt;memory&gt;
#endif
#include "nel/misc/hierarchical_timer.h"
#include "nel/misc/string_conversion.h"
#include "nel/net/message.h"
@ -45,7 +43,7 @@
</xsl:if>
<xsl:if test="//class/database">
#include "nel/misc/string_common.h"
#include "game_share/mysql_wrapper.h"
#include "server_share/mysql_wrapper.h"
</xsl:if>
<xsl:if test="//class/message">
#include "game_share/synchronised_message.h"

View file

@ -1,18 +1,3 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////
// WARNING : this is a generated file, don't change it !
@ -318,7 +303,7 @@ namespace RSMGR
}
else if (cmd == NOPE::cc_instance_count)
{
return (uint32)_ObjectCache.size();
return _ObjectCache.size();
}
// default return value
@ -336,7 +321,7 @@ namespace RSMGR
TReleasedObject::iterator first(_ReleasedObject.begin()), last(_ReleasedObject.end());
for (; first != last; ++first)
{
nbReleased += (uint32)first->second.size();
nbReleased += first->second.size();
}
nlinfo(" There are %u object instances in cache not referenced (waiting deletion or re-use))", nbReleased);
@ -586,16 +571,16 @@ namespace RSMGR
nlstop;
}
// remove object from cache map
if (_Prim != NOPE::INVALID_OBJECT_ID
if (_PermissionId != NOPE::INVALID_OBJECT_ID
&& _ObjectState != NOPE::os_removed
&& _ObjectState != NOPE::os_transient)
{
nldebug("NOPE: clearing CNelPermission @%p from cache with id %u", this, static_cast<uint32>(_Prim));
nlverify(_ObjectCache.erase(_Prim) == 1);
nldebug("NOPE: clearing CNelPermission @%p from cache with id %u", this, static_cast<uint32>(_PermissionId));
nlverify(_ObjectCache.erase(_PermissionId) == 1);
}
else if (_ObjectState != NOPE::os_transient)
{
nlassert(_ObjectCache.find(_Prim) == _ObjectCache.end());
nlassert(_ObjectCache.find(_PermissionId) == _ObjectCache.end());
}
if (_ObjectState == NOPE::os_released)
{
@ -626,18 +611,18 @@ namespace RSMGR
{
nlassert(getPersistentState() == NOPE::os_transient);
nlassert(_Prim != 0);
nlassert(_PermissionId != 0);
std::string qs;
qs = "INSERT INTO permission (";
qs += "prim, UId, ClientApplication, ShardId, AccessPrivilege";
qs += "PermissionId, UId, DomainId, ShardId, AccessPrivilege";
qs += ") VALUES (";
qs += "'"+MSW::escapeString(NLMISC::toString(_Prim), connection)+"'";
qs += "'"+MSW::escapeString(NLMISC::toString(_PermissionId), connection)+"'";
qs += ", ";
qs += "'"+MSW::escapeString(NLMISC::toString(_UserId), connection)+"'";
qs += ", ";
qs += "'"+MSW::escapeString(NLMISC::toString(_DomainName), connection)+"'";
qs += "'"+MSW::escapeString(NLMISC::toString(_DomainId), connection)+"'";
qs += ", ";
qs += "'"+MSW::escapeString(NLMISC::toString(_ShardId), connection)+"'";
qs += ", ";
@ -670,17 +655,17 @@ namespace RSMGR
std::string qs;
qs = "UPDATE permission SET ";
qs += "prim = '"+MSW::escapeString(NLMISC::toString(_Prim), connection)+"'";
qs += "PermissionId = '"+MSW::escapeString(NLMISC::toString(_PermissionId), connection)+"'";
qs += ", ";
qs += "UId = '"+MSW::escapeString(NLMISC::toString(_UserId), connection)+"'";
qs += ", ";
qs += "ClientApplication = '"+MSW::escapeString(NLMISC::toString(_DomainName), connection)+"'";
qs += "DomainId = '"+MSW::escapeString(NLMISC::toString(_DomainId), connection)+"'";
qs += ", ";
qs += "ShardId = '"+MSW::escapeString(NLMISC::toString(_ShardId), connection)+"'";
qs += ", ";
qs += "AccessPrivilege = '"+MSW::escapeString(NLMISC::toString(_AccessPriv), connection)+"'";
qs += " WHERE prim = '"+NLMISC::toString(_Prim)+"'";
qs += " WHERE PermissionId = '"+NLMISC::toString(_PermissionId)+"'";
if (connection.query(qs))
@ -702,7 +687,7 @@ namespace RSMGR
std::string qs;
qs = "DELETE FROM permission ";
qs += " WHERE prim = '"+NLMISC::toString(_Prim)+"'";
qs += " WHERE PermissionId = '"+NLMISC::toString(_PermissionId)+"'";
if (connection.query(qs))
@ -736,7 +721,7 @@ namespace RSMGR
std::string qs;
qs = "DELETE FROM permission ";
qs += " WHERE prim = '"+NLMISC::toString(id)+"'";
qs += " WHERE PermissionId = '"+NLMISC::toString(id)+"'";
if (connection.query(qs))
@ -796,7 +781,7 @@ namespace RSMGR
}
else if (cmd == NOPE::cc_instance_count)
{
return (uint32)_ObjectCache.size();
return _ObjectCache.size();
}
// default return value
@ -814,7 +799,7 @@ namespace RSMGR
TReleasedObject::iterator first(_ReleasedObject.begin()), last(_ReleasedObject.end());
for (; first != last; ++first)
{
nbReleased += (uint32)first->second.size();
nbReleased += first->second.size();
}
nlinfo(" There are %u object instances in cache not referenced (waiting deletion or re-use))", nbReleased);
@ -912,12 +897,12 @@ namespace RSMGR
if (_ObjectState == NOPE::os_transient && state != NOPE::os_transient)
{
nldebug("NOPE: inserting CNelPermission @%p in cache with id %u", this, static_cast<uint32>(_Prim));
nlverify(_ObjectCache.insert(std::make_pair(_Prim, this)).second);
nldebug("NOPE: inserting CNelPermission @%p in cache with id %u", this, static_cast<uint32>(_PermissionId));
nlverify(_ObjectCache.insert(std::make_pair(_PermissionId, this)).second);
}
if (_ObjectState != NOPE::os_transient)
nlassert(_ObjectCache.find(_Prim) != _ObjectCache.end());
nlassert(_ObjectCache.find(_PermissionId) != _ObjectCache.end());
_ObjectState = state;
@ -928,8 +913,8 @@ namespace RSMGR
}
else if (state == NOPE::os_removed)
{
nldebug("NOPE: erasing CNelPermission @%p in cache with id %u", this, static_cast<uint32>(_Prim));
nlverify(_ObjectCache.erase(_Prim) == 1);
nldebug("NOPE: erasing CNelPermission @%p in cache with id %u", this, static_cast<uint32>(_PermissionId));
nlverify(_ObjectCache.erase(_PermissionId) == 1);
}
}
@ -945,11 +930,11 @@ namespace RSMGR
std::string qs;
qs = "SELECT ";
qs += "prim, UId, ClientApplication, ShardId, AccessPrivilege";
qs += "PermissionId, UId, DomainId, ShardId, AccessPrivilege";
qs += " FROM permission";
qs += " WHERE prim = '"+NLMISC::toString(id)+"'";
qs += " WHERE PermissionId = '"+NLMISC::toString(id)+"'";
CNelPermissionPtr ret;
if (!connection.query(qs))
{
@ -965,9 +950,9 @@ namespace RSMGR
// ok, we have an object
result->fetchRow();
result->getField(0, ret->_Prim);
result->getField(0, ret->_PermissionId);
result->getField(1, ret->_UserId);
result->getField(2, ret->_DomainName);
result->getField(2, ret->_DomainId);
result->getField(3, ret->_ShardId);
result->getField(4, ret->_AccessPriv);

View file

@ -1,18 +1,3 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////
// WARNING : this is a generated file, don't change it !
@ -632,11 +617,11 @@ namespace RSMGR
{
protected:
//
uint32 _Prim;
uint32 _PermissionId;
//
uint32 _UserId;
//
std::string _DomainName;
uint32 _DomainId;
//
uint32 _ShardId;
//
@ -662,24 +647,20 @@ namespace RSMGR
}
//
const std::string &getDomainName() const
uint32 getDomainId() const
{
return _DomainName;
return _DomainId;
}
void setDomainName(const std::string &value)
void setDomainId(uint32 value)
{
if (_DomainName != value)
if (_DomainId != value)
{
if (getPersistentState() != NOPE::os_transient)
setPersistentState(NOPE::os_dirty);
_DomainName = value;
_DomainId = value;
}
@ -729,9 +710,9 @@ namespace RSMGR
bool operator == (const CNelPermission &other) const
{
return _Prim == other._Prim
return _PermissionId == other._PermissionId
&& _UserId == other._UserId
&& _DomainName == other._DomainName
&& _DomainId == other._DomainId
&& _ShardId == other._ShardId
&& _AccessPriv == other._AccessPriv;
}
@ -742,7 +723,7 @@ namespace RSMGR
CNelPermission()
: _PtrList(NULL),
_ObjectState(NOPE::os_transient),
_Prim(NOPE::INVALID_OBJECT_ID)
_PermissionId(NOPE::INVALID_OBJECT_ID)
{
// register the cache for this class (if not already done)
@ -860,7 +841,7 @@ namespace RSMGR
uint32 getObjectId() const
{
return _Prim;
return _PermissionId;
}
/** Set the object unique ID.
@ -874,8 +855,8 @@ namespace RSMGR
// can only be set when in transient state
nlassert(getPersistentState() == NOPE::os_transient);
// can only be set once
nlassert(_Prim == NOPE::INVALID_OBJECT_ID);
_Prim = objectId;
nlassert(_PermissionId == NOPE::INVALID_OBJECT_ID);
_PermissionId = objectId;
}
/** Return the current persistent state of the object.*/

View file

@ -24,9 +24,9 @@
<!-- activate database code generation -->
<database table="permission"/>
<property type="uint32" name="Prim" db_col="prim" unique_id="true"/>
<property type="uint32" name="PermissionId" db_col="PermissionId" unique_id="true"/>
<property type="uint32" name="UserId" db_col="UId"/>
<property type="std::string" name="DomainName" db_col="ClientApplication" byref="true"/>
<property type="uint32" name="DomainId" db_col="DomainId"/>
<property type="uint32" name="ShardId" db_col="ShardId"/>
<property type="std::string" name="AccessPriv" db_col="AccessPrivilege" byref="true"/>

View file

@ -0,0 +1,2 @@
xsltproc -o nel_database_mapping.cpp --stringparam output cpp --stringparam filename nel_database_mapping ../../../common/src/game_share/generate_module_interface.xslt nel_database_mapping.xml
xsltproc -o nel_database_mapping.h --stringparam output header --stringparam filename nel_database_mapping ../../../common/src/game_share/generate_module_interface.xslt nel_database_mapping.xml

View file

@ -648,7 +648,7 @@ namespace RSMGR
userAccessPriv.clear();
CSString query;
query << "SELECT AccessPrivilege FROM permission";
query << " WHERE UId = " << userId << " AND permission.ClientApplication = '"<<DomainName<<"'";
query << " WHERE UId = " << userId << " AND DomainId = " << DomainId;
if (!_NelDb.query(query))
{

View file

@ -659,12 +659,12 @@ function createPermissions($values) {
$sth = $dbh->prepare("SELECT UId FROM user WHERE Login='" . $values[0] . "';");
$sth->execute();
$result = $sth->fetchAll();
foreach ($result as $UId) {
/*foreach ($result as $UId) {
$statement = $dbh->prepare("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES ('" . $UId['UId'] . "', 'r2', 'OPEN');");
$statement->execute($values);
$statement = $dbh->prepare("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES ('" . $UId['UId'] . "', 'ryzom_open', 'OPEN');");
$statement->execute($values);
}
}*///FIXME: GARBAGE
}
catch (PDOException $e) {
watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR);

View file

@ -54,14 +54,14 @@ class Sync{
//make connection with and put into shard db & delete from the lib
$sth=$db->selectWithParameter("UId", "user", $values, "Login= :username" );
$result = $sth->fetchAll();
foreach ($result as $UId) {
/*foreach ($result as $UId) {
$ins_values = array('UId' => $UId['UId']);
$ins_values['ClientApplication'] = "r2";
$ins_values['AccessPrivilege'] = "OPEN";
$db->insert("permission", $ins_values);
$ins_values['ClientApplication'] = 'ryzom_open';
$db->insert("permission",$ins_values);
}
}*/ // FIXME: GARBAGE
break;
case 'change_pass':
$decode = json_decode($record['query']);

View file

@ -336,12 +336,12 @@ class Users{
$dbs = new DBLayer("shard");
$sth = $dbs->selectWithParameter("UId", "user", $values, "Login= :username");
$result = $sth->fetchAll();
foreach ($result as $UId) {
/*foreach ($result as $UId) {
$ins_values = array('UId' => $UId['UId'], 'clientApplication' => 'r2', 'AccessPrivilege' => 'OPEN');
$dbs->insert("permission", $ins_values);
$ins_values['clientApplication'] = 'ryzom_open';
$dbs->insert("permission", $ins_values);
}
}*/ // FIXME: GARBAGE
}
catch (PDOException $e) {
//oh noooz, the shard is offline! Put it in query queue at ams_lib db!

View file

@ -0,0 +1,5 @@
ALTER TABLE `permission` CHANGE `ClientApplication` `ClientApplication` CHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ;
ALTER TABLE `permission` DROP `prim` ;
ALTER TABLE `permission` ADD `PermissionId` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;
ALTER TABLE `permission` ADD `DomainId` INT NOT NULL DEFAULT '-1' AFTER `UId` ;
ALTER TABLE `permission` DROP `ClientApplication` ;

View file

@ -176,7 +176,6 @@
// if we need to create missing ring info
if ($AutoCreateRingInfo)
{
////////////// Temporary code alpha 0 only /////////////////////////////////////
// check if the ring user exist, and create it if not
$ringDb = mysqli_connect($DBHost, $RingDBUserName, $RingDBPassword) or die(errorMsgBlock(3004, 'Ring', $DBHost, $RingDBUserName));
mysqli_select_db ($ringDb, $domainInfo['ring_db_name']) or die(errorMsgBlock(3005, 'Ring', $domainInfo['ring_db_name'], $DBHost, $RingDBUserName));
@ -190,17 +189,6 @@
$query = "INSERT INTO ring_users SET user_id = '$id', user_name = '$login', user_type='ut_pioneer'";
$result = mysqli_query ($ringDb, $query) or die(errorMsgBlock(3006, $query, 'Ring', $domainInfo['ring_db_name'], $DBHost, $RingDBUserName, mysqli_error($ringDb)));
}
// // check that there is a character record (deprecated)
// $query = "SELECT user_id FROM characters where user_id = '".$id."'";
// $result = mysqli_query ($ringDb, $query) or die("Query ".$query." failed");
// if (mysqli_num_rows($result) == 0)
// {
// // no characters record, build a default one
// $charId = ($id * 16);
// $query = "INSERT INTO characters SET char_id='".$charId."', char_name='".$_GET["login"]."_default', user_id = '".$id."'";
// $result = mysqli_query ($ringDb, $query) or die("Query ".$query." failed");
// }
}
// // check domain status
@ -324,7 +312,7 @@
$extended = $row["ExtendedPrivilege"];
// add the default permission
$query = "INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES ('$id', 'r2', '$accessPriv')";
$query = "INSERT INTO permission (UId, DomainId, AccessPrivilege) VALUES ('$id', '$domainId', '$accessPriv')";
$result = mysqli_query ($link, $query) or die (errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysqli_error($link)));
$res = false;
@ -338,40 +326,6 @@
else
{
$reason = errorMsg(2001, $login, 'checkUserValidity');
// Check if this is not an unconfirmed account
/*
$query = "SELECT GamePassword, Email, Language FROM signup_data WHERE login='$login'";
$result = mysqli_query($link, $query) or die (errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysqli_error($link)));
if (mysqli_num_rows($result) == 0)
{
$reason = errorMsg(2001, $login, 'checkUserValidity');
$res = false;
}
else
{
// Check password to avoid revealing email address to third-party
$passwordMatchedRow = false;
while ($row = mysqli_fetch_assoc($result))
{
$salt = substr($row['GamePassword'],0,2);
if (($cp && $row['GamePassword'] == $password) || (!$cp && $row['GamePassword'] == crypt($password, $salt)))
{
$passwordMatchedRow = $row;
break;
}
}
if ($passwordMatchedRow !== false)
{
if ($lang == 'unknown')
setMsgLanguage($passwordMatchedRow['Language']);
$reason = errorMsg(2002, $passwordMatchedRow['Email']);
}
else
$reason = errorMsg(2004, 'db signup_data');
$res = false;
}
*/
}
}
else
@ -385,14 +339,14 @@
// check if the user can use this application
$clientApplication = mysqli_real_escape_string($link, $clientApplication);
$query = "SELECT * FROM permission WHERE UId='".$row["UId"]."' AND ClientApplication='$clientApplication'";
$query = "SELECT * FROM permission WHERE UId='".$row["UId"]."' AND DomainId='$domainId'";
$result = mysqli_query ($link, $query) or die (errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysqli_error($link)));
if (mysqli_num_rows ($result) == 0)
{
if ($AcceptUnknownUser)
{
// add default permission
$query = "INSERT INTO permission (UId, ClientApplication, ShardId, AccessPrivilege) VALUES ('".$row["UId"]."', '$clientApplication', -1, '$domainStatus')";
$query = "INSERT INTO permission (UId, DomainId, ShardId, AccessPrivilege) VALUES ('".$row["UId"]."', '$domainId', -1, '$domainStatus')";
$result = mysqli_query ($link, $query) or die (errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysqli_error($link)));
$reason = errorMsg(3010);
@ -416,7 +370,7 @@
if ($AcceptUnknownUser)
{
// set an additionnal privilege for this player
$query = "UPDATE permission set AccessPrivilege='".$permission['AccessPrivilege'].",$accessPriv' WHERE prim=".$permission['prim'];
$query = "UPDATE permission set AccessPrivilege='".$permission['AccessPrivilege'].",$accessPriv' WHERE PermissionId=".$permission['PermissionId'];
$result = mysqli_query ($link, $query) or die (errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysqli_error($link)));
$reason = errorMsg(3012, $accessPriv);

View file

@ -57,6 +57,10 @@ function upgrade_service_databases($continue_r) {
$continue = update_database_structure($continue, $con, "nel_00001.sql");
$continue = set_db_version($continue, "shard", 1);
}
if ($continue && get_db_version("shard") < 2) {
$continue = update_database_structure($continue, $con, "nel_00002.sql");
$continue = set_db_version($continue, "shard", 2);
}
disconnect_database($con, "shard");
$con = null;

View file

@ -34,6 +34,13 @@ include('header.php');
$continue = false;
}
if ($continue) {
if (!extension_loaded('mcrypt')) {
printalert("danger", "The mcrypt extension is missing. Please check your PHP configuration");
$continue = false;
}
}
// Validate basics
if ($continue) {
if (file_exists($_POST["privatePhpDirectory"])) {

View file

@ -28,6 +28,13 @@ if (!isset($NEL_SETUP_VERSION_CONFIGURED)) {
require_once('database.php');
if ($continue) {
if (!extension_loaded('mcrypt')) {
printalert("danger", "The mcrypt extension is missing. Please check your PHP configuration");
$continue = false;
}
}
if (file_exists("role_support")) {
$continue = upgrade_support_databases($continue);
}