Raised This Month: $ Target: $400
 0% 

Saving ip's into nvault


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Santaaa
BANNED
Join Date: May 2012
Old 07-06-2012 , 17:38   Saving ip's into nvault
Reply With Quote #1

Hello there,

i've tryed to save ip's into nvault but it wont work at all. Can someone help me?

Loaddata:
PHP Code:
public LoadData(id)
{
    new 
ip[33]
    
get_user_ip(idip321)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-KDRATIO"ip)
    
format(vaultdata,255,"%i#%i#"Kills[id], Deaths[id])
    
nvault_get(g_vault,vaultkey,vaultdata,255)
    
    
replace_all(vaultdata255"#"" ")
    
    new 
kills[32], deaths[32]
    
    
parse(vaultdatakills31deaths31)
    
    
Kills[id] = str_to_num(kills)
    
Deaths[id] = str_to_num(deaths)
    
    return 
PLUGIN_CONTINUE

Savedata:
PHP Code:
public SaveData(id)
{
    new 
ip[33]
    
get_user_ip(idip321)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-KDRATIO"ip)
    
format(vaultdata,255,"%i#%i#"Kills[id], Deaths[id])
    
nvault_set(g_vault,vaultkey,vaultdata)
    
    return 
PLUGIN_CONTINUE


Last edited by Santaaa; 07-06-2012 at 17:38.
Santaaa is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-06-2012 , 19:59   Re: Saving ip's into nvault
Reply With Quote #2

You need to initialize a person into the vault before you can save, or get their data. Check out my code from a plugin i use nvault for.

PHP Code:
retrieveFrags(id)    // gets the frags for the given clientID from vualt  @RETURNS player's frags or -1 if not authorized
{
    if(
get_pcvar_num(frags_pcvar) == || get_pcvar_num(toggle_pcvar) == 0)
    {
        
client_print(idprint_console"[AMX] %L"id"DISABLED")
        return 
PLUGIN_HANDLED
    
}
    if(!
is_user_connected(id) || is_user_bot(id))
        return -
1
    
    
new name[32], sz_vaultKey[34], data[5], timestamp
    
static frags
    
    get_user_name
(idnamecharsmax(name) )        // Used to show who we're talking about in logFile
        // This makes sure the user has a valid AuthID
    
if( !g_playerAuth[id] )
    {
        
g_idPending[id] = true
        client_print
(idprint_console"[BKF] %L"id"AUTH_FAIL_MSG")
        
gi_playerFrags[id] = 0
        
if(get_pcvar_num(log_pcvar) == 1)
            
log_to_file(nVaultLogFile"[BKF] User %s has not been authorized. No vault data created."name)
        return -
1
    
}
    
    
get_user_authid(idsz_vaultKeycharsmax(sz_vaultKey))  // we are usest the steamID as vault key
    
    
if(!nvault_lookup(g_vaultHandlesz_vaultKeydatacharsmax(data), timestamp))
    {
        
frags 0
        nvault_set
(g_vaultHandlesz_vaultKey"0")
        if(
get_pcvar_num(log_pcvar) == 1)
            
log_to_file(nVaultLogFile"[BKF] User %s (%s) is a new client and has been added to the vault."namesz_vaultKey)
    }
    else
        
frags nvault_get(g_vaultHandlesz_vaultKey)
        
    
gi_playerFrags[id] = frags
    g_idPending
[id] = false
    
if(get_pcvar_num(log_pcvar) == 1)
        
log_to_file(nVaultLogFile"[BKF] User %s (%s) has been authorized and loaded with %d frags."namesz_vaultKeyfrags)
    
client_print_color(idDontChange"[BKF] %L"id"WELCOME_MSG"frags)
    
    return 
frags

P.S. Read and understand the code. Don't just copy/paste it.
This code is run at client_putinserver

also....don't use parse and replace all to seperate your data use strtok, it'll save you some native calls.
Code:
strtok(vaultdata, kills, charsmax(kills), deaths, charsmax(deaths), '#', 1)
This will not remove the final #. Take it out. you don't need it, unless you have plans for it later.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Santaaa
BANNED
Join Date: May 2012
Old 07-06-2012 , 20:23   Re: Saving ip's into nvault
Reply With Quote #3

Well, what did i wrong with my version? it works for authid.
Santaaa is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-06-2012 , 20:41   Re: Saving ip's into nvault
Reply With Quote #4

Quote:
Originally Posted by Santaaa View Post
Well, what did i wrong with my version? it works for authid.
Only thing i can think of is that you never initialized the value if they're a new player.
But it could be (forgive techno-babble) that IP addresses are not static. (They can change whenever required by your ISP) and you may be connecting with a different IP. Or you could be running through a proxy which will mask your IP, or even some DNS servers and firewalls will mask IPs if you have them set to operate as such.
Long story short....IPs can be quite unreliable especially in situations like this. SteamIDs will never change. Unless the user gets a different account.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-06-2012 , 22:01   Re: Saving ip's into nvault
Reply With Quote #5

Quote:
Originally Posted by Santaaa View Post
Well, what did i wrong with my version? it works for authid.
There should be nothing wrong with the code posted. Having said the above post, ( many IP's not being static ) you should save by Steam ID - you have no reason not to.

EDIT: FYI the returns in your functions are not required.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 07-06-2012 at 22:01.
hornet is offline
Santaaa
BANNED
Join Date: May 2012
Old 07-07-2012 , 20:22   Re: Saving ip's into nvault
Reply With Quote #6

Then why doesnt it save ?:O
Santaaa is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-07-2012 , 22:16   Re: Saving ip's into nvault
Reply With Quote #7

Did you not read any of the above posts? Save by Steam ID. There's no reason to use IP.

You should also provide the full code because the error may be elsewhere.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Santaaa
BANNED
Join Date: May 2012
Old 07-08-2012 , 00:30   Re: Saving ip's into nvault
Reply With Quote #8

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <colorchat>
#include <nvault>

#define PLUGIN "K/D Ratio"
#define VERSION "1.0"
#define AUTHOR "Santaa"

new const Prefix[] = "[Test]";

new 
Kills[33], Deaths[33]

new 
g_vault

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_vault nvault_open("KDRATIO")
    
    if (
g_vault == INVALID_HANDLE)
    {
        
set_fail_state("Error loading logs")
    }
    
    
register_clcmd("say /ratio""Showratio")
    
    
register_event("DeathMsg""eDeath""a")
}

public 
client_putinserver(id)
{
    
LoadData(id)
}

public 
client_disconnect(id)
{
    
SaveData(id)
}

public 
Showratio(id)
{
    new 
name[32]
    
get_user_name(idname31)
    
    new 
Float:Ratio float(Kills[id]) / float(Deaths[id])
    
    
ColorChat(idGREY"%s ^1You have ^4%i^1 kills, ^4%i^1 deaths, ratio: ^4%.2f"PrefixKills[id], Deaths[id], Ratio);
    
ColorChat(0GREY"%s ^4%s ^1has a ratio of: ^4%.2f"PrefixnameRatio);
}

public 
eDeath()
{
    new 
killer read_data(1)
    new 
victim read_data(2)
    
    
Kills[killer]++
    
    
Deaths[victim]++
}

public 
SaveData(id)
{
    new 
ip[46]
    
get_user_ip(idipcharsmax(ip), 1)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-KDRATIO"ip)
    
format(vaultdata,255,"%i#%i#"Kills[id], Deaths[id])
    
nvault_set(g_vault,vaultkey,vaultdata)
    return 
PLUGIN_CONTINUE
}

public 
LoadData(id)
{
    new 
ip[46]
    
get_user_ip(idipcharsmax(ip), 1)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-PointMod"ip)
    
format(vaultdata,255,"%i#%i#"Kills[id], Deaths[id])
    
nvault_get(g_vault,vaultkey,vaultdata,255)
    
    
replace_all(vaultdata255"#"" ")
    
    new 
kills[32], deaths[32]
    
    
parse(vaultdatakills31deaths31)
    
    
Kills[id] = str_to_num(kills)
    
Deaths[id] = str_to_num(deaths)
    
    return 
PLUGIN_CONTINUE

Santaaa is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-08-2012 , 00:36   Re: Saving ip's into nvault
Reply With Quote #9

if you load ip-PointMod and save ip-KDRATIO as the keys you're not going to get consistent results. Just in case you didn't know that....
Also, not functionally different, but use formatex, its faster. And, again, use strtok instead of replace and parse. It'll be faster.

and....
Code:
ColorChat(0, GREY, "%s ^4%s ^1has a ratio of: ^4%.2f", Prefix, name, Ratio);

PHP Code:
ColorChat(0GREY"%s ^4%s ^1has a ration of: ^4%f"PrefixnameRatio
%f displays a float value. %.2f displays "%.2f". This will also cause the program to not have proper displays. Because Ratio is trying to display to nothing the engine will ignore this call and continue execution.

P.S. There is no point in adding a "KDRATIO" or "PointMod" to your key. If you need a difference, just use different vaults. It'll make it better organized and each vault smaller. (i don't know if vaultkeys are sorted or hashed, but if they're sorted....that will in turn make it faster. If they are hashed....well done developers.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-08-2012 at 00:50.
Liverwiz is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-08-2012 , 01:30   Re: Saving ip's into nvault
Reply With Quote #10

Quote:
Originally Posted by Liverwiz View Post
if you load ip-PointMod and save ip-KDRATIO as the keys you're not going to get consistent results.
In fact, he's actually not going to get any results.

Quote:
P.S. There is no point in adding a "KDRATIO" or "PointMod" to your key. If you need a difference, just use different vaults. It'll make it better organized and each vault smaller. (i don't know if vaultkeys are sorted or hashed, but if they're sorted....that will in turn make it faster. If they are hashed....well done developers.
If he's extending his plugin, then having different identifiers in the key may be useful, rather than mixing all kinds of data. No, vault entries are not sorted or hashed ( if they were hashed the value would not be able to be read ).

@Santaaa hopefully you've learnt and next time will show the correct the code, not write examples on the spot, hence giving helpers the wrong information. And I'll say it once again, your going to have many problems on your server if you continue to save by IP.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet 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 15:13.


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