PyObject *CharacterDB::GetCharPublicInfo3(uint32 characterID) {

    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
                           "SELECT "
                           " character_.bounty,"
                           " character_.title,"
                           " character_.startDateTime,"
                           " character_.description,"
                           " character_.corporationID"
                           " FROM character_"
                           " WHERE characterID=%u", characterID))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

    return DBResultToRowset(res);
}
uint32 CharacterDB::AddOwnerNote(uint32 charID, const std::string & label, const std::string & content) {
    DBerror err;
    uint32 id;

    std::string lblS;
    sDatabase.DoEscapeString(lblS, label);

    std::string contS;
    sDatabase.DoEscapeString(contS, content);

    if (!sDatabase.RunQueryLID(err, id,
                               "INSERT INTO chrOwnerNote (ownerID, label, note) VALUES (%u, '%s', '%s');",
                               charID, lblS.c_str(), contS.c_str()))
    {
        codelog(SERVICE__ERROR, "Error on query: %s", err.c_str());
        return 0;
    }

    return id;
}
// Should probably make this function more generic once we know how the Args to CharMgrBound::Handle_ListStations work
PyRep *CharacterDB::GetCharStations(uint32 charID) {
    DBQueryResult res;

    //Query returns StationID, ItemCount
    if(!sDatabase.RunQuery(res,
                           " SELECT stationID, count(stationID) as itemCount "
                           " FROM ( "
                           "	SELECT stationID, locationID "
                           "	FROM entity, stastations "
                           "	WHERE entity.locationID = stastations.stationID "
                           "		and ownerID = %u "
                           " ) as a "
                           " GROUP BY stationID ", charID))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

    return DBResultToRowset(res);
}
Beispiel #4
0
PyRep *MarketDB::GetContractBids( uint32 contractID )
{
	DBQueryResult res;
	bool success = false;

	if(contractID == NULL)
	{
		success = sDatabase.RunQuery(res,"SELECT bidID, contractID, issuerID, quantity, issuerCorpID, issuerStationID, issuerSolarSystemID, issuerRegionID FROM contract_bids", contractID);
	}else{
		success = sDatabase.RunQuery(res,"SELECT bidID, contractID, issuerID, quantity, issuerCorpID, issuerStationID, issuerSolarSystemID, issuerRegionID FROM contract_bids WHERE contractID=%u", contractID);
	}

	if(!success)
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return NULL;
	}

	return DBResultToRowset( res );
}
Beispiel #5
0
PyRep *MarketDB::GetContractList(  )
{
	// Dont care about anything at the moment, more packet stuff needed first, so return the whole list!
	DBQueryResult res;
	if(!sDatabase.RunQuery(res,
		"SELECT"
		" contractID,"
		" issuerID,"
		" issuerCorpID,"
		" type,"
		" avail AS availability,"
		" assigneeID,"
		" expiretime,"
		" duration AS numDays,"
		" startStationID,"
		" endStationID,"
		" startSolarSystemID,"
		" endSolarSystemID,"
		" startRegionID,"
		" endRegionID,"
		" price,"
		" reward,"
		" collateral,"
		" title,"
		" description,"
		" forCorp,"
		" status,"
		" isAccepted,"
		" acceptorID,"
		" dateIssued,"
		" dateExpired,"
		" dateAccepted,"
		" dateCompleted,"
		" volume"
		" FROM contract") )
	{
		codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return NULL;
	}
	return DBResultToRowset( res );
}
Beispiel #6
0
PyRep *MarketDB::GetContractListForOwner( uint32 characterID, bool isAccepted, uint32 status, uint32 contractType, uint32 issuerCorpID )
{
	DBQueryResult res;
	if(!sDatabase.RunQuery(res,
		"SELECT"
		" contractID,"
		" issuerID,"
		" issuerCorpID,"
		" type,"
		" avail AS availability,"
		" assigneeID,"
		" expiretime,"
		" duration AS numDays,"
		" startStationID,"
		" endStationID,"
		" startSolarSystemID,"
		" endSolarSystemID,"
		" startRegionID,"
		" endRegionID,"
		" price,"
		" reward,"
		" collateral,"
		" title,"
		" description,"
		" forCorp,"
		" status,"
		" isAccepted,"
		" acceptorID,"
		" dateIssued,"
		" dateExpired,"
		" dateAccepted,"
		" dateCompleted,"
		" volume"
		" FROM contract"
		" WHERE issuerID=%d", characterID) )
	{
		codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return NULL;
	}
	return DBResultToRowset( res );
}
Beispiel #7
0
PyRep *MarketDB::GetRegionBest(uint32 regionID) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT"
        "    typeID, MIN(price) AS price, volRemaining, stationID "
        " FROM market_orders "
        " WHERE regionID=%u AND bid=%d"
        //" WHERE regionID=%u"
        " GROUP BY typeID", regionID, TransactionTypeSell))
    {
        codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

    //NOTE: this SHOULD return a crazy dbutil.RowDict object which is
    //made up of packed blue.DBRow objects, but we do not understand
    //the marshalling of those well enough right now, and this object
    //provides the same interface. It is significantly bigger on the wire though.
    return(DBResultToIndexRowset(res, "typeID"));
}
Beispiel #8
0
PyRep *ConfigDB::GetMultiInvTypesEx(const std::vector<int32> &entityIDs) {

    std::string ids;
    ListToINString(entityIDs, ids, "-1");

    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT"
        "   typeID,groupID,typeName,description,graphicID,radius,"
        "   mass,volume,capacity,portionSize,raceID,basePrice,"
        "   published,marketGroupID,chanceOfDuplicating "
        " FROM invTypes "
        " WHERE typeID in (%s)", ids.c_str()))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

    return(DBResultToRowList(res));
}
Beispiel #9
0
PyRep *MarketDB::GetTransactions(uint32 characterID, uint32 typeID, uint32 quantity, double minPrice, double maxPrice, uint64 fromDate, int buySell)
{
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT"
        " transactionID,transactionDateTime,typeID,quantity,price,transactionType,"
        " 0 AS corpTransaction,clientID,stationID"
        " FROM market_transactions "
        " WHERE clientID=%u AND (typeID=%u OR 0=%u) AND"
        " quantity>=%u AND price>=%f AND (price<=%f OR 0=%f) AND"
        " transactionDateTime>=%" PRIu64 " AND (transactionType=%d OR -1=%d)",
        characterID, typeID, typeID, quantity, minPrice, maxPrice, maxPrice, fromDate, buySell, buySell))
    {
        codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );

        return NULL;
    }

    return DBResultToRowset(res);
}
Beispiel #10
0
PyRep *ConfigDB::GetMultiCorpTickerNamesEx(const std::vector<int32> &entityIDs) {

    std::string ids;
    ListToINString(entityIDs, ids, "-1");

    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT "
        "   corporationID, tickerName, "
        "   shape1, shape2, shape3,"
        "   color1, color2, color3 "
        " FROM corporation "
        " WHERE corporationID in (%s)", ids.c_str()))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

    return(DBResultToRowList(res));
}
PyObject *CharacterDB::GetCharacterAppearance(uint32 charID) {
	DBQueryResult res;
	
	if(!sDatabase.RunQuery(res,
		"SELECT "
		" accessoryID,beardID,costumeID,decoID,eyebrowsID,eyesID,hairID,"
		" lipstickID,makeupID,skinID,backgroundID,lightID,"
		" headRotation1,headRotation2,headRotation3,eyeRotation1,"
		" eyeRotation2,eyeRotation3,camPos1,camPos2,camPos3,"
		" morph1e,morph1n,morph1s,morph1w,morph2e,morph2n,"
		" morph2s,morph2w,morph3e,morph3n,morph3s,morph3w,"
		" morph4e,morph4n,morph4s,morph4w"
		" FROM character_ "
		" WHERE characterID=%u", charID))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}

	return DBResultToRowset(res);
}
Beispiel #12
0
// Function: Query 'channels' table for a list of all channelIDs and traverse that list from the beginning to find
// the first gap in consecutive channelIDs and return the value for the first number in that gap.
uint32 LSCDB::GetNextAvailableChannelID()
{
	DBQueryResult res;

    // Query the 'channels' table to get a list of all channel IDs.
    // NOTE: For large servers, this is inefficient and as everything in this file should be using
    // the cached object system rather than touching the database, this query could cause large server slow-down
    // if there is a very large number of existing channels in the database.
	if( !sDatabase.RunQuery( res,
		" SELECT "
		"	channelID "
		" FROM channels "
		" WHERE channelID >= %u ", LSCService::BASE_CHANNEL_ID ))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return 0;
	}

	uint32 currentChannelID = LSCService::BASE_CHANNEL_ID;

	// Traverse through the rows in the query result until the first gap is found
	// and return the value that would be first (or only one) in the gap as the next
	// free channel ID:
	DBResultRow row;
	while( res.GetRow(row) )
	{
        const uint32 channelID = row.GetUInt( 0 );

        if( currentChannelID < channelID )
            return currentChannelID;

        ++currentChannelID;
	}

        // Check to make sure that the next available channelID is not equal to the Maximum channel ID value
	if( currentChannelID <= LSCService::MAX_CHANNEL_ID )
        return currentChannelID;
	else
        return 0;	// No free channel IDs found (this should never happen as there are way too many IDs to exhaust)
}
Beispiel #13
0
PyResult ShipDB::GetInsuranceContractsByOwnerID(uint32 ownerID)
{
	DBQueryResult res;
	if(!sDatabase.RunQuery(res,
		"SELECT "
		"  i.shipID, "
		"  i.startDate, "
		"  i.endDate, "
		"  i.fraction "
		"FROM "
		"  insurance i LEFT JOIN entity e ON i.shipID=e.itemID "
		"WHERE "
		"  e.ownerID=%d",
		ownerID
		))
	{
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return new PyNone;
	}

	return(DBResultToCRowset(res));
}
Beispiel #14
0
void NPC::_AwardBounty(SystemEntity *who) {
	//double bounty = m_self->entityKillBounty();
    double bounty = m_self->GetAttribute(AttrEntityKillBounty).get_float();
	if(bounty <= 0) {
		return;	//no bounty to award...
	}
	
	//TODO: handle case where drone strikes fatal blow... bounty goes to master.

	//TODO: handle distribution to gangs.
	
	if(who->IsClient() == false) {
		_log(NPC__TRACE, "Refusing to award bounty on %u to non-client %u", GetID(), who->GetID());
		return;	//bounty doesn't make sense for anything other than clients.
	}

	Client *killer = who->CastToClient();

	killer->AddBalance(bounty);

	std::string reason = "Bounty";	//TODO: improve this.
	
	if(!m_services.serviceDB().GiveCash(
			killer->GetID(),
			RefType_playerDonation,	//TODO: find the proper type
			m_self->itemID(),	//probably actually a special concord item ID or something.
			killer->GetID(),
			"",	//unknown const char *argID1,
			killer->GetAccountID(),
			accountCash,
			bounty,
			killer->GetBalance(),
			reason.c_str()
	)) {
		codelog(CLIENT__ERROR, "%s: Failed to record bountry of %f from death of %u (type %u)", killer->GetName(), bounty, GetID(), m_self->typeID());
		//well.. this isnt a huge deal, so we will get over it.
	}
	
}
Beispiel #15
0
// Function: Return true or false result for the check of whether or not the specified
// channelID is available to be taken for a new channel's channelID.
bool LSCDB::IsChannelIDAvailable(uint32 channelID)
{
	DBQueryResult res;

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

	DBResultRow row;

    // Return true (this channelID not in use) if there are no rows returned by the query:
	if (!(res.GetRow(row)))
		return true;
	else
		return false;
}
Beispiel #16
0
bool CharacterDB::AddCharacterContractInfo( uint32 characterID )
{
	DBerror res;
	if(!sDatabase.RunQuery(res,
		"INSERT INTO chrcontractinfo ("
		"characterID,"
		" numOutstandingContractsNonCorp,"
		" numOutstandingContractsForCorp,"
		" numOutstandingContracts,"
		" numContractsLeft,"
		" numRequiresAttention,"
		" numRequiresAttentionCorp,"
		" numAssignedTo,"
		" numAssignedToCorp,"
		" numBiddingOn,"
		" numInProgress,"
		" numBiddingOnCorp,"
		" numInProgressCorp"
		") VALUES("
		"%d,"
		"0,"
		"0,"
		"0,"
		"0,"
		"0,"
		"0,"
		"0,"
		"0,"
		"0,"
		"0,"
		"0,"
		"0)", characterID ))
	{
		codelog( SERVICE__ERROR, "Error in query for %s", res.c_str() );
		return false;
	}
	return true;
}
PyObject *CharacterDB::GetCharPublicInfo(uint32 characterID) {
	DBQueryResult res;

	if(!sDatabase.RunQuery(res,
		"SELECT "
		" entity.typeID,"
		" character_.corporationID,"
        " chrBloodlines.raceID,"
		" bloodlineTypes.bloodlineID,"
		" character_.ancestryID,"
		" character_.careerID,"
		" character_.schoolID,"
		" character_.careerSpecialityID,"
		" entity.itemName AS characterName,"
		" 0 as age,"	//hack
		" character_.createDateTime,"
		" character_.gender,"
		" character_.characterID,"
		" character_.description,"
		" character_.corporationDateTime"
        " FROM character_ "
		"	LEFT JOIN entity ON characterID = itemID"
		"	LEFT JOIN bloodlineTypes USING (typeID)"
		"	LEFT JOIN chrBloodlines USING (bloodlineID)"
		" WHERE characterID=%u", characterID))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}
	
	DBResultRow row;
	if(!res.GetRow(row)) {
		_log(SERVICE__ERROR, "Error in GetCharPublicInfo query: no data for char %d", characterID);
		return NULL;
	}
	return(DBRowToKeyVal(row));
	
}
Beispiel #18
0
//helper routine for GetMarketGroups
static void _PropigateItems(std::map< int, std::set<uint32> > &types, std::map<int, int> &parentChild, std::map<int, std::set<int> > &childParent, int group) {
    std::map<int, std::set<int> >::iterator children_res;
    children_res = childParent.find(group);
    if(children_res != childParent.end()) {
        //recurse to all children first.
        std::set<int>::iterator ccur, cend;
        ccur = children_res->second.begin();
        cend = children_res->second.end();
        for(; ccur != cend; ccur++) {
            _PropigateItems(types, parentChild, childParent, *ccur);
        }
    }

    if(group == -1) {
        return;    //we are root, we have no parent
    }
    //find our parent.
    std::map<int, int>::iterator parent_res;
    parent_res = parentChild.find(group);
    if(parent_res == parentChild.end()) {
        codelog(MARKET__ERROR, "Failed to find parent group in parentChild for %d", group);
        return;    //should never happen...
    }
    int parentID = parent_res->second;
    if(parentID == -1) {
        return;    //do not propigate up to NULL, we dont need it, and it would contain ALL items..
    }

    //now propigate all our items (which now includes all children items) up to our parent.
    //find our items
    std::map< int, std::set<uint32> >::iterator self_res;
    self_res = types.find(group);
    if(self_res == types.end())
        return;    //we have nothing for this group??

    //add all of our items into parent.
    types[parentID].insert(self_res->second.begin(), self_res->second.end());
}
PyObject *CharacterDB::GetCharacterList(uint32 accountID) {
	DBQueryResult res;
	
	if(!sDatabase.RunQuery(res,
		"SELECT"
		" characterID,itemName AS characterName,0 as deletePrepareDateTime,"
		" gender,accessoryID,beardID,costumeID,decoID,eyebrowsID,eyesID,hairID,"
		" lipstickID,makeupID,skinID,backgroundID,lightID,"
		" headRotation1,headRotation2,headRotation3,eyeRotation1,"
		" eyeRotation2,eyeRotation3,camPos1,camPos2,camPos3,"
		" morph1e,morph1n,morph1s,morph1w,morph2e,morph2n,"
		" morph2s,morph2w,morph3e,morph3n,morph3s,morph3w,"
		" morph4e,morph4n,morph4s,morph4w"
		" FROM character_ "
		"	LEFT JOIN entity ON characterID = itemID"
		" WHERE accountID=%u", accountID))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}
	
	return DBResultToRowset(res);
}
PyResult MailMgrService::Handle_SyncMail(PyCallArgs &call)
{
    int firstId = 0, secondId = 0;

    if (call.tuple->size() == 2 && !call.tuple->GetItem(0)->IsNone() && !call.tuple->GetItem(1)->IsNone())
    {
        Call_TwoIntegerArgs args;
        if (!args.Decode(&call.tuple))
        {
            codelog(CLIENT__ERROR, "Failed to decode SyncMail args");
            return NULL;
        }

        // referring to a mail id range
        int firstId = args.arg1, secondId = args.arg2;
    }

    PyDict* dummy = new PyDict;
    dummy->SetItemString("oldMail", new PyNone());
    dummy->SetItemString("newMail", m_db->GetNewMail(call.client->GetCharacterID()));
    dummy->SetItemString("mailStatus", m_db->GetMailStatus(call.client->GetCharacterID()));
    return new PyObject("util.KeyVal", dummy);
}
Beispiel #21
0
// Function: Return true or false result for the check of whether or not the channel
// specified by channelID is already subscribed to by the character specified by charID.
bool LSCDB::IsChannelSubscribedByThisChar(uint32 charID, uint32 channelID)
{
	DBQueryResult res;

	if (!sDatabase.RunQuery(res, 
		" SELECT "
		"	channelID, "
		"   charID "
		" FROM channelChars "
		" WHERE channelID = %u AND charID = %u", channelID, charID ))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return false;
	}

	DBResultRow row;

    // Return false (no subscription exists) if there are no rows returned by the query:
	if (!(res.GetRow(row)))
		return false;
	else
		return true;
}
Beispiel #22
0
// Function: Return true or false result for the check of whether or not the specified
// channel 'displayName' is already being used by a channel.
bool LSCDB::IsChannelNameAvailable(std::string name)
{
	DBQueryResult res;

	// MySQL query channels table for any channel whose displayName matches "name":
	if (!sDatabase.RunQuery(res, 
		" SELECT "
		"	displayName "
		" FROM channels "
		" WHERE displayName = upper('%s')", name.c_str()))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return false;
	}

	DBResultRow row;

    // Return true (this 'displayName' not in use) if there are no rows returned by the query:
	if (!res.GetRow(row))
		return true;
	else
		return false;
}
Beispiel #23
0
PyObjectEx *ConfigDB::GetMapObjects(uint32 entityID, bool wantRegions,
    bool wantConstellations, bool wantSystems, bool wantStations)
{
    const char *key = "solarSystemID";
    if(wantRegions) {
        entityID = 3;   /* a little hackish... */
        key = "typeID";
    } else if(wantConstellations) {
        key = "regionID";
    } else if(wantSystems) {
        key = "constellationID";
    } else if(wantStations) {
        key = "solarSystemID";
    }

    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT "
        "   groupID,typeID,itemID,itemName,solarSystemID AS locationID,"
        "   orbitID,"
#ifndef WIN32
#warning hacked 'connector' field in GetMapObjects
#endif
        "   0 as connector,"
        "   x,y,z"
        " FROM mapDenormalize"
        " WHERE %s=%u", key, entityID
    ))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

    return DBResultToCRowset(res);
//    return DBResultToRowset(res);
}
Beispiel #24
0
PyObject *MarketDB::GetCorporationBills(uint32 corpID, bool payable)
{
    DBQueryResult res;
    bool success = false;

    if ( payable == true )
    {
        success = sDatabase.RunQuery(res, "SELECT billID, billTypeID, debtorID, creditorID, amount, dueDateTime, interest,"
            "externalID, paid externalID2 FROM billsPayable WHERE debtorID = %u", corpID);
    }
    else
    {
        success = sDatabase.RunQuery(res, "SELECT billID, billTypeID, debtorID, creditorID, amount, dueDateTime, interest,"
            "externalID, paid externalID2 FROM billsReceivable WHERE creditorID = %u", corpID);
    }

    if ( success == false )
    {
        codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

    return DBResultToRowset(res);
}
Beispiel #25
0
AgentLevel *MissionDB::LoadAgentLevel(uint8 level) {
	AgentLevel *result = new AgentLevel;
	
	DBQueryResult res;

	if(!sDatabase.RunQuery(res,
		"SELECT missionID,missionName,missionLevel,"
		"	agtMissions.missionTypeID,missionTypeName,"
		"	importantMission"
		" FROM agtMissions"
		"	NATURAL JOIN agtMissionTypes"
		" WHERE missionLevel=%d",
		level
	))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		delete result;
		return NULL;
	}

	std::vector<uint32> IDs;
	DBResultRow row;

	IDs.clear();
	while(res.GetRow(row)) {
		AgentMissionSpec *spec = new AgentMissionSpec;
		spec->missionID = row.GetUInt(0);
		spec->missionName = row.GetText(1);
		spec->missionLevel = row.GetUInt(2);
		spec->missionTypeID = row.GetUInt(3);
		spec->missionTypeName = row.GetText(1);
		spec->importantMission = (row.GetUInt(2)==0)?false:true;
		result->missions.push_back(spec);
	}
	
}
Beispiel #26
0
PyRep *MarketDB::GetOrders( uint32 regionID, uint32 typeID )
{
    DBQueryResult res;

    PyList* tup = new PyList();

    /*DBColumnTypeMap colmap;
    colmap["volRemaining"] = DBTYPE_R8;
    colmap["price"] = DBTYPE_CY;
    colmap["issued"] = DBTYPE_FILETIME;

    colmap["orderID"] = DBTYPE_I4;
    colmap["volEntered"] = DBTYPE_I4;
    colmap["minVolume"] = DBTYPE_I4;
    colmap["stationID"] = DBTYPE_I4;
    colmap["regionID"] = DBTYPE_I4;
    colmap["solarSystemID"] = DBTYPE_I4;
    colmap["jumps"] = DBTYPE_I4;

    colmap["duration"] = DBTYPE_I2;
    colmap["typeID"] = DBTYPE_I2;
    colmap["range"] = DBTYPE_I2;

    colmap["bid"] = DBTYPE_BOOL;

    //ordering: (painstakingly determined from packets)
    DBColumnOrdering ordering;
    ordering.push_back("price");
    ordering.push_back("volRemaining");
    ordering.push_back("issued");
    ordering.push_back("orderID");
    ordering.push_back("volEntered");
    ordering.push_back("minVolume");
    ordering.push_back("stationID");
    ordering.push_back("regionID");
    ordering.push_back("solarSystemID");
    ordering.push_back("jumps");    //not working right...
    ordering.push_back("typeID");
    ordering.push_back("range");
    ordering.push_back("duration");
    ordering.push_back("bid");*/

    //query sell orders
    //TODO: consider the `jumps` field... is it actually used? might be a pain in the ass if we need to actually populate it based on each queryier's location
    if(!sDatabase.RunQuery(res,
        "SELECT"
        "    price, volRemaining, typeID, `range`, orderID,"
        "   volEntered, minVolume, bid, issued as issueDate, duration,"
        "   stationID, regionID, solarSystemID, jumps"
        " FROM market_orders "
        " WHERE regionID=%u AND typeID=%u AND bid=%d", regionID, typeID, TransactionTypeSell))
    {
        codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );

        PyDecRef( tup );
        return NULL;
    }
    sLog.Debug("MarketDB::GetOrders", "Fetched %d sell orders for type %d", res.GetRowCount(), typeID);

    //this is wrong.
    tup->AddItem( DBResultToCRowset( res ) );

    //query buy orders
    if(!sDatabase.RunQuery(res,
        "SELECT"
        "    price, volRemaining, typeID, `range`, orderID,"
        "   volEntered, minVolume, bid, issued as issueDate, duration,"
        "   stationID, regionID, solarSystemID, jumps"
        " FROM market_orders "
        " WHERE regionID=%u AND typeID=%u AND bid=%d", regionID, typeID, TransactionTypeBuy))
    {
        codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );

        PyDecRef( tup );
        return NULL;
    }
    sLog.Debug("MarketDB::GetOrders", "Fetched %d buy orders for type %d", res.GetRowCount(), typeID);

    //this is wrong.
    tup->AddItem( DBResultToCRowset( res ) );

    return tup;
}
Beispiel #27
0
uint32 Agent::GetLoyaltyPoints(Client *who) {
	codelog(AGENT__ERROR, "Unimplemented.");
	return(0);
}
bool CorporationDB::CreateCorporationCreatePacket(Notify_OnCorporaionChanged & cc, uint32 oldCorpID, uint32 newCorpID) {
    DBQueryResult res;
    DBResultRow row;

    if (!sDatabase.RunQuery(res,
        " SELECT "
        "   corporationID,corporationName,description,tickerName,url,"
        "   taxRate,minimumJoinStanding,corporationType,hasPlayerPersonnelManager,"
        "   sendCharTerminationMessage,creatorID,ceoID,stationID,raceID,"
        "   allianceID,shares,memberCount,memberLimit,allowedMemberRaceIDs,"
        "   graphicID,shape1,shape2,shape3,color1,color2,color3,typeface,"
        "   division1,division2,division3,division4,division5,division6,"
        "   division7,deleted"
        " FROM corporation "
        " WHERE corporationID = %u ", newCorpID
        ))
    {
        codelog(SERVICE__ERROR, "Error in retrieving new corporation's data (%u)", newCorpID);
        return false;
    }

    if(!res.GetRow(row)) {
        codelog(SERVICE__ERROR, "Unable to find corporation's data (%u)", newCorpID);
        return false;
    }

    cc.allianceIDOld = new PyNone();
    cc.allowedMemberRaceIDsOld = new PyNone();
    cc.ceoIDOld = new PyNone();
    cc.color1Old = new PyNone();
    cc.color2Old = new PyNone();
    cc.color3Old = new PyNone();
    cc.corporationIDOld = new PyNone();
    cc.corporationNameOld = new PyNone();
    cc.corporationTypeOld = new PyNone();
    cc.creatorIDOld = new PyNone();
    cc.deletedOld = new PyNone();
    cc.descriptionOld = new PyNone();
    cc.division1Old = new PyNone();
    cc.division2Old = new PyNone();
    cc.division3Old = new PyNone();
    cc.division4Old = new PyNone();
    cc.division5Old = new PyNone();
    cc.division6Old = new PyNone();
    cc.division7Old = new PyNone();
    cc.graphicIDOld = new PyNone();
    cc.hasPlayerPersonnelManagerOld = new PyNone();
    cc.memberCountOld = new PyNone();
    cc.memberLimitOld = new PyNone();
    cc.minimumJoinStandingOld = new PyNone();
    cc.raceIDOld = new PyNone();
    cc.sendCharTerminationMessageOld = new PyNone();
    cc.shape1Old = new PyNone();
    cc.shape2Old = new PyNone();
    cc.shape3Old = new PyNone();
    cc.sharesOld = new PyNone();
    cc.stationIDOld = new PyNone();
    cc.taxRateOld = new PyNone();
    cc.tickerNameOld = new PyNone();
    cc.typefaceOld = new PyNone();
    cc.urlOld = new PyNone();

    cc.corporationIDNew = row.GetUInt(0);
    cc.corporationNameNew = row.GetText(1);
    cc.descriptionNew = row.GetText(2);
    cc.tickerNameNew = row.GetText(3);
    cc.urlNew = row.GetText(4);
    cc.taxRateNew = row.GetDouble(5);
    cc.minimumJoinStandingNew = row.GetDouble(6);
    cc.corporationTypeNew = row.GetUInt(7);
    cc.hasPlayerPersonnelManagerNew = row.GetUInt(8);
    cc.sendCharTerminationMessageNew = row.GetUInt(9);
    cc.creatorIDNew = row.GetUInt(10);
    cc.ceoIDNew = row.GetUInt(11);
    cc.stationIDNew = row.GetUInt(12);
    _NI(raceIDNew, 13);
    _NI(allianceIDNew, 14);
    cc.sharesNew = row.GetUInt64(15);
    cc.memberCountNew = row.GetUInt(16);
    cc.memberLimitNew = row.GetUInt(17);
    cc.allowedMemberRaceIDsNew = row.GetUInt(18);
    cc.graphicIDNew = row.GetUInt(19);
    _NI(shape1New, 20);
    _NI(shape2New, 21);
    _NI(shape3New, 22);
    _NI(color1New, 23);
    _NI(color2New, 24);
    _NI(color3New, 25);
    _NI(typefaceNew, 26);
    _NI(division1New, 27);
    _NI(division2New, 28);
    _NI(division3New, 29);
    _NI(division4New, 30);
    _NI(division5New, 31);
    _NI(division6New, 32);
    _NI(division7New, 33);
    cc.deletedNew = row.GetUInt(34);

    return true;
}
bool CorporationDB::AddCorporation(Call_AddCorporation & corpInfo, uint32 charID, uint32 stationID, uint32 & corpID) {
    DBerror err;
    corpID = 0;

    std::string cName, cDesc, cTick, cURL;
    sDatabase.DoEscapeString(cName, corpInfo.corpName);
    sDatabase.DoEscapeString(cDesc, corpInfo.description);
    sDatabase.DoEscapeString(cTick, corpInfo.corpTicker);
    sDatabase.DoEscapeString(cURL, corpInfo.url);

    //TODO: we should be able to get our race ID directly from our Client
    //object eventually, instead of pulling it from this join.
    if (!sDatabase.RunQueryLID(err, corpID,
        " INSERT INTO corporation ( "
        "   corporationName, description, tickerName, url, "
        "   taxRate, minimumJoinStanding, corporationType, hasPlayerPersonnelManager, sendCharTerminationMessage, "
        "   creatorID, ceoID, stationID, raceID, allianceID, shares, memberCount, memberLimit, "
        "   allowedMemberRaceIDs, graphicID, color1, color2, color3, shape1, shape2, shape3, "
        "   typeface "
        "   ) "
        " SELECT "
        "       '%s', '%s', '%s', '%s', "
        "       %lf, 0, 2, 0, 1, "
        "       %u, %u, %u, chrBloodlines.raceID, 0, 1000, 0, 10, "
        "       chrBloodlines.raceID, 0, %s, %s, %s, %s, %s, %s, "
        "       NULL "
        "    FROM entity "
        "       LEFT JOIN bloodlineTypes USING (typeID) "
        "       LEFT JOIN chrBloodlines USING (bloodlineID) "
        "    WHERE entity.itemID = %u ",
        cName.c_str(), cDesc.c_str(), cTick.c_str(), cURL.c_str(),
        corpInfo.taxRate,
        charID, charID, stationID,
        _IoN(corpInfo.color1).c_str(),
        _IoN(corpInfo.color2).c_str(),
        _IoN(corpInfo.color3).c_str(),
        _IoN(corpInfo.shape1).c_str(),
        _IoN(corpInfo.shape2).c_str(),
        _IoN(corpInfo.shape3).c_str(),
        charID))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
        return false;
    }

    // It has to go into the eveStaticOwners too
    // (well, not exactly there, but it has to be cached, and i don't know how
    // that works clientside...)
    // This is a temp hack to make my life easier
    if (!sDatabase.RunQuery(err,
        " REPLACE INTO eveStaticOwners (ownerID,ownerName,typeID) "
        "   VALUES (%u, '%s', 2)",
        corpID, cName.c_str()))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
        return false;
    }

    // And create a channel too
    if (!sDatabase.RunQuery(err,
        " INSERT INTO channels ("
        "   channelID, ownerID, displayName, motd, comparisonKey, "
        "   memberless, password, mailingList, cspa, temporary, "
        "   mode, subscribed, estimatedMemberCount"
        " ) VALUES ("
        "   %u, %u, '%s', '%s MOTD', '%s', "
        "   1, NULL, 0, 127, 0, "
        "   1, 1, 0"
        " )",
        corpID, corpID, cName.c_str(), cName.c_str(), cTick.c_str()
        ))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
        // This is not a serious problem either, but would be good if the channel
        // were working...
    }

    return true;
}
PyResult ContractMgrService::Handle_CreateContract( PyCallArgs& call )
{
	Call_CreateContract info;
	PyList* requestItemTypeList = new PyList;
	PyList* itemList = new PyList;
	uint32 flag = 0;
	bool forCorp = false;
	double volume = 0;
	uint32 maxCharContracts = 0;

	if( call.byname.find( "forCorp" ) != call.byname.end() )
	{
		forCorp = call.byname.find( "forCorp" )->second->AsBool()->value();
	}


	// Let's see the players limit of contracts
	CharacterRef ch = call.client->GetChar();
	
	if( forCorp )
	{
		if( ch->HasSkill( 25233 ) )
		{
			SkillRef skill = ch->GetSkill( 25233 );
			uint32 skillLevel = skill->GetAttribute( 280 ).get_int();
			maxCharContracts = ( 10 * skillLevel ) + 10;
		}
		else
		{
			maxCharContracts = 10;
		}
	}
	else
	{
		if( ch->HasSkill( 25235 ) )
		{
			SkillRef skill = ch->GetSkill( 25235 );
			uint32 skillLevel = skill->GetAttribute( 280 ).get_int();
			maxCharContracts = ( 4 * skillLevel ) + 1;
		}
		else
		{
			maxCharContracts = 1;
		}

		uint32 numOutstandingContractsNonCorp = 0;
		uint32 numOutstandingContractsForCorp = 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() ) numOutstandingContractsForCorp += 1;
				else numOutstandingContractsNonCorp += 1;
			}
		}

		if( ( forCorp ) && ( numOutstandingContractsForCorp >= maxCharContracts ) )
		{
			call.client->SendInfoModalMsg( "Your Corporation Contracting skill level only allows you to create %d public contracts for your corp/alliance", maxCharContracts );
			return new PyBool( false );
		}

		if( ( !forCorp ) && ( numOutstandingContractsNonCorp >= maxCharContracts ) )
		{
			call.client->SendInfoModalMsg( "Your Contracting skill level only allows you to create %d public contracts", maxCharContracts );
			return new PyBool( false );
		}
	}

	if( !info.Decode( &call.tuple ) )
	{
		codelog(SERVICE__ERROR, "%s: Bad arguments to CreateContract in contractMgr", call.client->GetCharacterName() );
		return NULL;
	}

	if( call.byname.find( "requestItemTypeList" ) != call.byname.end() )
	{
		requestItemTypeList = call.byname.find( "requestItemTypeList" )->second->AsList();
	}

	if( call.byname.find( "flag" ) != call.byname.end() )
	{
		flag = call.byname.find( "flag" )->second->AsInt()->value();
	}

	if( call.byname.find( "itemList" ) != call.byname.end() )
	{
		itemList = call.byname.find( "itemList" )->second->AsList();
	}

	if( info.endStationID == 0 )info.endStationID = info.startStationID;

	ContractData* cData = new ContractData(
		call.client->GetCharacterID(),
		call.client->GetCorporationID(),
		info.type,
		info.avail,
		info.assigneeID,
		info.expiretime,
		info.expiretime,
		info.startStationID,
		info.endStationID,
		call.client->GetSystemID(),
		call.client->GetSystemID(),
		call.client->GetRegionID(),
		call.client->GetRegionID(),
		info.price,
		info.reward,
		info.collateral,
		info.title,
		info.description,
		forCorp,
		conStatusOutstanding,
		false,
		0,
		Win32TimeNow(),
		Win32TimeNow() + ( info.duration * Win32Time_Day ),
		Win32TimeNow(),
		Win32TimeNow(),
		0,
		false,
		0,
		0,
		0
		);

	std::map<uint32, ContractRequestItemRef> requestItems;
	std::map<uint32, ContractGetItemsRef> items;

	uint32 itemID = 0;
	uint32 typeID = 0;

	for( size_t i = 0; i < itemList->size(); i ++ )
	{
		if( itemList->IsList() )
		{
			if( itemList->GetItem( i )->AsList()->GetItem( 0 )->IsInt() )
				itemID = itemList->GetItem( i )->AsList()->GetItem( 0 )->AsInt()->value();
			else{
				sLog.Error( "ContractMgrService", "Wrong list args" );
				break;
			}
		}

		InventoryItemRef item = m_manager->item_factory.GetItem( itemID );

		if( item == NULL )
		{
			sLog.Error( "ContractMgrService", "GetItem returned NULL" );
			break;
		}

		item->Move( call.client->GetStationID(), flagBriefcase, true );
		item->ChangeOwner( 1, true );
		items.insert( std::make_pair( itemID, ContractGetItemsRef( new ContractGetItems( itemID,  itemList->GetItem( i )->AsList()->GetItem( 1 )->AsInt()->value() ) ) ) );
	}

	if( cData->m_type == conTypeItemExchange )
	{
		for( size_t i = 0; i < requestItemTypeList->size(); i ++ )
		{
			if( itemList->IsList() )
			{
				if( requestItemTypeList->GetItem( i )->AsList()->GetItem( 0 )->IsInt() )
					typeID = requestItemTypeList->GetItem( i )->AsList()->GetItem( 0 )->AsInt()->value();
				else{
					sLog.Error( "ContractMgrService", "Wrong list args" );
					break;
				}
			}

			requestItems.insert( std::make_pair( itemID, ContractRequestItemRef( new ContractRequestItem(itemID, requestItemTypeList->GetItem( i )->AsList()->GetItem( 1 )->AsInt()->value() ) ) ) );
		}
	}

	uint32 contractID = 0;
	sLog.Debug( "ContractMgrService", "Creating contract..." );
	ContractRef _contract = ContractRef( new Contract( contractID, *cData, requestItems, items, m_manager->item_factory, *m_contractManager ) );

	contractID = m_contractManager->CreateContract( _contract );
	sLog.Debug( "ContractMgrService", "Contract created" );
	
	return new PyInt( contractID );
}