Raised This Month: $ Target: $400
 0% 

Solved nvault crashing the server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-12-2017 , 10:53   Re: nvault crashing the server
Reply With Quote #1

Quote:
Originally Posted by Natsheh View Post
So what nvautl get returns when i saved in a key value 5 as integer
Dose it returns 5 or 0?
You cannot save anything as an integer. nVault allows only saving as strings.

So you can save "5" as a string and then use nvault_get() to return it as an integer. nvault_get() can be used in 3 ways.
PHP Code:
nvault_getvaultkey[] ) // function returns 5 (integer)
nvault_getvaultkey[] , fVal // function returns 1. fVal set to 5.0 (float)
nvault_getvault key[] val[] , maxchars // function returns 1 (num chars). val[] equals "5" (string) 
The point I was making is it cannot safely be used to determine if an integer or float data value exists because if the data being stored is 0, the return value is 0 which is the same as if no value was found at all.

As an example, assume the below data exists in the vault [key:data]
[STEAM_1234 : "0" ]

The below would return 0, as would calling nvault_get() on a key that does not exist.
nvault_get( vault , "STEAM_1234" )

I think we're getting off topic here. I was just trying to give you a pointer about safely using nvault_get() to avoid issues in your code. If you want to make your code respond a particular way if the key exists in the vault, nvault_lookup() is the way to go. The downside is you will always need to convert the returned string value to an integer or float, if needed.

As you can see, there is no concept of 'return X only if the key was found.'
PHP Code:
static cell nvault_get(AMX *amxcell *params)
{
    
unsigned int id params[1];
    if (
id >= g_Vaults.length() || !g_Vaults.at(id))
    {
        
MF_LogError(amxAMX_ERR_NATIVE"Invalid vault id: %d\n"id);
        return 
0;
    }
    
NVault *pVault g_Vaults.at(id);
    
unsigned int numParams = (*params)/sizeof(cell);
    
int len;
    
char *key MF_GetAmxString(amxparams[2], 0, &len);
    const 
char *val pVault->GetValue(key);
    switch (
numParams)
    {
    case 
2:
        {
            return 
atoi(val);
            break;
        }
    case 
3:
        {
            
cell *fAddr MF_GetAmxAddr(amxparams[3]);
            *
fAddr amx_ftoc((REAL)atof(val));
            return 
1;
            break;
        }
    case 
4:
        {
            
len = *(MF_GetAmxAddr(amxparams[4]));
            return 
MF_SetAmxString(amxparams[3], vallen);
            break;
        }
    }

    return 
0;

__________________

Last edited by Bugsy; 03-12-2017 at 11:04.
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-12-2017 , 10:16   Re: nvault crashing the server
Reply With Quote #2

5 of course.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-12-2017 , 11:06   Re: nvault crashing the server
Reply With Quote #3

Anyway i solved it by nvault_lookup , i dont recommend to use nvault_get it might causes crashes..


and i was using it right... like iknow if i want to save an integer i must convert it to string then save it !
i was doing that exactly although it was causing crashes..
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-12-2017 at 11:08.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-12-2017 , 11:13   Re: nvault crashing the server
Reply With Quote #4

nvault_get() will not cause crashes. Can you show the code in question? I'm curious as to why it was causing a crash.
__________________
Bugsy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-12-2017 , 11:18   Re: nvault crashing the server
Reply With Quote #5

I see 'crash', I'm triggered. How do you reproduce exactly a crash?

I don't see how nvault_get could crash, safety checks are there and GetValue() will return empty string (not a null pointer) if not found.
__________________

Last edited by Arkshine; 03-12-2017 at 11:18.
Arkshine is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode