Page 1 of 1

created room and roomvars backup

Posted: 31 May 2006, 19:07
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?

Posted: 31 May 2006, 21:28
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.

Posted: 31 May 2006, 21:32
by DavidPesta
I noticed this was Lapo's answer as well:
http://forums.smartfoxserver.com/viewtopic.php?t=424

Posted: 31 May 2006, 23:15
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!! :?

Posted: 31 May 2006, 23:52
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

Posted: 31 May 2006, 23:57
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

Posted: 01 Jun 2006, 06:27
by Virusescu

Posted: 01 Jun 2006, 06:32
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")

ooh thanks that will be great!

Posted: 01 Jun 2006, 18:20
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..?

could it be by arrays?

Posted: 02 Jun 2006, 00:51
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?

Posted: 02 Jun 2006, 06:43
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.

ooh tanks!! but...

Posted: 02 Jun 2006, 22:23
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?

Posted: 03 Jun 2006, 07:03
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.