SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 25/08/2008, 12:21 PM   #1
DracoBlue
Gangsta
 
Join Date: Apr 2006
Posts: 815
Reputation: 43
Default DJson 1.6.2 - Fast/Extensive File Reader/Writer (Official Dini²) (Works in FS)

DJson
Version 1.6.2 (Changelog)

Dini got downloaded nearly 15.000 already! Big thank you to everyone trusting in it!

Today I want to publish the next level of saving data to files. DJson is the library to save more then just little text-strings to files. It contains a cache to make your advanced gamemodes faster, it contains objects/arrays and a transaction based environment (djAutocommit) to override all speed/space/structure limits of dini. With approx 1.700 lines of code its, way bigger then the 250loc dini .

And last but not least: Its published under MIT-License. Use it, love it, hack it, sell it!

I really hope and want to keep what most of you connect with my releases: reliable code! This library walked through massive api tests and technical proofs, so it should work as expectd. Please report if you got any issues, so all others have benefit, too!

Download
Latest Version of DJson is 1.6.2 and can be found at the Download-Area of DracoBlue.net (djson_1_6_2.zip).

Why Djson?
  • Fast: DJson uses a database for caching purpose. So you can easily access the whole filesystem, read/write data, because they are already in the memory! Take a look at djAutocommit if you want to use the full power!
  • Secure: You can use anything but "/" parts of the keys, so save whatever you want - no incompatibilites here! Files are saved, as soon as the whole data is in the cache, so you won't lose any data, even if you turn of the computer while adding data! (Att: This does not count for the final commit, but it's pretty fast, though )
  • Unlimited (512 chars) structured items for paths and content: In djson you can use pathes, like this/is/a/very/long/......./path/up/to/512/characters. In djson you can use so much content as you want, just properly update the DJSON_MAX_STRING, if 512 is still not enough! And of course this limit counts for every single item, so player/vehicle can have unlimited amount of subitems, with again 512 characters!
    • DJSON_MAX_STRING should be at least 170 + maxfilenamelength + maxkeylength + maxvaluelength
  • Files: A reason why to use djson is of course, that the data is saved to files! Since djson uses the JSON-standard, you may use JavaScript, PHP, Flash, Java, ... and so on, to read the data!
  • Arrays/Objects: In DJson you can use objects (hashtables) and arrays (lists) with values, which can be nested as deep as you want. The arrays have some sweet extra functionality, like for example the djCount and the djAppend, which allows you to work with that items, like a general list in any other programming language - and it's all saved!
  • Compatible: Since JSON is a standard, you may use (edit/read) the produced files with PHP/Flash/JavaScript/Java/C# and create for example an online map (see dmap), with nearly no effort!

References
- Official DJson-Page
- Examples
- Function List
- Tweaking DJson
- DJson-Blog in my DevDiary

Tutorials
- Register/Login System Using DJson
- Why not use ONE big file for all user data

Known Issues
- Writing strings with unescaped " does not work! You have to replace " with \" first! This will be fixed in future versions.

Usage
I added a small test-script, called stats.pwn to the release, which counts server restarts and player-connect/deaths.

And since I know, most of you guys are too lazy to read the entire API-Documentation at http://dracoblue.net/djson , here comes a quick and dirty script:
Includes!
pawn Code:
#include <a_samp>
#include <djson>
main() {
}

Register the callbacks:
pawn Code:
public OnGameModeInit() {
    djson_GameModeInit(); // <-- this must be called _before_ you can use any djson function!!
   
    djSetInt("stats.json","server/started",djInt("stats.json","server/started")+1);

    printf("Server starts: %d",djInt("stats.json","server/started"));
   
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit() {
    djson_GameModeExit(); // <-- when you exit the gamemode, after that you can't run any djson function anymore!
    return 1;
}

And now some counting:
pawn Code:
public OnPlayerRequestClass(playerid, classid) {
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid) {
    djSetInt("stats.json","players/connected",djInt("stats.json","players/connected")+1);
    return 1;
}

public OnPlayerSpawn(playerid) {
    djSetInt("stats.json","players/spawned",djInt("stats.json","players/spawned")+1);
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason) {
    djSetInt("stats.json","players/died",djInt("stats.json","players/died")+1);
    return 1;
}

Have fun coding,
Jan (DracoBlue)
__________________
Auto-Indent Your Code online with TidyPawn

dcmd 1.0 | dini 1.6 | djson 1.6.2 (The offic. Dini²) | DMap 0.4 | DModule 0.13 (Dynamic GM/FS) | DUDB 2.4 | DTest 1.2 | Dutils 1.10

[dracoblue's dev-diary][php + javascript developer][serverside javascript mvc framework]


Last edited by DracoBlue; 11/09/2012 at 12:19 PM.
DracoBlue is offline   Reply With Quote
Old 25/08/2008, 12:30 PM   #2
Antironix
High-roller
 
Join Date: May 2007
Posts: 1,438
Reputation: 18
Default Re: DJson 1.0 - Fast/Extensive File Reader/Writer (Official Dini²)

Nice one DracoBlue, especially the counting!
[me=Wadabak]is going to convert my codes [/me]
Antironix is offline   Reply With Quote
Old 25/08/2008, 12:37 PM   #3
Xalphox
Little Clucker
 
Join Date: Aug 2007
Posts: 41
Reputation: 0
Default Re: DJson 1.0 - Fast/Extensive File Reader/Writer (Official Dini²)

Oh shit.
Xalphox is offline   Reply With Quote
Old 25/08/2008, 01:12 PM   #4
MaTrIx4057
Gangsta
 
MaTrIx4057's Avatar
 
Join Date: Apr 2007
Posts: 819
Reputation: 23
Default Re: DJson 1.0 - Fast/Extensive File Reader/Writer (Official Dini²)

Awesome!!
MaTrIx4057 is offline   Reply With Quote
Old 25/08/2008, 01:21 PM   #5
Eyzi
Big Clucker
 
Join Date: Jan 2007
Posts: 152
Reputation: 0
Default Re: DJson 1.0 - Fast/Extensive File Reader/Writer (Official Dini²)

well done
Eyzi is offline   Reply With Quote
Old 25/08/2008, 01:39 PM   #6
Ycto
Big Clucker
 
Join Date: Jul 2007
Posts: 73
Reputation: 0
Default Re: DJson 1.0 - Fast/Extensive File Reader/Writer (Official Dini²)

Another nice release Draco! Thanks =)
Ycto is offline   Reply With Quote
Old 25/08/2008, 06:24 PM   #7
DracoBlue
Gangsta
 
Join Date: Apr 2006
Posts: 815
Reputation: 43
Default Re: DJson 1.0 - Fast/Extensive File Reader/Writer (Official Dini²)

Glad if you like it.

I am currently working on a (free) web-based-auto-updating map using that as data-source.

[edit] DJson 1.1 released!
* fixed bug in djSet if setting Array-Elements with children
* added djCreateFile
* added djRemoveFile

Djson 1.2 released!
* fixed crash in djUnset, when unsetting the last array element.

- Draco
__________________
Auto-Indent Your Code online with TidyPawn

dcmd 1.0 | dini 1.6 | djson 1.6.2 (The offic. Dini²) | DMap 0.4 | DModule 0.13 (Dynamic GM/FS) | DUDB 2.4 | DTest 1.2 | Dutils 1.10

[dracoblue's dev-diary][php + javascript developer][serverside javascript mvc framework]

DracoBlue is offline   Reply With Quote
Old 26/08/2008, 11:15 AM   #8
Antironix
High-roller
 
Join Date: May 2007
Posts: 1,438
Reputation: 18
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official Dini²)

Damn, this is nice. I've just had a better look at it, now I can have all accounts in just one file!

Question: Is it possible to delete 1 string of a line? I'll give you an example.

Code:
"vehicles":["PCJ","Cheetah","Banshee"],
Like deleting 'Cheetah' of that vehicles line so it would become this:

Code:
"vehicles":["PCJ","Banshee"],

Thanks.
Antironix is offline   Reply With Quote
Old 26/08/2008, 12:23 PM   #9
DracoBlue
Gangsta
 
Join Date: Apr 2006
Posts: 815
Reputation: 43
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official Dini²)

Quote:
Originally Posted by Wadabak
Damn, this is nice. I've just had a better look at it, now I can have all accounts in just one file!

Question: Is it possible to delete 1 string of a line? I'll give you an example.

Code:
"vehicles":["PCJ","Cheetah","Banshee"],
Like deleting 'Cheetah' of that vehicles line so it would become this:

Code:
"vehicles":["PCJ","Banshee"],

Thanks.
yes. djUnset("filename","vehicles/1"); // to delete the 2nd item.

- Draco
__________________
Auto-Indent Your Code online with TidyPawn

dcmd 1.0 | dini 1.6 | djson 1.6.2 (The offic. Dini²) | DMap 0.4 | DModule 0.13 (Dynamic GM/FS) | DUDB 2.4 | DTest 1.2 | Dutils 1.10

[dracoblue's dev-diary][php + javascript developer][serverside javascript mvc framework]

DracoBlue is offline   Reply With Quote
Old 26/08/2008, 12:34 PM   #10
Antironix
High-roller
 
Join Date: May 2007
Posts: 1,438
Reputation: 18
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official Dini²)

cool, great! Way better as dini
Antironix is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] [INC] SII 2.0.6 - Fast cache based INI Reader/Writer [DRuG]Slick Includes 86 20/04/2014 04:33 PM
From Dini To DjSon MafiaGuy™ Help Archive 5 27/08/2010 05:39 PM
Create Vehicle from file (Need Very Fast) epranka Help Archive 2 04/06/2010 10:31 AM
FAST READER (INI SYSTEM) MahmutBey Help Archive 2 08/05/2010 08:16 PM
Reading from file works not perfect.. [NOT SOLVED] RyDeR` Help Archive 9 28/02/2010 09:01 AM


All times are GMT. The time now is 01:03 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.