|
You last visited: Today at 07:51
Advertisement
[Release] Automatic/Default priv rates at the db startup
Discussion on [Release] Automatic/Default priv rates at the db startup within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.
08/06/2014, 16:15
|
#1
|
elite*gold: 100
Join Date: Jun 2009
Posts: 168
Received Thanks: 711
|
[Release] Automatic/Default priv rates at the db startup
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:
Code:
if (!__InitializeDefaultPriv())
{
// do as you please to manage this
// fprintf(stderr, "Failed Default Priv Setting so exit\n");
// return false;
}
Immediately above that function, paste:
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;
}
Inside CClientManager::AddGuildPriv:
Code:
__UpdateDefaultPriv("GUILD", p->guild_id, p->type, p->value, p->duration_sec);
Inside CClientManager::AddEmpirePriv:
Code:
__UpdateDefaultPriv("EMPIRE", p->empire, p->type, p->value, p->duration_sec);
Inside CClientManager::AddCharacterPriv:
Code:
__UpdateDefaultPriv("PLAYER", p->pid, p->type, p->value, 0);
You also need to create inside the db common this table:
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');
Result:
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 Raia pad (rd)
|
|
|
08/06/2014, 21:49
|
#2
|
elite*gold: 260
Join Date: Jan 2013
Posts: 178
Received Thanks: 104
|
thanks for that .. and keep up the good work !!
|
|
|
08/13/2014, 13:37
|
#3
|
elite*gold: 0
Join Date: Feb 2012
Posts: 95
Received Thanks: 29
|
great release thank you
|
|
|
08/13/2014, 21:21
|
#4
|
elite*gold: 0
Join Date: Jul 2014
Posts: 305
Received Thanks: 95
|
Danke fürs Teilen!
|
|
|
08/14/2014, 19:26
|
#5
|
elite*gold: 0
Join Date: Aug 2014
Posts: 388
Received Thanks: 83
|
Kann jemand helfen es mir einzubauen mein Englisch is recht mies
|
|
|
03/03/2016, 19:33
|
#6
|
elite*gold: 0
Join Date: Feb 2013
Posts: 16
Received Thanks: 2
|
can you help me i dont understand CClientManager::AddGuildPriv this line
|
|
|
05/03/2023, 13:30
|
#7
|
elite*gold: 0
Join Date: Jun 2011
Posts: 7
Received Thanks: 0
|
inside CClientManager::AddGuildPriv:
should we add the __UpdateDefaultPriv("GUILD", p->guild_id, p->type, p->value, p->duration_sec); line or replace with the existing one?
|
|
|
05/04/2023, 16:36
|
#8
|
elite*gold: 0
Join Date: Jun 2011
Posts: 7
Received Thanks: 0
|
Errors:
ClientManager.cpp:95:8: error: no member named 'auto_ptr' in namespace 'std'
std::auto_ptr<SQLMsg> pCleanStuff(CDBManager::instance().DirectQuery("DE LETE FROM priv_settings WHERE value <= 0 OR duration <= NOW();", SQL_COMMON));
~~~~~^
ClientManager.cpp:95:17: error: unexpected type name 'SQLMsg': expected expression
std::auto_ptr<SQLMsg> pCleanStuff(CDBManager::instance().DirectQuery("DE LETE FROM priv_settings WHERE value <= 0 OR duration <= NOW();", SQL_COMMON));
^
ClientManager.cpp:95:25: error: use of undeclared identifier 'pCleanStuff'
std::auto_ptr<SQLMsg> pCleanStuff(CDBManager::instance().DirectQuery("DE LETE FROM priv_settings WHERE value <= 0 OR duration <= NOW();", SQL_COMMON));
^
ClientManager.cpp:96:70: error: use of undeclared identifier 'pCleanStuff'
printf("DEFAULT_PRIV_EMPIRE: removed %u expired priv settings.\n", pCleanStuff->Get()->uiAffectedRows);
^
ClientManager.cpp:98:7: error: no member named 'auto_ptr' in namespace 'std'
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery("SELECT priv_type, id, type, value, UNIX_TIMESTAMP(duration) FROM priv_settings", SQL_COMMON));
~~~~~^
ClientManager.cpp:98:16: error: unexpected type name 'SQLMsg': expected expression
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery("SELECT priv_type, id, type, value, UNIX_TIMESTAMP(duration) FROM priv_settings", SQL_COMMON));
^
ClientManager.cpp:98:24: error: use of undeclared identifier 'pMsg'
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery("SELECT priv_type, id, type, value, UNIX_TIMESTAMP(duration) FROM priv_settings", SQL_COMMON));
^
ClientManager.cpp:99:6: error: use of undeclared identifier 'pMsg'
if (pMsg->Get()->uiNumRows == 0)
^
ClientManager.cpp:102:32: error: use of undeclared identifier 'pMsg'
while ((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
^
ClientManager.cpp:178:7: error: no member named 'auto_ptr' in namespace 'std'
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_COMMON));
~~~~~^
ClientManager.cpp:178:16: error: unexpected type name 'SQLMsg': expected expression
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_COMMON));
^
ClientManager.cpp:178:24: error: use of undeclared identifier 'pMsg'
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_COMMON));
^
ClientManager.cpp:179:9: error: use of undeclared identifier 'pMsg'
return pMsg->Get()->uiAffectedRows;
EDIT:
I've managed to figure it out...
std::auto_ptr has been deprecated and removed from the C++ standard as of C++11, and should no longer be used in modern C++ code. You may want to use std::unique_ptr instead.
a bit better-explained steps:
add:
Code:
if (!__InitializeDefaultPriv())
{
// do as you please to manage this
// fprintf(stderr, "Failed Default Priv Setting so exit\n");
// return false;
}
inside
Code:
bool CClientManager::Initialize()
Don't copy the following code but have a look at how it should look next to the existing code in the source:
Code:
bool CClientManager::Initialize()
{
int tmpValue;
if (!__InitializeDefaultPriv())
{
// do as you please to manage this
// fprintf(stderr, "Failed Default Priv Setting so exit\n");
// return false;
}
//BOOT_LOCALIZATION
if (!InitializeLocalization())
{
fprintf(stderr, "Failed Localization Infomation so exit\n");
return false;
}
//END_BOOT_LOCALIZATION
//ITEM_UNIQUE_ID
This code:
Code:
static bool bCleanOldPriv = true;
static bool __InitializeDefaultPriv()
{
if (bCleanOldPriv)
{
std::unique_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::unique_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::unique_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_COMMON));
return pMsg->Get()->uiAffectedRows;
}
should be added before:
Code:
bool CClientManager::Initialize()
Don't copy the following code but have a look at how it should be blent with the existing code:
Code:
void CClientManager::Destroy()
{
m_mChannelStatus.clear();
for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end(); ++i)
(*i)->Destroy();
m_peerList.clear();
if (m_fdAccept > 0)
{
socket_close(m_fdAccept);
m_fdAccept = -1;
}
}
static bool bCleanOldPriv = true;
static bool __InitializeDefaultPriv()
{
if (bCleanOldPriv)
{
std::unique_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::unique_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::unique_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_COMMON));
return pMsg->Get()->uiAffectedRows;
}
bool CClientManager::Initialize()
{
int tmpValue;
when adding :
Code:
__UpdateDefaultPriv("GUILD", p->guild_id, p->type, p->value, p->duration_sec);
it should look like this :
Code:
void CClientManager::AddGuildPriv(TPacketGiveGuildPriv* p)
{
CPrivManager::instance().AddGuildPriv(p->guild_id, p->type, p->value, p->duration_sec);
__UpdateDefaultPriv("GUILD", p->guild_id, p->type, p->value, p->duration_sec);
}
when adding:
Code:
__UpdateDefaultPriv("EMPIRE", p->empire, p->type, p->value, p->duration_sec);
it should look like this:
Code:
void CClientManager::AddEmpirePriv(TPacketGiveEmpirePriv* p)
{
CPrivManager::instance().AddEmpirePriv(p->empire, p->type, p->value, p->duration_sec);
__UpdateDefaultPriv("EMPIRE", p->empire, p->type, p->value, p->duration_sec);
}
when adding:
Code:
__UpdateDefaultPriv("PLAYER", p->pid, p->type, p->value, 0);
it should look like this:
Code:
void CClientManager::AddCharacterPriv(TPacketGiveCharacterPriv* p)
{
CPrivManager::instance().AddCharPriv(p->pid, p->type, p->value);
__UpdateDefaultPriv("PLAYER", p->pid, p->type, p->value, 0);
}
|
|
|
10/05/2023, 22:34
|
#9
|
elite*gold: 31
Join Date: Sep 2023
Posts: 26
Received Thanks: 3
|
helpfull, thanks.
|
|
|
 |
Similar Threads
|
[RELEASE] Charles default 443 error solution
01/15/2014 - Facebook - 0 Replies
Hi guys. New error solution. No program. See video.
Ty Trgala
Charles 443 Çözümü 2014 (Kesin) - YouTube
|
[HowTo] Aktionsleister von Priv oder Live zu Priv übertragen
09/26/2010 - WoW Private Server - 3 Replies
Hallo !,
Heute zeige ich euch wie man die Aktionsleisten und makros von Priv/live zu Priv live übertreigt
1.) Als erstes ladet ihr das addon Simple Action Sets
Simple Action Sets - Addons - Curse
2.) Nun loggt euch ein. Danach findet ihr ein icon auf der minimap darauf klickt ihr drauf
|
[Release]Metin2 Startup-Manager
07/03/2010 - Metin2 PServer Guides & Strategies - 16 Replies
Ich wollte euch ein kleines Programm vorstellen , welches ich in einem Forum gefunden habe. Ich habe mich noch nicht weiter damit beschäftigt, bitte keine Fragen wie es funktioniert thx ;)
Voici la dernière version du client Metin² multi-langues by Moustikk
Ce client contient à la base les fichiers US et FR, quelques patchs + un lanceur que j'ai développé pour facilité la configuration du client.
Version complète du client et lanceur en version 1.00H (569Mo)
Citer:
Utile: Logiciel de...
|
[Release] CSS Priv. Hack!!!
09/30/2009 - General Gaming Discussion - 1 Replies
Also.. ich habe noch einen Hack gefunden bei mir geht der wieder nicht...
kann den einer von euch bitte Testen ich hab bei dem sogar ein Video gesehen er muss eig. gehn !!
Scan
Antivir: Nothing found
ArcaVir: Nothing found
Avast: Nothing found
|
[Release] TServer1109[Priv]
12/16/2007 - SRO Hacks, Bots, Cheats & Exploits - 15 Replies
TServer1109 released 12/14/07
New Features:
-Zoomhack
-Multiclient
-Instant Log* Might not always work
-Check Server Status
-NODC
-Auto Timer/Shutdown
|
All times are GMT +1. The time now is 07:51.
|
|