rubyfox-server 2.12.5.1 → 2.13.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubyfox/server/data/config/admin/descriptors/config_room.txt +4 -4
  3. data/lib/rubyfox/server/data/config/admin/descriptors/config_server.txt +46 -98
  4. data/lib/rubyfox/server/data/config/admin/descriptors/config_zone.txt +3 -3
  5. data/lib/rubyfox/server/data/config/admin/descriptors/runtime_user.txt +8 -1
  6. data/lib/rubyfox/server/data/config/core.xml +2 -2
  7. data/lib/rubyfox/server/data/config/server.xml +5 -12
  8. data/lib/rubyfox/server/data/data/bannedusers/users.bin +0 -0
  9. data/lib/rubyfox/server/data/extensions/pyTest/Simple.py +1 -1
  10. data/lib/rubyfox/server/data/lib/cachedir/packages/charsets.pkc +0 -0
  11. data/lib/rubyfox/server/data/lib/cachedir/packages/cldrdata.pkc +0 -0
  12. data/lib/rubyfox/server/data/lib/cachedir/packages/dnsns.pkc +0 -0
  13. data/lib/rubyfox/server/data/lib/cachedir/packages/jaccess.pkc +0 -0
  14. data/lib/rubyfox/server/data/lib/cachedir/packages/javax.mail.glassfish-1.4.1.v201005082020.pkc +0 -0
  15. data/lib/rubyfox/server/data/lib/cachedir/packages/javax.transaction-api-1.2.pkc +0 -0
  16. data/lib/rubyfox/server/data/lib/cachedir/packages/jce.pkc +0 -0
  17. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-annotations-9.3.11.v20160721.pkc +0 -0
  18. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-deploy-9.3.11.v20160721.pkc +0 -0
  19. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-http-9.3.11.v20160721.pkc +0 -0
  20. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-io-9.3.11.v20160721.pkc +0 -0
  21. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-jndi-9.3.11.v20160721.pkc +0 -0
  22. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-plus-9.3.11.v20160721.pkc +0 -0
  23. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-schemas-3.1.pkc +0 -0
  24. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-security-9.3.11.v20160721.pkc +0 -0
  25. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-server-9.3.11.v20160721.pkc +0 -0
  26. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-servlet-9.3.11.v20160721.pkc +0 -0
  27. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-util-9.3.11.v20160721.pkc +0 -0
  28. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-webapp-9.3.11.v20160721.pkc +0 -0
  29. data/lib/rubyfox/server/data/lib/cachedir/packages/jetty-xml-9.3.11.v20160721.pkc +0 -0
  30. data/lib/rubyfox/server/data/lib/cachedir/packages/jfr.pkc +0 -0
  31. data/lib/rubyfox/server/data/lib/cachedir/packages/jfxrt.pkc +0 -0
  32. data/lib/rubyfox/server/data/lib/cachedir/packages/jsse.pkc +0 -0
  33. data/lib/rubyfox/server/data/lib/cachedir/packages/localedata.pkc +0 -0
  34. data/lib/rubyfox/server/data/lib/cachedir/packages/nashorn.pkc +0 -0
  35. data/lib/rubyfox/server/data/lib/cachedir/packages/packages.idx +0 -0
  36. data/lib/rubyfox/server/data/lib/cachedir/packages/resources.pkc +0 -0
  37. data/lib/rubyfox/server/data/lib/cachedir/packages/rt.pkc +0 -0
  38. data/lib/rubyfox/server/data/lib/cachedir/packages/servlet-api-3.1.pkc +0 -0
  39. data/lib/rubyfox/server/data/lib/cachedir/packages/sunec.pkc +0 -0
  40. data/lib/rubyfox/server/data/lib/cachedir/packages/sunjce_provider.pkc +0 -0
  41. data/lib/rubyfox/server/data/lib/cachedir/packages/sunpkcs11.pkc +0 -0
  42. data/lib/rubyfox/server/data/lib/cachedir/packages/zipfs.pkc +0 -0
  43. data/lib/rubyfox/server/data/lib/commons-collections-3.2.2.jar +0 -0
  44. data/lib/rubyfox/server/data/lib/jetty/etc/jetty.xml +37 -0
  45. data/lib/rubyfox/server/data/lib/js/JSApi.js +1298 -0
  46. data/lib/rubyfox/server/data/lib/js/LibApi.js +2046 -0
  47. data/lib/rubyfox/server/data/lib/js/LibUtil.js +22 -0
  48. data/lib/rubyfox/server/data/lib/logs-analysis-app.jar +0 -0
  49. data/lib/rubyfox/server/data/lib/sfs2x-admin.jar +0 -0
  50. data/lib/rubyfox/server/data/lib/sfs2x-core.jar +0 -0
  51. data/lib/rubyfox/server/data/lib/sfs2x.jar +0 -0
  52. data/lib/rubyfox/server/data/sfs2x-service +3 -3
  53. data/lib/rubyfox/server/data/sfs2x.sh +1 -1
  54. data/lib/rubyfox/server/data/www/root/admin/AdminTool.swf +0 -0
  55. data/lib/rubyfox/server/data/www/root/admin/ReleaseNotes.txt +8 -0
  56. data/lib/rubyfox/server/data/www/root/admin/index.html +6 -6
  57. data/lib/rubyfox/server/data/www/root/admin/modules/Analytics.swf +0 -0
  58. data/lib/rubyfox/server/data/www/root/admin/modules/BanManager.swf +0 -0
  59. data/lib/rubyfox/server/data/www/root/admin/modules/BlueBoxMonitor.swf +0 -0
  60. data/lib/rubyfox/server/data/www/root/admin/modules/Console.swf +0 -0
  61. data/lib/rubyfox/server/data/www/root/admin/modules/Dashboard.swf +0 -0
  62. data/lib/rubyfox/server/data/www/root/admin/modules/ExtensionManager.swf +0 -0
  63. data/lib/rubyfox/server/data/www/root/admin/modules/LicenseManager.swf +0 -0
  64. data/lib/rubyfox/server/data/www/root/admin/modules/LogViewer.swf +0 -0
  65. data/lib/rubyfox/server/data/www/root/admin/modules/ServerConfigurator.swf +0 -0
  66. data/lib/rubyfox/server/data/www/root/admin/modules/ZoneConfigurator.swf +0 -0
  67. data/lib/rubyfox/server/data/www/root/admin/modules/ZoneMonitor.swf +0 -0
  68. data/lib/rubyfox/server/data/www/sfs2x-ws.war +0 -0
  69. data/lib/rubyfox/server/data/zones/BasicExamples.zone.xml +147 -0
  70. data/lib/rubyfox/server/version.rb +1 -1
  71. metadata +42 -7
  72. data/lib/rubyfox/server/data/lib/commons-collections-3.2.1.jar +0 -0
  73. data/lib/rubyfox/server/data/lib/js.jar +0 -0
  74. data/lib/rubyfox/server/data/lib/netty-3.9.0.Final.jar +0 -0
@@ -0,0 +1,2046 @@
1
+ /* Simple JavaScript Inheritance
2
+ * By John Resig http://ejohn.org/
3
+ * MIT Licensed.
4
+ *
5
+ * See: http://ejohn.org/blog/simple-javascript-inheritance/
6
+ */
7
+ (function()
8
+ {
9
+ var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
10
+
11
+ // The base Class implementation (does nothing)
12
+ this.Class = function(){};
13
+
14
+ // Create a new Class that inherits from this class
15
+ Class.extend = function(prop) {
16
+ var _super = this.prototype;
17
+
18
+ // Instantiate a base class (but only create the instance,
19
+ // don't run the init constructor)
20
+ initializing = true;
21
+ var prototype = new this();
22
+ initializing = false;
23
+
24
+ // Copy the properties over onto the new prototype
25
+ for (var name in prop) {
26
+ // Check if we're overwriting an existing function
27
+ prototype[name] = typeof prop[name] == "function" &&
28
+ typeof _super[name] == "function" && fnTest.test(prop[name]) ?
29
+ (function(name, fn){
30
+ return function() {
31
+ var tmp = this._super;
32
+
33
+ // Add a new ._super() method that is the same method
34
+ // but on the super-class
35
+ this._super = _super[name];
36
+
37
+ // The method only need to be bound temporarily, so we
38
+ // remove it when we're done executing
39
+ var ret = fn.apply(this, arguments);
40
+ this._super = tmp;
41
+
42
+ return ret;
43
+ };
44
+ })(name, prop[name]) :
45
+ prop[name];
46
+ }
47
+
48
+ // The dummy class constructor
49
+ function Class() {
50
+ // All construction is actually done in the init method
51
+ if ( !initializing && this.init )
52
+ this.init.apply(this, arguments);
53
+ }
54
+
55
+ // Populate our constructed prototype object
56
+ Class.prototype = prototype;
57
+
58
+ // Enforce the constructor to be what we expect
59
+ Class.prototype.constructor = Class;
60
+
61
+ // And make this class extendable
62
+ Class.extend = arguments.callee;
63
+
64
+ return Class;
65
+ };
66
+ })();
67
+
68
+ //--- Import SFS2X names from Java scope ---------------------------------------
69
+
70
+ /**
71
+ * <img src="java-icon.png"></img><br>
72
+ * The <em>BanMode</em> enum lists all possible user banning modes.
73
+ *
74
+ * <p>Available <em>BanMode</em> values are:</p>
75
+ * <ul>
76
+ * <li><strong>BY_ADDRESS</strong>: ban by IP address</li>
77
+ * <li><strong>BY_NAME</strong>: ban by user name</li>
78
+ * </ul>
79
+ *
80
+ * <h5>Notes:</h5>
81
+ * <ul>
82
+ * <li>For members of the <em>BanMode</em> enum, please [refer to its Javadoc]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/managers/BanMode.html}.</li>
83
+ * </ul>
84
+ *
85
+ * <h5>See also</h5>
86
+ * <ul>
87
+ * <li>{@link SFSApi#banUser} method</li>
88
+ * </ul>
89
+ *
90
+ * @enum
91
+ */
92
+ var BanMode = Java.type('com.smartfoxserver.v2.entities.managers.BanMode');
93
+
94
+ var MatchExpression = Java.type('com.smartfoxserver.v2.entities.match.MatchExpression');
95
+ var $$TimeUnit = Java.type('java.util.concurrent.TimeUnit');
96
+
97
+ //==============================================================================
98
+ //--- Main API class -----------------------------------------------------------
99
+ //==============================================================================
100
+
101
+ /**
102
+ * <b>Developers never istantiate the <em>SFSApi</em> class</b>: this is done internally by the SmartFoxServer 2X API; get a reference to it using the Extension's {@link getApi} method.
103
+ *
104
+ * @class
105
+ * The <em>SFSApi</em> class provides the central access to the main SmartFoxServer 2X server side API.
106
+ * It contains all basic methods for interacting with the server: creating Rooms, joining them, logging in/out, handling messages, creating User/Room Variables and much more.
107
+ *
108
+ * <p>In addition to this API, a number of other specialized APIs provide the following features:</p>
109
+ * <ul>
110
+ * <li>Game API: quick games, challenges, invitations, etc</li>
111
+ * <li>Buyddy List API: managing buddy lists</li>
112
+ * <li>MMO API: MMORoom creation, MMOItems, positioning, Area of Interest, etc</li>
113
+ * <li>File API: access to files and directories</li>
114
+ * </ul>
115
+ *
116
+ * <h4>See also</h4>
117
+ * <ul>
118
+ * <li>{@link BuddyApi} class</li>
119
+ * <li>{@link GameApi} class</li>
120
+ * <li>{@link MMOApi} class</li>
121
+ * <li>{@link FileApi} class</li>
122
+ * </ul>
123
+ */
124
+ SFSApi = function()
125
+ {
126
+ this._javaApi = $$WrapperExt.getApi();
127
+ this._sfs = $$SfsInstance;
128
+ }
129
+
130
+ //--- Inner members: HttpRequest -----------------------------------------------
131
+
132
+ /**
133
+ * The <em>HttpMode</em> enum lists the POST and GET request modes.
134
+ *
135
+ * <h5>See:</h5>
136
+ * <ul>
137
+ * <li>{@link SFSApi.HttpRequest} class</li>
138
+ * </ul>
139
+ *
140
+ * @enum
141
+ */
142
+ SFSApi.HttpMode = {
143
+ /**
144
+ * HTTP request mode is POST.
145
+ * @type {string}
146
+ */
147
+ POST: "post",
148
+
149
+ /**
150
+ * HTTP request mode is GET.
151
+ * @type {string}
152
+ */
153
+ GET: "get"
154
+ };
155
+
156
+ /**
157
+ * Creates a new <em>HttpRequest</em> instance.
158
+ *
159
+ * <p>Using the {@link SFSApi#newHttpGetRequest} or {@link SFSApi#newHttpPostRequest} factory methods instead of this constructor is recommended. See the methods description for usage examples.</p>
160
+ *
161
+ * @param {string} url The address of the HTTP server to make the request to.
162
+ * @param {object} params An object containing the parameters to send to the HTTP server.
163
+ * @param {SFSApi.HttpMode} mode The HTTP request mode (GET or POST).
164
+ * @param {httpCallbackFn} httpCallbackFn The callback function that will process the response sent by the HTTP server.
165
+ *
166
+ * @class
167
+ * The <em>HttpRequest</em> class represents a request to be sent to an external HTTP/HTTPS server.
168
+ *
169
+ * <p>HTTP/S requests can be of type POST or GET. They are useful to retrieve data from or send data to external services.</p>
170
+ *
171
+ * <h4>See also</h4>
172
+ * <ul>
173
+ * <li>{@link SFSApi#newHttpGetRequest} method</li>
174
+ * <li>{@link SFSApi#newHttpPostRequest} method</li>
175
+ * </ul>
176
+ */
177
+ SFSApi.HttpRequest = function(url, params, mode, httpCallbackFn)
178
+ {
179
+ var PostRequest = Java.type('com.smartfoxserver.v2.util.http.PostRequest');
180
+ var GetRequest = Java.type('com.smartfoxserver.v2.util.http.GetRequest');
181
+
182
+ this._url = url;
183
+ this._params = this._processParams(params);
184
+ this._client = null;
185
+ this._callback = httpCallbackFn;
186
+
187
+ // If no "mode", use POST as default
188
+ if (mode == null)
189
+ this._client = new PostRequest(this._url, this._params);
190
+
191
+ else
192
+ {
193
+ mode = mode.toLowerCase();
194
+
195
+ if (mode == SFSApi.HttpMode.POST)
196
+ this._client = new PostRequest(this._url, this._params);
197
+
198
+ else if (mode == SFSApi.HttpMode.GET)
199
+ this._client = new GetRequest(this._url, this._params);
200
+
201
+ else
202
+ throw new java.lang.IllegalArgumentException("Invalid HTTP mode: " + mode + ". Must be either 'get' or 'post'");
203
+ }
204
+ }
205
+
206
+ /**
207
+ * This callback function is called when the Extension receives the response to an HTTP request sent using the {@link SFSApi.HttpRequest#execute} method.
208
+ *
209
+ * @callback httpCallbackFn
210
+ *
211
+ * @param {object} result An object providing the result of the HTTP request.<br>
212
+ * The object contains the following parameters:
213
+ * <ul>
214
+ * <li>statusCode (number) - The status code of the request</li>
215
+ * <li>html (string) - The content of the response (it could be HTML, JSON, XML, etc)</li>
216
+ * <li>error (string - The error message (if the request failed)</li>
217
+ * </ul>
218
+ */
219
+
220
+ /**
221
+ * Sets the HTTP request timeout seconds.
222
+ *
223
+ * @param {number} value The number of seconds after which the HTTP request will be considered failed.
224
+ */
225
+ SFSApi.HttpRequest.prototype.setConnectionTimeoutSeconds = function(value)
226
+ {
227
+ this._client.setConnectionTimeoutSeconds(value);
228
+ }
229
+
230
+ /**
231
+ * Gets the HTTP request timeout seconds.
232
+ *
233
+ * @return {number} The number of seconds after which the HTTP request will be considered failed.
234
+ */
235
+ SFSApi.HttpRequest.prototype.getConnectionTimeoutSeconds = function()
236
+ {
237
+ return this._client.getConnectionTimeoutSeconds(value);
238
+ }
239
+
240
+ /**
241
+ * Executes the HTTP request and calls the {@link httpCallbackFn} callback function passed to the constructor.
242
+ */
243
+ SFSApi.HttpRequest.prototype.execute = function()
244
+ {
245
+ function __dispatch__(resObj, context)
246
+ {
247
+ var exLock = $$WrapperExt.getExtensionLock();
248
+
249
+ try
250
+ {
251
+ // Lock if necessary
252
+ if ($$WrapperExt.isThreadSafe())
253
+ exLock.lock();
254
+
255
+ context._callback(resObj);
256
+ }
257
+
258
+ finally
259
+ {
260
+ // Release lock
261
+ if ($$WrapperExt.isThreadSafe())
262
+ exLock.unlock();
263
+ }
264
+
265
+ }
266
+
267
+ var runner = function()
268
+ {
269
+ var resObj;
270
+
271
+ try
272
+ {
273
+ var httpRes = this._client.execute();
274
+
275
+ resObj = {};
276
+ resObj.html = org.apache.http.util.EntityUtils.toString(httpRes.getEntity());
277
+ resObj.statusCode = httpRes.getStatusLine().getStatusCode();
278
+ }
279
+ catch(ex)
280
+ {
281
+ resObj = { error: ex.getMessage() };
282
+ }
283
+
284
+ __dispatch__(resObj, this);
285
+ };
286
+
287
+ var context = this;
288
+ var wrapper = function()
289
+ {
290
+ runner.apply(context, []);
291
+ };
292
+
293
+ // Delegate to SFSWorker:Ext
294
+ $$SfsInstance.getEventManager().getThreadPool().execute( wrapper );
295
+ };
296
+
297
+ /**
298
+ * @private
299
+ */
300
+ SFSApi.HttpRequest.prototype._processParams = function(params)
301
+ {
302
+ var list = new java.util.ArrayList();
303
+
304
+ for (var key in params)
305
+ {
306
+ list.add( new org.apache.http.message.BasicNameValuePair(key, params[key]) );
307
+ }
308
+
309
+ return list;
310
+ }
311
+
312
+ /**
313
+ * Creates a new <em>TaskScheduler</em> instance.
314
+ *
315
+ * <p>Using the {@link SFSApi#newScheduler} factory method instead of this constructor is recommended. See the method description for a usage example.</p>
316
+ *
317
+ * @param {number} threadPoolSize The number of threads backing the scheduler (recommended value between 1 and 4).
318
+ *
319
+ * @class
320
+ * The <em>TaskScheduler</em> class allows to manage multiple delayed or repeating activities.
321
+ *
322
+ * <p>In games, a delayed scheduled task can be useful to set the duration of a match, or set a time limit to a user action, etc.
323
+ * An interval-based task instead can be used to spawn new NPC enemies on a time basis, or divide the game in rounds, etc.</p>
324
+ *
325
+ * <h4>Notes</h4>
326
+ * <ul>
327
+ * <li>In general it is recommended to use one TaskScheduler per application/Zone. If this needs to be accessed in different parts of the code, a reference should be mantained in a Zone-level Extension and accessed from any other Extension(s) attached to Rooms in the same Zone.</li>
328
+ * <li>It is advisable to avoid spawning very large thread pools, unless there are specific reasons for doing so. A setting of 1-4 threads is usually sufficient to handle any number of concurrent delayed events. The only exception to this is when the tasks to be executed are long-running such as accessing a database, a remote web-service or HTTP server, etc.</li>
329
+ * <li>Any runtime exception will stop the execution of the task, so it is strongly recommended to always add a try/catch block to prevent this from happening.</li>
330
+ * </ul>
331
+ *
332
+ * <h4>See also</h4>
333
+ * <ul>
334
+ * <li>{@link SFSApi#newScheduler} method</li>
335
+ * </ul>
336
+ */
337
+ SFSApi.TaskScheduler = function(threadPoolSize)
338
+ {
339
+ this._sched = new com.smartfoxserver.v2.util.TaskScheduler(threadPoolSize);
340
+ }
341
+
342
+ /**
343
+ * Destroys the <em>TaskScheduler</em> instance and all the tasks that are currently running.
344
+ */
345
+ SFSApi.TaskScheduler.prototype.destroy = function()
346
+ {
347
+ this._sched.destroy(null);
348
+ }
349
+
350
+ /**
351
+ * Returns the size of the thread pool handling the tasks.
352
+ *
353
+ * @return {number} The number of threads backing the scheduler.
354
+ */
355
+ SFSApi.TaskScheduler.prototype.getThreadPoolSize = function()
356
+ {
357
+ return this._sched.getThreadPoolSize();
358
+ }
359
+
360
+ /**
361
+ * Schedules a new task to be executed in the future, once.
362
+ *
363
+ * @param {function} runnerFn The function to be executed after the provided time delay has passed.
364
+ * @param {number} delay The amount of time before the runner function is executed.
365
+ * @param {object} [context] An object representing the scope of the runner function (also known as the "this" object).
366
+ *
367
+ * @return {ScheduledFuture} A reference to the <em>ScheduledFuture</em> Java class representing the scheduled task; it is useful to keep a reference to this object, in case the task execution needs to be cancelled later.
368
+ *
369
+ * @throws An <em>IllegalArgumentException</em> Java exception if the delay is lower than or equal to 0.
370
+ */
371
+ SFSApi.TaskScheduler.prototype.schedule = function(runnerFn, delay, context)
372
+ {
373
+ if (delay == null || delay <= 0)
374
+ throw new java.lang.IllegalArgumentException("Scheduled task delay must be > 0");
375
+
376
+ var targetFn = runnerFn;
377
+
378
+ // If a context is passed wrap and call using the provided context
379
+ if (context != null)
380
+ {
381
+ targetFn = function()
382
+ {
383
+ var exLock = $$WrapperExt.getExtensionLock();
384
+
385
+ try
386
+ {
387
+ // Lock if necessary
388
+ if ($$WrapperExt.isThreadSafe())
389
+ exLock.lock();
390
+
391
+ runnerFn.apply(context, []);
392
+ }
393
+
394
+ finally
395
+ {
396
+ // Release lock
397
+ if ($$WrapperExt.isThreadSafe())
398
+ exLock.unlock();
399
+ }
400
+ };
401
+ }
402
+
403
+ return this._sched.schedule(targetFn, delay, $$TimeUnit.MILLISECONDS);
404
+ }
405
+
406
+ /**
407
+ * Schedules a new task to be executed periodically.
408
+ *
409
+ * @param {function} runnerFn The function to be executed at each interval.
410
+ * @param {number} interval The interval at which the runner function should be executed.
411
+ * @param {number} [delay=0] The initial amount of time before the runner function is executed for the first time.
412
+ * @param {object} [context] An object representing the scope of the runner function (also known as the "this" object).
413
+ *
414
+ * @return {ScheduledFuture} A reference to the <em>ScheduledFuture</em> Java class representing the scheduled task; it is useful to keep a reference to this object, in case the task execution needs to be cancelled later.
415
+ *
416
+ * @throws An <em>IllegalArgumentException</em> Java exception if the interval is lower than or equal to 0.
417
+ */
418
+ SFSApi.TaskScheduler.prototype.scheduleAtFixedRate = function(runnerFn, interval, delay, context)
419
+ {
420
+ if (interval == null || interval <= 0)
421
+ throw new java.lang.IllegalArgumentException("Scheduled task fixed interval must be > 0")
422
+
423
+ if (delay == null)
424
+ delay = 0;
425
+
426
+ var targetFn = runnerFn;
427
+
428
+ // If a context is passed wrap and call using the provided context
429
+ if (context != null)
430
+ {
431
+ targetFn = function()
432
+ {
433
+ var exLock = $$WrapperExt.getExtensionLock();
434
+
435
+ try
436
+ {
437
+ // Lock if necessary
438
+ if ($$WrapperExt.isThreadSafe())
439
+ exLock.lock();
440
+
441
+ runnerFn.apply(context, []);
442
+ }
443
+
444
+ finally
445
+ {
446
+ // Release lock
447
+ if ($$WrapperExt.isThreadSafe())
448
+ exLock.unlock();
449
+ }
450
+ };
451
+ }
452
+
453
+ return this._sched.scheduleAtFixedRate(targetFn, delay, interval, $$TimeUnit.MILLISECONDS);
454
+ }
455
+
456
+ //--- Public methods -----------------------------------------------------------
457
+
458
+ /**
459
+ * Returns a reference to the <img src="java-icon-small.png"></img> [SFSZone]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSZone.html} object corresponding to the passed Zone name.
460
+ *
461
+ * @param {string} zoneName The name of the <em>SFSZone</em> object to be retrieved.
462
+ *
463
+ * @return {SFSZone} A reference to a <img src="java-icon-small.png"></img> [SFSZone]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSZone.html} class instance.
464
+ */
465
+ SFSApi.prototype.getZoneByName = function(zoneName)
466
+ {
467
+ return this._sfs.getZoneManager().getZoneByName(zoneName);
468
+ }
469
+
470
+ /**
471
+ * Creates and returns a new <em>TaskScheduler</em> instance.
472
+ *
473
+ * <p>This is a factory method to create a {@link SFSApi.TaskScheduler} instance.</p>
474
+ *
475
+ * <h5>See also:</h5>
476
+ * <ul>
477
+ * <li>{@link SFSApi.TaskScheduler} class</li>
478
+ * </ul>
479
+ *
480
+ * @param {number} [threadPoolSize=1] The number of threads backing the scheduler (recommended value between 1 and 4).
481
+ *
482
+ * @example
483
+ * <caption>In this example we create a dummy task in the Extension's <em>init</em> method; the task runs every 3 seconds and prints how many times it was executed. A try/catch block makes sure that the execution never stops, even if an error occurs in the task.</caption>
484
+ * var stepCount = 0;
485
+ * var scheduler;
486
+ * var taskHandle;
487
+ *
488
+ * // Initialize the Extension
489
+ * function init()
490
+ * {
491
+ * // Initialize the scheduler and schedule the task
492
+ * scheduler = getApi().newScheduler();
493
+ * taskHandle = scheduler.scheduleAtFixedRate(runner, 3000);
494
+ * }
495
+ *
496
+ * // Destroy the Extension
497
+ * function destroy()
498
+ * {
499
+ * if (taskHandle != null)
500
+ * taskHandle.cancel(true);
501
+ * }
502
+ *
503
+ * function runner()
504
+ * {
505
+ * try
506
+ * {
507
+ * stepCount++;
508
+ * trace("I was called: ", stepCount, " times");
509
+ * }
510
+ * catch(err)
511
+ * {
512
+ * trace("An error occurred: ", err);
513
+ * }
514
+ * }
515
+ *
516
+ * @return {SFSApi.TaskScheduler} A new instance of the <em>TaskScheduler</em> class.
517
+ */
518
+ SFSApi.prototype.newScheduler = function(threadPoolSize)
519
+ {
520
+ if (threadPoolSize == null)
521
+ threadPoolSize = 1;
522
+
523
+ return new SFSApi.TaskScheduler(threadPoolSize);
524
+ }
525
+
526
+ /**
527
+ * Creates and returns a new <em>HttpRequest</em> instance of type GET.
528
+ *
529
+ * <p>This is a factory method to create a {@link SFSApi.HttpRequest} instance.</p>
530
+ *
531
+ * <h5>See also:</h5>
532
+ * <ul>
533
+ * <li>{@link SFSApi.HttpRequest} class</li>
534
+ * </ul>
535
+ *
536
+ * @param {string} url The address of the HTTP server to make the request to.
537
+ * @param {object} params An object containing the parameters to send to the HTTP server.
538
+ * @param {httpCallbackFn} httpCallbackFn The callback function that will process the response sent by the HTTP server.
539
+ *
540
+ * @example
541
+ * <caption>In this example we make an HTTP request to a dummy URL, passing an "id" parameter. We then process the response in the callback function.</caption>
542
+ * function sendHttpRequest()
543
+ * {
544
+ * var reqParams = { id: 25 };
545
+ * var httpReq = getApi().newHttpGetRequest('http://some.host.com/', reqParams, httpCallback);
546
+ * httpReq.execute();
547
+ * }
548
+ *
549
+ * function httpCallback(result)
550
+ * {
551
+ * if (result.error)
552
+ * trace("HTTP request failed: " + result.error);
553
+ * else
554
+ * {
555
+ * trace("HTTP request successful: " + result.statusCode);
556
+ * trace(result.html);
557
+ * }
558
+ * }
559
+ *
560
+ * @return {SFSApi.HttpRequest} A new instance of the <em>HttpRequest</em> class.
561
+ */
562
+ SFSApi.prototype.newHttpGetRequest = function(url, params, httpCallbackFn)
563
+ {
564
+ return new SFSApi.HttpRequest(url, params, SFSApi.HttpMode.GET, httpCallbackFn);
565
+ }
566
+
567
+ /**
568
+ * Creates and returns a new <em>HttpRequest</em> instance of type POST.
569
+ *
570
+ * <p>This is a factory method to create a {@link SFSApi.HttpRequest} instance.</p>
571
+ *
572
+ * <h5>See also:</h5>
573
+ * <ul>
574
+ * <li>{@link SFSApi.HttpRequest} class</li>
575
+ * </ul>
576
+ *
577
+ * @param {string} url The address of the HTTP server to make the request to.
578
+ * @param {object} params An object containing the parameters to send to the HTTP server.
579
+ * @param {httpCallbackFn} httpCallbackFn The callback function that will process the response sent by the HTTP server.
580
+ *
581
+ * @example
582
+ * <caption>In this example we make an HTTP request to a dummy URL, passing an "id" parameter. We then process the response in the callback function.</caption>
583
+ * function sendHttpRequest()
584
+ * {
585
+ * var reqParams = { id: 25 };
586
+ * var httpReq = getApi().newHttpPostRequest('http://some.host.com/', reqParams, httpCallback);
587
+ * httpReq.execute();
588
+ * }
589
+ *
590
+ * function httpCallback(result)
591
+ * {
592
+ * if (result.error)
593
+ * trace("HTTP request failed: " + result.error);
594
+ * else
595
+ * {
596
+ * trace("HTTP request successful: " + result.statusCode);
597
+ * trace(result.html);
598
+ * }
599
+ * }
600
+ *
601
+ * @return {SFSApi.HttpRequest} A new instance of the <em>HttpRequest</em> class.
602
+ */
603
+ SFSApi.prototype.newHttpPostRequest = function(url, params, httpCallbackFn)
604
+ {
605
+ return new SFSApi.HttpRequest(url, params, SFSApi.HttpMode.POST, httpCallbackFn);
606
+ }
607
+
608
+ /**
609
+ * Checks the encrypted password sent by a user at login time against the one registered in the system (typically in the users database).
610
+ *
611
+ * @param {Session} session The client's <img src="java-icon-small.png"></img> [Session]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/bitswarm/sessions/Session.html} object, usually provided by the <img src="java-icon-small.png"></img> [SFSEventType.USER_LOGIN]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#USER_LOGIN} event.
612
+ * @param {string} originalPass The original, un-encrypted password.
613
+ * @param {string} encryptedPass The encrypted password sent by the client.
614
+ *
615
+ * @return {boolean} <code>true</code> if the password is correct, <code>false</code> otherwise.
616
+ */
617
+ SFSApi.prototype.checkSecurePassword = function(session, originalPass, encryptedPass)
618
+ {
619
+ return this._javaApi.checkSecurePassword(session, originalPass, encryptedPass);
620
+ }
621
+
622
+ /**
623
+ * Logs a user out of the current Zone.
624
+ *
625
+ * <p>This method can be useful to force a user leave the current Zone and join a new one.</p>
626
+ *
627
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to be logged out.
628
+ */
629
+ SFSApi.prototype.logout = function(user)
630
+ {
631
+ this._javaApi.logout(user);
632
+ }
633
+
634
+ /**
635
+ * Creates a connection-less Non-Player Character (NPC).
636
+ *
637
+ * <p>The server handles NPCs just like any other regular user, although there is no real, physical connection to the server (in other words no TCP connection is established).<br>
638
+ * NPCs can be recognized from the <em>isNpc</em> flag on the <em>SFSUser</em> object representing them, which is always set to <code>true</code>.</p>
639
+ *
640
+ * <h5>Notes:</h5>
641
+ * <ul>
642
+ * <li>NPCs must be created once the server engine is up and running. As the <em>init</em> method of the Extension runs before the engine is ready, you will need to wait for
643
+ * the <img src="java-icon-small.png"></img> [SFSEventType.SERVER_READY]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#SERVER_READY} event before being able to instantiate any NPC.</li>
644
+ * </ul>
645
+ *
646
+ * @param {string} userName The name of the Non-Player Charachter.
647
+ * @param {SFSZone} zone The <img src="java-icon-small.png"></img> [SFSZone]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSZone.html} object representing the Zone the NPC should be created into.
648
+ * @param {boolean} forceLogin If a user with the same name is already logged in the system and <code>true</code> is passed, that user will be disconnected before creating the NPC.
649
+ *
650
+ * @return {SFSUser} The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the NPC.
651
+ *
652
+ * @throws A <img src="java-icon-small.png"></img> [SFSLoginException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSLoginException.html} exception if an error occurs during the NPC creation.
653
+ */
654
+ SFSApi.prototype.createNPC = function(userName, zone, forceLogin)
655
+ {
656
+ return this._javaApi.createNPC(userName, zone, forceLogin);
657
+ }
658
+
659
+ /**
660
+ * Kicks a user out of the server.
661
+ *
662
+ * <p>This operation allows to send a moderator message to the client, providing a number of seconds for reading it before the connection is closed.</p>
663
+ *
664
+ * @param {SFSUser} userToKick The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to be kicked out.
665
+ * @param {SFSUser} modUser The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing a moderator/administrator user executing the action; can be <code>null</code> to indicate the "Server" generically.
666
+ * @param {string} kickMessage A message from the moderator/administrator to be displayed to the user right before kicking him.
667
+ * @param {number} delaySeconds The delay in seconds before the disconnection is executed.
668
+ */
669
+ SFSApi.prototype.kickUser = function(userToKick, modUser, kickMessage, delaySeconds)
670
+ {
671
+ this._javaApi.kickUser(userToKick, modUser, kickMessage, delaySeconds);
672
+ }
673
+
674
+ /**
675
+ * Bans a user, preventing his reconnection for a configurable amount of time.
676
+ *
677
+ * <p>This operation allows to send a moderator message to the client, providing a number of seconds for reading it before the connection is closed.<br>
678
+ * The length of the banishment and the rules under which the ban can be removed are specified in the Zone configuration.</p>
679
+ *
680
+ * @param {SFSUser} userToBan The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to be banished.
681
+ * @param {SFSUser} modUser The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing a moderator/administrator user executing the action; can be <code>null</code> to indicate the "Server" generically.
682
+ * @param {string} banMessage A message from the moderator/administrator to be displayed to the user right before banishing him.
683
+ * @param {BanMode} mode A ban mode among those provided by the <em>BanMode</em> enum.
684
+ * @param {number} delaySeconds The delay in seconds before the disconnection is executed.
685
+ */
686
+ SFSApi.prototype.banUser = function(userToBan, modUser, banMessage, mode, durationMinutes, delaySeconds)
687
+ {
688
+ this._javaApi.banUser(userToBan, modUser, banMessage, mode, durationMinutes, delaySeconds);
689
+ }
690
+
691
+ /**
692
+ * Disconnect a user from the server.
693
+ *
694
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to be disconnected.
695
+ * @param {ClientDisconnectionReason} [reason] One of the disconnection reasons provided in the <em>ClientDisconnectionReason</em> enum; the reason will be provided to the client in the client-side <em>CONNECTION_LOST</em> event.
696
+ */
697
+ SFSApi.prototype.disconnectUser = function(user, reason)
698
+ {
699
+ if (reason == null)
700
+ this._javaApi.disconnectUser(user);
701
+ else
702
+ this._javaApi.disconnectUser(user, reason);
703
+ }
704
+
705
+ /**
706
+ * Removes a <em>Session</em> object, disconnecting the user associated with it (if one exists).
707
+ *
708
+ * @param {Session} session The client's <img src="java-icon-small.png"></img> [Session]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/bitswarm/sessions/Session.html} object to be disconnected.
709
+ */
710
+ SFSApi.prototype.disconnectSession = function(session)
711
+ {
712
+ this._javaApi.disconnect(session);
713
+ }
714
+
715
+ /**
716
+ * Creates a new Room.
717
+ *
718
+ * <p>This method can create both regular Rooms and MMO Rooms, depending on the passed settings object.</p>
719
+ *
720
+ * <h5>See also:</h5>
721
+ * <ul>
722
+ * <li>{@link CreateRoomSettings} class</li>
723
+ * <li>{@link CreateMMORoomSettings} class</li>
724
+ * <li>{@link GameApi#createGame} method</li>
725
+ * </ul>
726
+ *
727
+ * @param {SFSZone} zone The <img src="java-icon-small.png"></img> [SFSZone]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSZone.html} object representing the Zone the Room should be created into.
728
+ * @param {CreateRoomSettings|CreateMMORoomSettings} settings The Room configuration object.
729
+ * @param {SFSUser} [owner=null] The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the Room; if <code>null</code> is passed, the "Server" will be the owner.
730
+ * @param {boolean} [joinIt=false] If <code>true</code>, the Room will be joined by the owner right after the creation.
731
+ * @param {SFSRoom} [roomToLeave=null] The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to leave if the owner is supposed to join the new one; if <code>null</code> is passed, no previous Room will be left.
732
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>ROOM_ADD</em> event will be fired to notify the Room creation.
733
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.ROOM_ADDED]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#ROOM_ADDED} will be fired to notify the Room creation.
734
+ *
735
+ * @example
736
+ * <caption>In this simple example we create an hidden, private chat Room.<br>
737
+ * In particular we also set a Room Variable and enable three specific events for the Room.</caption>
738
+ * var crs = new CreateRoomSettings();
739
+ * crs.setName("chat#371");
740
+ * crs.setPassword("&12faGG");
741
+ * crs.setGroupId("chats");
742
+ * crs.setHidden(true);
743
+ * crs.setMaxUsers(10);
744
+ *
745
+ * // Set Room Variable
746
+ * crs.setRoomVariables([new SFSRoomVariable("topic", "Board Games")]);
747
+ *
748
+ * // Set Room permissions
749
+ * crs.setRoomSettings(EnumSet.of(SFSRoomSettings.USER_ENTER_EVENT, SFSRoomSettings.USER_EXIT_EVENT, SFSRoomSettings.PUBLIC_MESSAGES));
750
+ *
751
+ * // Create the Room
752
+ * getApi().createRoom(getParentZone(), crs, null, false, null, true, true);
753
+ *
754
+ * @example
755
+ * <caption>In this example we create an MMORoom for the SpaceWar game.<br>
756
+ * In particular we assign a Room Extension and configure the MMO-related features.</caption>
757
+ * var crs = new CreateMMORoomSettings();
758
+ * crs.setName("Sol");
759
+ * crs.setMaxUsers(10000);
760
+ * crs.setMaxSpectators(0);
761
+ * crs.setGame(true);
762
+ *
763
+ * // Set Room permissions
764
+ * crs.setRoomSettings(EnumSet.of(SFSRoomSettings.USER_ENTER_EVENT, SFSRoomSettings.USER_EXIT_EVENT, SFSRoomSettings.USER_COUNT_CHANGE_EVENT, SFSRoomSettings.USER_VARIABLES_UPDATE_EVENT));
765
+ *
766
+ * // Set the Extension attached to the Room
767
+ * crs.setExtension(new CreateRoomSettings.RoomExtensionSettings("SpaceWar", "sfs2x.extensions.games.spacewar.SpaceWarRoomExtension"));
768
+ *
769
+ * // Set MMORoom features
770
+ * crs.setDefaultAOI(Vectors.newVec3D(900, 750));
771
+ * crs.setUserMaxLimboSeconds(30);
772
+ * crs.setProximityListUpdateMillis(20);
773
+ * crs.setSendAOIEntryPoint(false);
774
+ *
775
+ * // Create the Room
776
+ * getApi().createRoom(getParentZone(), crs, null, false, null, true, true);
777
+ *
778
+ * @return {SFSRoom} The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room just created.
779
+ *
780
+ * @throws A <img src="java-icon-small.png"></img> [SFSCreateRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSCreateRoomException.html} exception if an error occurs during the Room creation.
781
+ */
782
+ SFSApi.prototype.createRoom = function(zone, settings, owner, joinIt, roomToLeave, fireClientEvent, fireServerEvent)
783
+ {
784
+ return this._javaApi.createRoom
785
+ (
786
+ zone,
787
+ settings,
788
+ (owner === undefined ? null : owner),
789
+ (joinIt === undefined ? false : joinIt),
790
+ (roomToLeave === undefined ? null : roomToLeave),
791
+ (fireClientEvent === undefined ? false : fireClientEvent),
792
+ (fireServerEvent === undefined ? false : fireServerEvent)
793
+ );
794
+ }
795
+
796
+ /**
797
+ * Find one or more users in a list of users matching the conditions set in a Match Expression.
798
+ *
799
+ * @param {SFSUser[]} userList An array of <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} objects to search in.
800
+ * @param {MatchExpression} expression The Match Expression setting the conditions to match.
801
+ * @param {number} [limit=10] When this limit is reached, the search is stopped; if set to <code>0</code>, all matching users are returned.
802
+ *
803
+ * @return {ArrayList} A <em>java.util.ArrayList</em> Java collection containing the list of matching <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} objects. This can be treated like native JavaScript array.
804
+ */
805
+ SFSApi.prototype.findUsers = function(userList, expression, limit)
806
+ {
807
+ if (limit == null)
808
+ limit = 10;
809
+
810
+ // Convert native JS array
811
+ if (userList instanceof Array)
812
+ userList = $$Util.toList(userList);
813
+
814
+ return this._javaApi.findUsers(userList, expression, limit);
815
+ }
816
+
817
+ /**
818
+ * Find one or more Rooms in a list of Rooms matching the conditions set in a Match Expression.
819
+ *
820
+ * @param {SFSRoom[]} roomList An array of <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} objects to search in.
821
+ * @param {MatchExpression} expression The Match Expression setting the conditions to match.
822
+ * @param {number} [limit=10] When this limit is reached, the search is stopped; if set to <code>0</code>, all matching Rooms are returned.
823
+ *
824
+ * @return {ArrayList} A <em>java.util.ArrayList</em> Java collection containing the list of matching <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} objects. This can be treated like native JavaScript array.
825
+ */
826
+ SFSApi.prototype.findRooms = function(roomList, expression, limit)
827
+ {
828
+ if (limit == null)
829
+ limit = 10;
830
+
831
+ // Convert native JS array
832
+ if (roomList instanceof Array)
833
+ roomList = $$Util.toList(roomList);
834
+
835
+ return this._javaApi.findRooms(roomList, expression, limit);
836
+ }
837
+
838
+ /**
839
+ * Retrieves a <em>SFSUser</em> object from its <em>id</em> property.
840
+ *
841
+ * @param {number} userId The id of the user to be retrieved.
842
+ *
843
+ * @return {SFSUser} The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the requested user.
844
+ */
845
+ SFSApi.prototype.getUserById = function(userId)
846
+ {
847
+ return this._javaApi.getUserById(userId);
848
+ }
849
+
850
+ /**
851
+ * Retrieves a <em>SFSUser</em> object in a Zone from its <em>name</em> property.
852
+ *
853
+ * @param {SFSZone} zone The <img src="java-icon-small.png"></img> [SFSZone]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSZone.html} object representing the Zone from which to retrieve the user.
854
+ * @param {string} name The name of the user to be retrieved.
855
+ *
856
+ * @return {SFSUser} The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the requested user.
857
+ */
858
+ SFSApi.prototype.getUserByName = function(zone, name)
859
+ {
860
+ return zone.getUserByName(name);
861
+ }
862
+
863
+ /**
864
+ * Retrieves a <em>SFSUser</em> object from its client session.
865
+ *
866
+ * @param {Session} session The <img src="java-icon-small.png"></img> [Session]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/bitswarm/sessions/Session.html} object of the user to be retrieved.
867
+ *
868
+ * @return {SFSUser} The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the requested user.
869
+ */
870
+ SFSApi.prototype.getUserBySession = function(session)
871
+ {
872
+ return this._javaApi.getUserBySession(session);
873
+ }
874
+
875
+ /**
876
+ * Joins a user in a Room.
877
+ *
878
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to join in the Room.
879
+ * @param {SFSRoom} roomToJoin The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to make the user join.
880
+ * @param {string} [password=null] The Room password, in case it is a private Room.
881
+ * @param {boolean} [asSpectator=false] If <code>true</code>, the user will join the Room as a spectator.
882
+ * @param {SFSRoom} [roomToLeave=null] The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room that the user must leave after joining the new one; if <code>null</code> is passed, no previous Room is left.
883
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, the client-side <em>ROOM_JOIN</em> and <em>USER_ENTER_ROOM</em> events will be fired to notify the Room joining.
884
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.USER_JOIN_ROOM]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#USER_JOIN_ROOM} will be fired to notify the Room joining.
885
+ *
886
+ * @example
887
+ * <caption>In this example we retrieve a user by his name and join him in the "Lobby" Room available in the Extension's parent Zone.</caption>
888
+ * // Get the target user and Room
889
+ * var user = getApi().getUserbyName("bax");
890
+ * var room = getParentZone().getRoomByName("Lobby");
891
+ *
892
+ * // Make the user join the Room
893
+ * getApi().joinRoom(user, room);
894
+ *
895
+ * @throws A <img src="java-icon-small.png"></img> [SFSJoinRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSJoinRoomException.html} exception if an error occurs during the Room joining process.
896
+ */
897
+ SFSApi.prototype.joinRoom = function(user, roomToJoin, password, asSpectator, roomToLeave, fireClientEvent, fireServerEvent)
898
+ {
899
+ this._javaApi.joinRoom
900
+ (
901
+ user,
902
+ roomToJoin,
903
+ (password === undefined ? null : password),
904
+ (asSpectator === undefined ? false : asSpectator),
905
+ (roomToLeave === undefined ? null : roomToLeave),
906
+ (fireClientEvent === undefined ? false : fireClientEvent),
907
+ (fireServerEvent === undefined ? false : fireServerEvent)
908
+ );
909
+ }
910
+
911
+ /**
912
+ * Makes a user leave a Room he joined previously.
913
+ *
914
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user that should leave the Room.
915
+ * @param {SFSRoom} room The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room that the user is going to leave.
916
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>USER_EXIT_ROOM</em> event will be fired to notify the action.
917
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.USER_LEAVE_ROOM]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#USER_LEAVE_ROOM} will be fired to notify the action.
918
+ */
919
+ SFSApi.prototype.leaveRoom = function(user, room, fireClientEvent, fireServerEvent)
920
+ {
921
+ this._javaApi.leaveRoom
922
+ (
923
+ user,
924
+ room,
925
+ (fireClientEvent === undefined ? false : fireClientEvent),
926
+ (fireServerEvent === undefined ? false : fireServerEvent)
927
+ );
928
+ }
929
+
930
+ /**
931
+ * Removes a Room from its Zone.
932
+ *
933
+ * @param {SFSRoom} room The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room that the user is going to leave.
934
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>ROOM_REMOVE</em> event will be fired to notify the Room removal.
935
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.ROOM_REMOVED]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#ROOM_REMOVED} will be fired to notify the Room removal.
936
+ */
937
+ SFSApi.prototype.removeRoom = function(room, fireClientEvent, fireServerEvent)
938
+ {
939
+ this._javaApi.removeRoom
940
+ (
941
+ room,
942
+ (fireClientEvent === undefined ? false : fireClientEvent),
943
+ (fireServerEvent === undefined ? false : fireServerEvent)
944
+ );
945
+ }
946
+
947
+ /**
948
+ * Sends a public chat message from a user.
949
+ *
950
+ * <p>The message is broadcast to all users in the target Room, including the sender himself.</p>
951
+ *
952
+ * @param {SFSRoom} targetRoom The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to send the message to.
953
+ * @param {SFSUser} sender The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user sending the message to the target Room.
954
+ * @param {string} message The chat message to send.
955
+ * @param {SFSObject} [params] A <em>SFSObject</em> containing custom parameters to be attached to the message (e.g. text color, font size, etc).
956
+ */
957
+ SFSApi.prototype.sendPublicMessage = function(targetRoom, sender, message, params)
958
+ {
959
+ this._javaApi.sendPublicMessage
960
+ (
961
+ targetRoom,
962
+ sender,
963
+ message,
964
+ (params === undefined ? null : params)
965
+ );
966
+ }
967
+
968
+ /**
969
+ * Sends a private chat message from a user to another one.
970
+ *
971
+ * <p>The message is sent to both the sender and the recipient. The sender and recipient can be in any Room, or even not joined in any Room at all.</p>
972
+ *
973
+ * @param {SFSUser} sender The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user sending the message.
974
+ * @param {SFSUser} recipient The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the message recipient.
975
+ * @param {string} message The chat message to send.
976
+ * @param {SFSObject} [params] A <em>SFSObject</em> containing custom parameters to be attached to the message (e.g. text color, font size, etc).
977
+ */
978
+ SFSApi.prototype.sendPrivateMessage = function(sender, recipient, message, params)
979
+ {
980
+ this._javaApi.sendPrivateMessage
981
+ (
982
+ sender,
983
+ recipient,
984
+ message,
985
+ (params === undefined ? null : params)
986
+ );
987
+ }
988
+
989
+ /**
990
+ * Sends a message from a moderator to a list of clients.
991
+ *
992
+ * <p>The sender must be either an actual user with "Super User" privileges, or <code>null</code>. In this case the sender becomes the "Server" itself.</p>
993
+ *
994
+ * @param {SFSUser} sender The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the moderator sending the message; if <code>null</code>, the sender is the "server" itself.
995
+ * @param {string} message The message to send.
996
+ * @param {SFSObject} params A <em>SFSObject</em> containing custom parameters to be attached to the message.
997
+ * @param {Session[]} recipients An array of <img src="java-icon-small.png"></img> [Session]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/bitswarm/sessions/Session.html} objects representing the clients to deliver the message to.
998
+ */
999
+ SFSApi.prototype.sendModeratorMessage = function(sender, message, params, recipients)
1000
+ {
1001
+ // Convert native JS array
1002
+ if (recipients instanceof Array)
1003
+ recipients = $$Util.toList(recipients);
1004
+
1005
+ this._javaApi.sendModeratorMessage(sender, message, params, recipients);
1006
+ }
1007
+
1008
+ /**
1009
+ * Sends a message from an administrator to a list of clients.
1010
+ *
1011
+ * <p>The sender must be either an actual user with "Super User" privileges, or <code>null</code>. In this case the sender becomes the "Server" itself.</p>
1012
+ *
1013
+ * @param {SFSUser} sender The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the administrator sending the message; if <code>null</code>, the sender is the "server" itself.
1014
+ * @param {string} message The message to send.
1015
+ * @param {SFSObject} params A <em>SFSObject</em> containing custom parameters to be attached to the message.
1016
+ * @param {Session[]} recipients An array of <img src="java-icon-small.png"></img> [Session]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/bitswarm/sessions/Session.html} objects representing the clients to deliver the message to.
1017
+ */
1018
+ SFSApi.prototype.sendAdminMessage = function(sender, message, params, recipients)
1019
+ {
1020
+ // Convert native JS array
1021
+ if (recipients instanceof Array)
1022
+ recipients = $$Util.toList(recipients);
1023
+
1024
+ this._javaApi.sendAdminMessage(sender, message, params, recipients);
1025
+ }
1026
+
1027
+ /**
1028
+ * Sends a data object from a user to a list of other users in a Room.
1029
+ *
1030
+ * <p>This method sends a custom <em>SFSObject</em> that can contain any data. Typically this is used to send game moves to players or other game/app related updates.<br>
1031
+ * By default the message is sent to all users in the specified target Room, but a list of <em>SFSUser</em> object can be passed to specify which user in that Room should receive the message. The sender must be joined in the target Room too.</p>
1032
+ *
1033
+ * @param {SFSRoom} targetRoom The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to send the data to.
1034
+ * @param {SFSUser} sender The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user sending the data to the target Room.
1035
+ * @param {SFSObject} message The data object to send.
1036
+ * @param {SFSUser[]} [recipients] An array of <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} objects representing the recipients to deliver the data to.
1037
+ */
1038
+ SFSApi.prototype.sendObjectMessage = function(targetRoom, sender, message, recipients)
1039
+ {
1040
+ // Convert native JS array
1041
+ if (recipients instanceof Array)
1042
+ recipients = $$Util.toList(recipients);
1043
+
1044
+ this._javaApi.sendObjectMessage
1045
+ (
1046
+ targetRoom,
1047
+ sender,
1048
+ message,
1049
+ (recipients === undefined ? null : recipients)
1050
+ );
1051
+ }
1052
+
1053
+ /**
1054
+ * @private
1055
+ */
1056
+ SFSApi.prototype.sendExtensionResponse = function(cmdName, params, recipients, room, useUDP)
1057
+ {
1058
+ // Convert native JS array
1059
+ if (recipients instanceof Array)
1060
+ recipients = $$Util.toList(recipients);
1061
+
1062
+ this._javaApi.sendExtensionResponse(cmdName, params, recipients, room, useUDP);
1063
+ }
1064
+
1065
+ /**
1066
+ * Sets the Room Variables for the passed Room.
1067
+ *
1068
+ * <p>Only new/updated variables are broadcast to the users in the target Room. A variable can also be deleted by setting it to <code>null</code>.</p>
1069
+ *
1070
+ * @example
1071
+ * <caption>In this example we set a Room Variable for the "chat37" Room. The variable is set as "global", so its value is visible to users outside the Room too.</caption>
1072
+ * // Create Room Variable
1073
+ * var topicRoomVar = new SFSRoomVariable("topic", "Tabletop games", VariableType.STRING);
1074
+ * topicRoomVar.setGlobal(true);
1075
+ *
1076
+ * // Get Room
1077
+ * var targetRoom = getParentZone().getRoomByName("chat37");
1078
+ *
1079
+ * // Set Room Variable
1080
+ * getApi().setRoomVariables(null, targetRoom, [topicRoomVar], true);
1081
+ *
1082
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the Room Variables; if <code>null</code>, the ownership is assigned to the "Server" itself.
1083
+ * @param {SFSRoom} targetRoom The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room in which to set the Room Variables.
1084
+ * @param {SFSRoomVariable[]} variables An array of {@link SFSRoomVariable} objects to set.
1085
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>ROOM_VARIABLES_UPDATE</em> event will be fired to notify the Room Variables creation/update.
1086
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.ROOM_VARIABLES_UPDATE]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#ROOM_VARIABLES_UPDATE} will be fired to notify the Room Variables creation/update.
1087
+ * @param {boolean} [overrideOwnership=false] If <code>true</code>, the ownership of variables can be overridden.
1088
+ */
1089
+ SFSApi.prototype.setRoomVariables = function(user, targetRoom, variables, fireClientEvent, fireServerEvent, overrideOwnership)
1090
+ {
1091
+ // Convert native JS array
1092
+ if (variables instanceof Array)
1093
+ variables = $$Util.toList(variables);
1094
+
1095
+ this._javaApi.setRoomVariables
1096
+ (
1097
+ user,
1098
+ targetRoom,
1099
+ variables,
1100
+ (fireClientEvent === undefined ? false : fireClientEvent),
1101
+ (fireServerEvent === undefined ? false : fireServerEvent),
1102
+ (overrideOwnership === undefined ? false : overrideOwnership)
1103
+ );
1104
+ }
1105
+
1106
+ /**
1107
+ * Sets the User Variables for the passed user.
1108
+ *
1109
+ * <p>Only new/updated variables are broadcast to the users that can "see" the owner. A variable can also be deleted by setting it to <code>null</code>.</p>
1110
+ *
1111
+ * @example
1112
+ * <caption>In this example we receive an Extension request which triggers the creation of a couple of User Variables for the requester.<br>
1113
+ * Usually an Extension request is not necessary, because User Variables can be set by the client directly, but in this case we want to validate the
1114
+ * "age" value sent by the client.</caption>
1115
+ * function init()
1116
+ * {
1117
+ * // Register client request handlers
1118
+ * addRequestHandler("setMyVars", onSetMyVarsRequest);
1119
+ * }
1120
+ *
1121
+ * function onSetMyVarsRequest(inParams, sender)
1122
+ * {
1123
+ * // Get parameters sent by the client
1124
+ * var userNick = inParams.getUtfString("nick");
1125
+ * var userAge = inParams.getInt("age");
1126
+ *
1127
+ * // Validate user age
1128
+ * if (userAge >= 13)
1129
+ * {
1130
+ * // Create User Variables
1131
+ * var userVar1 = new SFSUserVariable("nick", userNick, VariableType.STRING);
1132
+ * var userVar2 = new SFSUserVariable("age", userAge, VariableType.INT);
1133
+ *
1134
+ * // Set User Variables
1135
+ * getApi().setUserVariables(sender, [userVar1,userVar2], true);
1136
+ * }
1137
+ * }
1138
+ *
1139
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user for which the User Variables are set.
1140
+ * @param {SFSUserVariable[]} variables An array of {@link SFSUserVariable} objects to set.
1141
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>USER_VARIABLES_UPDATE</em> event will be fired to notify the User Variables creation/update.
1142
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.USER_VARIABLES_UPDATE]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#USER_VARIABLES_UPDATE} will be fired to notify the User Variables creation/update.
1143
+ */
1144
+ SFSApi.prototype.setUserVariables = function(owner, variables, fireClientEvent, fireServerEvent)
1145
+ {
1146
+ // Convert native JS array
1147
+ if (variables instanceof Array)
1148
+ variables = $$Util.toList(variables);
1149
+
1150
+ this._javaApi.setUserVariables
1151
+ (
1152
+ owner,
1153
+ variables,
1154
+ (fireClientEvent === undefined ? false : fireClientEvent),
1155
+ (fireServerEvent === undefined ? false : fireServerEvent)
1156
+ );
1157
+ }
1158
+
1159
+ /**
1160
+ * Renames a Room.
1161
+ *
1162
+ * @param {SFSUser} owner The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the Room; if <code>null</code>, the authorization of the user to change the Room name is not checked.
1163
+ * @param {SFSRoom} targetRoom The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to change the name to.
1164
+ * @param {string} newName The new Room name.
1165
+ *
1166
+ * @throws A <img src="java-icon-small.png"></img> [SFSRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSRoomException.html} exception if the new name is already assigned to another Room, its length is out of the range allowed by the Zone configuration or it contains bad words (if the Words Filter is active).
1167
+ */
1168
+ SFSApi.prototype.changeRoomName = function(owner, targetRoom, newName)
1169
+ {
1170
+ this._javaApi.changeRoomName(owner, targetRoom, newName);
1171
+ }
1172
+
1173
+ /**
1174
+ * Changes the Room password and the Room password-protection state.
1175
+ *
1176
+ * <p>The password-protection state indicates if a Room is private and requires a password to access it. Passing a <code>null</code> or empty string makes the Room public. Passing a valid string as the password makes the Room private.</p>
1177
+ *
1178
+ * @param {SFSUser} owner The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the Room; if <code>null</code>, the authorization of the user to change the Room password-protection state is not checked.
1179
+ * @param {SFSRoom} targetRoom The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to change the password-protection state to.
1180
+ * @param {string} newPassword The new password; <code>null</code> or empty string to remove the password protection.
1181
+ *
1182
+ * @throws A <img src="java-icon-small.png"></img> [SFSRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSRoomException.html} exception if the password-protection state couldn't be modified.
1183
+ */
1184
+ SFSApi.prototype.changeRoomPassword = function(owner, targetRoom, newPassword)
1185
+ {
1186
+ this._javaApi.changeRoomPassword(owner, targetRoom, newPassword);
1187
+ }
1188
+
1189
+ /**
1190
+ * Changes the capacity (maximum number of users/players and spectators) of the Room.
1191
+ *
1192
+ * <p>In case the Room size is shrunk, extra players or spectators will not be kicked out of the Room.</p>
1193
+ *
1194
+ * @param {SFSUser} owner The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the Room; if <code>null</code>, the authorization of the user to change the Room capacity is not checked.
1195
+ * @param {SFSRoom} targetRoom The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to change the capacity to.
1196
+ * @param {number} maxUsers The new maximum number of users (aka players in Game Rooms).
1197
+ * @param {number} maxSpectators The new maximum number of spectators (for Game Rooms only).
1198
+ *
1199
+ * @throws A <img src="java-icon-small.png"></img> [SFSRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSRoomException.html} exception if the Room capacity couldn't be modified.
1200
+ */
1201
+ SFSApi.prototype.changeRoomCapacity = function(owner, targetRoom, maxUsers, maxSpectators)
1202
+ {
1203
+ this._javaApi.changeRoomCapacity(owner, targetRoom, maxUsers, maxSpectators);
1204
+ }
1205
+
1206
+ /**
1207
+ * Subscribes a user to a Room Group.
1208
+ *
1209
+ * <p>This action enables the user to receive events related to the Rooms belonging the passed Group.</p>
1210
+ *
1211
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to subscribe to a Room Group.
1212
+ * @param {string} groupId The name of the Group to subscribe.
1213
+ */
1214
+ SFSApi.prototype.subscribeRoomGroup = function(user, groupId)
1215
+ {
1216
+ this._javaApi.subscribeRoomGroup(user, groupId);
1217
+ }
1218
+
1219
+ /**
1220
+ * Unsubscribes a user from a Room Group.
1221
+ *
1222
+ * <p>This action disables the user to receive events related to the Rooms belonging the passed Group.</p>
1223
+ *
1224
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to unsubscribe from a Room Group.
1225
+ * @param {string} groupId The name of the Group to unsubscribe.
1226
+ */
1227
+ SFSApi.prototype.unsubscribeRoomGroup = function(user, groupId)
1228
+ {
1229
+ this._javaApi.unsubscribeRoomGroup(user, groupId);
1230
+ }
1231
+
1232
+ /**
1233
+ * Turns a spectator in a Game Room to player.
1234
+ *
1235
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to turn from spectator to player.
1236
+ * @param {SFSRoom} targetRoom The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room in which the spectator will be turned into a player.
1237
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>SPECTATOR_TO_PLAYER</em> event will be fired to notify the change.
1238
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.SPECTATOR_TO_PLAYER]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#SPECTATOR_TO_PLAYER} will be fired to notify the change.
1239
+ *
1240
+ * @throws A <img src="java-icon-small.png"></img> [SFSRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSRoomException.html} exception if no player slot is available in the Game Room.
1241
+ */
1242
+ SFSApi.prototype.spectatorToPlayer = function(user, targetRoom, fireClientEvent, fireServerEvent)
1243
+ {
1244
+ this._javaApi.spectatorToPlayer
1245
+ (
1246
+ user,
1247
+ targetRoom,
1248
+ (fireClientEvent === undefined ? false : fireClientEvent),
1249
+ (fireServerEvent === undefined ? false : fireServerEvent)
1250
+ );
1251
+ }
1252
+
1253
+ /**
1254
+ * Turns a player in a Game Room to spectator.
1255
+ *
1256
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to turn from player to spectator.
1257
+ * @param {SFSRoom} targetRoom The <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room in which the player will be turned into a spectator.
1258
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>PLAYER_TO_SPECTATOR</em> event will be fired to notify the change.
1259
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.PLAYER_TO_SPECTATOR]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#PLAYER_TO_SPECTATOR} will be fired to notify the change.
1260
+ *
1261
+ * @throws A <img src="java-icon-small.png"></img> [SFSRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSRoomException.html} exception if no spectator slot is available in the Game Room.
1262
+ */
1263
+ SFSApi.prototype.playerToSpectator = function(user, targetRoom, fireClientEvent, fireServerEvent)
1264
+ {
1265
+ this._javaApi.playerToSpectator
1266
+ (
1267
+ user,
1268
+ targetRoom,
1269
+ (fireClientEvent === undefined ? false : fireClientEvent),
1270
+ (fireServerEvent === undefined ? false : fireServerEvent)
1271
+ );
1272
+ }
1273
+
1274
+ //==============================================================================
1275
+ //--- Buddy API class ----------------------------------------------------------
1276
+ //==============================================================================
1277
+
1278
+ /**
1279
+ * <b>Developers never istantiate the <em>BuddyApi</em> class</b>: this is done internally by the SmartFoxServer 2X API; get a reference to it using the Extension's {@link getBuddyApi} method.
1280
+ *
1281
+ * @class
1282
+ * The <em>BuddyApi</em> class provides all the features to manage the users' Buddy Lists.
1283
+ * It contains methods to initialize the Buddy List of a user, add and remove buddies, set the online status and more.
1284
+ *
1285
+ * <h4>See also</h4>
1286
+ * <ul>
1287
+ * <li>{@link SFSApi} class</li>
1288
+ * <li>{@link GameApi} class</li>
1289
+ * <li>{@link MMOApi} class</li>
1290
+ * <li>{@link FileApi} class</li>
1291
+ * </ul>
1292
+ */
1293
+ BuddyApi = function()
1294
+ {
1295
+ this._sfs = $$SfsInstance;
1296
+ this._javaApi = this._sfs.getAPIManager().getBuddyApi();
1297
+ }
1298
+
1299
+ /**
1300
+ * Initializes the Buddy List for the passed user.
1301
+ *
1302
+ * <p>This causes saved data (the list of buddies and their persistent Buddy Variables) to be loaded from the Buddy List storage.</p>
1303
+ *
1304
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user whose Buddy List should be loaded.
1305
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.BUDDY_LIST_INIT]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#BUDDY_LIST_INIT} will be fired to notify the Buddy List initialization success.
1306
+ *
1307
+ * @return {SFSBuddyList} A <img src="java-icon-small.png"></img> [SFSBuddyList]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/buddylist/SFSBuddyList.html} class instance representing the usere's Buddy List.
1308
+ *
1309
+ * @throws An <em>IOException</em> Java exception if the Buddy List data couldn't be retrieved from the storage.
1310
+ */
1311
+ BuddyApi.prototype.initBuddyList = function(user, fireServerEvent)
1312
+ {
1313
+ return this._javaApi.initBuddyList
1314
+ (
1315
+ user,
1316
+ (fireServerEvent === undefined ? false : fireServerEvent)
1317
+ );
1318
+ }
1319
+
1320
+ /**
1321
+ * Activates/deactivates the ONLINE status of the user in the Buddy List system.
1322
+ *
1323
+ * <p>All clients who have the user as their Buddy will see him as online or offline respectively.</p>
1324
+ *
1325
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to set online/offline in the Buddy List system.
1326
+ * @param {boolean} online If <code>true</code>, the user is set as online in the Buddy List system; if <code>false</code>, he is set as offline.
1327
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.BUDDY_ONLINE_STATE_UPDATE]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#BUDDY_ONLINE_STATE_UPDATE} will be fired to notify the user's online state change.
1328
+ */
1329
+ BuddyApi.prototype.goOnline = function(user, online, fireServerEvent)
1330
+ {
1331
+ this._javaApi.goOnline
1332
+ (
1333
+ user,
1334
+ online,
1335
+ (fireServerEvent === undefined ? false : fireServerEvent)
1336
+ );
1337
+ }
1338
+
1339
+ /**
1340
+ * Adds a new buddy to the Buddy List of the passed user.
1341
+ *
1342
+ * @param {SFSUser} owner The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the Buddy List to add a new buddy to.
1343
+ * @param {string} buddyName The name of the user to add as a buddy.
1344
+ * @param {boolean} isTemp If <code>true</code>, the buddy is only temporary and will be removed when the owner logs out of the system.
1345
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>BUDDY_ADD</em> event will be fired to notify the action.
1346
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.BUDDY_ADD]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#BUDDY_ADD} will be fired to notify the action.
1347
+ *
1348
+ * @throws A <img src="java-icon-small.png"></img> [SFSBuddyListException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSBuddyListException.html} exception if the Buddy List of the user is full or the buddy is already in the Buddy List.
1349
+ */
1350
+ BuddyApi.prototype.addBuddy = function(owner, buddyName, isTemp, fireClientEvent, fireServerEvent)
1351
+ {
1352
+ this._javaApi.addBuddy
1353
+ (
1354
+ owner,
1355
+ buddyName,
1356
+ isTemp,
1357
+ (fireClientEvent === undefined ? false : fireClientEvent),
1358
+ (fireServerEvent === undefined ? false : fireServerEvent)
1359
+ );
1360
+ }
1361
+
1362
+ /**
1363
+ * Sets the Buddy Variables for the passed user.
1364
+ *
1365
+ * <p>Only new/updated variables are broadcast to the users that have the owner in their Buddy list. A variable can also be deleted by setting it to <code>null</code>.</p>
1366
+ *
1367
+ * @param {SFSUser} owner The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to set the Buddy Variables for.
1368
+ * @param {SFSBuddyVariable[]} variables An array of {@link SFSBuddyVariable} objects to set.
1369
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>BUDDY_VARIABLES_UPDATE</em> event will be fired to notify the Buddy Variables creation/update.
1370
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.BUDDY_VARIABLES_UPDATE]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#BUDDY_VARIABLES_UPDATE} will be fired to notify the Buddy Variables creation/update.
1371
+ *
1372
+ * @throws A <img src="java-icon-small.png"></img> [SFSBuddyListException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSBuddyListException.html} exception if the limit on the number of allowed Buddy Variables is exceeded.
1373
+ */
1374
+ BuddyApi.prototype.setBuddyVariables = function(owner, variables, fireClientEvent, fireServerEvent)
1375
+ {
1376
+ // Convert native JS array
1377
+ if (variables instanceof Array)
1378
+ variables = $$Util.toList(variables);
1379
+
1380
+ this._javaApi.setBuddyVariables
1381
+ (
1382
+ user,
1383
+ variables,
1384
+ (fireClientEvent === undefined ? false : fireClientEvent),
1385
+ (fireServerEvent === undefined ? false : fireServerEvent)
1386
+ );
1387
+ }
1388
+
1389
+ /**
1390
+ * Removes a buddy from the Buddy List of the passed user.
1391
+ *
1392
+ * @param {SFSUser} owner The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the Buddy List to remove a buddy from.
1393
+ * @param {string} buddyName The name of the buddy to remove.
1394
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>BUDDY_REMOVE</em> event will be fired to notify the buddy removal.
1395
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.BUDDY_REMOVE]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#BUDDY_REMOVE} will be fired to notify the buddy removal.
1396
+ */
1397
+ BuddyApi.prototype.removeBuddy = function(owner, buddyName, fireClientEvent, fireServerEvent)
1398
+ {
1399
+ this._javaApi.removeBuddy
1400
+ (
1401
+ owner,
1402
+ buddyName,
1403
+ (fireClientEvent === undefined ? false : fireClientEvent),
1404
+ (fireServerEvent === undefined ? false : fireServerEvent)
1405
+ );
1406
+ }
1407
+
1408
+ /**
1409
+ * Blocks/unblocks a buddy in the Buddy List of a user.
1410
+ *
1411
+ * <p>Blocked buddies won't be able to see the user online status and send him messages or Buddy Variables updates.</p>
1412
+ *
1413
+ * @param {SFSUser} owner The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the Buddy List in which the buddy should be blocked/unblocked.
1414
+ * @param {string} buddyName The name of the buddy to block/unblock.
1415
+ * @param {boolean} isBlocked If <code>true</code>, the buddy will be blocked in the Buddy List of the user; if <code>false</code>, the block will be removed.
1416
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>BUDDY_BLOCK</em> event will be fired to notify the change.
1417
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.BUDDY_BLOCK]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#BUDDY_BLOCK} will be fired to notify the change.
1418
+ */
1419
+ BuddyApi.prototype.blockBuddy = function(owner, buddyName, isBlocked, fireClientEvent, fireServerEvent)
1420
+ {
1421
+ this._javaApi.blockBuddy
1422
+ (
1423
+ owner,
1424
+ buddyName,
1425
+ isBlocked,
1426
+ (fireClientEvent === undefined ? false : fireClientEvent),
1427
+ (fireServerEvent === undefined ? false : fireServerEvent)
1428
+ );
1429
+ }
1430
+
1431
+ /**
1432
+ * Sends a Buddy Message from a user to one of his buddies.
1433
+ *
1434
+ * <p>A Buddy Message is similar to a regular private chat message, but it is meant to work with the Buddy List system, taking into account the buddy blocked state, online presence, etc.<br>
1435
+ * The message is sent to both the sender and the receiver. The recipient must be in the sender's Buddy List.</p>
1436
+ *
1437
+ * @param {SFSUser} sender The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user sending the message.
1438
+ * @param {SFSUser} recipient The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the message recipient (must be a buddy in the sender's Buddy List).
1439
+ * @param {string} message The chat message to send.
1440
+ * @param {SFSObject} params A <em>SFSObject</em> containing custom parameters to be attached to the message (e.g. text color, font size, etc).
1441
+ *
1442
+ * @throws A <img src="java-icon-small.png"></img> [SFSBuddyListException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSBuddyListException.html} exception if the recipient is not in the sender's Buddy List or if the recipient has blocked the sender.
1443
+ */
1444
+ BuddyApi.prototype.sendBuddyMessage = function(sender, recipient, message, params)
1445
+ {
1446
+ this._javaApi.sendBuddyMessage(sender, recipient, message, params);
1447
+ }
1448
+
1449
+ //==============================================================================
1450
+ //--- Game API class -----------------------------------------------------------
1451
+ //==============================================================================
1452
+
1453
+ /**
1454
+ * <b>Developers never istantiate the <em>GameApi</em> class</b>: this is done internally by the SmartFoxServer 2X API; get a reference to it using the Extension's {@link getGameApi} method.
1455
+ *
1456
+ * @class
1457
+ * The <em>GameApi</em> class provides specialized API calls for advanced game functionalities.
1458
+ * It contains methods to search opponents based on matching criteria, challenge other players or send invitations to join a game, start quick games and more.
1459
+ *
1460
+ * <h4>See also</h4>
1461
+ * <ul>
1462
+ * <li>{@link SFSApi} class</li>
1463
+ * <li>{@link BuddyApi} class</li>
1464
+ * <li>{@link MMOApi} class</li>
1465
+ * <li>{@link FileApi} class</li>
1466
+ * </ul>
1467
+ */
1468
+ GameApi = function()
1469
+ {
1470
+ this._sfs = $$SfsInstance;
1471
+ this._javaApi = this._sfs.getAPIManager().getGameApi();
1472
+ }
1473
+
1474
+ /**
1475
+ * Creates a new Room of type SFSGame.
1476
+ *
1477
+ * <p>The SFSGame class extends the normal capabilities of a Room, adding the ability to set the game as private and provide a list of users that the system will invite to play automatically.
1478
+ * Additionally the system is be able to invite more users if the number of players is not sufficient to start the game.</p>
1479
+ *
1480
+ * <h5>See also:</h5>
1481
+ * <ul>
1482
+ * <li>{@link CreateRoomSettings} class</li>
1483
+ * <li>{@link CreateMMORoomSettings} class</li>
1484
+ * <li>{@link SFSApi#createRoom} method</li>
1485
+ * </ul>
1486
+ *
1487
+ * @param {SFSZone} zone The <img src="java-icon-small.png"></img> [SFSZone]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSZone.html} object representing the Zone the SFSGame should be created into.
1488
+ * @param {CreateSFSGameSettings} settings The SFSGame configuration object.
1489
+ * @param {SFSUser} [owner=null] The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the owner of the SFSGame; if <code>null</code> is passed, the "Server" will be the owner.
1490
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>ROOM_ADD</em> event will be fired to notify the SFSGame creation.
1491
+ * @param {boolean} [fireServerEvent=false] If <code>true</code>, a server-side event of type <img src="java-icon-small.png"></img> [SFSEventType.ROOM_ADDED]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/core/SFSEventType.html#ROOM_ADDED} will be fired to notify the SFSGame creation.
1492
+ *
1493
+ * @example
1494
+ * <caption>In this example we create a public SFSGame, using a Match Expression to make the Room joinable by
1495
+ * players from United States and with a rank greater than or equal to 50 only.</caption>
1496
+ * var cgs = new CreateSFSGameSettings();
1497
+ * cgs.setName("battle-room-173");
1498
+ * cgs.setMaxUsers(4);
1499
+ * cgs.setMaxSpectators(0);
1500
+ * cgs.setGame(true);
1501
+ * cgs.setGamePublic(true);
1502
+ * cgs.setMinPlayersToStartGame(4);
1503
+ *
1504
+ * // Set a Match Expression to filter players willing to join
1505
+ * var exp = new MatchExpression("country", StringMatch.EQUALS, "US");
1506
+ * exp.and("rank", NumberMatch.GREATER_THAN_OR_EQUAL_TO, 50);
1507
+ * cgs.setPlayerMatchExpression(exp);
1508
+ *
1509
+ * // Create the SFSGame
1510
+ * getGameApi().createGame(getParentZone(), cgs, null, true, true);
1511
+ *
1512
+ * @return {SFSGame} The <img src="java-icon-small.png"></img> [SFSGame]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/game/SFSGame.html} object representing the Room of type SFSGame just created.
1513
+ *
1514
+ * @throws A <img src="java-icon-small.png"></img> [SFSCreateRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSCreateRoomException.html} exception if an error occurs during the Room creation.
1515
+ * @throws A <img src="java-icon-small.png"></img> [SFSCreateGameException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSCreateGameException.html} exception if the specific settings of the SFSGame are invalid.
1516
+ */
1517
+ GameApi.prototype.createGame = function(zone, settings, owner, fireClientEvent, fireServerEvent)
1518
+ {
1519
+ return this._javaApi.createGame
1520
+ (
1521
+ zone,
1522
+ settings,
1523
+ (owner === undefined ? null : owner),
1524
+ (fireClientEvent === undefined ? false : fireClientEvent),
1525
+ (fireServerEvent === undefined ? false : fireServerEvent)
1526
+ );
1527
+ }
1528
+
1529
+ /**
1530
+ * Quickly joins a user in an Room of type SFSGame.
1531
+ *
1532
+ * <p>When this method is called, the API:</p>
1533
+ * <ul>
1534
+ * <li>if a Zone and Group name are passed, matches the provided Match Expression in the scope (Zone+Group) to find a list of possible Rooms that the player can join;</li>
1535
+ * <li>matches the user properties with the Match Expression assigned to the SFSGames in the list (if any - see the {@link GameApi#createGame} method).</li>
1536
+ * </ul>
1537
+ * The first SFSGames that matches the user properties is joined, otherwise an error is returned.
1538
+ *
1539
+ * @param {SFSUser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to join in the SFSGame.
1540
+ * @param {MatchExpression} expression A Match Expression containing the Room search criteria to find the appropriate SFSGame to join the user in.
1541
+ * @param {SFSZone} zone The <img src="java-icon-small.png"></img> [SFSZone]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSZone.html} object representing the Zone where to search available SFSGames in. This is ignored if a list of <em>SFSGame</em> objects is passed as the next parameter.
1542
+ * @param {string|SFSGame[]} searchItem The name of a Room Group or a list of <img src="java-icon-small.png"></img> [SFSGame]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/game/SFSGame.html} objects where to search an available SFSGame in.
1543
+ * @param {SFSRoom} roomToLeave A <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to leave after having successfully joined the SFSGame.
1544
+ *
1545
+ * @return {SFSGame} The <img src="java-icon-small.png"></img> [SFSGame]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/game/SFSGame.html} object representing the SFSGame that was joined.
1546
+ *
1547
+ * @throws A <img src="java-icon-small.png"></img> [SFSJoinRoomException]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/exceptions/SFSJoinRoomException.html} exception if an error occurs during the SFSGame joining process.
1548
+ */
1549
+ GameApi.prototype.quickJoinGame = function(user, expression, zone, searchItem, roomToLeave)
1550
+ {
1551
+ // Array of searchable rooms?
1552
+ if (searchItem instanceof Array)
1553
+ return this._javaApi.quickJoinGame(user, expression. $$Util.toList(searchItem), roomToLeave);
1554
+
1555
+ else
1556
+ return this._javaApi.quickJoinGame(user, expression, zone, groupId, roomToLeave);
1557
+ }
1558
+
1559
+ /**
1560
+ * Sends an invitation to a user.
1561
+ *
1562
+ * <p>An invitation can be sent for various purposes, such as joining a Room (both regular and game ones), adding a friend to the Buddy List, etc.</p>
1563
+ *
1564
+ * <h5>See also:</h5>
1565
+ * <ul>
1566
+ * <li>{@link GameApi#replyToInvitation} method</li>
1567
+ * </ul>
1568
+ *
1569
+ * @param {SFSUser} inviter The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user sending the invitation.
1570
+ * @param {SFSUser[]} invitees A list of <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} objects representing the recipients of the invitation.
1571
+ * @param {number} expirySeconds The amount of time allowed to each invitee to accept or refuse the invitation.
1572
+ * @param {invCallBackHandler} invCallBackHandler The object that will handle the reply to the invitation (accept or refuse).
1573
+ * @param {SFSObject} [params] A <em>SFSObject</em> containing custom parameters to be attached to the invitation (e.g. a message).
1574
+ */
1575
+ GameApi.prototype.sendInvitation = function(inviter, invitees, expirySeconds, invCallBackHandler, params)
1576
+ {
1577
+ // Check implementation of callback handler was done correctly
1578
+ if (!invCallBackHandler.onAccepted || !invCallBackHandler.onRefused || !invCallBackHandler.onExpired)
1579
+ throw new java.lang.IllegalArgumentException("Callback handler must implement these three methods: onAccepted, onRefused, onExpired");
1580
+
1581
+ var handler = Java.extend(InvitationCallback, invCallBackHandler);
1582
+ this._javaApi.sendInvitation
1583
+ (
1584
+ inviter,
1585
+ invitees,
1586
+ expirySeconds,
1587
+ new handler(),
1588
+ (params === undefined ? null : params)
1589
+ );
1590
+ }
1591
+
1592
+ /**
1593
+ * This callback handler is an object containing the <em>onAccepted</em>, <em>onRefused</em> and <em>onExpired</em> methods, respectively called when an invitation sent using the {@link GameApi#sendInvitation} method is accepted, refused or expires before a reply is received.
1594
+ *
1595
+ * <p></p>
1596
+ *
1597
+ * <h5>See also:</h5>
1598
+ * <ul>
1599
+ * <li>{@link GameApi#replyToInvitation} method</li>
1600
+ * </ul>
1601
+ *
1602
+ * @example
1603
+ * <caption>This example shows how to create this callback handler.</caption>
1604
+ * var invitationCallBackHandler = {
1605
+ * onAccepted: function(invObj, params)
1606
+ * {
1607
+ * // Handle invitation accepted
1608
+ * ...
1609
+ * },
1610
+ *
1611
+ * onRefused(invObj, params)
1612
+ * {
1613
+ * // Handle invitation refused
1614
+ * ...
1615
+ * },
1616
+ *
1617
+ * onExpired: function(invObj)
1618
+ * {
1619
+ * // Handle invitation expired
1620
+ * ...
1621
+ * }
1622
+ * };
1623
+ *
1624
+ * @callback invCallBackHandler
1625
+ *
1626
+ * @param {Invitation} invObj A <img src="java-icon-small.png"></img> [SFSInvitation]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/invitation/SFSInvitation.html} object representing the invitation sent to the recipient(s).
1627
+ * @param {SFSObject} params The <em>SFSObject</em> containing the custom parameters attached to the invitation reply, if any. This parameter is passed to <em>onAccepted</em> and <em>onRefused</em> functions only.
1628
+ */
1629
+
1630
+ /**
1631
+ * Sends a reply to an invitation.
1632
+ *
1633
+ * <p>Replying to an invitation means to accept or refuse it.</p>
1634
+ *
1635
+ * <h5>See also:</h5>
1636
+ * <ul>
1637
+ * <li>{@link GameApi#sendInvitation} method</li>
1638
+ * </ul>
1639
+ *
1640
+ * @param {SFSUser} invitedUser The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user who received the invitation.
1641
+ * @param {number} invitationId The id of the invitation, which can be retrieved from the <em>SFSInvitation</em> object received by the invited client.
1642
+ * @param {InvitationResponse} reply One of the invitation replies provided in the <em>InvitationResponse</em> enum; only <em>ACCEPT<em> and <em>REFUSE</em> are valid replies, while <em>EXPIRED</em> is reserved to the system.
1643
+ * @param {SFSObject} [params] A <em>SFSObject</em> containing custom parameters to be attached to the reply.
1644
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>INVITATION_REPLY</em> event will be fired to notify the reply.
1645
+ */
1646
+ GameApi.prototype.replyToInvitation = function(invitedUser, invitationId, reply, params, fireClientEvent)
1647
+ {
1648
+ this._javaApi.replyToInvitation
1649
+ (
1650
+ invitedUser,
1651
+ invitationId,
1652
+ reply,
1653
+ (params === undefined ? null : params),
1654
+ (fireClientEvent === undefined ? false : fireClientEvent)
1655
+ );
1656
+ }
1657
+
1658
+ /**
1659
+ * Invites a user to join an existing Room of any type.
1660
+ *
1661
+ * <p>If the invitation is accepted, the invitee will be automatically joined in the target Room.</p>
1662
+ *
1663
+ * @param {SFSRoom} target A <img src="java-icon-small.png"></img> [SFSRoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html} object representing the Room to invite the invitees to.
1664
+ * @param {SFSUser} inviter The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user sending the invitation.
1665
+ * @param {SFSUser[]} invitees A list of <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} objects representing the recipients of the invitation.
1666
+ * @param {number} expirySeconds The amount of time allowed to each invitee to accept or refuse the invitation.
1667
+ * @param {boolean} [asSpect=false] If <code>true</code>, the provided list of invitees will be joined as spectators (where applicable, i.e. Rooms of type game).
1668
+ * @param {boolean} [leaveLastJoinedRoom=false] If <code>true</code>, the users joining the target Room will leave the previously joined Room.
1669
+ * @param {SFSObject} [params] A <em>SFSObject</em> containing custom parameters to be attached to the invitation (e.g. a message).
1670
+ */
1671
+ GameApi.prototype.sendJoinRoomInvitation = function(target, inviter, invitees, expirySeconds, asSpect, leaveLastJoinedRoom, params)
1672
+ {
1673
+ if (invitees instanceof Array)
1674
+ invitees = $$Util.toList(invitees);
1675
+
1676
+ this._javaApi.sendJoinRoomInvitation
1677
+ (
1678
+ target,
1679
+ inviter,
1680
+ invitees,
1681
+ expirySeconds,
1682
+ (asSpect === undefined ? false : asSpect),
1683
+ (leaveLastJoinedRoom === undefined ? false : leaveLastJoinedRoom),
1684
+ (params === undefined ? null : params)
1685
+ );
1686
+ }
1687
+
1688
+ //==============================================================================
1689
+ //--- MMO API class ------------------------------------------------------------
1690
+ //==============================================================================
1691
+
1692
+ /**
1693
+ * <b>Developers never istantiate the <em>MMOApi</em> class</b>: this is done internally by the SmartFoxServer 2X API; get a reference to it using the Extension's {@link getMMOApi} method.
1694
+ *
1695
+ * @class
1696
+ * The <em>MMOApi</em> class provides specialized API calls for advanced MMO-related functionalities.
1697
+ * All the methods are targeted at an MMORoom and take its Area of Interest into account in order to dispatch events to the clients.
1698
+ *
1699
+ * <h4>Notes</h4>
1700
+ * <ul>
1701
+ * <li>Whenever a <em>Vec3D</em> object must be passed to a method of this API, use the {@link Vectors.newVec3D} helper method to generate it.
1702
+ * The reason is that this class is not available in JavaScript due to constructor overloading in the corresponding <img src="java-icon-small.png"></img> [Vec3D]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/Vec3D.html} class.</li>
1703
+ * </ul>
1704
+ *
1705
+ * <h4>See also</h4>
1706
+ * <ul>
1707
+ * <li>{@link SFSApi} class</li>
1708
+ * <li>{@link BuddyApi} class</li>
1709
+ * <li>{@link GameApi} class</li>
1710
+ * <li>{@link FileApi} class</li>
1711
+ * </ul>
1712
+ */
1713
+ MMOApi = function()
1714
+ {
1715
+ this._sfs = $$SfsInstance;
1716
+ this._javaApi = this._sfs.getAPIManager().getMMOApi()
1717
+ }
1718
+
1719
+ /**
1720
+ * Sends a data object from a user to all the other users in his Area of Interest (AOI).
1721
+ *
1722
+ * <p>This method sends a custom <em>SFSObject</em> that can contain any data. Typically this is used to send game moves to players or other game/app related updates.<br>
1723
+ * The difference with the regular version of this method (see {@link SFSApi#sendObjectMessage} method) is that it works with the AOI set for the target MMORoom.
1724
+ * Also, instead of using the default AOI, a custom AOI can be provided. This must be smaller than the default one; attempting to use a larger AOI is not possible.<br>
1725
+ * The sender must be joined in the target MMORoom too.</p>
1726
+ *
1727
+ * @param {MMORoom} targetRoom The <img src="java-icon-small.png"></img> [MMORoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/MMORoom.html} object representing the MMORoom to send the data to.
1728
+ * @param {SFSUser} sender The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user sending the data to the target MMORoom.
1729
+ * @param {SFSObject} message The data object to send.
1730
+ * @param {Vec3D} [aoi] A <img src="java-icon-small.png"></img> [Vec3D]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/Vec3D.html} instance representing a custom AOI.<br>Read the notes in the {@link MMOApi} class description.
1731
+ */
1732
+ MMOApi.prototype.sendObjectMessage = function(targetRoom, sender, message, aoi)
1733
+ {
1734
+ this._javaApi.sendObjectMessage
1735
+ (
1736
+ targetRoom,
1737
+ sender,
1738
+ message,
1739
+ (aoi === undefined ? null : aoi)
1740
+ );
1741
+ }
1742
+
1743
+ /**
1744
+ * Sends a public chat message from user to all the other users in his Area of Interest (AOI).
1745
+ *
1746
+ * <p>The difference with the regular version of this method (see {@link SFSApi#sendPublicMessage} method) is that it works with the AOI set for the target MMORoom.
1747
+ * Also, instead of using the default AOI, a custom AOI can be provided. This must be smaller than the default one; attempting to use a larger AOI is not possible.<br>
1748
+ * The sender must be joined in the target MMORoom too.</p>
1749
+ *
1750
+ * @param {MMORoom} targetRoom The <img src="java-icon-small.png"></img> [MMORoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/MMORoom.html} object representing the MMORoom to send the message to.
1751
+ * @param {SFSUser} sender The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user sending the message to the target MMORoom.
1752
+ * @param {string} message The chat message to send.
1753
+ * @param {SFSObject} [params] A <em>SFSObject</em> containing custom parameters to be attached to the message (e.g. text color, font size, etc).
1754
+ * @param {Vec3D} [aoi] A <img src="java-icon-small.png"></img> [Vec3D]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/Vec3D.html} instance representing a custom AOI.<br>Read the notes in the {@link MMOApi} class description.
1755
+ */
1756
+ MMOApi.prototype.sendPublicMessage = function(targetRoom, sender, message, params, aoi)
1757
+ {
1758
+ this._javaApi.sendPublicMessage
1759
+ (
1760
+ targetRoom,
1761
+ sender,
1762
+ message,
1763
+ (params === undefined ? null : params),
1764
+ (aoi === undefined ? null : aoi)
1765
+ );
1766
+ }
1767
+
1768
+ /**
1769
+ * Sets the position of a user inside an MMORoom.
1770
+ *
1771
+ * @param {SFSuser} user The <img src="java-icon-small.png"></img> [SFSUser]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSUser.html} object representing the user to set the position of.
1772
+ * @param {Vec3D} pos A <img src="java-icon-small.png"></img> [Vec3D]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/Vec3D.html} instance representing the user position in the target MMORoom.<br>Read the notes in the {@link MMOApi} class description.
1773
+ * @param {MMORoom} targetRoom The <img src="java-icon-small.png"></img> [MMORoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/MMORoom.html} object representing the MMORoom where to set the user position.
1774
+ */
1775
+ MMOApi.prototype.setUserPosition = function(user, pos, targetRoom)
1776
+ {
1777
+ this._javaApi.setUserPosition(user, pos, targetRoom);
1778
+ }
1779
+
1780
+ /**
1781
+ * Sets the position of an MMOItem inside an MMORoom.
1782
+ *
1783
+ * @param {MMOItem} item The <em>MMOItem</em> object representing the MMOItem to set the position of.
1784
+ * @param {Vec3D} pos A <img src="java-icon-small.png"></img> [Vec3D]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/Vec3D.html} instance representing the MMOItem position in the target MMORoom.<br>Read the notes in the {@link MMOApi} class description.
1785
+ * @param {MMORoom} targetRoom The <img src="java-icon-small.png"></img> [MMORoom]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/MMORoom.html} object representing the MMORoom where to set the MMOItem position.
1786
+ */
1787
+ MMOApi.prototype.setMMOItemPosition = function(item, pos, targetRoom)
1788
+ {
1789
+ this._javaApi.setMMOItemPosition(item, pos, targetRoom);
1790
+ }
1791
+
1792
+ /**
1793
+ * Removes an MMOItem from an MMORoom.
1794
+ *
1795
+ * <p>The target MMORoom is not required by this method because the system already keeps track of which MMOItem belongs to which MMORoom.</p>
1796
+ *
1797
+ * @param {MMOItem} item The <em>MMOItem</em> object representing the MMOItem to be removed from the MMORoom where it is located.
1798
+ */
1799
+ MMOApi.prototype.removeMMOItem = function(item)
1800
+ {
1801
+ this._javaApi.removeMMOItem(item);
1802
+ }
1803
+
1804
+ /**
1805
+ * Sets the MMOItem Variables for the passed MMOItem.
1806
+ *
1807
+ * <p>Only new/updated variables are broadcast to the users that are within the range defined by the MOORoom's Area of Interest from the target MMOItem. A variable can also be deleted by setting it to <code>null</code>.</p>
1808
+ *
1809
+ * @param {MMOItem} item The <em>MMOItem</em> object representing the MMOItem for which the MMOItem Variables are set.
1810
+ * @param {MMOItemVariable[]} variables An array of {@link MMOItemVariable} objects to set.
1811
+ * @param {boolean} [fireClientEvent=false] If <code>true</code>, a client-side <em>MMOITEM_VARIABLES_UPDATE</em> event will be fired to notify the MMOItem Variables creation/update.
1812
+ */
1813
+ MMOApi.prototype.setMMOItemVariables = function(item, variables, fireClientEvent)
1814
+ {
1815
+ // Convert native JS array
1816
+ if (variables instanceof Array)
1817
+ variables = $$Util.toList(variables);
1818
+
1819
+ this._javaApi.setMMOItemVariables
1820
+ (
1821
+ item,
1822
+ variables,
1823
+ (fireClientEvent === undefined ? false : fireClientEvent)
1824
+ );
1825
+ }
1826
+
1827
+ //--- MMOApi helper object -----------------------------------------------------
1828
+
1829
+ /**
1830
+ * A factory object containing an helper method to generate <img src="java-icon-small.png"></img> [Vec3D]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/Vec3D.html} instances.
1831
+ * @namespace
1832
+ */
1833
+ Vectors = {}
1834
+
1835
+ /**
1836
+ * Creates an instance of <img src="java-icon-small.png"></img> [Vec3D]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/Vec3D.html}, which defines a set of coordinates in a virtual world represented by a MMORoom.
1837
+ *
1838
+ * @param {number} x The position along the X axis.
1839
+ * @param {number} y The position along the Y axis.
1840
+ * @param {number} z The position along the Z axis.
1841
+ * @param {boolean} isFloat Force the coordinates to be treated as floating point numbers (even if integers are passed).
1842
+ *
1843
+ * @return {Vec3D} A <img src="java-icon-small.png"></img> [Vec3D]{@link http://docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/mmo/Vec3D.html} instance.
1844
+ *
1845
+ * @static
1846
+ */
1847
+ Vectors.newVec3D = function (x, y, z, isFloat)
1848
+ {
1849
+ if (isFloat)
1850
+ return $$Helper.makeFloatVector(x, y, z);
1851
+
1852
+ else
1853
+ return $$Helper.makeIntVector(x, y, z);
1854
+ }
1855
+
1856
+ //==============================================================================
1857
+ //--- File API class -----------------------------------------------------------
1858
+ //==============================================================================
1859
+
1860
+ /**
1861
+ * <b>Developers never istantiate the <em>FileApi</em> class</b>: this is done internally by the SmartFoxServer 2X API; get a reference to it using the Extension's {@link getFileApi} method.
1862
+ *
1863
+ * @class
1864
+ * The <em>FileApi</em> class provides specialized API calls to interact with the file system.
1865
+ *
1866
+ * <h4>See also</h4>
1867
+ * <ul>
1868
+ * <li>{@link SFSApi} class</li>
1869
+ * <li>{@link BuddyApi} class</li>
1870
+ * <li>{@link GameApi} class</li>
1871
+ * <li>{@link MMOApi} class</li>
1872
+ * </ul>
1873
+ */
1874
+ FileApi = function()
1875
+ {
1876
+ this._javaApi = org.apache.commons.io.FileUtils
1877
+ }
1878
+
1879
+ /**
1880
+ * Reads the contents of a file into a string using the default encoding for the Java Virtual Machine. The file is always closed.
1881
+ *
1882
+ * @param {string} filePath The path of the file to read.
1883
+ *
1884
+ * @return {string} The file contents.
1885
+ *
1886
+ * @throws An <em>IOException</em> Java exception in case of an I/O error.
1887
+ */
1888
+ FileApi.prototype.readTextFile = function(filePath)
1889
+ {
1890
+ return this._javaApi.readFileToString(new java.io.File(filePath));
1891
+ }
1892
+
1893
+ /**
1894
+ * Writes a string to a file using the default encoding for the Java Virtual Machine, creating the file if it does not exist.
1895
+ *
1896
+ * @param {string} filePath The path of the file to write.
1897
+ * @param {string} data The content to write to the file.
1898
+ *
1899
+ * @throws An <em>IOException</em> Java exception in case of an I/O error.
1900
+ */
1901
+ FileApi.prototype.writeTextFile = function(filePath, data)
1902
+ {
1903
+ this._javaApi.writeStringToFile(new java.io.File(filePath), data);
1904
+ }
1905
+
1906
+ /**
1907
+ * Returns the relative path to the current Extension folder.
1908
+ *
1909
+ * <p>Typically this method will return a string like "extensions/{name-of-extension}/".
1910
+ * The path is relative to the server root folder and it can be used to load external data files that are stored together with the Extension's JavaScript file(s).</p>
1911
+ *
1912
+ * @return {string} The path of the current Extension folder.
1913
+ */
1914
+ FileApi.prototype.getCurrentFolder = function()
1915
+ {
1916
+ return $$WrapperExt.getCurrentFolder();
1917
+ }
1918
+
1919
+ /**
1920
+ * Copies a file to a new location.
1921
+ *
1922
+ * <p>This method copies the contents of the specified source path to the specified destination path.
1923
+ * The folder holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.</p>
1924
+ *
1925
+ * @param {string} srcPath The path to an existing file to copy.
1926
+ * @param {string} destPath The path of the destination file.
1927
+ *
1928
+ * @throws An <em>IOException</em> Java exception in case the source or destination is invalid, or an IO error occurs during copying.
1929
+ */
1930
+ FileApi.prototype.copyFile = function(srcPath, destPath)
1931
+ {
1932
+ this._javaApi.copyFile(new java.io.File(srcPath), new java.io.File(destPath));
1933
+ }
1934
+
1935
+ /**
1936
+ * Moves a file to a new location.
1937
+ *
1938
+ * @param {string} srcPath The path to an existing file to be moved.
1939
+ * @param {string} destPath The path of the destination file.
1940
+ *
1941
+ * @throws An <em>IOException</em> Java exception in case the source or destination is invalid, or an IO error occurs during copying.
1942
+ * @throws An <em>FileExistsException</em> Java exception in case the destination file already exists.
1943
+ */
1944
+ FileApi.prototype.moveFile = function(srcPath, destPath)
1945
+ {
1946
+ this._javaApi.moveFile(new java.io.File(srcPath), new java.io.File(destPath));
1947
+ }
1948
+
1949
+ /**
1950
+ * Deletes a file, never throwing an exception.
1951
+ *
1952
+ * @param {string} filePath The path of the file to delete.
1953
+ *
1954
+ * @return {boolean} <code>true</code> if the file was deleted, <code>false</code> otherwise.
1955
+ */
1956
+ FileApi.prototype.deleteFile = function(filePath)
1957
+ {
1958
+ return this._javaApi.deleteQuietly(new java.io.File(filePath));
1959
+ }
1960
+
1961
+ /**
1962
+ * Deletes a folder including all its sub-folders, never throwing an exception.
1963
+ *
1964
+ * @param {string} dirPath The path of the folder to delete.
1965
+ *
1966
+ * @return {boolean} <code>true</code> if the folder was deleted, <code>false</code> otherwise.
1967
+ */
1968
+ FileApi.prototype.deleteDirectory = function(dirPath)
1969
+ {
1970
+ return this.deleteFile(dirPath);
1971
+ }
1972
+
1973
+ /**
1974
+ * Makes a directory, including any necessary but nonexistent parent directories.
1975
+ *
1976
+ * @param {string} fullPath The path of the direcotry to create.
1977
+ *
1978
+ * @throws An <em>IOException</em> Java exception in case the directory cannot be created or the file already exists but is not a directory.
1979
+ */
1980
+ FileApi.prototype.makeDirectory = function(fullPath)
1981
+ {
1982
+ this._javaApi.forceMkdir(new java.io.File(fullPath));
1983
+ }
1984
+
1985
+ /**
1986
+ * Reads the contents of a file into an array of bytes. The file is always closed.
1987
+ *
1988
+ * @param {string} filePath The path of the file to read.
1989
+ *
1990
+ * @return {byte[]} The file contents as a Java byte array (byte[]). The content of the array can be accessed using the methods of native JavaScript arrays.
1991
+ *
1992
+ * @throws An <em>IOException</em> Java exception in case of an I/O error.
1993
+ */
1994
+ FileApi.prototype.readBinaryFile = function(filePath)
1995
+ {
1996
+ return this._javaApi.readFileToByteArray(new java.io.File(filePath));
1997
+ }
1998
+
1999
+ /**
2000
+ * Writes a Java byte array (byte[]) to a file, creating the file if it does not exist.
2001
+ *
2002
+ * @param {string} filePath The path of the file to write.
2003
+ * @param {byte[]} data The Java byte array to write to the file.
2004
+ *
2005
+ * @throws An <em>IOException</em> Java exception in case of an I/O error.
2006
+ */
2007
+ FileApi.prototype.writeBinaryFile = function(filePath, data)
2008
+ {
2009
+ this._javaApi.writeByteArrayToFile(new java.io.File(filePath), data);
2010
+ }
2011
+
2012
+ /**
2013
+ * Tests whether the file denoted by the passed path is a normal file.
2014
+ *
2015
+ * @param {string} filePath The path of the file to check.
2016
+ *
2017
+ * @return {boolean} <code>true</code> if and only if the file denoted by the passed path exists and is a normal file; <code>false</code> otherwise.
2018
+ */
2019
+ FileApi.prototype.isFile = function(filePath)
2020
+ {
2021
+ return (new java.io.File(filePath).isFile());
2022
+ }
2023
+
2024
+ /**
2025
+ * Tests whether the file denoted by the passed path is a directory.
2026
+ *
2027
+ * @param {string} filePath The path of the file to check.
2028
+ *
2029
+ * @return {boolean} <code>true</code> if and only if the file denoted by the passed path exists and is directory; <code>false</code> otherwise.
2030
+ */
2031
+ FileApi.prototype.isDirectory = function(filePath)
2032
+ {
2033
+ return (new java.io.File(filePath).isDirectory());
2034
+ }
2035
+
2036
+ /**
2037
+ * Returns the length of the file denoted by the passed path.
2038
+ *
2039
+ * @param {string} filePath The path of the file to get the size of.
2040
+ *
2041
+ * @return {number} The length, in bytes, of the file denoted by the passed path.
2042
+ */
2043
+ FileApi.prototype.getFileSize = function(filePath)
2044
+ {
2045
+ return (new java.io.File(filePath).length());
2046
+ }