Make rooms, Independent & Persistent

Post here your questions about the OpenSpace 2.x or notify bugs and suggestions.

Moderators: Lapo, Bax

Post Reply
PabloStarka
Posts: 10
Joined: 19 Mar 2011, 01:12

Make rooms, Independent & Persistent

Post by PabloStarka »

-- Problem #1
Well, i need create rooms from the client. Easily i can use the method provided in the documentation, and add the variable from any room map file, but no! Because the openspace do the decoration changes in that file, and if a do a change in my room map, the map of another room is the same, so the changes i do happens in the 2 rooms with the same map!

So? What's what i need? I need create a method to write a specific map file, when i create the room...
Well, in the documentation includes this server object function called .writeFile() this creates a file in the Server folder (I Have Modified the OpenSpace Extension to use the maps from this folder) perfect! i'm gonna use this code :

Code: Select all

		private function onCreateClick(e:MouseEvent):void
		{
			logTrace("Creating Room...")			
			// --- Room Data --------------------------------
			
			var roomObj = {}
            roomObj.name = ti_room.text
            roomObj.maxU = 25
            roomObj.isGame = false
			var room = ti_room.text
			
			// --- Vars --------------------------------
            var roomVars = 	[
				        {name:"_os_mapId", type:"s", val:"Houses#"+ room +"", priv:false, persistent:true},
			            ]
						
            // --- Room Data Export --------------------------------
            var newRoom = smartFox.createRoom(roomObj, roomVars)
            var map = map.text
            var ok = smartFox.writeFile("Houses#"+ room +".map", map)

            if (ok)
	    trace("File saved!")
            else 
	   trace("File write failed!")
            
			// --- Room Data Export - Process Status --------------------------------
            if (newRoom != null)
	        trace("Room Created...")
            else
	        trace("An Error Ocurred : onCreateRoom Function...#18!")
		    }

the map instance contains the Houses#default.map text content, so if we create a file with the same content of the default maps, it looks like the same, but this is independent...

NOTE : THIS DON'T WORKS - THE writeFile() Doesn't work! Why? I DON'T KNOW!
So i need a method to create a file...

-- Problem #2 : Create a Persistent Room,
When a use the method mentioned, the server creates a dynamic room...What it means? THE ROOM IS DELETED WHEN THE USER IS OUT!!...
So? How i can create a persistent(static) room from the client?

_________________________________________________________________

Thanks! Please Reply....
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Make rooms, Independent & Persistent

Post by rjgtav »

Hello,

The writeFile method is only available on Server-side extensions, not from the client. Also, only the server-side can create persistent rooms, by specifying null as the room's creator.
It is never safe to give such powers to the client, imagine a hacked client creating multiple files at the server, and killing its resources. In order to achieve this, you can send an extension message and do the necessary steps from the server-side.

Cheers
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Make rooms, Independent & Persistent

Post by Bax »

For you problem #1, create a "master" map file, then duplicate it and assign it to each new Room (of course everything must be done on the server side - check the OpenSpaceExtension.sendAvatarToMap method in the server side API JavaDoc: http://openspace-engine.com/static/serv ... index.html).

Problem #2. As rjgtav pointed out, on the server side you can create Rooms which aren't removed after the user is gone.
Paolo Bax
The SmartFoxServer Team
PabloStarka
Posts: 10
Joined: 19 Mar 2011, 01:12

Re: Make rooms, Independent & Persistent

Post by PabloStarka »

So i can create a ActionScript Extension, to when the client send a event of a room created, he duplicates the map file, and what method i can use fo that? it not appears in the documentation...

I can create persistent rooms with a Flash Extensions? On the Server Side obviusly
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Make rooms, Independent & Persistent

Post by rjgtav »

Hello,

You can find the sendAvatarToMap method on the documentation link that Bax shared, more specifically here:
http://openspace-engine.com/static/serv ... atarToMap2

Regarding the AS Extensions questions, yes, you can, in fact, the ActionScript Extensions can do pratically everything a Java Extension can do. You can check the server-side AS API here:
http://www.smartfoxserver.com/docs/1x/d ... /index.htm

Cheers
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Make rooms, Independent & Persistent

Post by Bax »

I need to make a correction to Rjgtav's answer. The OpenSpace Extension is written in Java, and you will need to extend it (sorry for the pun) to add your custom code. This document is your starting point: http://openspace-engine.com/support/manuals/extension
Paolo Bax
The SmartFoxServer Team
Post Reply