25.08.2008, 12:21
(
Последний раз редактировалось DracoBlue; 11.08.2015 в 06:59.
)
DJson
Version 1.6.2 (Changelog)
Dini got downloaded nearly 15.000 already! Big thank you to everyone trusting in it!Version 1.6.2 (Changelog)
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!
- 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
- none
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://web.archive.org/web/201404151...ndex.php/DJson , here comes a quick and dirty script:
Includes!
pawn Код:
#include <a_samp>
#include <djson>
main() {
}
pawn Код:
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;
}
pawn Код:
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;
}
Jan (DracoBlue)