Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tutorial] GetGold (/gg) fix

Initiate Mage
Joined
Jan 15, 2014
Messages
1
Reaction score
0
#I'm not english.


Hello,
On this tutorial we will learn how to fix GetGold command.
The bug make your penya goes to 0 by exceeding of int max value
Ok, let's go.


First you have to open FuncTextCmd.cpp (Interface folder)
Search (CTRL+F): BOOL TextCmd_GetGold( CScanner& scanner )

You should have the following code:

PHP:
BOOL TextCmd_GetGold( CScanner& scanner )           
{ 
#ifdef __WORLDSERVER
    CUser* pUser = (CUser*)scanner.dwValue;
    int nGold = scanner.GetNumber(); 
    pUser->AddGold( nGold );
#endif // __WORLDSERVER 
    return TRUE;
}

Well, now we must check if nGold > 2147483646 (Max int size - 1):
First, create a variable call for example maxIntValue and assign it to 2147483646
PHP:
BOOL TextCmd_GetGold( CScanner& scanner ) 
{ 
#ifdef __WORLDSERVER
    CUser* pUser = (CUser*)scanner.dwValue;
                            int maxIntValue = 2147483646; // max int value  - 1
    int nGold = scanner.GetNumber(); 
    pUser->AddGold( nGold );
#endif // __WORLDSERVER 
    return TRUE;
}

Ok, well the variable is create. Now we must make a condition who check if nGold > MaxIntValue.
PHP:
BOOL TextCmd_GetGold( CScanner& scanner ) 
{ 
#ifdef __WORLDSERVER
    CUser* pUser = (CUser*)scanner.dwValue;
int maxIntValue = 2147483646; // max int value  - 1
int nGold = scanner.GetNumber(); 
if(nGold > MaxIntValue)
{
  pUser->AddText("Oversized !");
}
else
{
    int nGold = scanner.GetNumber(); 
    pUser->AddGold( nGold );
#endif // __WORLDSERVER 
}
    return TRUE;
}

Ok, right. The next part is optional. We must check if maxIntValue >= gold user + nGold.
That's simply check if user gold + nGold (input) is inferior than maxIntValue


PHP:
BOOL TextCmd_GetGold( CScanner& scanner ) 
{ 
#ifdef __WORLDSERVER
    CUser* pUser = (CUser*)scanner.dwValue;
int maxIntValue = 2147483646; // max int value  - 1
 int userGold = pUser->GetGold(); // Get user gold
int nGold = scanner.GetNumber(); 
if(nGold > MaxIntValue)
{
  pUser->AddText("Oversized !");
}
    else   
 {       
 if(maxIntValue >= (userGold + nGold))        
{ 
           pUser->AddGold( nGold );       
 }            
else        
{           
 pUser->AddGold(maxIntValue);      
  }    
}        
return TRUE;
}

Pastebin final link
with correct indentation:

Should work, bye ;)

 
Last edited:
Initiate Mage
Joined
Feb 24, 2014
Messages
1
Reaction score
0
Code:
BOOL TextCmd_GetGold( CScanner& scanner )          
{
#ifdef __WORLDSERVER
        CUser* pUser    = (CUser*)scanner.dwValue;
        int maxIntValue = 2147483646; 
        int userGold = pUser->GetGold();
       
        int nGold = scanner.GetNumber();
       
        if(nGold > (maxIntValue - userGold) )
        {
            maxIntValue = maxIntValue - userGold;
            pUser->AddGold(maxIntValue);
        }
        else
        {
            pUser->AddGold( nGold );    
        }      
#endif  // __WORLDSERVER       
        return TRUE;
}

i dont test it!
 
[R8]ℓσℓ32
Loyal Member
Joined
Oct 6, 2008
Messages
1,396
Reaction score
198
const int maxIntValue = INT_MAX;

Code:
BOOL TextCmd_GetGold( CScanner& scanner )          
{
#ifdef __WORLDSERVER
        CUser* pUser    = (CUser*)scanner.dwValue;
        int userGold = pUser->GetGold();
       
        int nGold = scanner.GetNumber();
       
        if(nGold > INT_MAX)
        {
                pUser->AddText("Valeur trop importante (max: 2147483646)");
        }
        else
        {
                if(INT_MAX >= (userGold + nGold))
                {
                        pUser->AddGold( nGold );
                }      
                else
                {
                        pUser->AddGold(INT_MAX);
                }
        }      
#endif  // __WORLDSERVER       
        return TRUE;
}
 
Back
Top