[C++ ] Szorzó állítás adatbázisból

Indította huzsihun1997, 2016-01-15, 15:05:12

A lényege a következő, mysql-ből olvassa ki a szorzókat (ott birod állítani, nem fog lejárni így 24 óránként)
questel pedig belehet állítani, hogy X órától, Y óráig más szorzó legyen, utánna pedig visszaáll az alapra (amit mysqlből olvas ki) nem pedig 0-ára.

db\src\ClientManager.cpp

CClientManager::Initialize()
add hozzá ezt:
if (!__InitializeDefaultPriv())
{
// do as you please to manage this
// fprintf(stderr, "Nem lehetett betölteni az adatbázist\n");
// return false;
}


ezt a funkciót tedd bele a cpp-be.

static bool bCleanOldPriv = true;
static bool __InitializeDefaultPriv()
{
if (bCleanOldPriv)
{
std::auto_ptr<SQLMsg> pCleanStuff(CDBManager::instance().DirectQuery("DELETE FROM szorzo_beallitas WHERE value <= 0 OR duration <= NOW();", SQL_COMMON));
printf("DEFAULT_PRIV_EMPIRE: removed %u expired priv settings.\n", pCleanStuff->Get()->uiAffectedRows);
}
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery("SELECT priv_type, id, type, value, UNIX_TIMESTAMP(duration) FROM szorzo_beallitas", SQL_COMMON));
if (pMsg->Get()->uiNumRows == 0)
return false;
MYSQL_ROW row = NULL;
while ((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
{
if (!strcmp(row[0], "EMPIRE"))
{
// init
BYTE empire = 0;
BYTE type = 1;
int value = 0;
time_t duration_sec = 0;
// set
str_to_number(empire, row[1]);
str_to_number(type, row[2]);
str_to_number(value, row[3]);
str_to_number(duration_sec, row[4]);
// recalibrate time
time_t now_time_sec = CClientManager::instance().GetCurrentTime();
if (now_time_sec>duration_sec)
duration_sec = 0;
else
duration_sec -= now_time_sec;
// send priv
printf("DEFAULT_PRIV_EMPIRE: set empire(%u), type(%u), value(%d), duration(%u)\n", empire, type, value, duration_sec);
CPrivManager::instance().AddEmpirePriv(empire, type, value, duration_sec);
}
else if (!strcmp(row[0], "GUILD"))
{
// init
DWORD guild_id = 0;
BYTE type = 1;
int value = 0;
time_t duration_sec = 0;
// set
str_to_number(guild_id, row[1]);
str_to_number(type, row[2]);
str_to_number(value, row[3]);
str_to_number(duration_sec, row[4]);
// recalibrate time
time_t now_time_sec = CClientManager::instance().GetCurrentTime();
if (now_time_sec>duration_sec)
duration_sec = 0;
else
duration_sec -= now_time_sec;
// send priv
if (guild_id)
{
printf("DEFAULT_PRIV_GUILD: set guild_id(%u), type(%u), value(%d), duration(%u)\n", guild_id, type, value, duration_sec);
CPrivManager::instance().AddGuildPriv(guild_id, type, value, duration_sec);
}
}
else if (!strcmp(row[0], "PLAYER"))
{
// init
DWORD pid = 0;
BYTE type = 1;
int value = 0;
// set
str_to_number(pid, row[1]);
str_to_number(type, row[2]);
str_to_number(value, row[3]);
// send priv
if (pid)
{
printf("DEFAULT_PRIV_PLAYER: set pid(%u), type(%u), value(%d)\n", pid, type, value);
CPrivManager::instance().AddCharPriv(pid, type, value);
}
}
}
return true;
}

static bool __UpdateDefaultPriv(const char* priv_type, DWORD id, BYTE type, int value, time_t duration_sec)
{
char szQuery[1024];
snprintf(szQuery, 1024,
"REPLACE INTO szorzo_beallitas SET priv_type='%s', id=%u, type=%u, value=%d, duration=DATE_ADD(NOW(), INTERVAL %u SECOND);",
priv_type, id, type, value, duration_sec
);
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_COMMON));
return pMsg->Get()->uiAffectedRows;
}


keress rá erre:
CClientManager::AddGuildPriv
add hozzá ezt:
__UpdateDefaultPriv("GUILD", p->guild_id, p->type, p->value, p->duration_sec);

keress rá erre:
CClientManager::AddEmpirePriv
add hozzá ezt:
__UpdateDefaultPriv("EMPIRE", p->empire, p->type, p->value, p->duration_sec);

keress rá erre:
CClientManager::AddCharacterPriv:
add hozzá ezt:
__UpdateDefaultPriv("PLAYER", p->pid, p->type, p->value, 0);


commonba (navicaton belül) tedd be a következő querryt
CREATE TABLE `szorzo_beallitas` (
`priv_type`  enum('PLAYER','GUILD','EMPIRE') NOT NULL DEFAULT 'EMPIRE' COMMENT 'GUILD and PLAYER are untested.' ,
`id`  int UNSIGNED NOT NULL DEFAULT 0 COMMENT 'this is for empire_id, player_id or guild_id' ,
`type`  int UNSIGNED NOT NULL DEFAULT 4 COMMENT '1:item_drop, 2:gold_drop, 3:gold10_drop, 4:exp (1~4)' ,
`value`  int NOT NULL DEFAULT 0 COMMENT '0~1000%' ,
`duration`  datetime NOT NULL DEFAULT 0 ,
PRIMARY KEY (`priv_type`, `id`, `type`)
)
;



szorzo_beallitason belül lesz PLAYER EMPIRE GUILD, itt értelemszerűen amit beirsz, annyi lesz a szorzó.

Remélem segítettem üdv.