Raised This Month: $ Target: $400
 0% 

automatic write file


Post New Thread Reply   
 
Thread Tools Display Modes
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-29-2016 , 10:36   Re: automatic write file
Reply With Quote #11

Open file ...addons/sourcemod/data/MyKv.txt

Re-open that file when new players has joined server.

This now only save players name who join into server.
PHP Code:


KeyValues MyKv
;

public 
void OnPluginStart()
{
    
char buffer[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMbuffersizeof(buffer), "data/MyKv.txt");

    
MyKv = new KeyValues("data");
    
MyKv.ImportFromFile(buffer);
}

public 
void OnClientPostAdminCheck(int client)
{
    if(
IsFakeClient(client)) return;

    
char buffer[PLATFORM_MAX_PATH];

    
GetClientAuthId(clientAuthId_Enginebuffersizeof(buffer));

    
MyKv.JumpToKey(buffertrue); // Find or Create entry

    
GetClientName(clientbuffersizeof(buffer));

    
MyKv.SetString("name"buffer);
    
MyKv.Rewind();

    
BuildPath(Path_SMbuffersizeof(buffer), "data/MyKv.txt");
    
MyKv.ExportToFile(buffer);

__________________
Do not Private Message @me

Last edited by Bacardi; 09-29-2016 at 12:55. Reason: edit, add ImportFromFile
Bacardi is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 09-29-2016 , 15:58   Re: automatic write file
Reply With Quote #12

Quote:
Originally Posted by Bacardi View Post
Open file ...addons/sourcemod/data/MyKv.txt

Re-open that file when new players has joined server.

This now only save players name who join into server.
PHP Code:


KeyValues MyKv
;

public 
void OnPluginStart()
{
    
char buffer[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMbuffersizeof(buffer), "data/MyKv.txt");

    
MyKv = new KeyValues("data");
    
MyKv.ImportFromFile(buffer);
}

public 
void OnClientPostAdminCheck(int client)
{
    if(
IsFakeClient(client)) return;

    
char buffer[PLATFORM_MAX_PATH];

    
GetClientAuthId(clientAuthId_Enginebuffersizeof(buffer));

    
MyKv.JumpToKey(buffertrue); // Find or Create entry

    
GetClientName(clientbuffersizeof(buffer));

    
MyKv.SetString("name"buffer);
    
MyKv.Rewind();

    
BuildPath(Path_SMbuffersizeof(buffer), "data/MyKv.txt");
    
MyKv.ExportToFile(buffer);

thank you
I will test it later.
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests
BraveFox is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 09-29-2016 , 20:29   Re: automatic write file
Reply With Quote #13

https://sm.alliedmods.net/new-api/keyvalues
Kolapsicle is offline
Vergil333
Member
Join Date: Apr 2016
Old 09-30-2016 , 11:00   Re: automatic write file
Reply With Quote #14

Quote:
Originally Posted by shavit View Post
have fun with files over 10mb and insane server lag when you read them to memory..
don't you think a database is a more proper approach?
This interests me. I'm catching a few events and storing them to a multiarray. After a match an array is inserted to db and unset/null/erased/whatever.

An array can have 500 rows... 500 times 4 columns... Let's say 10 characters per value...
500x4x10 = 20 000 bytes.

So stored array can reach 20 kB? That's low for causing any lag... isn't it???
Vergil333 is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 09-30-2016 , 22:28   Re: automatic write file
Reply With Quote #15

Quote:
Originally Posted by Vergil333 View Post
This interests me. I'm catching a few events and storing them to a multiarray. After a match an array is inserted to db and unset/null/erased/whatever.

An array can have 500 rows... 500 times 4 columns... Let's say 10 characters per value...
500x4x10 = 20 000 bytes.

So stored array can reach 20 kB? That's low for causing any lag... isn't it???
A hard drive is a lot slower than a CPU or RAM, accessing (reading/writing to) it regularly is something you want to avoid if possible, especially when dealing with a single thread that has a lot of work to do. Utilizing a database on a separate thread circumvents the issue of interrupting the main game thread. Not to mention the vast benefits an SQL database holds over a locally stored raw text file.
Kolapsicle is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-01-2016 , 06:29   Re: automatic write file
Reply With Quote #16

Quote:
Originally Posted by Vergil333 View Post
This interests me. I'm catching a few events and storing them to a multiarray. After a match an array is inserted to db and unset/null/erased/whatever.

An array can have 500 rows... 500 times 4 columns... Let's say 10 characters per value...
500x4x10 = 20 000 bytes.

So stored array can reach 20 kB? That's low for causing any lag... isn't it???
but OP wants -keyvalues- that will have a new subkey for every unique player

so..
Code:
"{{key}}"
{
	"{{STEAMID}}"
	{
		"Name"	"{{NAME}}"
	}
	
	"{{STEAMID}}"
	{
		"Name"	"{{NAME}}"
	}

	
	"{{STEAMID}}"
	{
		"Name"	"{{NAME}}"
	}

	
	"{{STEAMID}}"
	{
		"Name"	"{{NAME}}"
	}

	
	"{{STEAMID}}"
	{
		"Name"	"{{NAME}}"
	}
	
	... /* and so on */
}
i have had over 10,000 unique players in one of my servers, imagine such a large file being read and written to every time a player joins (read) and if he's new, also write
= insane lag
__________________
retired
shavit is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 10-01-2016 , 09:57   Re: automatic write file
Reply With Quote #17

Keyvalues are horrible for data storage, great for parsing config files.

Use SQLite if you want data storage. Leverage SQL without needing an SQL server.
Potato Uno 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 11:01.


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