Intro:
You can use this code in db` source code or in a well-written lib.
This code will set the default priv rates at the db startup.
How To:
Open .db\src\ClientManager.cpp and inside CClientManager::Initialize() paste:
Immediately above that function, paste:
Inside CClientManager::AddGuildPriv:
Inside CClientManager::AddEmpirePriv:
Inside CClientManager::AddCharacterPriv:
You also need to create inside the db common this table:
Example:
Result:
[Only registered and activated users can see links. Click Here To Register...]
Changelog:
Credits:
Me and also to Raiapad (rd) :pimp:
You can use this code in db` source code or in a well-written lib.
This code will set the default priv rates at the db startup.
How To:
Open .db\src\ClientManager.cpp and inside CClientManager::Initialize() paste:
Code:
if (!__InitializeDefaultPriv())
{
// do as you please to manage this
// fprintf(stderr, "Failed Default Priv Setting so exit\n");
// return false;
}
Code:
static bool bCleanOldPriv = true;
static bool __InitializeDefaultPriv()
{
if (bCleanOldPriv)
{
std::auto_ptr<SQLMsg> pCleanStuff(CDBManager::instance().DirectQuery("DELETE FROM priv_settings 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 priv_settings", 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 priv_settings 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;
}
Code:
__UpdateDefaultPriv("GUILD", p->guild_id, p->type, p->value, p->duration_sec);
Code:
__UpdateDefaultPriv("EMPIRE", p->empire, p->type, p->value, p->duration_sec);
Code:
__UpdateDefaultPriv("PLAYER", p->pid, p->type, p->value, 0);
Code:
CREATE TABLE `priv_settings` (
`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`)
)
;
Example:
Code:
INSERT INTO `priv_settings` VALUES ('EMPIRE', '0', '1', '200', '2014-08-07 14:26:03');
INSERT INTO `priv_settings` VALUES ('EMPIRE', '0', '2', '66', '2014-08-07 14:26:03');
INSERT INTO `priv_settings` VALUES ('EMPIRE', '0', '3', '1', '2014-08-07 14:26:03');
INSERT INTO `priv_settings` VALUES ('EMPIRE', '0', '4', '15', '2014-08-07 14:26:03');
[Only registered and activated users can see links. Click Here To Register...]
Changelog:
Code:
v1.0 +base v2.0 +clean of expired rows inside priv_settings +update priv_settings when refreshing rates from game/adminpage +changed priv_settings table structure
Credits:
Me and also to Raiapad (rd) :pimp: