Jump to content

Bug with kingdom changing and clan


Recommended Posts

So my server has a bug .

Lets say my account has 2 players one without clan and one with clan on the red kingdom for example

so when i try to change kingdom with the player that is a member of a clan it wouldnt let me but if i change character to the one without a clan it would let me change a kingdom so im on blue kingdom (for example) with a red kingdom's clan!!

help 

THANKS

Link to comment
Share on other sites

  • Nitro Booster
1 hour ago, Hik said:

I believe it is not possible to change kingdoms when in a guild.

You're correct
but i believe his problem is that it doesn't check all the characters within the account, so if one character (name him char1) has a guild, and the other character (name him char2) doesn't, It wouldn't allow char1 to not change kingdom, but char2 would be able to change kingdom while char1 maintains his guild

if that makes sense?

Link to comment
Share on other sites

Let me explain an other time.

So lets say i have 2 characters in 1 account which they both are in blue kingdom.

Character1 is a part of a guild while character 2 isn't okay?

So when i try to change kingdom with the character1 it wouldn't let me because it will say you are a member of a guild BUT if i try to change kingdom from character2 it would let me!

So im on BOTH characters to red kingdom for example and the character 1 is at red kingdom and he is a member at a guild from blue kingdom!

Thanks for your help guys!

Link to comment
Share on other sites

  • Contributor

I don't get it.. mine's working just fine.

Here's the code, I've also commented to see what's what:

char_change_empire.cpp

Spoiler

int CHARACTER::ChangeEmpire(BYTE empire)
{
    if (GetEmpire() == empire)
        return 1;//return 1 means you're trying to change to the same empire. Aka: you're already there..

    char szQuery[1024 + 1];
    DWORD dwAID;
    DWORD dwPID[4];
    memset(dwPID, 0, sizeof(dwPID));

    {//get all the players on this account
        snprintf(szQuery, sizeof(szQuery),        //pid5 after pid4 if you have lykan                            //pid5=%u if you have lykan
                 "SELECT id, pid1, pid2, pid3, pid4 FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
                                     //add one more GetPlayerID() if you have lykan
                 get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());

        std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));

        if (msg->Get()->uiNumRows == 0)
        {
            return 0;//return 0 is unknown or query error
        }

        MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);

        str_to_number(dwAID, row[0]);
        str_to_number(dwPID[0], row[1]);
        str_to_number(dwPID[1], row[2]);
        str_to_number(dwPID[2], row[3]);
        str_to_number(dwPID[3], row[4]);
        // str_to_number(dwPID[4], row[5]);//if you have lykan.
    }

    const int loop = 4;//number of characters available(should be 5 if you have lykan)

    {
        DWORD dwGuildID[4];
        CGuild *pGuild[4];
        SQLMsg *pMsg = NULL;

        for (int i = 0; i < loop; ++i)
        {

            snprintf(szQuery, sizeof(szQuery), "SELECT guild_id FROM guild_member%s WHERE pid=%u", get_table_postfix(), dwPID[i]);

            pMsg = DBManager::instance().DirectQuery(szQuery);

            
            if (pMsg != NULL)//query failed
            {
                if (pMsg->Get()->uiNumRows > 0)//query didn't fail, we've got some results.
                {
                    MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
                    str_to_number(dwGuildID[i], row[0]);

                    pGuild[i] = CGuildManager::instance().FindGuild(dwGuildID[i]);//look for a guild

                    if (pGuild[i] != NULL)//we found a guild on one of the accounts
                    {
                        M2_DELETE(pMsg);
                        return 2;
                    }
                }
                else // we didn't get any results
                {
                    dwGuildID[i] = 0;
                    pGuild[i] = NULL;
                }
                M2_DELETE(pMsg);
            }
        }
    }

    {//return 3 means one of the characters is married.
        for (int i = 0; i < loop; ++i)
        {
            if (marriage::CManager::instance().IsEngagedOrMarried(dwPID[i]) == true)
                return 3;
        }
    }

    {
        //don't forget to add your 5th pid if you have lykan.
        snprintf(szQuery, sizeof(szQuery), "UPDATE player_index%s SET empire=%u WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
                 get_table_postfix(), empire, GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());

        std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));

        if (msg->Get()->uiAffectedRows > 0)
        {
            SetChangeEmpireCount();
            SetEmpire(empire);
            UpdatePacket();
            return 999;//it means everything ran as expected.
        }
    }

    return 0;//unexpectedly, we've reached the final destination. How did this happen ?
}

This should do the trick.

 

Good luck !

  • Love 1
Link to comment
Share on other sites

34 minutes ago, Amun said:

I don't get it.. mine's working just fine.

Here's the code, I've also commented to see what's what:

char_change_empire.cpp

  Hide contents

int CHARACTER::ChangeEmpire(BYTE empire)
{
    if (GetEmpire() == empire)
        return 1;//return 1 means you're trying to change to the same empire. Aka: you're already there..

    char szQuery[1024 + 1];
    DWORD dwAID;
    DWORD dwPID[4];
    memset(dwPID, 0, sizeof(dwPID));

    {//get all the players on this account
        snprintf(szQuery, sizeof(szQuery),        //pid5 after pid4 if you have lykan                            //pid5=%u if you have lykan
                 "SELECT id, pid1, pid2, pid3, pid4 FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
                                     //add one more GetPlayerID() if you have lykan
                 get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());

        std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));

        if (msg->Get()->uiNumRows == 0)
        {
            return 0;//return 0 is unknown or query error
        }

        MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);

        str_to_number(dwAID, row[0]);
        str_to_number(dwPID[0], row[1]);
        str_to_number(dwPID[1], row[2]);
        str_to_number(dwPID[2], row[3]);
        str_to_number(dwPID[3], row[4]);
        // str_to_number(dwPID[4], row[5]);//if you have lykan.
    }

    const int loop = 4;//number of characters available(should be 5 if you have lykan)

    {
        DWORD dwGuildID[4];
        CGuild *pGuild[4];
        SQLMsg *pMsg = NULL;

        for (int i = 0; i < loop; ++i)
        {

            snprintf(szQuery, sizeof(szQuery), "SELECT guild_id FROM guild_member%s WHERE pid=%u", get_table_postfix(), dwPID[i]);

            pMsg = DBManager::instance().DirectQuery(szQuery);

            
            if (pMsg != NULL)//query failed
            {
                if (pMsg->Get()->uiNumRows > 0)//query didn't fail, we've got some results.
                {
                    MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
                    str_to_number(dwGuildID[i], row[0]);

                    pGuild[i] = CGuildManager::instance().FindGuild(dwGuildID[i]);//look for a guild

                    if (pGuild[i] != NULL)//we found a guild on one of the accounts
                    {
                        M2_DELETE(pMsg);
                        return 2;
                    }
                }
                else // we didn't get any results
                {
                    dwGuildID[i] = 0;
                    pGuild[i] = NULL;
                }
                M2_DELETE(pMsg);
            }
        }
    }

    {//return 3 means one of the characters is married.
        for (int i = 0; i < loop; ++i)
        {
            if (marriage::CManager::instance().IsEngagedOrMarried(dwPID[i]) == true)
                return 3;
        }
    }

    {
        //don't forget to add your 5th pid if you have lykan.
        snprintf(szQuery, sizeof(szQuery), "UPDATE player_index%s SET empire=%u WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
                 get_table_postfix(), empire, GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());

        std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));

        if (msg->Get()->uiAffectedRows > 0)
        {
            SetChangeEmpireCount();
            SetEmpire(empire);
            UpdatePacket();
            return 999;//it means everything ran as expected.
        }
    }

    return 0;//unexpectedly, we've reached the final destination. How did this happen ?
}

This should do the trick.

 

Good luck !

Thank you very much i will try it and keep you updated!

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.