created room and roomvars backup

Post here your suggestions for new possible features in SmartFoxServer.

Moderators: Lapo, Bax

Post Reply
Portuguese
Posts: 12
Joined: 07 Apr 2006, 23:43

created room and roomvars backup

Post by Portuguese »

I would like a created room and roomvars backup so they won't erase when the servers resets, please i need it

sorry for posting in an other "topic" i pressed the wrong button...

but is it possible what i asked?
DavidPesta
Posts: 27
Joined: 13 Apr 2006, 19:22

Post by DavidPesta »

I would guess that an application can be designed to store room variables in a database so that when the server is taken down and brought back up, the variables are loaded from the database and the room is restored.
DavidPesta
Posts: 27
Joined: 13 Apr 2006, 19:22

Post by DavidPesta »

I noticed this was Lapo's answer as well:
http://forums.smartfoxserver.com/viewtopic.php?t=424
Portuguese
Posts: 12
Joined: 07 Apr 2006, 23:43

Post by Portuguese »

How should i save the roomvariables in a database, because if i do it 1 variable per variable it will take me lot of spaces at the DataBase... how should i save it just using one box in the database??

Please someone help me!! :?
DavidPesta
Posts: 27
Joined: 13 Apr 2006, 19:22

Post by DavidPesta »

A solution to this that occurred to me recently is to format all of your variables in an XML structure and store that structure in a single mediumtext field. 'TEXT' (65K) is smaller than 'MEDIUMTEXT' (16M) in MySQL, which may be too small, so use 'MEDIUM' instead of 'TEXT' if you have a lot going on in that room. Use 'LONGTEXT' only if you are saving especially massive rooms.

Of course, this may not be so good for keeping a persistent/continual copy of room variables, only for a single backup before the server comes down, which requires prior knowledge of the server coming down beforehand. You could take minutely snapshots--but with massive rooms that would really slow down your server.

So it looks like your best bet for especially massive rooms would be to keep all room data in their own variable fields afterall. Keep player data in their own database table and report the room that the player exists in inside of the player database table.

Okay, these are a few strategies that I would begin to think about. Your goal is to evaluate the way your application functions and structure your tables for data accordingly. :wink:

David
DavidPesta
Posts: 27
Joined: 13 Apr 2006, 19:22

Post by DavidPesta »

Another interesting thought. If you're using Python you could shelve all your data continuously in a SINGLE FILE without the need for a database! (It may work well, I haven't played with shelve a lot yet.)

Oh wait, no Python extensions yet. :lol:

David
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Post by Virusescu »

function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Post by Virusescu »

@DavidPesta.
Using a database is not a must here eigther. You can use _server.writeFile() method to write to a file and then read them with something like

Code: Select all

var roomVarsString = _server.readFile("../room1vars.bkp")
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
Portuguese
Posts: 12
Joined: 07 Apr 2006, 23:43

ooh thanks that will be great!

Post by Portuguese »

ooh thanks that will be great! but where can i find like a toturial or where in the DOCs could i fin it to read more... and how should i save the variable text? because if i write variable per variable it would take me lot memory and time.... or if there is another way to save the variables in the text files with saving them one per one..?
Portuguese
Posts: 12
Joined: 07 Apr 2006, 23:43

could it be by arrays?

Post by Portuguese »

if i do it by arrays, how can i load the array from the mySQL because if i do it.. in the clientside.. if i do vars[2] it will tell me 'undefined' so how can i do it?
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Post by Virusescu »

Example of saving and reading an array as a string.

Code: Select all

var myArr = [1,343,3,53,23,64];
var str = myArr.join(",");
var ok = _server.writeFile("testarray.txt", str);
if (ok) 
	trace("File saved!")
else 
	trace("File write failed!")
/// ------------ let's assume the file was saved.
// - you can read them like
var str = _server.readFile("testarray.txt");
myArray = str.split(",");
Only thing to note is that now you have strings as elements of your myArray and not numbers anymore.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
Portuguese
Posts: 12
Joined: 07 Apr 2006, 23:43

ooh tanks!! but...

Post by Portuguese »

thanks but... when i reset the server and the server starts again... all the inits(); in the extension will be invoked? or what can i do that when the server resets and starts again... do something?
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Post by Virusescu »

Yes, when the server restarts, as long as the extensions is a zone level extension and is attached from the config.xml, the init method will be called.

If your rooms where static, they also are in the xml with some extension attached. When server starts the rooms will be created.

If you created the rooms dinamically then you will also need to constantly save data about the rooms from the zone extension so that you will be able to recreate the rooms when the zone level extension's init method's is called.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
Post Reply