Raised This Month: $ Target: $400
 0% 

Array Module messes up on steamID's?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 01-08-2005 , 18:06   Array Module messes up on steamID's?
Reply With Quote #1

I attempted to make a vault-like system using array module. It read from a file really well, changed the data in the memory really fast, and wrote the data again perfectly file.

However, I went to use it with steamid's as the keys, and it messed up really quickly.

Any idea's?

Code:
/* Cvault Array
*
* by Twilight Suzka
*  originally developed by Avalanche
*
* This file is provided as is (no warranties).
*/

#if defined _cvault_array_included
  #endinput
#endif
#define _cvault_array_included
#include <array>


public open_cvault(file[]){
	if(!file_exists(file)) { // no file 
		write_file(file,"key	data",0); 
	} 

	new listid = new_keytable()
	new line = 0, text[1024], txtlen;
 	// go through file 
	while((line=read_file(file,line,text,2047,txtlen)) != 0) { 
		// get data and keys 
		new currkey[512], currdata[512]; // key, data 
		strtok(text,currkey,512,currdata,512,'	',1); // split into parts 
		store_string(listid, currkey, currdata);
		
	}
	return listid;
}

public reload_cvault(file[],listid){
	if(!file_exists(file)) { // no file 
		write_file(file,"key	data",0); 
	} 
	new line = 0, text[1024], txtlen;
 	// go through file 
	while((line=read_file(file,line,text,2047,txtlen)) != 0) { 
		// get data and keys 
		new currkey[512], currdata[512]; // key, data 
		strtok(text,currkey,512,currdata,512,'	',1); // split into parts 
		store_string(listid, currkey, currdata);
		
	}
	return 1;
}

public reset_vault(file[],listid){
	keytable_clear(listid)
	reload_cvault(file,listid)
	save_cvault(file,listid,1)
	reload_cvault(file,listid)
	return listid;
}

public save_cvault(file[],listid,reset){
 	delete_file ( file )
	new text[1024], key[512], data[512]
	keytable_reset(listid);
	new size = keytable_count ( listid )
	for( new i = 0; i < size; i++) { 
		keytable_getkey(listid, key, sizeof(key));
		getkey_string(listid, key, data, sizeof(data));
		if(!equal(data,"DELETE",6)){
			format(text,sizeof(text),"%s	%s",key,data)
			write_file(file,text,i)
		}
		keytable_next(listid)
	}
	keytable_reset(listid)
	if(reset) keytable_clear(listid);
	return 1;
}

public get_cvaultdata(listid, key[], data[], len){
	getkey_string(listid, key, data, len)
	return 1;
}

public get_cvaultdata_int(listid, key[], data){
	new int[256];
	getkey_string(listid, key, int, 255)
	data = str_to_num(int)
	return 1;
}

public get_cvaultdata_float(listid, key[], Float:data, len){
	new storage[256]
	getkey_string(listid, key, storage, 255)
	data = floatstr(storage)
	return 1;
}

public set_cvaultdata(listid,key[], data[]){
	store_string(listid, key, data);
	return 1;
}

public set_cvaultdata_int(listid,key[], data){
	new string[256]
	format(string,sizeof(string),"%i",data)
	store_string(listid, key, string);
	return 1;
}

public set_cvaultdata_float(listid,key[], Float:data){
	new string[256]
	format(string,sizeof(string),"%f",data)
	store_string(listid, key, string);
	return 1;
}

public set_cvaultdata2(file[],listid,key[],data[]){
	new string[512]
	set_cvaultdata(listid,key,data)
	format(string,sizeof(string),"%s	%s",key,data)
	write_file(file,string,-1)
	return 1;
}

public remove_cvaultdata(listid,key[]){
	store_string(listid, key, "DELETE");
	return 1;
}

public cvaultdata_exists(listid, key[]){
	new data[512]
	getkey_string(listid, key, data, sizeof(data));
	if(equal(data,"")) return 0;
	return 1;
}
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
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 19:23.


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