Skip to content

Commit

Permalink
Merge branch 'contracts_implementation' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
VizanArkonin authored Nov 19, 2021
2 parents 45a0653 + 02b5e58 commit 3f43c1b
Show file tree
Hide file tree
Showing 14 changed files with 832 additions and 386 deletions.
5 changes: 3 additions & 2 deletions doc/code_and_design_notes/readme
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ this will eventually contain my coding and design notes.
as i get time, i will populate this directory with everything i have.
im hoping this will help everyone trying to learn or work with evemu source

for discussions, please use the forums at https://forums.evemu.dev/ or join our discord at *put link here*
for discussions, please use the forums at https://forums.evemu.dev/ or join our discord at https://discord.gg/0vF5ux3158ulAMmU
alternate forums can be found on my server at http://eve.alasiya.net/phpBB3/

-Allan
1 April 2021
(really, not a joke)
(really, not a joke)
65 changes: 65 additions & 0 deletions sql/migrations/20211019155214-contracts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-- Add table for contracts data
-- +migrate Up
create table if not exists ctrContracts
(
contractId int auto_increment primary key,
contractType int not null,
issuerID int not null,
issuerCorpID int not null,
forCorp bit(1) default b'0' not null,
isPrivate int not null,
assigneeID int not null,
acceptorID int default 0 not null,
dateIssued bigint(20) unsigned not null,
dateExpired bigint(20) unsigned not null,
dateAccepted bigint(20) unsigned default 0 not null,
expireTimeInMinutes int not null,
duration bigint not null,
numDays int not null,
dateCompleted bigint(20) unsigned default 0 not null,
startStationID int not null,
startSolarSystemID int not null,
startRegionID int not null,
endStationID int default 0 not null,
endSolarSystemID int default 0 not null,
endRegionID int default 0 not null,
price int not null,
reward int not null,
collateral int not null,
title varchar(100) not null,
description varchar(100) not null,
status int default 0 not null,
crateID int default 0 not null,
volume decimal(16,2) default 0.00 not null,
issuerAllianceID int default 0 not null,
issuerWalletKey int default 0 not null,
acceptorWalletKey int default 0 not null,
startStationDivision int not null
);
create table if not exists ctrItems
(
contractId int not null,
itemID int not null,
quantity int not null,
itemTypeID int not null,
inCrate bit(1) default b'0' not null,
parentID int not null,
productivityLevel int default 0 not null,
materialLevel int default 0 not null,
isCopy bit(1) default b'0' not null,
licensedProductionRunsRemaining int default 0 not null,
damage int default 0 not null,
flagID int default 0 not null
);
create table if not exists ctrBids
(
contractId int not null,
amount int not null,
bidderID int not null,
bidDateTime bigint(20) unsigned not null
);

-- +migrate Down
drop table ctrContracts;
drop table ctrItems;
drop table ctrBids;
3 changes: 3 additions & 0 deletions src/eve-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ SET( packets_INCLUDE
"${TARGET_PACKETS_DIR}/packets/Calendar.h"
"${TARGET_PACKETS_DIR}/packets/Character.h"
"${TARGET_PACKETS_DIR}/packets/CorporationPkts.h"
"${TARGET_PACKETS_DIR}/packets/Contracts.h"
"${TARGET_PACKETS_DIR}/packets/Crypto.h"
"${TARGET_PACKETS_DIR}/packets/Destiny.h"
"${TARGET_PACKETS_DIR}/packets/DogmaIM.h"
Expand Down Expand Up @@ -126,6 +127,7 @@ SET( packets_SOURCE
"${TARGET_PACKETS_DIR}/packets/Calendar.cpp"
"${TARGET_PACKETS_DIR}/packets/Character.cpp"
"${TARGET_PACKETS_DIR}/packets/CorporationPkts.cpp"
"${TARGET_PACKETS_DIR}/packets/Contracts.cpp"
"${TARGET_PACKETS_DIR}/packets/Crypto.cpp"
"${TARGET_PACKETS_DIR}/packets/Destiny.cpp"
"${TARGET_PACKETS_DIR}/packets/DogmaIM.cpp"
Expand Down Expand Up @@ -158,6 +160,7 @@ SET( packets_XMLP
"${TARGET_SOURCE_DIR}/packets/Calendar.xmlp"
"${TARGET_SOURCE_DIR}/packets/Character.xmlp"
"${TARGET_SOURCE_DIR}/packets/CorporationPkts.xmlp"
"${TARGET_SOURCE_DIR}/packets/Contracts.xmlp"
"${TARGET_SOURCE_DIR}/packets/Crypto.xmlp"
"${TARGET_SOURCE_DIR}/packets/Destiny.xmlp"
"${TARGET_SOURCE_DIR}/packets/DogmaIM.xmlp"
Expand Down
23 changes: 23 additions & 0 deletions src/eve-common/database/EVEDBUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,29 @@ PyTuple *DBResultToTupleSet(DBQueryResult &result) {
return res;
}

/**
* Service function - for now used particularly as substitution of DBResultToTupleSet in case if we have multiple DB queries
* and we need to get the values from them all.
* This function extracts the values and pushes them in provided PyList. Just values, not including columns header.
* @param result - DBQueryResult object
* @param into - PyList to dump values into
*/
void populateResListWithValues(DBQueryResult &result, PyList *into) {
uint32 cc = result.ColumnCount();
if (cc == 0) {
return;
}

DBResultRow row;
uint32 r(0);
while(result.GetRow(row)) {
PyList *linedata = new PyList(cc);
for(auto index = 0; index < cc; index++)
linedata->SetItem(index, DBColumnToPyRep(row, index));
into->items.push_back(linedata);
}
}

PyObject *DBResultToIndexRowset(DBQueryResult &result, const char *key) {
uint32 cc(result.ColumnCount());
uint32 key_index(0);
Expand Down
1 change: 1 addition & 0 deletions src/eve-common/database/EVEDBUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ PyObject *DBResultToIndexRowset(DBQueryResult &result, const char *key);
PyObject *DBResultToIndexRowset(DBQueryResult &result, uint32 key_index);

PyTuple *DBResultToTupleSet(DBQueryResult &result);
void populateResListWithValues(DBQueryResult &result, PyList *into);
// 2 lists, 1-colNames, 2-PyObject "util.Row" with data in 'lines'
PyTuple *DBResultToRowList(DBQueryResult &result, const char *type = "util.Row");
PyTuple *DBResultToPackedRowListTuple(DBQueryResult &result);
Expand Down
21 changes: 21 additions & 0 deletions src/eve-common/packets/Contracts.xmlp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

<elements>

<elementDef name="Call_CreateContract">
<tupleInline>
<int name="contractType"/>
<bool name="isPrivate"/>
<int name="assigneeID" safe="true" none_marker="0"/>
<int name="expireTime"/>
<int name="duration"/>
<int name="startStationId"/>
<int name="endStationId" safe="true" none_marker="0"/>
<int name="price"/>
<int name="reward"/>
<int name="collateral"/>
<wstring name="title" safe="true"/>
<wstring name="description" safe="true"/>
</tupleInline>
</elementDef>

</elements>
31 changes: 31 additions & 0 deletions src/eve-core/utils/utils_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,37 @@ double GetFileTimeNow() // -allan
return time;
}

/**
* Returns a FileTime stamp, with specified amount of time added/subtracted to/from it.
* Positive arguments will add given amount of time. Negative values will subtract it.
* @param days : Days to add/subtract
* @param hours : Hours to add/subtract
* @param minutes: Minutes to add/subtract
* @param seconds: Seconds to add/subtract
* @return FileTime value.
*/
double GetRelativeFileTime(int days, int hours, int minutes, int seconds) {
double time = GetTimeMSeconds();

time /= 1000; // to second
if (days != 0) {
time += (days * 86400);
}
if (hours != 0) {
time += (hours * 3600);
}
if (minutes != 0) {
time += (minutes * 60);
}
if (seconds != 0) {
time += seconds;
}

time += SECS_BETWEEN_EPOCHS; // offset
time *= EvE::Time::Second; // to 100 uSeconds
return time;
}

// NOTE auto and std::chrono require C++11
int64 GetSteadyTime() { // -allan
// simulation of Windows GetTickCount()
Expand Down
1 change: 1 addition & 0 deletions src/eve-core/utils/utils_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ extern std::string Win32TimeToString(int64 win32t);
int32 GetElapsedHours(int64 time);
// this returns 100 nanosecond resolution in filetime format
double GetFileTimeNow(); // replacement for Win32TimeNow()
double GetRelativeFileTime(int days=0, int hours=0, int minutes=0, int seconds=0);
// this returns milliseconds
int64 GetSteadyTime();
// this returns milliseconds in microsecond resolution
Expand Down
6 changes: 4 additions & 2 deletions src/eve-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ SET( config_SOURCE

SET( contract_INCLUDE
"${TARGET_INCLUDE_DIR}/contract/ContractMgr.h"
"${TARGET_INCLUDE_DIR}/contract/ContractProxy.h" )
"${TARGET_INCLUDE_DIR}/contract/ContractProxy.h"
"${TARGET_INCLUDE_DIR}/contract/ContractUtils.h" )
SET( contract_SOURCE
"${TARGET_SOURCE_DIR}/contract/ContractMgr.cpp"
"${TARGET_SOURCE_DIR}/contract/ContractProxy.cpp")
"${TARGET_SOURCE_DIR}/contract/ContractProxy.cpp"
"${TARGET_SOURCE_DIR}/contract/ContractUtils.cpp" )

SET( corporation_INCLUDE
"${TARGET_INCLUDE_DIR}/corporation/BillMgr.h"
Expand Down
32 changes: 31 additions & 1 deletion src/eve-server/config/ConfigDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ PyRep *ConfigDB::GetMultiOwnersEx(const std::vector<int32> &entityIDs) {
// will have to hardcode data, then run thru db query cause i dont know how to build packet for this return
}

/**
* This function used to return only the last requested value - DB results were not persisted.
* With this in mind, i had to move the logic from DBResultToTupleSet here, so that we could compose result tuple
* from bits of different queries.
*/
PyList *results = new PyList();
DBQueryResult res;
std::string ids = "";

Expand All @@ -73,6 +79,8 @@ PyRep *ConfigDB::GetMultiOwnersEx(const std::vector<int32> &entityIDs) {
" WHERE corporationID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
} else {
populateResListWithValues(res, results);
}
ids = "";
}
Expand All @@ -90,6 +98,8 @@ PyRep *ConfigDB::GetMultiOwnersEx(const std::vector<int32> &entityIDs) {
" WHERE allianceID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
} else {
populateResListWithValues(res, results);
}
ids = "";
}
Expand All @@ -107,6 +117,8 @@ PyRep *ConfigDB::GetMultiOwnersEx(const std::vector<int32> &entityIDs) {
" WHERE characterID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
} else {
populateResListWithValues(res, results);
}
ids = "";
}
Expand All @@ -124,6 +136,8 @@ PyRep *ConfigDB::GetMultiOwnersEx(const std::vector<int32> &entityIDs) {
" WHERE typeID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
} else {
populateResListWithValues(res, results);
}
ids = "";
}
Expand All @@ -139,6 +153,8 @@ PyRep *ConfigDB::GetMultiOwnersEx(const std::vector<int32> &entityIDs) {
" WHERE corporationID IN (SELECT corporationID FROM staStations WHERE stationID IN (%s))", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
} else {
populateResListWithValues(res, results);
}
ids = "";
}
Expand All @@ -156,10 +172,24 @@ PyRep *ConfigDB::GetMultiOwnersEx(const std::vector<int32> &entityIDs) {
" WHERE ownerID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
} else {
populateResListWithValues(res, results);
}
}

return DBResultToTupleSet(res);
if (!results->empty()) {
uint32 cc = res.ColumnCount();
PyTuple *response = new PyTuple(2);
PyList *cols = new PyList(cc);
for(uint32 r(0); r < cc; ++r)
cols->SetItemString(r, res.ColumnName(r));
response->items[0] = cols;
response->items[1] = results;

return response;
} else {
return new PyTuple(0);
}
}

PyRep *ConfigDB::GetMultiAllianceShortNamesEx(const std::vector<int32> &entityIDs) {
Expand Down
Loading

0 comments on commit 3f43c1b

Please sign in to comment.