EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Bots (https://www.eqemulator.org/forums/forumdisplay.php?f=676)
-   -   Fix for #bot create when same named PC exists (https://www.eqemulator.org/forums/showthread.php?t=36506)

NatedogEZ 02-22-2013 09:46 PM

Tested and I can confirm this issue is fixed with those changes! Thanks ZippZipp

Zamthos 02-22-2013 09:47 PM

Thanks ZippZipp! Works 100%!

NatedogEZ 02-24-2013 04:46 AM

Can anyone put this fix into the newest revision?

lerxst2112 02-24-2013 05:52 AM

It'd be easier to do so if an actual diff was posted.

NatedogEZ 07-10-2013 04:03 AM

Bot.cpp
Code:

old        new       
...        ...        @@ -2347,16 +2347,17 @@ bool Bot::IsValidName() {
2347        2347                return Result;
2348        2348        }
2349        2349       
2350                -bool Bot::IsBotNameAvailable(std::string* errorMessage) {
2351                -        bool Result = false;
        2350        +bool Bot::IsBotNameAvailable(char *botName, std::string* errorMessage) {
        2351        +        bool Result1 = false;
        2352        +        bool Result2 = false;
2352        2353       
2353                -        if(this->GetCleanName()) {
        2354        +        if(botName !="") {
2354        2355                        char* Query = 0;
2355        2356                        char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
2356        2357                        MYSQL_RES* DatasetResult;
2357        2358                        MYSQL_ROW DataRow;
2358        2359       
2359                -                if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT COUNT(id) FROM vwBotCharacterMobs WHERE name LIKE '%s'", this->GetCleanName()), TempErrorMessageBuffer, &DatasetResult)) {
        2360        +                if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT COUNT(id) FROM vwBotCharacterMobs WHERE name LIKE '%s'", botName), TempErrorMessageBuffer, &DatasetResult)) {
2360        2361                                *errorMessage = std::string(TempErrorMessageBuffer);
2361        2362                        }
2362        2363                        else {
...        ...        @@ -2368,15 +2369,34 @@ bool Bot::IsBotNameAvailable(std::string* errorMessage) {
2368        2369                                }
2369        2370       
2370        2371                                if(ExistingNameCount == 0)
2371                -                                Result = true;
        2372        +                                Result1 = true;
2372        2373       
2373        2374                                mysql_free_result(DatasetResult);
2374                -                }
2375        2375       
        2376        +                        if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT COUNT(id) FROM character_ WHERE name LIKE '%s'", botName), TempErrorMessageBuffer, &DatasetResult)) {
        2377        +                                *errorMessage = std::string(TempErrorMessageBuffer);
        2378        +                        } else {
        2379        +                                uint32 ExistingNameCount = 0;
        2380        +
        2381        +                                while(DataRow = mysql_fetch_row(DatasetResult)) {
        2382        +                                        ExistingNameCount = atoi(DataRow[0]);
        2383        +                                        break;
        2384        +                                }
        2385        +
        2386        +                                if(ExistingNameCount == 0)
        2387        +                                        Result2 = true;
        2388        +
        2389        +                                mysql_free_result(DatasetResult);
        2390        +
        2391        +                        }
        2392        +                }
2376        2393                        safe_delete(Query);
2377        2394                }
2378        2395       
2379                -        return Result;
        2396        +        if(Result1 && Result2)
        2397        +                return true;
        2398        +        else
        2399        +                return false;
2380        2400        }
2381        2401       
2382        2402        bool Bot::Save() {
...        ...        @@ -12182,6 +12202,11 @@ void Bot::ProcessBotCommands(Client *c, const Seperator *sep) {
12182        12202                        if(!strcasecmp(sep->arg[5], "female"))
12183        12203                                gender = 1;
12184        12204       
        12205        +                if(!IsBotNameAvailable(sep->arg[2],&TempErrorMessage)) {
        12206        +                        c->Message(0, "The name %s is already being used. Please choose a different name.", sep->arg[2]);
        12207        +                        return;
        12208        +                }
        12209        +
12185        12210                        NPCType DefaultNPCTypeStruct = CreateDefaultNPCTypeStructForBot(std::string(sep->arg[2]), std::string(), c->GetLevel(), atoi(sep->arg[4]), atoi(sep->arg[3]), gender);
12186        12211                        Bot* NewBot = new Bot(DefaultNPCTypeStruct, c);
12187        12212       
...        ...        @@ -12196,11 +12221,6 @@ void Bot::ProcessBotCommands(Client *c, const Seperator *sep) {
12196        12221                                        return;
12197        12222                                }
12198        12223       
12199                -                        if(!NewBot->IsBotNameAvailable(&TempErrorMessage)) {
12200                -                                c->Message(0, "The name %s is already being used. Please choose a different name.", NewBot->GetCleanName());
12201                -                                return;
12202                -                        }
12203                -
12204        12224                                if(!TempErrorMessage.empty()) {
12205        12225                                        c->Message(13, "Database Error: %s", TempErrorMessage.c_str());
12206        12226                                        return;



Bot.h
Code:

old        new       
...        ...        @@ -152,7 +152,7 @@ public:
152        152                // Class Methods
153        153                bool IsValidRaceClassCombo();
154        154                bool IsValidName();
155                -        bool IsBotNameAvailable(std::string* errorMessage);
        155        +        static bool IsBotNameAvailable(char *botName, std::string* errorMessage);
156        156                bool DeleteBot(std::string* errorMessage);
157        157                void Spawn(Client* botCharacterOwner, std::string* errorMessage);
158        158                virtual void SetLevel(uint8 in_level, bool command = false);


questmgr.cpp
Code:

old        new       
...        ...        @@ -2011,6 +2011,11 @@ bool QuestManager::createBot(const char *name, const char *lastname, uint8 level
2011        2011                                return false;
2012        2012                        }
2013        2013       
        2014        +                if(Bot::IsBotNameAvailable((char*)name,&TempErrorMessage)) {
        2015        +                        initiator->Message(0, "The name %s is already being used. Please choose a different name.", (char*)name);
        2016        +                        return false;
        2017        +                }
        2018        +
2014        2019                        NPCType DefaultNPCTypeStruct = Bot::CreateDefaultNPCTypeStructForBot(name, lastname, level, race, botclass, gender);
2015        2020                        Bot* NewBot = new Bot(DefaultNPCTypeStruct, initiator);
2016        2021       
...        ...        @@ -2026,11 +2031,6 @@ bool QuestManager::createBot(const char *name, const char *lastname, uint8 level
2026        2031                                        return false;
2027        2032                                }
2028        2033       
2029                -                        if(!NewBot->IsBotNameAvailable(&TempErrorMessage)) {
2030                -                                initiator->Message(0, "The name %s is already being used. Please choose a different name.", NewBot->GetCleanName());
2031                -                                return false;
2032                -                        }
2033                -
2034        2034                                if(!TempErrorMessage.empty()) {
2035        2035                                        initiator->Message(13, "Database Error: %s", TempErrorMessage.c_str());
2036        2036                                        return false;




If that is the correct format...

Kingly_Krab 01-08-2014 02:43 PM

Can we get this committed? I haven't seen anything in the changelog about committing it, or was it a silent commit?


All times are GMT -4. The time now is 09:16 PM.

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