void DGM_Types_to_Wrecks_Table::_Populate()
{
    uint32 wreckID, typeID;

    //first get list of all effects from dgmEffects table
    DBQueryResult *res = new DBQueryResult();
    SystemDB::GetWrecksToTypes(*res);

    //counter
	uint32 total_effect_count = 0;
	uint32 error_count = 0;

	//go through and populate each effect
    DBResultRow row;
    while( res->GetRow(row) )
    {
        typeID = row.GetInt(0);
        wreckID = row.GetInt(1);
		m_WrecksToTypesMap.insert(std::pair<uint32, uint32>(typeID,wreckID));
    }

    //cleanup
    delete res;
    res = NULL;
}
bool ReprocessingDB::GetRecoverables(const uint32 typeID, std::vector<Recoverable> &into) {
    DBQueryResult res;
    DBResultRow row;

    if(!sDatabase.RunQuery(res,
                "SELECT requiredTypeID, MIN(quantity) FROM typeActivityMaterials"
                " LEFT JOIN invBlueprintTypes ON typeID = blueprintTypeID"
                " WHERE damagePerJob = 1 AND ("
                "   (activityID = 6 AND typeID = %u)"
                "   OR"
                "    (activityID = 1 AND productTypeID = %u))"
                " GROUP BY requiredTypeID",
                typeID, typeID, typeID))
    {
        _log(DATABASE__ERROR, "Unable to get recoverables for type ID %u: '%s'", typeID, res.error.c_str());
        return false;
    }

    Recoverable rec;

    while(res.GetRow(row)) {
        rec.typeID = row.GetInt(0);
        rec.amountPerBatch = row.GetInt(1);
        into.push_back(rec);
    }

    return true;
}
Exemple #3
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;
}
PyRep *CorporationDB::Fetch(uint32 corpID, uint32 from, uint32 count) {
    DBQueryResult res;
    DBResultRow rr;

    if (!sDatabase.RunQuery(res,
        " SELECT stationID, typeID, itemID, officeFolderID "
        " FROM crpOffices "
        " WHERE corporationID = %u "
        " LIMIT %u, %u ", corpID, from, count
        ))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

    res.GetRow(rr);

    // Have to send back a list that contains a tuple that contains an int and a list...
    // params probably needs the following stuff: stationID, typeID, officeID, officeFolderID
    Reply_FetchOffice reply;
    reply.params = new PyList;

    reply.params->AddItemInt( rr.GetInt(0) );
    reply.params->AddItemInt( rr.GetInt(1) );
    reply.officeID = rr.GetInt(2);
    reply.params->AddItemInt( reply.officeID );
    reply.params->AddItemInt( rr.GetInt(3) );

    return reply.Encode();
}
Exemple #5
0
bool SystemDB::LoadSystemDynamicEntities(uint32 systemID, std::vector<DBSystemDynamicEntity> &into) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT"
        "    entity.itemID,"
        "   entity.itemName,"
        "    entity.typeID,"
        "   entity.ownerID,"
        "   entity.locationID,"
        "   entity.flag,"
        "    invTypes.groupID,"
        "    invGroups.categoryID,"
        "   0,"//"   character_.corporationID,"
        "   0,"//"   corporation.allianceID,"
        "   x,"
        "   y,"
        "   z"
        " FROM entity, invTypes, invGroups"//, character_, corporation"
        " WHERE"
        "        entity.typeID=invTypes.typeID"
        "    AND invTypes.groupID=invGroups.groupID"
        "    AND invGroups.categoryID NOT IN (%d,%d)"
        //"   AND character_.characterID = entity.ownerID"
        //"   AND corporation.corporationID = character_.corporationID"
        "    AND locationID=%u",
        //excluded categories:
            //celestials:
            EVEDB::invCategories::_System, EVEDB::invCategories::Station,
            //NPCs:
            //EVEDB::invCategories::Entity,
        systemID
    ))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return false;
    }

    DBResultRow row;
    DBSystemDynamicEntity entry;
    while(res.GetRow(row)) {
        entry.itemID = row.GetInt(0);
        entry.itemName = row.GetText(1);
        entry.typeID = row.GetInt(2);
        entry.ownerID = row.GetInt(3);
        entry.locationID = row.GetInt(4);
        entry.flag = row.GetInt(5);
        entry.groupID = row.GetInt(6);
        entry.categoryID = row.GetInt(7);
        entry.corporationID = row.GetInt(8);
        entry.allianceID = row.GetInt(9);
        entry.x = row.GetDouble(10);
        entry.y = row.GetDouble(11);
        entry.z = row.GetDouble(12);
        into.push_back(entry);
    }

    return true;
}
Exemple #6
0
int CommandDB::GetAccountID(std::string name) {

    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        " SELECT "
        " AccountID "
        " FROM character_ "
        " WHERE characterID = ( SELECT itemID FROM entity WHERE itemName = '%s' )", name.c_str()))
    {
        sLog.Error("CommandDB", "Failed to retrieve accountID for %s", name.c_str());
        return 0;
    }

    DBResultRow row;

    if( !res.GetRow(row) )
    {
        sLog.Error("CommandDB", "Query Returned no results");
        return 0;
    }

    return row.GetInt( 0 );

}
Exemple #7
0
bool MailDB::CreateLabel(int characterID, Call_CreateLabel& args, uint32& newID) const
{
    // we need to get the next free bit index; can't avoid a SELECT
    DBQueryResult res;
    sDatabase.RunQuery(res, "SELECT bit FROM mailLabel WHERE ownerID = %u ORDER BY bit DESC LIMIT 1", characterID);

    // 6 is a guessed default; there are some hardcoded labels that we don't have the details on yet
    int bit = 6;

    if (res.GetRowCount() > 0)
    {
        DBResultRow row;
        res.GetRow(row);
        // we want the next one, not the current one, so +1
        bit = row.GetInt(0) + 1;
    }

    DBerror error;
    if (!sDatabase.RunQuery(error, "INSERT INTO mailLabel (bit, name, color, ownerID) VALUES (%u, '%s', %u, %u)", bit, args.name.c_str(), args.color, characterID))
    {
        codelog(SERVICE__ERROR, "Failed to insert new mail label into database");
        // since this is an out parameter, make sure we assign this even in case of an error
        newID = 0;
        return false;
    }

    // the client wants the power of 2, not the bitset index
    newID = (uint32)pow((float)2, bit);
    return true;
}
Exemple #8
0
bool RamProxyDB::GetRequiredItems(const uint32 typeID, const EVERamActivity activity, std::vector<RequiredItem> &into) {
    DBQueryResult res;

    if(!DBcore::RunQuery(res,
        "SELECT"
        " material.requiredTypeID,"
        " material.quantity,"
        " material.damagePerJob,"
        " IF(materialGroup.categoryID = 16, 1, 0) AS isSkill"
        " FROM typeActivityMaterials AS material"
        " LEFT JOIN invTypes AS materialType ON material.requiredTypeID = materialType.typeID"
        " LEFT JOIN invGroups AS materialGroup ON materialType.groupID = materialGroup.groupID"
        " WHERE material.typeID = %u"
        " AND material.activityID = %d"
        //this is needed as db is quite crappy ...
        " AND material.quantity > 0",
        typeID, (const int)activity))
    {
        _log(DATABASE__ERROR, "Failed to query data to build BillOfMaterials: %s.", res.error.c_str());
        return false;
    }

    DBResultRow row;
    while(res.GetRow(row))
        into.push_back(RequiredItem(row.GetUInt(0), row.GetUInt(1), row.GetFloat(2), row.GetInt(3) ? true : false));

    return true;
}
void DGM_Effects_Table::_Populate()
{
    //first get list of all effects from dgmEffects table
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetAllDgmEffects(*res);

    //counter
    MEffect * mEffectPtr;
    mEffectPtr = NULL;
    uint32 effectID;

	int total_effect_count = 0;
	int error_count = 0;

	//go through and populate each effect
    DBResultRow row;
    while( res->GetRow(row) )
    {
        effectID = row.GetInt(0);
        mEffectPtr = new MEffect(effectID);
		if( mEffectPtr->IsEffectLoaded() )
			m_EffectsMap.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
		else
			error_count++;

		total_effect_count++;
    }

	if( error_count > 0 )
		sLog.Error("DGM_Effects_Table::_Populate()","ERROR Populating the DGM_Effects_Table memory object: %u of %u effects failed to load!", error_count, total_effect_count);

    //cleanup
    delete res;
    res = NULL;
}
Exemple #10
0
bool CharacterDB::GetCareerBySchool(uint32 schoolID, uint32 &careerID) {
    DBQueryResult res;
    if (!sDatabase.RunQuery(res,
     "SELECT "
     " careerID, "
     " schoolID, "
     " raceID "
     " FROM careers"
     " WHERE schoolID = %u", schoolID))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return (false);
    }


    DBResultRow row;
    if(!res.GetRow(row)) {
        codelog(SERVICE__ERROR, "Failed to find matching career for school %u", schoolID);
        return false;
    }

    careerID = row.GetInt(0);

    return (true);
}
Exemple #11
0
uint32 LSCDB::GetChannelIDFromComparisonKey(std::string compkey)
{
	DBQueryResult res;

	if(!sDatabase.RunQuery(res,
		"SELECT "
		"	channelID "
		" FROM channels"
		" WHERE comparisonKey RLIKE '%s'", 
        compkey.c_str()
	))
	{
		_log(SERVICE__ERROR, "Error in GetChannelIDFromComparisonKey query: %s", res.error.c_str());
		return 0;
	}

	DBResultRow row;

	if (!res.GetRow(row)) {
		_log(SERVICE__ERROR, "Couldn't find %s in table channels", compkey.c_str());
        return 0;
	}

    return (row.GetInt(0));
}
Exemple #12
0
/**
 * this function isn't used.
 */
void DBResultToIntIntlistDict( DBQueryResult &result, std::map<int32, PyRep *> &into ) {
    /* this builds a map from the int in result[0], to a list of each result[1]
     * which is has the same result[0]. This function assumes the result is
     * ORDER BY result[0]
     */
    uint32 last_key = 0xFFFFFFFF;

    PyList *l = NULL;

    DBResultRow row;
    while( result.GetRow( row ) )
    {
        uint32 k = row.GetUInt(0);
        if( k != last_key )
        {
            //watch for overwrite, no guarantee we are dealing with a key.
            std::map<int32, PyRep *>::iterator res = into.find(k);
            if( res != into.end() )
                //log an error or warning?
                PyDecRef( res->second );

            into[k] = l = new PyList();
            last_key = k;
        }

        l->AddItemInt( row.GetInt( 1 ) );
    }
}
Exemple #13
0
PyRep *LSCDB::GetMailDetails(uint32 messageID, uint32 readerID) {
	DBQueryResult result;
	DBResultRow row;

	//we need to query out the primary message here... not sure how to properly
	//grab the "main message" though... the text/plain clause is pretty hackish.
	if (!sDatabase.RunQuery(result,
		" SELECT eveMail.messageID, eveMail.senderID, eveMail.subject, " // need messageID as char*
		" eveMailDetails.attachment, eveMailDetails.mimeTypeID, "
		" eveMailMimeType.mimeType, eveMailMimeType.`binary`, "
		" eveMail.created, eveMail.channelID "
		" FROM eveMail "
		" LEFT JOIN eveMailDetails"
		"	ON eveMailDetails.messageID = eveMail.messageID "
		" LEFT JOIN eveMailMimeType"
		"	ON eveMailMimeType.mimeTypeID = eveMailDetails.mimeTypeID "
		" WHERE eveMail.messageID=%u"
		"	AND channelID=%u",
			messageID, readerID
		))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", result.error.c_str());
		return (NULL);
	}

	if (!result.GetRow(row)) {
		codelog(SERVICE__MESSAGE, "No message with messageID %u", messageID);
		return (NULL);
	}

	Rsp_GetEVEMailDetails details;
	details.messageID = row.GetUInt(0);
	details.senderID = row.GetUInt(1);
	details.subject = row.GetText(2);
	details.body = row.GetText(3);
	details.created = row.GetUInt64(7);
	details.channelID = row.GetUInt(8);
	details.deleted = 0; // If a message's details are sent, then it isn't deleted. If it's deleted, details cannot be sent
	details.mimeTypeID = row.GetInt(4);
	details.mimeType = row.GetText(5);
	details.binary = row.GetInt(6);

	return(details.Encode());
}
Exemple #14
0
bool MarketDB::GetOrderInfo(uint32 orderID, uint32 *orderOwnerID, uint32 *typeID, uint32 *stationID, uint32 *quantity, double *price, bool *isBuy, bool *isCorp) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT"
        " volRemaining,"
        " price,"
        " typeID,"
        " stationID,"
        " charID,"
        " bid,"
        " isCorp"
        " FROM market_orders"
        " WHERE orderID=%u",
        orderID))
    {
        _log(MARKET__ERROR, "Error in query: %s.", res.error.c_str());
        return false;
    }

    DBResultRow row;
    if(!res.GetRow(row)) {
        _log(MARKET__ERROR, "Order %u not found.", orderID);
        return false;
    }

    if(quantity != NULL)
        *quantity = row.GetUInt(0);
    if(price != NULL)
        *price = row.GetDouble(1);
    if(typeID != NULL)
        *typeID = row.GetUInt(2);
    if(stationID != NULL)
        *stationID = row.GetUInt(3);
    if(orderOwnerID != NULL)
        *orderOwnerID = row.GetUInt(4);
    if(isBuy != NULL)
        *isBuy = row.GetInt(5) ? true : false;
    if(isCorp != NULL)
        *isCorp = row.GetInt(6) ? true : false;

    return true;
}
Exemple #15
0
PyRep* MailDB::GetLabels(int characterID) const
{
    DBQueryResult res;
    if (!sDatabase.RunQuery(res, "SELECT bit, name, color, ownerId FROM mailLabel WHERE ownerID = %u", characterID))
        return NULL;

    PyDict* ret = new PyDict();

    DBResultRow row;
    while (res.GetRow(row))
    {
        MailLabel label;
        label.id = (int)pow((float)2, row.GetInt(0));
        label.name = row.GetText(1);
        label.color = row.GetInt(2);

        ret->SetItem(new PyInt(label.id), label.Encode());
    }

    return ret;
}
Exemple #16
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;
}
bool ReprocessingDB::GetRecoverables(const uint32 typeID, std::vector<Recoverable> &into) {
	DBQueryResult res;
	DBResultRow row;

	if (!sDatabase.RunQuery(res,
		"SELECT materialTypeID, MIN(quantity) FROM invTypeMaterials WHERE typeID = %u"
		" GROUP BY materialTypeID",
		typeID))
	{
		_log(DATABASE__ERROR, "Unable to get recoverables for type ID %u: '%s'", typeID, res.error.c_str());
		return false;
	}

	Recoverable rec;

	while (res.GetRow(row)) {
		rec.typeID = row.GetInt(0);
		rec.amountPerBatch = row.GetInt(1);
		into.push_back(rec);
	}

	return true;
}
bool EVEStatic::loadStaStationTypes()
{
    DBQueryResult result;
    DBResultRow row;
    std::string columns = "stationTypeID, dockEntryX, dockEntryY, dockEntryZ,"
            " dockOrientationX, dockOrientationY, dockOrientationZ,"
            " operationID, officeSlots, reprocessingEfficiency, conquerable,"
            " dockingBayGraphicID, hangarGraphicID";
    std::string qry = "SELECT " + columns + " FROM staStationTypes LEFT JOIN extStaStationTypes Using(stationTypeID)";
    if (!DBcore::RunQuery(result, qry.c_str()))
    {
        SysLog::Error("Static DB", "Error in query: %s", result.error.c_str());
        return false;
    }
    while (result.GetRow(row))
    {
        uint32 stationTypeID = row.GetInt(0);
        double dockEntryX = row.GetDouble(1);
        double dockEntryY = row.GetDouble(2);
        double dockEntryZ = row.GetDouble(3);
        double dockOrientationX = row.GetDouble(4);
        double dockOrientationY = row.GetDouble(5);
        double dockOrientationZ = row.GetDouble(6);
        uint32 operationID = row.getIntNC(7);
        uint32 officeSlots = row.getIntNC(8);
        double reprocessingEfficiency = row.getDoubleNC(9);
        bool conquerable = row.GetBool(10);
        // From extStaStationTypes
        uint32 dockingBayGraphicID = row.getIntNC(11);
        uint32 hangarGraphicID = row.getIntNC(12);
        new StaStationType(
                           stationTypeID,
                           dockEntryX,
                           dockEntryY,
                           dockEntryZ,
                           dockOrientationX,
                           dockOrientationY,
                           dockOrientationZ,
                           operationID,
                           officeSlots,
                           reprocessingEfficiency,
                           conquerable,
                           dockingBayGraphicID,
                           hangarGraphicID
                           );
    }

    return true;
}
Exemple #19
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;
    }
}
Exemple #20
0
uint32 MarketDB::GetPlayerNumberOutstandingContracts(uint32 characterID )
{
	// As atm i dont know wich table is contracts one so we hack it to one
	DBQueryResult res;
	DBResultRow row;
	if(!sDatabase.RunQuery(res,
		"SELECT numOutstandingContracts"
		" FROM chrcontractinfo"
		" WHERE characterID=%d", characterID ))
	{
		codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return NULL;
	}
	res.GetRow(row);
	return row.GetInt( 0 );
}
Exemple #21
0
PyDict *DBResultToIntRowDict(DBQueryResult &result, uint32 key_index, const char *type) {
    PyDict *res = new PyDict();

    //add a line entry for each result row:
    DBResultRow row;
    while(result.GetRow(row)) {
        //this could be more efficient by not building the column list each time, but cloning it instead.
        PyObject *r = DBRowToRow(row, type);
        int32 k = row.GetInt(key_index);
        if(k == 0)
            continue;   //likely a non-integer key
        res->SetItem(new PyInt(k), r);
    }

    return res;
}
Exemple #22
0
bool CharacterDB::GetCorporationBySchool(uint32 schoolID, uint32 &corporationID)
{
    DBQueryResult res;

    if(!sDatabase.RunQuery(res, "SELECT corporationID FROM chrSchools WHERE schoolID = %u", schoolID))
    {
        codelog(SERVICE__ERROR, "Error in query: %S", res.error.c_str());
        return false;
    }

    DBResultRow row;
    if(!res.GetRow(row))
    {
        codelog(SERVICE__ERROR, "Failed to find matching corporation for school %u", schoolID);
        return false;
    }

    corporationID = row.GetInt(0);

    return true;
}
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);
    }
}
PyRep *CorporationDB::GetCorporationIDForCharacter( uint32 characterID )
{
	DBQueryResult res;
	if(!sDatabase.RunQuery(res, 
		"SELECT"
		" corporationID"
		" FROM character_"
		" WHERE characterID=%d", characterID))
	{
		codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str() );
		return new PyInt( 0 );
	}
 
	DBResultRow row;
	if( !res.GetRow( row ) )
	{
		codelog(DATABASE__ERROR, "Character %s not found.", characterID);
		return new PyInt( 0 );
	}
 
	return new PyInt( row.GetInt(0) );
}
Exemple #25
0
void DGM_Ship_Bonus_Modifiers_Table::_Populate()
{
    //first get list of all effects from dgmShipBonusModifiers table
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetAllDgmShipBonusModifiers(*res);

    //counter
    ShipBonusModifier * mShipBonusModifierPtr;
    mShipBonusModifierPtr = NULL;
    uint32 shipID;

	uint32 total_modifier_count = 0;
	uint32 error_count = 0;

	//go through and populate each ship bonus modifier
    DBResultRow row;
    while( res->GetRow(row) )
    {
        shipID = row.GetInt(0);
        mShipBonusModifierPtr = new ShipBonusModifier(shipID);
		if( mShipBonusModifierPtr->IsModifierLoaded() )
			m_ShipBonusModifiersMap.insert(std::pair<uint32, ShipBonusModifier *>(shipID,mShipBonusModifierPtr));
		else
			error_count++;

		total_modifier_count++;
    }

	if( error_count > 0 )
		sLog.Error("DGM_Ship_Bonus_Modifiers_Table::_Populate()","ERROR Populating the DGM_Ship_Bonus_Modifiers_Table memory object: %u of %u ship bonus modifiers failed to load!", error_count, total_modifier_count);

	sLog.Log("DGM_Ship_Bonus_Modifiers_Table", "..........%u total modifier objects loaded", total_modifier_count);

    //cleanup
    delete res;
    res = NULL;
}
void ModuleEffects::_populate(uint32 typeID)
{
    //first get list of all of the effects associated with the typeID
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetDgmTypeEffectsInformation(typeID, *res);

    //counter
    MEffect * mEffectPtr;
    mEffectPtr = NULL;
    m_defaultEffect = NULL;     // Set this to NULL until the default effect is found, if there is any
    uint32 effectID;
    uint32 isDefault;

    //go through and populate each effect
    DBResultRow row;
    while( res->GetRow(row) )
    {
        effectID = row.GetInt(0);
        isDefault = row.GetInt(1);
        switch( effectID )
        {
            case 11:    // loPower
            case 12:    // hiPower
            case 13:    // medPower
                // We do not need to make MEffect objects these effectIDs, since they do nothing
                mEffectPtr = NULL;
                break;

            default:
                mEffectPtr = new MEffect( effectID );
                break;
        }

        if( isDefault > 0 )
            m_defaultEffect = mEffectPtr;

        // This switch is assuming that all entries in 'dgmEffectsInfo' for this effectID are applied during the same module state,
        // which should really be the case anyway, for every effectID, so we just check index 0 of the effectIDs list of attributes
        // that are modified by this effect for which module state during which the effect is active:
        if( mEffectPtr != NULL )
        {
            switch( mEffectPtr->GetModuleStateWhenEffectApplied(0) )
            {
                case EFFECT_ONLINE:
                    m_OnlineEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
                    break;
                case EFFECT_ACTIVE:
                    m_ActiveEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
                    break;
                case EFFECT_OVERLOAD:
                    m_OverloadEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
                    break;
                default:
                    sLog.Error("ModuleEffects::_populate()", "Illegal value '%u' obtained from the 'effectAppliedInState' field of the 'dgmEffectsInfo' table", mEffectPtr->GetModuleStateWhenEffectApplied(0));
                    break;
            }
        }
    }

    //cleanup
    delete res;
    res = NULL;

}
Exemple #27
0
PyRep *MarketDB::DeleteContract( uint32 contractID, uint32 characterID )
{
	DBerror err;

	DBQueryResult res;

	// Update the user info
	int forCorp = false;
	if(!sDatabase.RunQuery(res,
		"SELECT forCorp"
		" FROM contract"
		" WHERE contractID=%d", contractID))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return new PyBool(false);
	}
	DBResultRow row;

	if( !res.GetRow(row) )
	{
		codelog(MARKET__ERROR, "Contract %d not found.", contractID);
		return NULL;
	}

	forCorp = row.GetInt(0);

	if(!sDatabase.RunQuery(err, 
		"DELETE FROM contract"
		" WHERE contractID=%d", contractID ) )
	{
		codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
		return new PyBool(false);
	}

	if(!sDatabase.RunQuery(err,
		"DELETE FROM contracts_items"
		" WHERE contractID=%d", contractID ) )
	{
		codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
		return new PyBool(false);
	}

	if(!sDatabase.RunQuery(err,
		"DELETE FROM contract_bids"
		" WHERE contractID=%d", contractID ) )
	{
		codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
		return new PyBool(false);
	}

	if(!forCorp)
	{
		if(!sDatabase.RunQuery(err, 
			"UPDATE"
			" chrcontractinfo"
			" SET numOutStandingContractsNonCorp=numOutStandingContractsNonCorp-1,"
			" numOutstandingContracts=numOutstandingContracts-1"
			" WHERE characterID=%d", characterID))
		{
			codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
			return new PyBool(false);
		}
	}else{
		if(!sDatabase.RunQuery(err, 
			"UPDATE"
			" chrcontractinfo"
			" SET numOutStandingContractsForCorp=numOutStandingContractsForCorp-1,"
			" numOutstandingContracts=numOutstandingContracts-1"
			" WHERE characterID=%d", characterID))
		{
			codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
			return new PyBool(false);
		}
	}
	return new PyBool(true);
}
Exemple #28
0
PyRep *MarketDB::CollectMyPageInfo( uint32 clientID )
{
	DBQueryResult res;
	DBResultRow row;
	if(!sDatabase.RunQuery(res,
		"SELECT numOutstandingContractsNonCorp,"
		" numOutstandingContractsForCorp,"
		" numOutstandingContracts,"
		" numContractsLeft,"
		" numRequiresAttention,"
		" numRequiresAttentionCorp,"
		" numAssignedTo,"
		" numAssignedToCorp,"
		" numBiddingOn,"
		" numInProgress,"
		" numBiddingOnCorp,"
		" numInProgressCorp"
		" FROM chrcontractinfo"
		" WHERE characterID=%d", clientID))
	{
		codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return NULL;
	}

	if(!res.GetRow(row)) {
		codelog(MARKET__ERROR, "Player %u chrcontractinfo not found.", clientID);
		return NULL;
	}

	PyDict* PageInfo = new PyDict;
	PageInfo->SetItemString( "numOutstandingContractsNonCorp", new PyInt( row.GetInt( 0 ) ) );
	PageInfo->SetItemString( "numOutstandingContractsForCorp", new PyInt( row.GetInt( 1 ) ) );
	PageInfo->SetItemString( "numOutstandingContracts", new PyInt( row.GetInt( 2 ) ) );
	PageInfo->SetItemString( "numContractsLeft", new PyInt( row.GetInt( 3 ) ) );
	PageInfo->SetItemString( "numRequiresAttention", new PyInt( row.GetInt( 4 ) ) );
	PageInfo->SetItemString( "numRequiresAttentionCorp", new PyInt( row.GetInt( 5 ) ) );
	PageInfo->SetItemString( "numAssignedTo", new PyInt( row.GetInt( 6 ) ) );
	PageInfo->SetItemString( "numAssignedToCorp", new PyInt( row.GetInt( 7 ) ) );
	PageInfo->SetItemString( "numBiddingOn", new PyInt( row.GetInt( 8 ) ) );
	PageInfo->SetItemString( "numInProgress", new PyInt( row.GetInt( 9 ) ) );
	PageInfo->SetItemString( "numBiddingOnCorp", new PyInt( row.GetInt( 10 ) ) );
	PageInfo->SetItemString( "numInProgressCorp", new PyInt( row.GetInt( 11 ) ) );
	return PageInfo;
}
Exemple #29
0
bool ServiceDB::DoLogin( const char* login, const char* pass, uint32& accountID, uint32& role )
{
    if( pass[0] == '\0' )
    {
        sLog.Error( "ServiceDB", "Empty password not allowed ('%s').", login );
        return false;
    }

    if( !sDatabase.IsSafeString( login ) || !sDatabase.IsSafeString( pass ) )
    {
        sLog.Error( "ServiceDB", "Invalid characters in login or password." );
        return false;
    }
    
    DBQueryResult res;
    if( !sDatabase.RunQuery( res,
        "SELECT accountID, role, password, PASSWORD( '%s' ), MD5( '%s' ), online, banned"
        " FROM account"
        " WHERE accountName = '%s'",
        pass, pass, login ) )
    {
        sLog.Error( "ServiceDB", "Error in query: %s.", res.error.c_str() );
        return false;
    }

    DBResultRow row;
    if( res.GetRow( row ) )
    {
        if( 0 != row.GetInt( 5 ) )
        {
            sLog.Error( "ServiceDB", "Account '%s' already logged in.", login );
            return false;
        }
		if( 0 != row.GetInt( 6 ) )
		{
			sLog.Error( "ServiceDB", "Account '%s' has been banned from the server.", login);
			return false;
		}

        const std::string dbPass = row.GetText( 2 );

        if( dbPass != pass
            && dbPass != row.GetText( 3 )
            && dbPass != row.GetText( 4 ) )
        {
            sLog.Error( "ServiceDB", "Login failed for account '%s'.", login );
            return false;
        }

        accountID = row.GetUInt( 0 );
        role = row.GetUInt( 1 );

        return true;
    }
    else if( 0 == sConfig.account.autoAccountRole )
    {
        // autoAccount disabled

        sLog.Error( "ServiceDB", "Unknown account '%s'.", login );
        return false;
    }
    else
    {
        // autoAccount enabled, try to create a new account

        sLog.Log( "ServiceDB", "Creating a new account '%s' with role %u.", login, sConfig.account.autoAccountRole );

        accountID = CreateNewAccount( login, pass, sConfig.account.autoAccountRole );
        if( 0 == accountID )
        {
            sLog.Error( "ServiceDB", "Failed to create a new account." );
            return false;
        }

        role = sConfig.account.autoAccountRole;

        return true;
    }
}
Exemple #30
0
PyRep *MarketDB::CreateContract( uint32 characterID, uint32 characterCorpID, uint32 type, uint32 avail, uint32 assigneeID, uint32 expiretime, uint32 duration, uint32 startStationID, uint32 endStationID, uint32 startSolarSystemID, uint32 endSolarSystemID, uint32 startRegionID, uint32 endRegionID, uint32 price, uint32 reward, uint32 collateral, std::string title, std::string description/*, std::vector<int32> itemsID, std::vector<int32> quantity, uint32 flag, std::vector<int32> requestItemID, std::vector<int32> requestItemQuantity*/, bool forCorp )
{
	DBerror err;
	DBQueryResult res;
	DBResultRow row;
	uint32 contractID = 0;
	uint64 timeNow = Win32TimeNow();
	uint64 timeExpired = Win32TimeNow() + ((expiretime / 60) * Win32Time_Hour);
	uint8 numDays = ((expiretime / 60) * Win32Time_Hour) / Win32Time_Day ;

	if(endStationID == 0)endStationID = startStationID;
	if(!sDatabase.RunQuery(res,
		"SELECT solarSystemID, regionID"
		" FROM stastations"
		" WHERE stationID=%d", endStationID))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return NULL;
	}

	if( !res.GetRow(row) )
	{
		codelog(MARKET__ERROR, "StationID %u not found", endStationID);
		return NULL;
	}
	endSolarSystemID = row.GetInt( 0 );
	endRegionID = row.GetInt( 1 );

	if(assigneeID == 0)assigneeID = characterID;

	if(!sDatabase.RunQueryLID(err, contractID,
		"INSERT INTO"
		" contract("
		" contractID,"
		" issuerID,"
		" issuerCorpID,"
		" type,"
		" avail,"
		" assigneeID,"
		" expiretime,"
		" duration,"
		" startStationID,"
		" endStationID,"
		" startSolarSystemID,"
		" endSolarSystemID,"
		" startRegionID,"
		" endRegionID,"
		" price,"
		" reward,"
		" collateral,"
		" title,"
		" description,"
		" forCorp,"
		" status,"
		" isAccepted,"
		" acceptorID,"
		" dateIssued,"
		" dateExpired,"
		" dateAccepted,"
		" dateCompleted,"
		" volume" // This should be the volume of all the items
		")VALUES("
		"NULL, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, '%s', '%s', %u, 0, false, NULL, " I64u ", " I64u ", NULL, " I64u ", 0)",
		characterID, characterCorpID, type, avail, assigneeID, expiretime, numDays, startStationID, endStationID, startSolarSystemID, 
		endSolarSystemID, startRegionID, endRegionID, price, reward, collateral, "contract title", "contract description", forCorp, timeNow, timeExpired, timeExpired))
	{
		codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
		return NULL;
	}

	if(!forCorp)
	{
		if(!sDatabase.RunQuery(err, 
			"UPDATE"
			" chrcontractinfo"
			" SET numOutStandingContractsNonCorp=numOutStandingContractsNonCorp+1,"
			" numOutstandingContracts=numOutstandingContracts+1"
			" WHERE characterID=%d", characterID))
		{
			codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
			return NULL;
		}
	}else{
		if(!sDatabase.RunQuery(err, 
			"UPDATE"
			" chrcontractinfo"
			" SET numOutStandingContractsForCorp=numOutStandingContractsForCorp+1,"
			" numOutstandingContracts=numOutstandingContracts+1"
			" WHERE characterID=%d", characterID))
		{
			codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
			return NULL;
		}
	}
	/*uint32 max = itemsID.capacity();
	uint32 i = 0;
	for(i = 0; i <= max; i++)
	{
		if(!sDatabase.RunQuery(err,
			"INSERT INTO contracts_items("
			" itemID,"
			" contractID,"
			" characterID,"
			" quantity,"
			" flag,"
			" get"
			") VALUES("
			" %d, %d, %d, %d, 4, false)",
			itemsID.at(i), contractID, characterID, quantity.at(i)
			))
		{
			codelog(MARKET__ERROR, "Error in query: %s", res.c_str() );
			return NULL;
		}
	}
	max = requestItemID.capacity();
	for(i = 0; i <= max; i++)
	{
		if(!sDatabase.RunQuery(err,
			"INSERT INTO contracts_items("
			" itemID,"
			" contractID,"
			" characterID,"
			" quantity,"
			" flag,"
			" get"
			") VALUES("
			" %d, %d, %d, %d, 4, true)",
			requestItemID.at(i), contractID, characterID, requestItemQuantity.at(i)
			))
		{
			codelog(MARKET__ERROR, "Error in query: %s", res.c_str() );
			return NULL;
		}
	}*/
	return new PyInt( contractID );
}