EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Archive::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=621)
-   -   /guildwar /guildpeace added (https://www.eqemulator.org/forums/showthread.php?t=14277)

monalin crusader 06-12-2004 07:20 AM

/guildwar /guildpeace added
 
Ok i was looking for someting i could fix/add with my knowledge of eqemu source code. I figured /guildwar would be easy. So i added some code to make /guildwar work. It works just fine except for if there are more than 2 sets of guilds warring it doesnt work. I think i've fixed it i'll include what i think will fix that problem but i havent been on yet to check it because it requires 2 people to get on and check its a little harder than jsut logging on.

database.h Line 179 right after #endif

Code:

        bool        SetGuildWar(int32 guildid, int32 gildid2);
        bool        CheckGuildWar(int32 guildid, int32 guildid2);

client_process.cpp around Line 1845
insert this code into "case OP_GuildWar: { break; }"

Code:

        GuildCommand_Struct* gc = (GuildCommand_Struct*) app->pBuffer;
                                        Client* client=entity_list.GetClientByName(gc->othername);

                                        if ((GuildRank() == 2) && (client->GuildRank() == 2)) // If both clients are guild leaders
                                        {

                                                if(!database.SetGuildWar(GuildDBID(), client->GuildDBID()))
                                                        Message(0, "And error occured while writing to Database");

                                        }
                                        else if (client->GuildRank() != 2)
                                                Message(0, "Error: Your target is not a guild leader!");
                                        else if (client->GuildDBID == 0)
                                                Message(0, "Error: Your target is not in a guild!");
                                        else if (GuildRank() !=2)
                                                Message(0, "Error: You arent the guild leader!");
                                        else if (!worldserver.Connected())
                                                Message(0, "Error: World server disconnected");
                                        else if (client->GuildDBID() == GuildDBID())
                                                Message(0,"You are in the same guild, what do you think you are doing?");
                                        else if (guilddbid == 0)
                                                Message(0, "Error: You arent in a guild!");

                                        break;


database.cpp line 740
after bool Database::SetGMSpeed(int32 account_id, int8 gmspeed) function

Code:

bool Database::SetGuildWar(int32 guildid, int32 guildid2)
{
        char errbuf[MYSQL_ERRMSG_SIZE];
    char *query = 0;

        if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO guildwar SET guildid1=%i, guildid2=%i;", guildid, guildid2), errbuf))
        {
                cerr << "Error in SetGuildWar Query '" << query << "' " << errbuf << endl;
                safe_delete_array(query);

                return false;
        }
        else
        {
        safe_delete_array(query);
        return true;
        }
}

bool Database::CheckGuildWar(int32 guildid1, int32 guildid2)
{
        char errbuf[MYSQL_ERRMSG_SIZE];
        char *query = 0;
        MYSQL_RES *result;
        MYSQL_ROW row;
        int x;

        if (!RunQuery(query, MakeAnyLenString(&query, "SELECT guildid2 FROM guildwar WHERE guildid1='%i';", guildid1), errbuf, &result))
        {
                cerr << "Error in CheckGuildWar Query '" << query << "' " << errbuf << endl;
                safe_delete_array(query);

                return false;
        }
        else
        {

//********************************************************
//Possible Fix for having more than one set of guilds warring at same time       
//                for(x = 0; x <= result; x++)
//                {
//                                row = mysql_fetch_row(x);
//                                int32 guildid2_match = atoi(row[x]);
//
//                                mysql_free_result(x);
//
//                                if(guildid2_match == guildid2)
//                                        return true;
//                }
//********************************************************

                if (mysql_num_rows(result) == 1)
                {
                        row = mysql_fetch_row(result);
                        int32 guildid2_match = atoi(row[0]);

                        mysql_free_result(result);

                        if(guildid2_match == guildid2)
                                return true;
                }
        }
       
        return false;

}

mob.cpp Line 2080
inside the if(_CLIENT(mob2)) statment should read.

Code:

                                c1 = mob1->CastToClient();
                                c2 = mob2->CastToClient();

                                if        // if both are pvp they can fight
                                (
                                        c1->GetPVP() &&
                                        c2->GetPVP()
                                )
                                        return true;
                                else if        // if they're dueling they can go at it
                                (
                                        c1->IsDueling() &&
                                        c2->IsDueling() &&
                                        c1->GetDuelTarget() == c2->GetID() &&
                                        c2->GetDuelTarget() == c1->GetID()
                                )
                                        return true;
                                // If the two guilds are at war and not in same guild
                                else if ((c1->GuildDBID() != 0) && (c2->GuildDBID() != 0) || (c1->GuildDBID() == c2->GuildDBID()))
                                {
                                        if(!database.CheckGuildWar(c1->GuildDBID(), c2->GuildDBID()) || !database.CheckGuildWar(c2->GuildDBID(), c1->GuildDBID()))
                                        {
                                                Message(0, "You do not have permission to attack that player");
                                                return false;
                                        }
                                        else
                                                return true;
                                }
                                else
                                        return false;

I think that is all of it however if it doesnt complile i didnt get all of it i didnt get any errors compiling and it worked fine in game in alot of testing.

monalin crusader 06-12-2004 10:07 AM

Oh yes forgot this important part. Add this to your db

CREATE TABLE guildwar (
guildwarid int(11) unsigned NOT NULL auto_increment,
guildid1 int(11) unsigned NOT NULL default '0',
guildid2 int(11) unsigned NOT NULL default '0',
PRIMARY KEY (guildwarid)
) TYPE=MyISAM;

=P

Dspirit 06-14-2004 02:18 PM

thanks your work is appreciated lets hope this bumps till its added to cvs by a dev

Xabob 06-14-2004 02:25 PM

Noice work there man i bet yea will get Jr dev now :D

monalin crusader 06-14-2004 02:28 PM

heres /guildpeace

not sure if this works yet i'll have to test it. Doing so soon.

line 808 in database.cpp

Code:

bool Database::SetGuildPeace(int32 guildid, int32 guildid2)
{
        char errbuf[MYSQL_ERRMSG_SIZE];
    char *query = 0;

        if (!RunQuery(query, MakeAnyLenString(&query, "DELETE FROM guildwar WHERE guildid1=%i, guildid2=%i;", guildid, guildid2), errbuf))
        {
                cerr << "Error in SetGuildPeace Query '" << query << "' " << errbuf << endl;
                safe_delete_array(query);

                return false;
        }
        else
        {
        safe_delete_array(query);
        return true;
        }
}

Line 181 in database.h

Code:

        bool        SetGuildPeace(int32 guildid, int32 guildid2);
around line 1857 in client_process.cpp

change

Code:

                case OP_GuildPeace: { break; }
to

Code:

                case OP_GuildPeace: {

                                        GuildCommand_Struct* gc = (GuildCommand_Struct*) app->pBuffer;
                                        Client* client=entity_list.GetClientByName(gc->othername);

                                        if ((GuildRank() == 2) && (client->GuildRank() == 2)) // If both clients are guild leaders
                                        {

                                                if(!database.CheckGuildWar(GuildDBID(), client->GuildDBID()))
                                                        Message(0, "Error: You are not at war with this guild!");
                                                else if(!database.SetGuildPeace(GuildDBID(), client->GuildDBID()))
                                                        Message(0, "There was an error writing to db!");
                                                else
                                                        Message(0, "You are now at peace.");

                                        }        else if (client->GuildRank() != 2)
                                                Message(0, "Error: Your target is not a guild leader!");
                                        else if (client->GuildDBID == 0)
                                                Message(0, "Error: Your target is not in a guild!");
                                        else if (GuildRank() !=2)
                                                Message(0, "Error: You arent the guild leader!");
                                        else if (!worldserver.Connected())
                                                Message(0, "Error: World server disconnected");
                                        else if (client->GuildDBID() == GuildDBID())
                                                Message(0,"You are in the same guild, what do you think you are doing?");
                                        else if (guilddbid == 0)
                                                Message(0, "Error: You arent in a guild!");
                                        break;
                                }



All times are GMT -4. The time now is 07:41 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.