Exemplo n.º 1
0
bool SystemDB::LoadSystemEntities(uint32 systemID, std::vector<DBSystemEntity> &into) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT "
        " itemID,typeID,groupID,orbitID,"
        " x,y,z,radius,security,itemName"
        " FROM mapDenormalize"
        " WHERE solarSystemID=%u", systemID
    ))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return false;
    }

    DBResultRow row;
    DBSystemEntity entry;
    while(res.GetRow(row)) {
        entry.itemID = row.GetInt(0);
        entry.typeID = row.GetInt(1);
        entry.groupID = row.GetInt(2);
        entry.orbitID = (row.IsNull(3) ? 0 : row.GetInt(3));
        entry.position.x = row.GetDouble(4);
        entry.position.y = row.GetDouble(5);
        entry.position.z = row.GetDouble(6);
        entry.radius = (row.IsNull(7) ? 1 : row.GetDouble(7));
        entry.security = (row.IsNull(8) ? 0.0 : row.GetDouble(8));
        entry.itemName = row.GetText(9);
        into.push_back(entry);
    }

    return true;
}
Exemplo n.º 2
0
//this is a crap load of work... there HAS to be a better way to do this..
PyRep *MarketDB::GetMarketGroups() {
    
    DBQueryResult res;
    DBResultRow row;

    if(!sDatabase.RunQuery(res,
        "SELECT * "
        " FROM invMarketGroups"))
    {
        codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

	DBRowDescriptor *header = new DBRowDescriptor(res);
    
    CFilterRowSet *filterRowset = new CFilterRowSet(&header);
    
    PyDict *keywords = filterRowset->GetKeywords();
	keywords->SetItemString("giveMeSets", new PyBool(false)); //+
	keywords->SetItemString("allowDuplicateCompoundKeys", new PyBool(false)); //+
	keywords->SetItemString("indexName", new PyNone); //+
	keywords->SetItemString("columnName", new PyString("parentGroupID")); //+
    std::map< int, PyRep* > tt;

    while( res.GetRow(row) )
    {
        int parentGroupID = ( row.IsNull( 0 ) ? -1 : row.GetUInt( 0 ) );
        PyRep *pid;
        CRowSet *rowset;
        if(tt.count(parentGroupID) == 0) {
            pid = parentGroupID!=-1 ? (PyRep*)new PyInt(parentGroupID) : (PyRep*)new PyNone();
            tt.insert( std::pair<int, PyRep*>(parentGroupID, pid) );
            rowset = filterRowset->NewRowset(pid);
        } else {
            pid = tt[parentGroupID];
            rowset = filterRowset->GetRowset(pid);
        }
        
        PyPackedRow* pyrow = rowset->NewRow();

        pyrow->SetField((uint32)0, pid); //prentGroupID
        pyrow->SetField(1, new PyInt(row.GetUInt( 1 ) ) ); //marketGroupID
        pyrow->SetField(2, new PyString(row.GetText( 2 ) ) ); //marketGroupName
        pyrow->SetField(3, new PyString(row.GetText( 3 ) ) ); //description
        pyrow->SetField(4, row.IsNull( 4 ) ? 
            (PyRep*)(new PyNone()) : new PyInt(row.GetUInt( 4 ))  ); //graphicID
        pyrow->SetField(5, new PyBool(row.GetBool( 5 ) ) ); //hasTypes
        pyrow->SetField(6, row.IsNull( 6 ) ? 
            (PyRep*)(new PyNone()) : new PyInt(row.GetUInt( 6 ))  ); // iconID 
        pyrow->SetField(7, new PyInt( row.GetUInt(7) )  ); //dataID
        pyrow->SetField(8, new PyInt( row.GetUInt(8) )  ); //marketGroupNameID
        pyrow->SetField(9, new PyInt( row.GetUInt(9) )  ); //descriptionID
    }

    return filterRowset;
}
Exemplo n.º 3
0
bool ServiceDB::GetAccountInformation( const char* username, const char* password, AccountInfo & account_info )
{
    std::string _username = username;
    std::string _escaped_username;

    DBcore::DoEscapeString(_escaped_username, _username);

    DBQueryResult res;
    if (!DBcore::RunQuery(res, "SELECT accountID, password, hash, role, online, banned, logonCount, lastLogin FROM srvAccount WHERE accountName = '%s'", _escaped_username.c_str()))
    {
        SysLog::Error( "ServiceDB", "Error in query: %s.", res.error.c_str() );
        return false;
    }

    DBResultRow row;
    if (!res.GetRow( row )) {
		// account not found, create new one if autoAccountRole is not zero (0)
		if(EVEServerConfig::account.autoAccountRole > 0) {
			uint32 accountID = CreateNewAccount( _username.c_str(), password, EVEServerConfig::account.autoAccountRole);
			if( accountID > 0 ) {
				// add new account successful, get account info again
				bool ret = GetAccountInformation(username, password, account_info);
				return ret;
			}
			else
				return false;
		}
		else
			return false;
	}

    /* when any of the text gets are NULL it will fail... I think.. */
    account_info.id         = row.GetUInt(0);

    if (!row.IsNull(1))
        account_info.password = row.GetText(1);

    if (!row.IsNull(2))
        account_info.hash   = row.GetText(2);

    account_info.name       = _escaped_username;
    account_info.role       = row.GetUInt64(3);
    account_info.online     = row.GetBool(4);
    account_info.banned     = row.GetBool(5);
    account_info.visits     = row.GetUInt(6);

    if (!row.IsNull(7))
        account_info.last_login = row.GetText(7);

    return true;
}
Exemplo n.º 4
0
void DBResultToUIntUIntDict(DBQueryResult &result, std::map<uint32, uint32> &into) {
    //add a line entry for each result row:
    DBResultRow row;
    while(result.GetRow(row)) {
        if(row.IsNull(0))
            continue;   //no working with NULL keys...
        uint32 k = row.GetUInt(0);
        int32 v;
        if(row.IsNull(1))
            v = 0;      //we can deal with assuming NULL == 0
        else
            v = row.GetInt(1);
        into[k] = v;
    }
}
Exemplo n.º 5
0
bool AttributeMap::ResetAttribute(uint32 attrID, bool notify)
{
    //this isn't particularly efficient, but until I write a better solution, this will do
    DBQueryResult res;

    if(!sDatabase.RunQuery(res, "SELECT * FROM dgmTypeAttributes WHERE typeID='%u'", mItem.typeID())) {
        sLog.Error("AttributeMap", "Error in db load query: %s", res.error.c_str());
        return false;
    }

    DBResultRow row;
    EvilNumber attrVal;
    uint32 attributeID;

    int amount = res.GetRowCount();
    for (int i = 0; i < amount; i++)
    {
        res.GetRow(row);
        attributeID = row.GetUInt(1);
        if( attributeID == attrID )
        {
            if(!row.IsNull(2))
                attrVal = row.GetUInt64(2);
            else
                attrVal = row.GetDouble(3);

            SetAttribute(attributeID, attrVal, notify);
        }
    }

    return true;

}
Exemplo n.º 6
0
// ////////////////////// DGM_Type_Effects_Table Class ////////////////////////////
TypeEffectsList::TypeEffectsList(uint32 typeID)
{
    //first get list of all effects from dgmTypeEffects table for the given typeID
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetDgmTypeEffects(typeID, *res);

    //counter
	uint32 effectID = 0;
	uint32 isDefault = 0;
	uint32 total_effect_count = 0;

	m_typeEffectsList.clear();

	//go through and insert each effectID into the list
    DBResultRow row;
    while( res->GetRow(row) )
    {
		effectID = row.GetUInt(0);
		isDefault = row.IsNull(1) ? 0 : row.GetUInt(1);
		m_typeEffectsList.insert(std::pair<uint32,uint32>(effectID,isDefault));
		total_effect_count++;
    }

    //cleanup
    delete res;
    res = NULL;
}
Exemplo n.º 7
0
PyDict *DBResultToIntIntDict(DBQueryResult &result) {
    PyDict *res = new PyDict();

    //add a line entry for each result row:
    DBResultRow row;
    while(result.GetRow(row)) {
        if(row.IsNull(0))
            continue;   //no working with NULL keys...
        int32 k = row.GetInt(0);
        if(k == 0)
            continue;   //likely a non-integer key
        int32 v;
        if(row.IsNull(1))
            v = 0;      //we can deal with assuming NULL == 0
        else
            v = row.GetInt(1);

        res->SetItem( new PyInt(k), new PyInt(v) );
    }

    return res;
}
Exemplo n.º 8
0
PyString* MailDB::GetMailBody(int id) const
{
    DBQueryResult res;
    if (!sDatabase.RunQuery(res, "SELECT body FROM mailMessage WHERE messageID = %u", id))
        return NULL;
    if (res.GetRowCount() <= 0)
        return NULL;

    DBResultRow row;
    if (!res.GetRow(row) || row.IsNull(0))
        return NULL;

    return new PyString(row.GetText(0), row.ColumnLength(0));
}
Exemplo n.º 9
0
bool ServiceDB::GetSystemInfo(uint32 systemID, uint32 *constellationID, uint32 *regionID, std::string *name, std::string *securityClass) {
    if(       constellationID == NULL
        && regionID == NULL
        && name == NULL
        && securityClass == NULL
    )
        return true;

    DBQueryResult res;
    if(!DBcore::RunQuery(res,
        "SELECT"
        " constellationID,"
        " regionID,"
        " solarSystemName,"
        " securityClass"
        " FROM mapSolarSystems"
        " WHERE solarSystemID = %u",
        systemID))
    {
        _log(DATABASE__ERROR, "Failed to query info for system %u: %s.", systemID, res.error.c_str());
        return false;
    }

    DBResultRow row;
    if(!res.GetRow(row)) {
        _log(DATABASE__ERROR, "Failed to query info for system %u: System not found.", systemID);
        return false;
    }

    if(constellationID != NULL)
        *constellationID = row.GetUInt(0);
    if(regionID != NULL)
        *regionID = row.GetUInt(1);
    if(name != NULL)
        *name = row.GetText(2);
    if(securityClass != NULL)
        *securityClass = row.IsNull(3) ? "" : row.GetText(3);

    return true;
}
Exemplo n.º 10
0
dgmtypeattributemgr::dgmtypeattributemgr()
{
    // load shit from db
    DBQueryResult res;

    if( !DBcore::RunQuery( res,
        "SELECT * FROM dgmTypeAttributes ORDER BY typeID" ) )
    {
        SysLog::Error("DgmTypeAttrMgr", "Error in db load query: %s", res.error.c_str());
        return;
    }

    uint32 currentID = 0;
    DgmTypeAttributeSet * entry = NULL;
    DBResultRow row;

    int amount = res.GetRowCount();
    for (int i = 0; i < amount; i++)
    {
        res.GetRow(row);
        uint32 typeID = row.GetUInt(0);

        if (currentID != typeID) {
            currentID = typeID;
            entry = new DgmTypeAttributeSet;
            mDgmTypeAttrInfo.insert(std::make_pair(currentID, entry));
        }

        DgmTypeAttribute * attr_entry = new DgmTypeAttribute();
        attr_entry->attributeID = row.GetUInt(1);
        if (row.IsNull(2) == true) {
            attr_entry->number = EvilNumber(row.GetFloat(3));
        } else {
            attr_entry->number = EvilNumber(row.GetInt(2));
        }

        entry->attributeset.push_back(attr_entry);
    }
}
Exemplo n.º 11
0
//this is a crap load of work... there HAS to be a better way to do this..
PyObject *MarketDB::GetMarketGroups() {
	DBQueryResult res;

	//returns cached object marketProxy.GetMarketGroups
	//marketGroupID, parentGroupID, marketGroupName, description, graphicID, hasTypes, types
	//this is going to be a real pain... another "nested" query thing...
	// I really wanna know how they do this crap with their MS SQL server.. 
	// I hope its not as much of a nightmare as it is for us....

	//first we need to query out all the types because we need them to 
	// fill in the 'types' subquery for each row of the result
	std::map< int, std::set<uint32> > types;	//maps marketGroupID -> typeID
	if(!sDatabase.RunQuery(res,
		"SELECT"
		"	marketGroupID,typeID"
		" FROM invTypes"
		" WHERE marketGroupID IS NOT NULL"
		" ORDER BY marketGroupID"))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}
	
	DBResultRow row;
	while(res.GetRow(row))
		types[row.GetUInt(0)].insert(row.GetUInt(1));

	if(!sDatabase.RunQuery(res,
		"SELECT"
		"	marketGroupID, parentGroupID"
		" FROM invMarketGroups"))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}

	std::map<int, int> parentChild;	//maps child -> parent
	std::map<int, std::set<int> > childParent; //maps parent -> all children.
	while(res.GetRow(row)) {
		//figure out the parent ID, mapping NULL to -1 for our map.
		int marketGroupID = row.GetUInt(0);
		int parentGroupID = row.IsNull(1) ? -1 : row.GetUInt(1);

		parentChild[marketGroupID] = parentGroupID;
		childParent[parentGroupID].insert(marketGroupID);
	}

	//now we need to propigate all of the items up the tree (a parent group's items list contains ALL items of its children.)
	_PropigateItems(types, parentChild, childParent, -1);

	//now we get to do the other query.
	if(!sDatabase.RunQuery(res,
		"SELECT"
		"	marketGroupID, parentGroupID, marketGroupName, description, graphicID, hasTypes"
		" FROM invMarketGroups"))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}

	//doing this the long (non XML) way to avoid the extra copies due to the huge volume of data here.
	PyDict *args = new PyDict();

	PyDict *parentSets = new PyDict();
	PyList *header = new PyList();
	
	header->AddItemString("marketGroupID");
	header->AddItemString("parentGroupID");
	header->AddItemString("marketGroupName");
	header->AddItemString("description");
	header->AddItemString("graphicID");
	header->AddItemString("hasTypes");
	header->AddItemString("types");	//this column really contains an entire list.
	header->AddItemString("dataID");
	
	args->SetItemString("header", header);
	args->SetItemString("idName", new PyString("parentGroupID"));
	args->SetItemString("RowClass", new PyToken("util.Row"));
	args->SetItemString("idName2", new PyNone);
	args->SetItemString("items", parentSets);
	
	//now fill in items.
	// we have to satisfy this structure... which uses parentGroupID as the
	// main dict key, each dict entry is then a list of MarketGroup_Entrys
	// which have that parentGroupID
	//marketGroupID, parentGroupID, marketGroupName, description, graphicID, hasTypes, types
	std::map< int, std::set<uint32> >::const_iterator tt;
	MarketGroup_Entry entry;
    PyList* list;
    PyList* parents = new PyList();
	while( res.GetRow(row) )
	{
		entry.marketGroupID = row.GetUInt( 0 );

		//figure out the parent ID, mapping NULL to -1 for our map.
		entry.parentGroupID = ( row.IsNull( 1 ) ? -1 : row.GetUInt( 1 ) );

		entry.marketGroupName = row.GetText( 2 );
		entry.description = row.GetText( 3 );
		entry.graphicID = ( row.IsNull( 4 ) ? -1 : row.GetUInt( 4 ) );		
		entry.hasTypes = row.GetUInt( 5 );

		// Insert all types
		entry.types.clear();
		tt = types.find( entry.marketGroupID );
		if( tt != types.end() )
			entry.types.insert( entry.types.begin(), tt->second.begin(), tt->second.end() );

        if(entry.parentGroupID == -1)
			list = parents;
		else
			list = static_cast<PyList*> (parentSets->GetItem(new PyInt( entry.parentGroupID )));
        if(list == NULL)
            list = new PyList();
        list->AddItem(entry.Encode());
        PySafeIncRef(list);
        if(entry.parentGroupID != -1)
			parentSets->SetItem(new PyInt(entry.parentGroupID), list);
	}
    parentSets->SetItem(new PyNone, parents);

	return new PyObject( "util.FilterRowset", args );
}
Exemplo n.º 12
0
bool AttributeMap::Load()
{
    /* First, we load default attributes values using existing attribute system */
    DgmTypeAttributeSet *attr_set = sDgmTypeAttrMgr.GetDmgTypeAttributeSet( mItem.typeID() );
    if (attr_set == NULL)
        return false;

    DgmTypeAttributeSet::AttrSetItr itr = attr_set->attributeset.begin();

    for (; itr != attr_set->attributeset.end(); itr++)
        SetAttribute((*itr)->attributeID, (*itr)->number, false);

    /* Then we load the saved attributes from the db, if there are any yet, and overwrite the defaults */
    DBQueryResult res;

	if(mDefault)
	{
		if(!sDatabase.RunQuery(res, "SELECT * FROM entity_default_attributes WHERE itemID='%u'", mItem.itemID())) {
			sLog.Error("AttributeMap (DEFAULT)", "Error in db load query: %s", res.error.c_str());
			return false;
		}
	}
	else
	{
		if(!sDatabase.RunQuery(res, "SELECT * FROM entity_attributes WHERE itemID='%u'", mItem.itemID())) {
			sLog.Error("AttributeMap", "Error in db load query: %s", res.error.c_str());
			return false;
		}
	}

    DBResultRow row;

    int amount = res.GetRowCount();
    for (int i = 0; i < amount; i++)
    {
        EvilNumber attr_value;
        res.GetRow(row);
        uint32 attributeID = row.GetUInt(1);
        if (!row.IsNull(2))
            attr_value = row.GetInt64(2);
        else
            attr_value = row.GetDouble(3);
        SetAttribute(attributeID, attr_value, false);
    }

    return true;

/*
    /// EXISTING AttributeMap::Load() function
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,"SELECT * FROM entity_attributes WHERE itemID='%u'", mItem.itemID())) {
        sLog.Error("AttributeMap", "Error in db load query: %s", res.error.c_str());
        return false;
    }

    DBResultRow row;

    int amount = res.GetRowCount();

    // Right now, assume that we need to load all attributes with default values from dgmTypeAttributes table
    // IF AND ONLY IF the number of attributes pulled from the entity_attributes table for this item is ZERO:
    if( amount > 0 )
    {
        // This item was found in the 'entity_attributes' table, so load all attributes found there
        // into the Attribute Map for this item:
        for (int i = 0; i < amount; i++)
        {
            res.GetRow(row);
            EvilNumber attr_value;
            uint32 attributeID = row.GetUInt(1);
            if ( !row.IsNull(2) )
                attr_value = row.GetInt64(2);
            else if( !row.IsNull(3) )
                attr_value = row.GetDouble(3);
            else
                sLog.Error( "AttributeMap::Load()", "Both valueInt and valueFloat fields of this (itemID,attributeID) = (%u,%u) are NULL.", row.GetInt(0), attributeID );

            SetAttribute(attributeID, attr_value, false);
            //Add(attributeID, attr_value);
        }
    }
    else
    {
        // This item was NOT found in the 'entity_attributes' table, so let's assume that
        // this item was just created.
        // 1) Get complete list of attributes with default values from dgmTypeAttributes table using the item's typeID:
        DgmTypeAttributeSet *attr_set = sDgmTypeAttrMgr.GetDmgTypeAttributeSet( mItem.typeID() );
        if (attr_set == NULL)
            return false;

        DgmTypeAttributeSet::AttrSetItr itr = attr_set->attributeset.begin();

        // Store all these attributes to the item's AttributeMap
        for (; itr != attr_set->attributeset.end(); itr++)
        {
            SetAttribute((*itr)->attributeID, (*itr)->number, false);
            //Add((*itr)->attributeID, (*itr)->number);
        }

        // 2) Save these newly created and loaded attributes to the 'entity_attributes' table
        SaveAttributes();
    }

    return true;
*/
}