ENABLE_DEFAULT_PRIV | MEKA-SF

  • Konuyu açan Konuyu açan MEKA
  • Açılış Tarihi Açılış Tarihi
  • Yanıt Yanıt 0
  • Gösterim Gösterim 821

MEKA

Discord: mekaprojects
Süper Moderatör
Grafiker
Geliştirici
Yardımsever Üye
Mesaj
3.011
Çözümler
319
Beğeni
2.268
Puan
1.850
Ticaret Puanı
2
Sistem ne işe yarar; Reboot attığınızda bile droplar tekrardan otomatik olarak açılacaktır tekrar el ile açmanıza vs gerek kalmaz.
Sistem yazarı:

ClientManager.cpp
Arat:
Genişlet Daralt Kopyala
bool CClientManager::Initialize()
Üstüne Ekle:
Genişlet Daralt Kopyala
#define ENABLE_DEFAULT_PRIV
#ifdef ENABLE_DEFAULT_PRIV
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;
}
#endif

Bul:
Genişlet Daralt Kopyala
    if (!InitializeLocalization())
    {
        fprintf(stderr, "Failed Localization Infomation so exit\n");
        return false;
    }

Altına Ekle:
Genişlet Daralt Kopyala
#ifdef ENABLE_DEFAULT_PRIV
    if (!__InitializeDefaultPriv())
    {
        fprintf(stderr, "Failed Default Priv Setting so exit\n");
        // return false;
    }
#endif


Aşağıdaki kod bloklarını arat ekle ayırmak yerine birleşik yazıyorum

C++:
Genişlet Daralt Kopyala
void CClientManager::AddGuildPriv(TPacketGiveGuildPriv* p)
{
    CPrivManager::instance().AddGuildPriv(p->guild_id, p->type, p->value, p->duration_sec);
#ifdef ENABLE_DEFAULT_PRIV
    __UpdateDefaultPriv("GUILD", p->guild_id, p->type, p->value, p->duration_sec);
#endif
}

C++:
Genişlet Daralt Kopyala
void CClientManager::AddEmpirePriv(TPacketGiveEmpirePriv* p)
{
    CPrivManager::instance().AddEmpirePriv(p->empire, p->type, p->value, p->duration_sec);
#ifdef ENABLE_DEFAULT_PRIV
    __UpdateDefaultPriv("EMPIRE", p->empire, p->type, p->value, p->duration_sec);
#endif
}

C++:
Genişlet Daralt Kopyala
void CClientManager::AddCharacterPriv(TPacketGiveCharacterPriv* p)
{
    CPrivManager::instance().AddCharPriv(p->pid, p->type, p->value);
#ifdef ENABLE_DEFAULT_PRIV
    __UpdateDefaultPriv("PLAYER", p->pid, p->type, p->value, 0);
#endif
}

Navicat common içerisine bu query kodunu okut.

SQL:
Genişlet Daralt Kopyala
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`)
)
;
 
Son düzenleme:
Uyarı: Bu konu açıldığından bu yana baya zaman geçmiş.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.
Geri
Üst