PyObject *DBResultToIndexRowset(DBQueryResult &result, uint32 key_index) { uint32 cc = result.ColumnCount(); //start building the IndexRowset PyDict *args = new PyDict(); PyObject *res = new PyObject( "util.IndexRowset", args ); if(cc == 0 || cc < key_index) return res; //list off the column names: PyList *header = new PyList(cc); args->SetItemString("header", header); for(uint32 i = 0; i < cc; i++) header->SetItemString(i, result.ColumnName(i)); //RowClass: args->SetItemString("RowClass", new PyToken("util.Row")); //idName: args->SetItemString("idName", new PyString( result.ColumnName(key_index) )); //items: PyDict *items = new PyDict(); args->SetItemString("items", items); //add a line entry for each result row: DBResultRow row; while(result.GetRow(row)) { PyRep *key = DBColumnToPyRep(row, key_index); PyList *line = new PyList(cc); for(uint32 i = 0; i < cc; i++) line->SetItem(i, DBColumnToPyRep(row, i)); items->SetItem(key, line); } return res; }
PyRep *SearchDB::Query(std::string match, std::vector<int> *searchID) { DBQueryResult res; DBResultRow row; std::string id; uint32 i,size; std::string equal = ""; std::string matchEsc = ""; // Find out if search is exact or not and remove the trailing '*' std::size_t found=match.find('*'); if (found!=std::string::npos) { match.erase (std::remove(match.begin(), match.end(), '*'), match.end()); equal = " RLIKE "; } else { equal = " = "; } // Escape the searchString sDatabase.DoEscapeString(matchEsc, match.c_str()); // The client wants a dict in return // [searchID][Results] PyDict *dict = new PyDict(); size = searchID->size(); for(i=0; i<size; i++){ switch(searchID->at(i)) { case 1: //searchResultAgent = 1 sDatabase.RunQuery(res, "SELECT" " itemID AS agentID" " FROM entity" " WHERE itemName %s '%s' " " AND itemID BETWEEN 2999999 AND 4000000 " " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() ); break; case 2: //searchResultCharacter = 2 sDatabase.RunQuery(res, "SELECT" " itemID" " FROM entity" " WHERE itemName %s '%s' " " AND itemId >= %u" " AND ownerID = 1",equal.c_str(), matchEsc.c_str(),EVEMU_MINIMUM_ID ); break; case 3: //searchResultCorporation = 3 sDatabase.RunQuery(res, "SELECT" " corporationID" " FROM corporation" " WHERE corporationName %s '%s' " " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() ); break; case 4: //searchResultAlliance = 4 sDatabase.RunQuery(res, "SELECT allianceID" " FROM alliance_ShortNames" " WHERE shortName %s '%s'" " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() ); break; case 5: //searchResultFaction = 5 sDatabase.RunQuery(res, "SELECT factionID" " FROM chrFactions" " WHERE factionName %S '%s' " " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() ); break; case 6: //searchResultConstellation = 6 sDatabase.RunQuery(res, "SELECT" " constellationID" " FROM mapConstellations" " WHERE constellationName %s '%s' " " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() ); break; case 7: //searchResultSolarSystem = 7 sDatabase.RunQuery(res, "SELECT " " solarSystemID" " FROM mapSolarSystems" " WHERE solarSystemName %s '%s' " " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() ); break; case 8: //searchResultRegion = 8 sDatabase.RunQuery(res, "SELECT " " regionID" " FROM mapRegions" " WHERE regionName %s '%s' " " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() ); break; case 9: //searchResultStation = 9 sDatabase.RunQuery(res, "SELECT " " stationID" " FROM staStations " " WHERE stationName %s '%s' " " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() ); break; case 10: //searchResultInventoryType = 10 sDatabase.RunQuery(res, "SELECT" " typeID" " FROM entity" " WHERE itemName %s '%s'", equal.c_str(), matchEsc.c_str() ); break; } dict->SetItem(new PyInt(searchID->at(i)),DBResultToIntIntDict(res)); res.Reset(); } return dict; }
PyResult ContractMgrService::Handle_CollectMyPageInfo( PyCallArgs& call ) { PyDict* ret = new PyDict; uint32 numOutstandingContractsNonCorp = 0; uint32 numOutstandingContractsForCorp = 0; uint32 numContractsLeft = 0; uint32 numRequiresAttention = 0; uint32 numRequiresAttentionCorp = 0; uint32 numAssignedTo = 0; uint32 numAssignedToCorp = 0; uint32 numBiddingOn = 0; uint32 numInProgress = 0; uint32 numBiddingOnCorp = 0; uint32 numInProgressCorp = 0; std::map<uint32, ContractRef>::const_iterator cur, end; std::map<uint32, ContractRef> contracts = m_contractManager->GetContractList(); cur = contracts.begin(); end = contracts.end(); for(; cur != end; cur++ ) { ContractRef contract = cur->second; if( contract->issuerID() == call.client->GetCharacterID() ) { if( contract->forCorp() == true ) { if( contract->requiresAttention() ) numRequiresAttentionCorp += 1; if( contract->assigneeID() ) numAssignedToCorp += 1; if( contract->status() == conStatusInProgress ) numInProgressCorp += 1; numOutstandingContractsForCorp += 1; }else{ if( contract->requiresAttention() ) numRequiresAttention += 1; if( contract->assigneeID() ) numAssignedTo += 1; if( contract->status() == conStatusInProgress ) numInProgress += 1; numOutstandingContractsNonCorp += 1; } } } ret->SetItemString( "numOutstandingContractsNonCorp", new PyInt( numOutstandingContractsNonCorp ) ); ret->SetItemString( "numOutstandingContractsForCorp", new PyInt( numOutstandingContractsForCorp ) ); ret->SetItemString( "numOutstandingContracts", new PyInt( numOutstandingContractsNonCorp + numOutstandingContractsForCorp ) ); ret->SetItemString( "numContractsLeft", new PyInt( numContractsLeft ) ); ret->SetItemString( "numRequiresAttention", new PyInt( numRequiresAttention ) ); ret->SetItemString( "numRequiresAttentionCorp", new PyInt( numRequiresAttentionCorp ) ); ret->SetItemString( "numAssignedTo", new PyInt( numAssignedTo ) ); ret->SetItemString( "numAssignedToCorp", new PyInt( numAssignedToCorp ) ); ret->SetItemString( "numBiddingOn", new PyInt( numBiddingOn ) ); ret->SetItemString( "numInProgress", new PyInt( numInProgress ) ); ret->SetItemString( "numBiddingOnCorp", new PyInt( numBiddingOnCorp ) ); ret->SetItemString( "numInProgressCorp", new PyInt( numInProgressCorp ) ); return new PyObject( new PyString( "util.KeyVal" ), ret ); }
//this is a big hack just to document the kind of stuff a dungeon conveys. PyDict *SystemDungeonEntranceEntity::MakeSlimItem() const { PyDict *slim = ItemSystemEntity::MakeSlimItem(); if(slim == NULL) return NULL; //slim->SetItemString("itemID", new PyInt(2100000396)); //slim->SetItemString("typeID", new PyInt(12273)); //slim->SetItemString("ownerID", new PyInt(500021)); slim->SetItemString("dunSkillLevel", new PyInt(0)); slim->SetItemString("dunSkillTypeID", new PyNone); slim->SetItemString("dunObjectID", new PyInt(160449)); slim->SetItemString("dunWipeNPC", new PyInt(1)); slim->SetItemString("dunToGateID", new PyInt(160484)); slim->SetItemString("dunCloaked", new PyInt(0)); slim->SetItemString("dunScenarioID", new PyInt(23)); slim->SetItemString("dunSpawnID", new PyInt(4)); slim->SetItemString("dunAmount", new PyFloat(0.0)); slim->SetItemString("dunShipClasses", new PyList(/*237, 31*/)); slim->SetItemString("dunDirection", new PyList(/*235, 0, 1*/)); slim->SetItemString("dunKeyLock", new PyInt(0)); //slim->SetItemString("dunKeyQuantity", new PyInt(1)); //slim->SetItemString("dunKeyTypeID", new PyInt(21839)); //slim->SetItemString("dunOpenUntil", new PyInt(Win32TimeNow()+Win32Time_Hour)); slim->SetItemString("dunMusicUrl", new PyString("res:/Sound/Music/Ambient031combat.ogg")); return(slim); }
//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 ); }
bool MiningLaser::endCycle(bool continuing) { // Check to see if our target is still in this bubble or has left or been destroyed: if( m_ship->GetOperator()->GetSystemEntity()->Bubble()->GetEntity(m_targetID) == nullptr ) { // Target has left our bubble or been destroyed, deactivate this module: return false; } if (m_ship->GetOperator()->GetSystemEntity()->targets.getTarget(m_targetID, true) == nullptr) { // Target no longer targeted. return false; } // Check range double maxRange = m_item->GetAttribute(AttrMaxRange).get_float(); double targetRange = m_targetEntity->DistanceTo2(m_ship->GetOperator()->GetSystemEntity()); targetRange = std::sqrt(targetRange); targetRange -= m_targetEntity->GetRadius(); if (targetRange > maxRange) { // We must have drifted out of range. // TO-DO: send proper out or range response. SysLog::Error("MiningLaser::Activate()", "ERROR: mining laser target moved out of range!"); return false; } // Retrieve ore from target Asteroid and put into flagCargoHold InventoryItemRef asteroidRef = m_targetEntity->Item(); uint32 remainingOreUnits = asteroidRef->GetAttribute(AttrQuantity).get_int(); double oreUnitVolume = asteroidRef->GetAttribute(AttrVolume).get_float(); // Calculate how many units of ore to pull from the asteroid on this cycle: // Get base mining amount. double oreUnitsToPull = m_item->GetAttribute(AttrMiningAmount).get_float() / oreUnitVolume; // Do we have a crystal? if( m_chargeRef ) { // Yes, apply yield multiplier. if (m_chargeRef->HasAttribute(AttrSpecialisationAsteroidYieldMultiplier)) { // TO-DO: check for correct type of crystal. oreUnitsToPull *= m_chargeRef->GetAttribute(AttrSpecialisationAsteroidYieldMultiplier).get_float(); } // TO-DO: do crystal damage. } // Get percent cycle complete. double cycleTime = getTotalCycleTimeMS(); double percent = 1.0; // Assume full cycle if timer disabled. if(cycleTime != -1) { double usedTime = getElapsedCycleTimeMS(); percent = usedTime / cycleTime; // Limit to range 0.0 - 1.0. percent = std::min(1.0, std::max(0.0, percent)); if(percent == 0.0) { percent = 1.0; } } // Round down to next lowest integer value. oreUnitsToPull = floor(oreUnitsToPull * percent); // Limit to units remaining in asteroid. oreUnitsToPull = std::min(oreUnitsToPull, (double) remainingOreUnits); // Find what cargo hold to use. EVEItemFlags cargoFlag = flagCargoHold; // Check for specialized cargo hold. if (m_ship->HasAttribute(AttrSpecialOreHoldCapacity)) { // We have a specialized ore hold all or goes here. cargoFlag = flagSpecializedOreHold; } // Get cargo hold and remaining capacity. double remainingCargoVolume = m_ship->GetRemainingVolumeByFlag(cargoFlag); // Do we have enough room for the whole stack? if (remainingCargoVolume < (floor((oreUnitsToPull * oreUnitVolume) * 100.0)/100.0)) { // No, Do we have room for at least one unit? if (remainingCargoVolume < oreUnitVolume) { // No, Send cargo full message. PyDict *dict = new PyDict(); PyTuple *tuple = new PyTuple(2); tuple->SetItem(0, new PyInt(MOD_ACTIVATED)); //???? what is this really? tuple->SetItem(1, new PyInt(m_item->typeID())); dict->SetItem(new PyString("modulename"), tuple); PyTuple *error = new PyTuple(2); error->SetItem(0, new PyString("MiningDronesDeactivatedCargoHoldNowFull")); error->SetItem(1, dict); m_error = error; return false; } // Yes, reduce the stack size. oreUnitsToPull = floor(remainingCargoVolume / oreUnitVolume); } // Are we actually pulling anything? if (oreUnitsToPull <= 0.0) { // No, hmmm... thats bad! // TO-DO: send client miner deactivated because hold full message. SysLog::Warning("MiningLaser::DoCycle()", "Somehow MiningLaser could not extract ore from current target asteroid '%s' (id %u)", m_targetEntity->Item()->itemName().c_str(), m_targetEntity->GetID()); checkAsteroidDepleted(remainingOreUnits); return false; } // Check for an existing ore item in the cargo. InventoryItemRef existing = m_ship->GetByTypeFlag(asteroidRef->typeID(), cargoFlag); if (existing.get() != nullptr) { // We have an existing ore sample, add to it. m_ship->AlterCargoQty(existing, oreUnitsToPull); } else { // No existing ore sample, create one. ItemData idata( asteroidRef->typeID(), m_ship->ownerID(), 0, //temp location cargoFlag, oreUnitsToPull ); InventoryItemRef ore = ItemFactory::SpawnItem(idata); if (ore) { m_ship->AddItem(cargoFlag, ore); } else { SysLog::Error("MiningLaser::DoCycle()", "ERROR: Could not create ore stack for '%s' ship (id %u)!", m_ship->itemName().c_str(), m_ship->itemID()); return false; } } // Finally, reduce the amount of ore in the asteroid by how much we took out: remainingOreUnits -= oreUnitsToPull; asteroidRef->SetAttribute(AttrQuantity, remainingOreUnits); // Check to see is ship is full or asteroid depleted. remainingCargoVolume = m_ship->GetRemainingVolumeByFlag(cargoFlag); if ((remainingCargoVolume < oreUnitVolume) || remainingOreUnits == 0) { // Asteroid is empty OR cargo hold is entirely full, either way, DEACTIVATE module immediately! checkAsteroidDepleted(remainingOreUnits); return false; } return true; }
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; }
PyDict *SystemStargateEntity::MakeSlimItem() const { PyDict *slim = SystemStationEntity::MakeSlimItem(); if(m_jumps != NULL) slim->SetItemString("jumps", m_jumps->Clone()); return(slim); }