Code: Select all
String tempfile = data.getString("home");
String templName = tempfile = "123#"+tempfile;
String mapName = templName + requester.getName();
// Create a new map file, and check if it already exists
File newMap = new File("openSpace/data/" + mapName + ".map");
if(!newMap.exists())
{
// If the map doesn't exist already, duplicate the template
File templMap = new File("openSpace/data/" + templName + ".map");
InputStream in = new FileInputStream(templMap);
OutputStream out = new FileOutputStream(newMap);
// Copy data from template file to new file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
// Set the properties of a dynamic SmartFoxServer Room corresponding to the map.
Map<String, String> params = new HashMap<String, String>();
params.put("name", templName+ requester.getName());
params.put("maxU", "10");
params.put("pwd", "testpwd"); // We add a password so other users can't enter the requester's home.
// Assign the map to the Room by means of the _os_mapId Room Variable.
HashMap<String, RoomVariable> roomVars = new HashMap<String, RoomVariable>();
RoomVariable mapRoomVar = new RoomVariable(templName + requester.getName(), "s", null, true, false);
roomVars.put("_os_mapId", mapRoomVar);
// Create the dynamic SmartFoxServer Room corresponding to the map.
Room newRoom = null;
try {
newRoom = ExtensionHelper.instance().createRoom(ExtensionHelper.instance().getZone(this.getOwnerZone()), params, requester, roomVars, null, false, true, true);
} catch (ExtensionHelperException e)
{
e.printStackTrace();
}
// If Room creation was successful, send the user to his own home.
if(newRoom != null)
super.sendAvatarToMap(requester, newRoom.getId(), "testpwd");