Completed
Pull Request — master (#1)
by
unknown
02:17
created

ts3admin::getDebugLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?PHP
2
/**
3
 *                         ts3admin.class.php
4
 *                         ------------------                    
5
 *   begin                : 18. December 2009
6
 *   copyright            : (C) 2009-2016 Par0noid Solutions
7
 *   email                : [email protected]
8
 *   version              : 1.0.0.1
9
 *   last modified        : 29. September 2016
10
 *
11
 *
12
 *  This file is a powerful library for querying TeamSpeak3 servers.
13
 *  
14
 *  This program is free software: you can redistribute it and/or modify
15
 *  it under the terms of the GNU General Public License as published by
16
 *  the Free Software Foundation, either version 3 of the License, or
17
 *  (at your option) any later version.
18
 *  
19
 *  This program is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *  
24
 *  You should have received a copy of the GNU General Public License
25
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 */
27
28
/** 
29
 * The ts3admin.class.php is a powerful library that offers functions to communicate with Teamspeak 3 Servers from your website!
30
 * 
31
 * You can do everything, your creativity knows no bounds!
32
 * That library is faster than all other librarys because its optimized to find the shortest way to your information.
33
 * No unneeded PHP 5 OOP Stuff, just the basics!
34
 * There are a lot of professional developers and some big companys using my library.
35
 * The best thing is that you can use it for free under the terms of the GNU General Public License v3.
36
 * Take a look on the project website where you can find code examples, a manual and some other stuff.
37
 * 
38
 * @author      Par0noid Solutions <[email protected]>
39
 * @version     1.0.0.1
40
 * @copyright   Copyright (c) 2009-2016, Stefan Z.
41
 * @package		ts3admin
42
 * @link        http://ts3admin.info
43
 *
44
 */
45
class ts3admin {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
46
47
//*******************************************************************************************	
48
//****************************************** Vars *******************************************
49
//*******************************************************************************************
50
51
/**
52
  * runtime is an private handle and configuration storage
53
  *
54
  * @author     Par0noid Solutions
55
  */
56
	private $runtime = array('socket' => '', 'selected' => false, 'host' => '', 'queryport' => '10011', 'timeout' => 2, 'debug' => array(), 'fileSocket' => '');
57
58
59
//*******************************************************************************************	
60
//************************************ Public Functions *************************************
61
//******************************************************************************************
62
63
/**
64
  * banAddByIp
65
  *
66
  * Adds a new ban rule on the selected virtual server.
67
  *
68
  *	<b>Output:</b>
69
  * <pre>
70
  * Array
71
  * {
72
  *  [banid] => 109
73
  * }
74
  * </pre>
75
  *
76
  * @author     Par0noid Solutions
77
  * @param		string	$ip			clientIp
78
  * @param		integer	$time		bantime in seconds (0=unlimited/default)  [optional]
79
  * @param		string	$banreason	Banreason [optional]
80
  * @return     array banId
81
  */
82 View Code Duplication
	function banAddByIp($ip, $time = 0, $banreason = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
84
		
85
		if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
86
87
		return $this->getData('array', 'banadd ip='.$ip.' time='.$time.$msg);
88
	}
89
90
/**
91
  * banAddByUid
92
  *
93
  *	Adds a new ban rule on the selected virtual server.
94
  *
95
  * <b>Output:</b>
96
  * <pre>
97
  * Array
98
  * {
99
  *  [banid] => 110
100
  * }
101
  * </pre>
102
  *
103
  * @author     Par0noid Solutions
104
  * @param		string	$uid		clientUniqueId
105
  * @param		integer	$time		bantime in seconds (0=unlimited/default)  [optional]
106
  * @param		string	$banreason	Banreason [optional]
107
  * @return     array banId
108
  */
109 View Code Duplication
	function banAddByUid($uid, $time = 0, $banreason = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
111
		
112
		if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
113
		
114
		return $this->getData('array', 'banadd uid='.$uid.' time='.$time.$msg);
115
	}
116
117
/**
118
  * banAddByName
119
  *
120
  *	Adds a new ban rule on the selected virtual server.
121
  *
122
  * <b>Output:</b>
123
  * <pre>
124
  * Array
125
  * {
126
  *  [banid] => 111
127
  * }
128
  * </pre>
129
  *
130
  * @author     Par0noid Solutions
131
  * @param		string	$name		clientName
132
  * @param		integer	$time		bantime in seconds (0=unlimited/default)  [optional]
133
  * @param		string	$banreason	Banreason [optional]
134
  * @return     array banId
135
  */
136 View Code Duplication
	function banAddByName($name, $time = 0, $banreason = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
138
		
139
		if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
140
										
141
		return $this->getData('array', 'banadd name='.$this->escapeText($name).' time='.$time.$msg);
142
	}
143
144
/**
145
  * banClient
146
  * 
147
  * Bans the client specified with ID clid from the server. Please note that this will create two separate ban rules for the targeted clients IP address and his unique identifier.
148
  *
149
  * <b>Output:</b>
150
  * <pre>
151
  * Array
152
  * {
153
  *  [1] => 129
154
  *  [2] => 130
155
  * }
156
  * </pre>
157
  *
158
  * @author     Par0noid Solutions
159
  * @param		integer $clid		clientId
160
  * @param		integer $time		bantime in seconds (0=unlimited/default)  [optional]
161
  * @param		string	$banreason	Banreason [optional]
162
  * @return     array banIds
163
  */
164
	function banClient($clid, $time = 0, $banreason = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
165
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
166
		
167
		if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = ''; }
168
		
169
		$result = $this->getData('plain', 'banclient clid='.$clid.' time='.$time.$msg);
170
		
171
		if($result['success']) {
172
			return $this->generateOutput(true, $result['errors'], $this->splitBanIds($result['data']));
173
		}else{
174
			return $this->generateOutput(false, $result['errors'], false);
175
		}
176
	}
177
178
/**
179
  * banDelete
180
  * 
181
  * Deletes the ban rule with ID banid from the server.
182
  *
183
  * @author     Par0noid Solutions
184
  * @param		integer $banID	banID
185
  * @return     boolean success
186
  */
187
	function banDelete($banID) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
188
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
189
		return $this->getData('boolean', 'bandel banid='.$banID);
190
	}
191
192
/**
193
  * banDeleteAll
194
  * 
195
  * Deletes all active ban rules from the server.
196
  *
197
  * @author     Par0noid Solutions
198
  * @return     boolean success
199
  */
200
	function banDeleteAll() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
201
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
202
		return $this->getData('boolean', 'bandelall');
203
	}
204
205
/**
206
  * banList
207
  * 
208
  * Displays a list of active bans on the selected virtual server.
209
  * 
210
  * <b>Output:</b>
211
  * <pre>
212
  * Array
213
  * {
214
  *  [banid] => 131
215
  *  [ip] => 1.2.3.4
216
  *  [name] => eugen
217
  *  [uid] => IYAntAcZHgVC7s3n3DNWmuJB/aM=
218
  *  [created] => 1286660391
219
  *  [duration] => 0
220
  *  [invokername] => Par0noid
221
  *  [invokercldbid] => 2086
222
  *  [invokeruid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
223
  *  [reason] => insult
224
  *  [enforcements] => 0
225
  * }
226
  * </pre>
227
  *
228
  * @author     Par0noid Solutions
229
  * @return     array banlist
230
  */
231
	function banList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
232
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
233
		return $this->getData('multi', 'banlist');
234
	}
235
236
/**
237
  * bindingList
238
  * 
239
  * Displays a list of IP addresses used by the server instance on multi-homed machines.
240
  *
241
  * <b>Output:</b>
242
  * <pre>
243
  * Array
244
  * {
245
  *  [ip] => 0.0.0.0
246
  * }
247
  * </pre>
248
  *
249
  * @author     Par0noid Solutions
250
  * @return     array bindingList
251
  */
252
	function bindingList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
253
		return $this->getData('multi', 'bindinglist');
254
	}
255
256
/**
257
  * channelAddPerm
258
  * 
259
  * Adds a set of specified permissions to a channel. Multiple permissions can be added by providing the two parameters of each permission. A permission can be specified by permid or permsid.
260
  * 
261
  * <b>Input-Array like this:</b>
262
  * <pre>
263
  * $permissions = array();
264
  * $permissions['permissionID'] = 'permissionValue';
265
  * //or you could use Permission Name
266
  * $permissions['permissionName'] = 'permissionValue';
267
  * </pre>
268
  *
269
  * @author     Par0noid Solutions
270
  * @param		integer	$cid			channelId
271
  * @param		array	$permissions	permissions
272
  * @return     boolean success
273
  */
274 View Code Duplication
	function channelAddPerm($cid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
275
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
276
		
277
		if(count($permissions) > 0) {
278
			//Permissions given
279
			
280
			//Errorcollector
281
			$errors = array();
282
			
283
			//Split Permissions to prevent query from overload
284
			$permissions = array_chunk($permissions, 50, true);
285
			
286
			//Action for each splitted part of permission
287
			foreach($permissions as $permission_part)
288
			{
289
				//Create command_string for each command that we could use implode later
290
				$command_string = array();
291
				
292
				foreach($permission_part as $key => $value)
293
				{
294
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
295
				}
296
				
297
				$result = $this->getData('boolean', 'channeladdperm cid='.$cid.' '.implode('|', $command_string));
298
				
299
				if(!$result['success'])
300
				{
301
					foreach($result['errors'] as $error)
302
					{
303
						$errors[] = $error;
304
					}
305
				}
306
			}
307
			
308
			if(count($errors) == 0)
309
			{
310
				return $this->generateOutput(true, array(), true);
311
			}else{
312
				return $this->generateOutput(false, $errors, false);
313
			}
314
			
315
		}else{
316
			// No permissions given
317
			$this->addDebugLog('no permissions given');
318
			return $this->generateOutput(false, array('Error: no permissions given'), false);
319
		}
320
	}
321
322
/**
323
  * channelClientAddPerm
324
  * 
325
  * Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by providing the three parameters of each permission. A permission can be specified by permid or permsid.
326
  * 
327
  * <b>Input-Array like this:</b>
328
  * <pre>
329
  * $permissions = array();
330
  * $permissions['permissionID'] = 'permissionValue';
331
  * //or you could use Permission Name
332
  * $permissions['permissionName'] = 'permissionValue';
333
  * </pre>
334
  *
335
  * @author     Par0noid Solutions
336
  * @param		integer		$cid			channelID
337
  * @param		integer		$cldbid			clientDBID
338
  * @param		array		$permissions	permissions
339
  * @return     boolean success
340
  */
341 View Code Duplication
	function channelClientAddPerm($cid, $cldbid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
342
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
343
		
344
		if(count($permissions) > 0) {
345
			//Permissions given
346
				
347
			//Errorcollector
348
			$errors = array();
349
				
350
			//Split Permissions to prevent query from overload
351
			$permissions = array_chunk($permissions, 50, true);
352
				
353
			//Action for each splitted part of permission
354
			foreach($permissions as $permission_part)
355
			{
356
				//Create command_string for each command that we could use implode later
357
				$command_string = array();
358
		
359
				foreach($permission_part as $key => $value)
360
				{
361
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
362
				}
363
		
364
				$result = $this->getData('boolean', 'channelclientaddperm cid='.$cid.' cldbid='.$cldbid.' '.implode('|', $command_string));
365
		
366
				if(!$result['success'])
367
				{
368
					foreach($result['errors'] as $error)
369
					{
370
						$errors[] = $error;
371
					}
372
				}
373
			}
374
				
375
			if(count($errors) == 0)
376
			{
377
				return $this->generateOutput(true, array(), true);
378
			}else{
379
				return $this->generateOutput(false, $errors, false);
380
			}
381
				
382
		}else{
383
			// No permissions given
384
			$this->addDebugLog('no permissions given');
385
			return $this->generateOutput(false, array('Error: no permissions given'), false);
386
		}
387
	}
388
389
/**
390
  * channelClientDelPerm
391
  * 
392
  * Removes a set of specified permissions from a client in a specific channel. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
393
  *
394
  * <b>Input-Array like this:</b>
395
  * <pre>
396
  * $permissions = array();
397
  * $permissions[] = 'permissionID';
398
  * $permissions[] = 'permissionName';
399
  * //or
400
  * $permissions = array('permissionID', 'permissionName', 'permissionID');
401
  * </pre>
402
  *
403
  * @author     Par0noid Solutions
404
  * @param		integer		$cid				channelID
405
  * @param		integer		$cldbid				clientDBID
406
  * @param		array		$permissions		permissions
407
  * @return     boolean success
408
  */
409
	function channelClientDelPerm($cid, $cldbid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
410
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
411
		$permissionArray = array();
412
		
413
		if(count($permissions) > 0) {
414
			foreach($permissions AS $value) {
415
				$permissionArray[] = is_numeric($value) ? 'permid='.$value : 'permsid='.$value;
416
			}
417
			return $this->getData('boolean', 'channelclientdelperm cid='.$cid.' cldbid='.$cldbid.' '.implode('|', $permissionArray));
418
		}else{
419
			$this->addDebugLog('no permissions given');
420
			return $this->generateOutput(false, array('Error: no permissions given'), false);
421
		}
422
	}
423
424
/**
425
  * channelClientPermList
426
  * 
427
  * Displays a list of permissions defined for a client in a specific channel.
428
  *
429
  * <b>Output:</b>
430
  * <pre>
431
  * Array
432
  * {
433
  *  [cid] => 250 (only in first result)
434
  *  [cldbid] => 2086 (only in first result)
435
  *  [permid] => 12876 (if permsid = false)
436
  *  [permsid] => b_client_info_view (if permsid = true)
437
  *  [permvalue] => 1
438
  *  [permnegated] => 0
439
  *  [permskip] => 0
440
  * }
441
  * </pre>
442
  *
443
  * @author     Par0noid Solutions
444
  * @param		integer		$cid		channelID
445
  * @param		integer		$cldbid		clientDBID
446
  * @param		boolean		$permsid	displays permissionName instead of permissionID
447
  * @return     array	channelclientpermlist
448
  */
449
	function channelClientPermList($cid, $cldbid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
450
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
451
		return $this->getData('multi', 'channelclientpermlist cid='.$cid.' cldbid='.$cldbid.($permsid ? ' -permsid' : ''));
452
	}
453
454
/**
455
  * channelCreate
456
  * 
457
  * Creates a new channel using the given properties and displays its ID. Note that this command accepts multiple properties which means that you're able to specifiy all settings of the new channel at once.
458
  * 
459
  * <b style="color:red">Hint:</b> don't forget to set channel_flag_semi_permanent = 1 or channel_flag_permanent = 1
460
  * 
461
  * <b style="color:red">Hint:</b> you'll get an error if you want to create a channel without channel_name
462
  * 
463
  * <b>Input-Array like this:</b>
464
  * <pre>
465
  * $data = array();
466
  * 
467
  * $data['setting'] = 'value';
468
  * $data['setting'] = 'value';
469
  * </pre>
470
  * 
471
  * <b>Output:</b>
472
  * <pre>
473
  * Array
474
  * {
475
  *  [cid] => 257
476
  * }
477
  * </pre>
478
  *
479
  * @author     Par0noid Solutions
480
  * @param		array $data properties
481
  * @return     array channelInfo
482
  */
483 View Code Duplication
	function channelCreate($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
484
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
485
		
486
		$propertiesString = '';
487
		
488
		foreach($data as $key => $value) {
489
			$propertiesString .= ' '.$key.'='.$this->escapeText($value);
490
		}
491
		
492
		return $this->getData('array', 'channelcreate '.$propertiesString);
493
	}
494
495
/**
496
  * channelDelete
497
  * 
498
  * Deletes an existing channel by ID. If force is set to 1, the channel will be deleted even if there are clients within. The clients will be kicked to the default channel with an appropriate reason message.
499
  *
500
  * @author     Par0noid Solutions
501
  * @param		integer $cid channelID
502
  * @param		integer $force {1|0} (default: 1)
503
  * @return     boolean success
504
  */
505
	function channelDelete($cid, $force = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
506
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
507
		return $this->getData('boolean', 'channeldelete cid='.$cid.' force='.$force);
508
	}
509
510
/**
511
  * channelDelPerm
512
  * 
513
  * Removes a set of specified permissions from a channel. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
514
  *
515
  * <b>Input-Array like this:</b>
516
  * <pre>
517
  * $permissions = array();
518
  * $permissions[] = 'permissionID';
519
  * //or you could use
520
  * $permissions[] = 'permissionName';
521
  * </pre>
522
  *
523
  * @author     Par0noid Solutions
524
  * @param		integer		$cid				channelID
525
  * @param		array		$permissions		permissions
526
  * @return     boolean	success
527
  */
528
	function channelDelPerm($cid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
529
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
530
		$permissionArray = array();
531
		
532
		if(count($permissions) > 0) {
533
			foreach($permissions AS $value) {
534
				$permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
535
			}
536
			return $this->getData('boolean', 'channeldelperm cid='.$cid.' '.implode('|', $permissionArray));
537
		}else{
538
			$this->addDebugLog('no permissions given');
539
			return $this->generateOutput(false, array('Error: no permissions given'), false);
540
		}
541
	}
542
543
/**
544
  * channelEdit
545
  * 
546
  * Changes a channels configuration using given properties. Note that this command accepts multiple properties which means that you're able to change all settings of the channel specified with cid at once.
547
  *
548
  * <b>Input-Array like this:</b>
549
	<pre>
550
	$data = array();
551
		
552
	$data['setting'] = 'value';
553
	$data['setting'] = 'value';
554
	</pre>
555
  *
556
  * @author     Par0noid Solutions
557
  * @param		integer	$cid	$channelID
558
  * @param		array	$data	edited settings
559
  * @return     boolean success
560
  */
561 View Code Duplication
	function channelEdit($cid, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
562
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
563
		
564
		$settingsString = '';
565
		
566
		foreach($data as $key => $value) {
567
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
568
		}
569
570
		return $this->getData('boolean', 'channeledit cid='.$cid.$settingsString);
571
	}
572
573
/**
574
  * channelFind
575
  * 
576
  * displays a list of channels matching a given name pattern.
577
  *
578
  * <b>Output:</b>
579
  * <pre>
580
  * Array
581
  * {
582
  *  [cid] => 2
583
  *  [channel_name] => Lobby
584
  * }
585
  * </pre>
586
  *
587
  * @author     Par0noid Solutions
588
  * @param		string	$pattern	channelName
589
  * @return     array channelList 
590
  */
591
	function channelFind($pattern) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
592
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
593
		return $this->getData('multi', 'channelfind pattern='.$this->escapeText($pattern));
594
	}
595
596
/**
597
  * channelGroupAdd
598
  * 
599
  * Creates a new channel group using a given name and displays its ID. The optional type parameter can be used to create ServerQuery groups and template groups.
600
  *
601
  * <b>groupDbTypes:</b>
602
  *	<ol start="0">
603
  *		<li>template group (used for new virtual servers)</li>
604
  *		<li>regular group (used for regular clients)</li>
605
  *		<li>global query group (used for ServerQuery clients)</li>
606
  *	</ol>
607
  *
608
  * <b>Output:</b>
609
  * <pre>
610
  * Array
611
  * {
612
  *  [cgid] => 86
613
  * }
614
  * </pre>
615
  *
616
  * @author     Par0noid Solutions
617
  * @param		integer	$name	groupName
618
  * @param		integer	$type   groupDbType [optional] (default: 1)
619
  * @return     boolean success
620
  */
621
	function channelGroupAdd($name, $type = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
622
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
623
		return $this->getData('array', 'channelgroupadd name='.$this->escapeText($name).' type='.$type);
624
	}
625
626
/**
627
  * channelGroupAddPerm
628
  * 
629
  * Adds a set of specified permissions to a channel group. Multiple permissions can be added by providing the two parameters of each permission. A permission can be specified by permid or permsid.
630
  *
631
  * <b>Input-Array like this:</b>
632
  * <pre>
633
  * $permissions = array();
634
  * $permissions['permissionID'] = 'permissionValue';
635
  * //or you could use:
636
  * $permissions['permissionName'] = 'permissionValue';
637
  * </pre>
638
  *
639
  * @author     Par0noid Solutions
640
  * @param		integer		$cgid			channelGroupID
641
  * @param		array		$permissions	permissions
642
  * @return     boolean success
643
  */
644 View Code Duplication
	function channelGroupAddPerm($cgid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
645
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
646
		
647
		if(count($permissions) > 0) {
648
			//Permissions given
649
		
650
			//Errorcollector
651
			$errors = array();
652
		
653
			//Split Permissions to prevent query from overload
654
			$permissions = array_chunk($permissions, 50, true);
655
		
656
			//Action for each splitted part of permission
657
			foreach($permissions as $permission_part)
658
			{
659
				//Create command_string for each command that we could use implode later
660
				$command_string = array();
661
		
662
				foreach($permission_part as $key => $value)
663
				{
664
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
665
				}
666
		
667
				$result = $this->getData('boolean', 'channelgroupaddperm cgid='.$cgid.' '.implode('|', $command_string));
668
		
669
				if(!$result['success'])
670
				{
671
					foreach($result['errors'] as $error)
672
					{
673
						$errors[] = $error;
674
					}
675
				}
676
			}
677
		
678
			if(count($errors) == 0) {
679
				return $this->generateOutput(true, array(), true);
680
			}else{
681
				return $this->generateOutput(false, $errors, false);
682
			}
683
		
684
		}else{
685
			// No permissions given
686
			$this->addDebugLog('no permissions given');
687
			return $this->generateOutput(false, array('Error: no permissions given'), false);
688
		}
689
	}
690
691
/**
692
  * channelGroupClientList
693
  * 
694
  * Displays all the client and/or channel IDs currently assigned to channel groups. All three parameters are optional so you're free to choose the most suitable combination for your requirement
695
  *
696
  * <b>Output:</b>
697
  * <pre>
698
  * Array
699
  * {
700
  *  [cid] => 2
701
  *  [cldbid] => 9
702
  *  [cgid] => 9
703
  * }
704
  * </pre>
705
  *
706
  * @author     Par0noid Solutions
707
  * @param		integer $cid		channelID [optional]
708
  * @param		integer $cldbid		clientDBID [optional]
709
  * @param		integer $cgid		channelGroupID [optional]
710
  * @return     array channelGroupClientList
711
  */
712
	function channelGroupClientList($cid = NULL, $cldbid = NULL, $cgid = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
713
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
714
		
715
		return $this->getData('multi', 'channelgroupclientlist'.(!empty($cid) ? ' cid='.$cid : '').(!empty($cldbid) ? ' cldbid='.$cldbid : '').(!empty($cgid) ? ' cgid='.$cgid : ''));
716
	}
717
718
/**
719
  * channelGroupCopy
720
  * 
721
  * Creates a copy of the channel group specified with scgid. If tcgid is set to 0, the server will create a new group. To overwrite an existing group, simply set tcgid to the ID of a designated target group. If a target group is set, the name parameter will be ignored. The type parameter can be used to create ServerQuery groups and template groups.
722
  *
723
  * <b>groupDbTypes:</b>
724
  *	<ol start="0">
725
  *		<li>template group (used for new virtual servers)</li>
726
  *		<li>regular group (used for regular clients)</li>
727
  *		<li>global query group (used for ServerQuery clients)</li>
728
  *	</ol>
729
  *
730
  * <b>Output:</b>
731
  * <pre>
732
  * Array
733
  * {
734
  *  [cgid] => 86
735
  * }
736
  * </pre>
737
  *
738
  * @author     Par0noid Solutions
739
  * @param		integer	$scgid	sourceChannelGroupID
740
  * @param		integer	$tcgid	targetChannelGroupID 
741
  * @param		integer $name	groupName
742
  * @param		integer	$type	groupDbType
743
  * @return     array groupId
744
  */
745
	function channelGroupCopy($scgid, $tcgid, $name, $type = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
746
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
747
		return $this->getData('array', 'channelgroupcopy scgid='.$scgid.' tcgid='.$tcgid.' name='.$this->escapeText($name).' type='.$type);
748
	}
749
750
/**
751
  * channelGroupDelete
752
  * 
753
  * Deletes a channel group by ID. If force is set to 1, the channel group will be deleted even if there are clients within.
754
  *
755
  * @author     Par0noid Solutions
756
  * @param		integer $cgid	channelGroupID
757
  * @param		integer $force	forces deleting channelGroup (default: 1)
758
  * @return     boolean success
759
  */
760
	function channelGroupDelete($cgid, $force = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
761
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
762
		return $this->getData('boolean', 'channelgroupdel cgid='.$cgid.' force='.$force);
763
	}
764
765
/**
766
  * channelGroupDelPerm
767
  * 
768
  * Removes a set of specified permissions from the channel group. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
769
  *
770
  * <b>Input-Array like this:</b>
771
  * <pre>
772
  * $permissions = array();
773
  * $permissions[] = 'permissionID';
774
  * $permissions[] = 'permissionName';
775
  * </pre>
776
  *
777
  * @author     Par0noid Solutions
778
  * @param		integer		$cgid				channelGroupID
779
  * @param		array		$permissions		permissions
780
  * @return     boolean success
781
  */
782
	function channelGroupDelPerm($cgid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
783
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
784
		$permissionArray = array();
785
		
786
		if(count($permissions) > 0) {
787
			foreach($permissions AS $value) {
788
				$permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
789
			}
790
			return $this->getData('boolean', 'channelgroupdelperm cgid='.$cgid.' '.implode('|', $permissionArray));
791
		}else{
792
			$this->addDebugLog('no permissions given');
793
			return $this->generateOutput(false, array('Error: no permissions given'), false);
794
		}
795
	}
796
797
/**
798
  * channelGroupList
799
  * 
800
  * Displays a list of channel groups available on the selected virtual server.
801
  * 
802
  * <b>Output:</b>
803
  * <pre>
804
  * Array
805
  * {
806
  *  [cgid] => 3
807
  *  [name] => Testname
808
  *  [type] => 0
809
  *  [iconid] => 100
810
  *  [savedb] => 1
811
  *  [sortid] => 0
812
  *  [namemode] => 0
813
  *  [n_modifyp] => 75
814
  *  [n_member_addp] => 50
815
  *  [n_member_removep] => 50
816
  * }
817
  * </pre>
818
  *
819
  * @author     Par0noid Solutions
820
  * @return     array channelGroupList
821
  */
822
	function channelGroupList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
823
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
824
		
825
		return $this->getData('multi', 'channelgrouplist');
826
	}
827
828
/**
829
  * channelGroupPermList
830
  * 
831
  * Displays a list of permissions assigned to the channel group specified with cgid.
832
  * If the permsid option is specified, the output will contain the permission names instead of the internal IDs.
833
  * 
834
  * <b>Output:</b>
835
  * <pre>
836
  * Array
837
  * {
838
  *  [permid] => 8471 (displayed if permsid is false)
839
  *  [permsid] => i_channel_create_modify_with_codec_latency_factor_min (displayed if permsid is true)
840
  *  [permvalue] => 1
841
  *  [permnegated] => 0
842
  *  [permskip] => 0
843
  * }
844
  * </pre>
845
  *
846
  * @author     Par0noid Solutions
847
  * @param		integer		$cgid		channelGroupID
848
  * @param		boolean		$permsid	permsid
849
  * @return		array	channelGroupPermlist
850
  */
851
  	function channelGroupPermList($cgid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
852
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
853
		return $this->getData('multi', 'channelgrouppermlist cgid='.$cgid.($permsid ? ' -permsid' : ''));
854
	}
855
856
/**
857
  * channelGroupRename
858
  * 
859
  * Changes the name of a specified channel group.
860
  *
861
  * @author     Par0noid Solutions
862
  * @param		integer $cgid groupID
863
  * @param		integer $name groupName
864
  * @return     boolean success
865
  */
866
	function channelGroupRename($cgid, $name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
867
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
868
		return $this->getData('boolean', 'channelgrouprename cgid='.$cgid.' name='.$this->escapeText($name));
869
	}
870
871
/**
872
  * channelInfo
873
  *
874
  *	Displays detailed configuration information about a channel including ID, topic, description, etc.
875
876
  * <b>Output:</b>
877
  * <pre>
878
  * Array
879
  * {
880
  *  [pid] => 0
881
  *  [channel_name] => Test
882
  *  [channel_topic] => 
883
  *  [channel_description] => 
884
  *  [channel_password] => cc97Pm4oOYq0J9fXDAgiWv/qScQ=
885
  *  [channel_codec] => 2
886
  *  [channel_codec_quality] => 7
887
  *  [channel_maxclients] => -1
888
  *  [channel_maxfamilyclients] => -1
889
  *  [channel_order] => 1
890
  *  [channel_flag_permanent] => 1
891
  *  [channel_flag_semi_permanent] => 0
892
  *  [channel_flag_default] => 0
893
  *  [channel_flag_password] => 0
894
  *  [channel_codec_latency_factor] => 1
895
  *  [channel_codec_is_unencrypted] => 1
896
  *	 [channel_security_salt] => 
897
  *  [channel_delete_delay] => 0
898
  *  [channel_flag_maxclients_unlimited] => 1
899
  *  [channel_flag_maxfamilyclients_unlimited] => 0
900
  *  [channel_flag_maxfamilyclients_inherited] => 1
901
  *  [channel_filepath] => files\\virtualserver_1\\channel_2
902
  *  [channel_needed_talk_power] => 0
903
  *  [channel_forced_silence] => 0
904
  *  [channel_name_phonetic] => 
905
  *  [channel_icon_id] => 0
906
  *	 [channel_flag_private] => 0
907
  *  [seconds_empty] => 61 (If it's a temporary channel with a channel delete delay)
908
  * }
909
  * </pre>
910
  *
911
  * @author     Par0noid Solutions
912
  * @param		integer $cid channelID
913
  * @return     array channelInfo
914
  */
915
	function channelInfo($cid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
916
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
917
		return $this->getData('array', 'channelinfo cid='.$cid);
918
	}
919
920
/**
921
  * channelList
922
  * 
923
  * Displays a list of channels created on a virtual server including their ID, order, name, etc. The output can be modified using several command options.
924
  *
925
  * <b>Possible parameters:</b> [-topic] [-flags] [-voice] [-limits] [-icon] [-seconds_empty]
926
  *
927
  * <b>Output: (without parameters)</b>
928
  * <pre>
929
  * Array
930
  * {
931
  *  [cid] => 2
932
  *  [pid] => 0
933
  *  [channel_order] => 1
934
  *  [channel_name] => Test
935
  *  [total_clients] => 0
936
  *  [channel_needed_subscribe_power] => 0
937
  * }
938
  * </pre>
939
  * <b>Output: (from parameters)</b>
940
  * <pre>
941
  * Array
942
  * {
943
  *  [-topic] => [channel_topic] => Default Channel has no topic
944
  *  [-flags] => [channel_flag_default] => 1
945
  *  [-flags] => [channel_flag_password] => 0
946
  *  [-flags] => [channel_flag_permanent] => 1
947
  *  [-flags] => [channel_flag_semi_permanent] => 0
948
  *  [-voice] => [channel_codec] => 2
949
  *  [-voice] => [channel_codec_quality] => 7
950
  *  [-voice] => [channel_needed_talk_power] => 0
951
  *  [-limits] => [total_clients_family] => 1
952
  *  [-limits] => [channel_maxclients] => -1
953
  *  [-limits] => [channel_maxfamilyclients] => -1
954
  *  [-icon] => [channel_icon_id] => 0
955
  *  [-seconds_empty] => [seconds_empty] => -1
956
  * }
957
  * </pre>
958
  * <b>Usage:</b>
959
  * <pre>
960
  * $ts3->channelList(); //No parameters
961
  * $ts3->channelList("-flags"); //Single parameter
962
  * $ts3->channelList("-topic -flags -voice -limits -icon"); //Multiple parameters / all
963
  * </pre>
964
  *
965
  * @author     Par0noid Solutions
966
  * @param		string		$params		additional parameters [optional]
967
  * @return		array	channelList
968
  */
969
	function channelList($params = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
970
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
971
		if(!empty($params)) { $params = ' '.$params; }
972
		
973
		return $this->getData('multi', 'channellist'.$params);
974
	}
975
976
/**
977
  * channelMove
978
  * 
979
  * Moves a channel to a new parent channel with the ID cpid. If order is specified, the channel will be sorted right under the channel with the specified ID. If order is set to 0, the channel will be sorted right below the new parent.
980
  *
981
  * @author     Par0noid Solutions
982
  * @param		integer $cid	channelID
983
  * @param		integer $cpid	channelParentID
984
  * @param		integer $order	channelSortOrder
985
  * @return     boolean success
986
  */
987
	function channelMove($cid, $cpid, $order = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
988
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
989
		return $this->getData('boolean', 'channelmove cid='.$cid.' cpid='.$cpid.($order != null ? ' order='.$order : ''));
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $order of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
990
	}
991
992
/**
993
  * channelPermList
994
  * 
995
  * Displays a list of permissions defined for a channel.
996
  *
997
  * <b>Output:</b>
998
  * <pre>
999
  * Array
1000
  * {
1001
  *  [cid] => 2 (only in first result)
1002
  *  [permid] => 8471 (if permsid = false)
1003
  *  [permsid] => i_channel_needed_delete_power (if permsid = true)
1004
  *  [permvalue] => 1
1005
  *  [permnegated] => 0
1006
  *  [permskip] => 0
1007
  * }
1008
  * </pre>
1009
  *
1010
  * @author     Par0noid Solutions
1011
  * @param		integer		$cid		channelID
1012
  * @param		boolean		$permsid	displays permissionName instead of permissionID [optional]
1013
  * @return     array channelpermlist
1014
  */
1015
	function channelPermList($cid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1016
		if(!$this->runtime['selected']) { return $this->checkSelected(); }	
1017
		return $this->getData('multi', 'channelpermlist cid='.$cid.($permsid ? ' -permsid' : ''));
1018
	}
1019
1020
/**
1021
  * clientAddPerm
1022
  * 
1023
  * Adds a set of specified permissions to a client. Multiple permissions can be added by providing the three parameters of each permission. A permission can be specified by permid or permsid.
1024
  *
1025
  * <b>Input-Array like this:</b>
1026
  * <pre>
1027
  * $permissions = array();
1028
  * $permissions['permissionID'] = array('permissionValue', 'permskip');
1029
  * //or you could use Permission Name
1030
  * $permissions['permissionName'] = array('permissionValue', 'permskip');
1031
  * </pre>
1032
  *
1033
  * @author     Par0noid Solutions
1034
  * @param		integer	$cldbid			clientDBID
1035
  * @param		array	$permissions	permissions
1036
  * @return     boolean success
1037
  */
1038
	function clientAddPerm($cldbid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1039
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1040
		
1041
		if(count($permissions) > 0) {
1042
			//Permissions given
1043
				
1044
			//Errorcollector
1045
			$errors = array();
1046
				
1047
			//Split Permissions to prevent query from overload
1048
			$permissions = array_chunk($permissions, 50, true);
1049
				
1050
			//Action for each splitted part of permission
1051
			foreach($permissions as $permission_part)
1052
			{
1053
				//Create command_string for each command that we could use implode later
1054
				$command_string = array();
1055
		
1056
				foreach($permission_part as $key => $value)
1057
				{
1058
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$this->escapeText($value[0]).' permskip='.$this->escapeText($value[1]);
1059
				}
1060
		
1061
				$result = $this->getData('boolean', 'clientaddperm cldbid='.$cldbid.' '.implode('|', $command_string));
1062
		
1063
				if(!$result['success'])
1064
				{
1065
					foreach($result['errors'] as $error)
1066
					{
1067
						$errors[] = $error;
1068
					}
1069
				}
1070
			}
1071
				
1072
			if(count($errors) == 0)
1073
			{
1074
				return $this->generateOutput(true, array(), true);
1075
			}else{
1076
				return $this->generateOutput(false, $errors, false);
1077
			}
1078
		}else{
1079
			// No permissions given
1080
			$this->addDebugLog('no permissions given');
1081
			return $this->generateOutput(false, array('Error: no permissions given'), false);
1082
		}
1083
	}
1084
1085
/**
1086
 * clientAvatar
1087
 *
1088
 * Will return the base64 encoded binary of the clients avatar
1089
 * 
1090
 * <pre>
1091
 * $result = $tsAdmin->clientAvatar($uid);
1092
 * You can display it like: echo '<img src="data:image/png;base64,'.$result["data"].'" />';
1093
 * </pre>
1094
 *
1095
 * @author  Par0noid Solutions
1096
 * @param  string  $uid  clientUID
1097
 * @return array  base64 image
1098
 */
1099
	function clientAvatar($uid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1100
	  if(!$this->runtime['selected']) { return $this->checkSelected(); }
1101
1102
	  if(empty($uid))
1103
	  {
1104
		return $this->generateOutput(false, array('Error: empty uid'), false);
1105
	  }
1106
1107
	  $newChars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p');
1108
	  $auid = '';
1109
1110
	  for ($i = 0; $i <= 19; $i++) {
1111
			  $char = ord(substr(base64_decode($uid), $i, 1));
1112
			  $auid .= $newChars[($char & 0xF0) >> 4];
1113
			  $auid .= $newChars[$char & 0x0F];
1114
	  }
1115
1116
	  $check = $this->ftgetfileinfo(0, '', '/avatar_'.$auid);
1117
1118
	  if(!$check["success"])
1119
	  {
1120
		return $this->generateOutput(false, array('Error: avatar does not exist'), false);
1121
	  }
1122
1123
	  $init = $this->ftInitDownload('/avatar_'.$auid, 0, '');
1124
1125
	  if(!$init["success"])
1126
	  {
1127
		return $this->generateOutput(false, array('Error: init failed'), false);
1128
	  }
1129
1130
	  $download = $this->ftDownloadFile($init);
1131
1132
	  if(is_array($download))
1133
	  {
1134
		return $download;
1135
	  }else{
1136
		return $this->generateOutput(true, false, base64_encode($download));
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1137
	  }
1138
1139
	}
1140
	
1141
/**
1142
  * clientDbDelete
1143
  * 
1144
  * Deletes a clients properties from the database.
1145
  *
1146
  * @author     Par0noid Solutions
1147
  * @param		integer $cldbid	clientDBID
1148
  * @return     boolean success
1149
  */
1150
	function clientDbDelete($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1151
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1152
		return $this->getData('boolean', 'clientdbdelete cldbid='.$cldbid);
1153
	}
1154
1155
/**
1156
  * clientDbEdit
1157
  * 
1158
  * Changes a clients settings using given properties.
1159
  *
1160
  * <b>Input-Array like this:</b>
1161
  * <pre>
1162
  * $data = array();
1163
  * 
1164
  * $data['property'] = 'value';
1165
  * $data['property'] = 'value';
1166
  * </pre>
1167
  *
1168
  * @author     Par0noid Solutions
1169
  * @param		integer		$cldbid		clientDBID
1170
  * @param		array		$data	 	clientProperties
1171
  * @return     boolean success
1172
  */
1173 View Code Duplication
	function clientDbEdit($cldbid, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1174
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1175
		
1176
		$settingsString = '';
1177
		
1178
		foreach($data as $key => $value) {
1179
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
1180
		}
1181
		
1182
		return $this->getData('boolean', 'clientdbedit cldbid='.$cldbid.$settingsString);
1183
	}
1184
1185
/**
1186
  * clientDbFind
1187
  * 
1188
  * Displays a list of client database IDs matching a given pattern. You can either search for a clients last known nickname or his unique identity by using the -uid option.
1189
  *
1190
  * <b>Output:</b>
1191
  * <pre>
1192
  * Array
1193
  * {
1194
  *  [cldbid] => 2
1195
  * }
1196
  *	</pre>
1197
  *
1198
  * @author     Par0noid Solutions
1199
  * @param		string	$pattern	clientName
1200
  * @param		boolean	$uid		set true to add -uid param [optional]
1201
  * @return     array clientList 
1202
  */
1203
	function clientDbFind($pattern, $uid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1204
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1205
		return $this->getData('multi', 'clientdbfind pattern='.$this->escapeText($pattern).($uid ? ' -uid' : ''));
1206
	}
1207
1208
/**
1209
  * clientDbInfo
1210
  *
1211
  * Displays detailed database information about a client including unique ID, creation date, etc.
1212
  *
1213
  * <b>Output:</b>
1214
  * <pre>
1215
  * Array
1216
  * {
1217
  *  [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1218
  *  [client_nickname] => par0noid
1219
  *  [client_database_id] => 2
1220
  *  [client_created] => 1361027850
1221
  *  [client_lastconnected] => 1361027850
1222
  *  [client_totalconnections] => 1
1223
  *  [client_flag_avatar] => 
1224
  *  [client_description] => 
1225
  *  [client_month_bytes_uploaded] => 0
1226
  *  [client_month_bytes_downloaded] => 0
1227
  *  [client_total_bytes_uploaded] => 0
1228
  *  [client_total_bytes_downloaded] => 0
1229
  *  [client_icon_id] => 0
1230
  *  [client_base64HashClientUID] => jneilbgomklpfnkjclkoggokfdmdlhnbbpmdpagh
1231
  *  [client_lastip] => 127.0.0.1
1232
  * }
1233
  * </pre>
1234
  *
1235
  * @author     Par0noid Solutions
1236
  * @param		integer		$cldbid		clientDBID
1237
  * @return     array	clientDbInfo
1238
  */
1239
	function clientDbInfo($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1240
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1241
		return $this->getData('array', 'clientdbinfo cldbid='.$cldbid);
1242
	}
1243
1244
/**
1245
  * clientDbList
1246
  * 
1247
  * Displays a list of client identities known by the server including their database ID, last nickname, etc.
1248
  *
1249
  * <b>Possible params:</b> [start={offset}] [duration={limit}] [-count]
1250
  *
1251
  * <b>Output:</b>
1252
  * <pre>
1253
  * Array
1254
  * {
1255
  *  [count] => 1 (if count parameter is set)
1256
  *  [cldbid] => 2
1257
  *  [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1258
  *  [client_nickname] => par0noid
1259
  *  [client_created] => 1361027850
1260
  *  [client_lastconnected] => 1361027850
1261
  *  [client_totalconnections] => 1
1262
  *  [client_description] => 
1263
  *  [client_lastip] => 127.0.0.1
1264
  * }
1265
  * </pre>
1266
  *
1267
  * @author     Par0noid Solutions
1268
  * @param		integer	$start		offset [optional] (Default: 0)
1269
  * @param		integer	$duration	limit [optional] (Default: -1)
1270
  * @param		boolean	$count		set true to add -count param [optional]
1271
  * @return     array clientdblist
1272
  */
1273
	function clientDbList($start = 0, $duration = -1, $count = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1274
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1275
		return $this->getData('multi', 'clientdblist start='.$start.' duration='.$duration.($count ? ' -count' : ''));
1276
	}
1277
1278
/**
1279
  * clientDelPerm
1280
  * 
1281
  * Removes a set of specified permissions from a client. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
1282
  *
1283
  * <b>Input-Array like this:</b>
1284
  * <pre>
1285
  * $permissions = array();
1286
  * $permissions['permissionID'] = 'permissionValue';
1287
  * //or you could use Permission Name
1288
  * $permissions['permissionName'] = 'permissionValue';
1289
  * </pre>
1290
  *
1291
  * @author     Par0noid Solutions
1292
  * @param		integer		$cldbid				clientDBID
1293
  * @param		array		$permissionIds		permissionIDs
1294
  * @return     boolean success
1295
  */
1296
	function clientDelPerm($cldbid, $permissionIds) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1297
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1298
		
1299
		$permissionArray = array();
1300
		
1301
		if(count($permissionIds) > 0) {
1302
			foreach($permissionIds AS $value) {
1303
				$permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
1304
			}
1305
			return $this->getData('boolean', 'clientdelperm cldbid='.$cldbid.' '.implode('|', $permissionArray));
1306
		}else{
1307
			$this->addDebugLog('no permissions given');
1308
			return $this->generateOutput(false, array('Error: no permissions given'), false);
1309
		}
1310
	}
1311
1312
/**
1313
  * clientEdit
1314
  * 
1315
  * Changes a clients settings using given properties.
1316
  *
1317
  * <b>Input-Array like this:</b>
1318
  * <pre>
1319
  * $data = array();
1320
  *	
1321
  * $data['property'] = 'value';
1322
  * $data['property'] = 'value';
1323
  * </pre>
1324
  *
1325
  * @author     Par0noid Solutions
1326
  * @param		integer	$clid 			clientID
1327
  * @param		array	$data			clientProperties
1328
  * @return     boolean success
1329
  */
1330 View Code Duplication
	function clientEdit($clid, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1331
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1332
		
1333
		$settingsString = '';
1334
		
1335
		foreach($data as $key => $value) {
1336
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
1337
		}
1338
		
1339
		return $this->getData('boolean', 'clientedit clid='.$clid.$settingsString);
1340
	}
1341
1342
/**
1343
  * clientFind
1344
  * 
1345
  * Displays a list of clients matching a given name pattern.
1346
  *
1347
  * <b>Output:</b>
1348
  * <pre>
1349
  * Array
1350
  * {
1351
  *  [clid] => 18
1352
  *  [client_nickname] => par0noid
1353
  * }
1354
  * </pre>
1355
  *
1356
  * @author     Par0noid Solutions
1357
  * @param		string	$pattern	clientName
1358
  * @return     array clienList
1359
  */
1360
	function clientFind($pattern) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1361
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1362
		return $this->getData('multi', 'clientfind pattern='.$this->escapeText($pattern));
1363
	}
1364
1365
/**
1366
  * clientGetDbIdFromUid
1367
  * 
1368
  * Displays the database ID matching the unique identifier specified by cluid.
1369
  *
1370
  *	<b>Output:</b>
1371
  * <pre>
1372
  * Array
1373
  * {
1374
  *  [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1375
  *  [cldbid] => 2
1376
  * }
1377
  * </pre>
1378
  *
1379
  * @author     Par0noid Solutions
1380
  * @param		string	$cluid	clientUID
1381
  * @return     array clientInfo
1382
  */
1383
	function clientGetDbIdFromUid($cluid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1384
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1385
		return $this->getData('array', 'clientgetdbidfromuid cluid='.$cluid);
1386
	}
1387
1388
/**
1389
  * clientGetIds
1390
  * 
1391
  * Displays all client IDs matching the unique identifier specified by cluid.
1392
  *
1393
  * <b>Output:</b>
1394
  * <pre>
1395
  * Array
1396
  * {
1397
  *  [cluid] => nUixbdf/XakrrmsdffO30R/D8Gc=
1398
  *  [clid] => 7
1399
  *  [name] => Par0noid
1400
  * }
1401
  * </pre>
1402
  *
1403
  * @author     Par0noid Solutions
1404
  * @param		string	$cluid	clientUID
1405
  * @return     array clientList 
1406
  */
1407
	function clientGetIds($cluid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1408
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1409
		return $this->getData('multi', 'clientgetids cluid='.$cluid);
1410
	}
1411
1412
/**
1413
  * clientGetNameFromDbid
1414
  * 
1415
  * Displays the unique identifier and nickname matching the database ID specified by cldbid.
1416
  *
1417
  *	<b>Output:</b>
1418
  * <pre>
1419
  * Array
1420
  * {
1421
  *  [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1422
  *  [cldbid] => 2
1423
  *  [name] => Par0noid
1424
  * }
1425
  * </pre>
1426
  *
1427
  * @author     Par0noid Solutions
1428
  * @param		integer	$cldbid	clientDBID
1429
  * @return     array clientInfo
1430
  */
1431
	function clientGetNameFromDbid($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1432
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1433
		return $this->getData('array', 'clientgetnamefromdbid cldbid='.$cldbid);
1434
	}
1435
	
1436
/**
1437
  * clientGetNameFromUid
1438
  * 
1439
  * Displays the database ID and nickname matching the unique identifier specified by cluid.
1440
  *
1441
  *	<b>Output:</b>
1442
  * <pre>
1443
  * Array
1444
  * {
1445
  *  [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1446
  *  [cldbid] => 2
1447
  *  [name] => Par0noid
1448
  * }
1449
  * </pre>
1450
  *
1451
  * @author     Par0noid Solutions
1452
  * @param		string	$cluid	clientUID
1453
  * @return     array clientInfo
1454
  */
1455
	function clientGetNameFromUid($cluid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1456
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1457
		return $this->getData('array', 'clientgetnamefromuid cluid='.$cluid);
1458
	}
1459
1460
/**
1461
  * clientInfo
1462
  * 
1463
  * Displays detailed configuration information about a client including unique ID, nickname, client version, etc.
1464
  *
1465
  * <b>Output:</b>
1466
  * <pre>
1467
  * Array
1468
  * {
1469
  *  [cid] => 2
1470
  *  [client_idle_time] => 4445369
1471
  *  [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1472
  *  [client_nickname] => par0noid
1473
  *  [client_version] => 3.0.9.2 [Build: 1351504843]
1474
  *  [client_platform] => Windows
1475
  *  [client_input_muted] => 1
1476
  *  [client_output_muted] => 1
1477
  *  [client_outputonly_muted] => 0
1478
  *  [client_input_hardware] => 1
1479
  *  [client_output_hardware] => 1
1480
  *  [client_default_channel] => 
1481
  *  [client_meta_data] => 
1482
  *  [client_is_recording] => 0
1483
  *  [client_version_sign] => ldWL49uDKC3N9uxdgWRMTOzUabc1nBqUiOa+Nal5HvdxJiN4fsTnmmPo5tvglN7WqoVoFfuuKuYq1LzodtEtCg==
1484
  *  [client_security_hash] => 
1485
  *  [client_login_name] => 
1486
  *  [client_database_id] => 2
1487
  *  [client_channel_group_id] => 5
1488
  *  [client_servergroups] => 6
1489
  *  [client_created] => 1361027850
1490
  *  [client_lastconnected] => 1361027850
1491
  *  [client_totalconnections] => 1
1492
  *  [client_away] => 0
1493
  *  [client_away_message] => 
1494
  *  [client_type] => 0
1495
  *  [client_flag_avatar] => 
1496
  *  [client_talk_power] => 75
1497
  *  [client_talk_request] => 0
1498
  *  [client_talk_request_msg] => 
1499
  *  [client_description] => 
1500
  *  [client_is_talker] => 0
1501
  *  [client_month_bytes_uploaded] => 0
1502
  *  [client_month_bytes_downloaded] => 0
1503
  *  [client_total_bytes_uploaded] => 0
1504
  *  [client_total_bytes_downloaded] => 0
1505
  *  [client_is_priority_speaker] => 0
1506
  *  [client_nickname_phonetic] => 
1507
  *  [client_needed_serverquery_view_power] => 75
1508
  *  [client_default_token] => 
1509
  *  [client_icon_id] => 0
1510
  *  [client_is_channel_commander] => 0
1511
  *  [client_country] => 
1512
  *  [client_channel_group_inherited_channel_id] => 2
1513
  *  [client_badges] => Overwolf=0
1514
  *  [client_base64HashClientUID] => jneilbgomklpfnkjclkoggokfdmdlhnbbpmdpagh
1515
  *  [connection_filetransfer_bandwidth_sent] => 0
1516
  *  [connection_filetransfer_bandwidth_received] => 0
1517
  *  [connection_packets_sent_total] => 12130
1518
  *  [connection_bytes_sent_total] => 542353
1519
  *  [connection_packets_received_total] => 12681
1520
  *  [connection_bytes_received_total] => 592935
1521
  *  [connection_bandwidth_sent_last_second_total] => 82
1522
  *  [connection_bandwidth_sent_last_minute_total] => 92
1523
  *  [connection_bandwidth_received_last_second_total] => 84
1524
  *  [connection_bandwidth_received_last_minute_total] => 88
1525
  *  [connection_connected_time] => 5908749
1526
  *  [connection_client_ip] => 127.0.0.1
1527
  * } 
1528
  * </pre>
1529
  *
1530
  * @author     Par0noid Solutions
1531
  * @param		integer	$clid	clientID
1532
  * @return     array	clientInformation
1533
  */
1534
	function clientInfo($clid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1535
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1536
		return $this->getData('array', 'clientinfo clid='.$clid);
1537
	}
1538
1539
/**
1540
  * clientKick
1541
  * 
1542
  * Kicks one or more clients specified with clid from their currently joined channel or from the server, depending on reasonid. The reasonmsg parameter specifies a text message sent to the kicked clients. This parameter is optional and may only have a maximum of 40 characters.
1543
  *
1544
  * @author     Par0noid Solutions
1545
  * @param		integer $clid		clientID
1546
  * @param		string	$kickMode	kickMode (server or channel) (Default: server)
1547
  * @param		string	$kickmsg 	kick reason [optional]
1548
  * @return     boolean success
1549
  */
1550
	function clientKick($clid, $kickMode = "server", $kickmsg = "") {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1551
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1552
		
1553
		if(in_array($kickMode, array('server', 'channel'))) {
1554
		
1555
			if($kickMode == 'server') { $from = '5'; }
1556
			if($kickMode == 'channel') { $from = '4'; }
1557
			
1558
			if(!empty($kickmsg)) { $msg = ' reasonmsg='.$this->escapeText($kickmsg); } else{ $msg = ''; }
1559
			
1560
			return $this->getData('boolean', 'clientkick clid='.$clid.' reasonid='.$from.$msg);
0 ignored issues
show
Bug introduced by
The variable $from does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1561
		}else{
1562
			$this->addDebugLog('invalid kickMode');
1563
			return $this->generateOutput(false, array('Error: invalid kickMode'), false);
1564
		}
1565
	}
1566
1567
/**
1568
  * clientList
1569
  * 
1570
  * Displays a list of clients online on a virtual server including their ID, nickname, status flags, etc. The output can be modified using several command options. Please note that the output will only contain clients which are currently in channels you're able to subscribe to.
1571
  *
1572
  * <b>Possible params:</b> [-uid] [-away] [-voice] [-times] [-groups] [-info] [-icon] [-country] [-ip] [-badges]
1573
  *
1574
  * <b>Output: (without parameters)</b>
1575
  * <pre>
1576
  * Array
1577
  * {
1578
  *  [clid] => 1
1579
  *  [cid] => 1
1580
  *  [client_database_id] => 2
1581
  *  [client_nickname] => Par0noid
1582
  *  [client_type] => 0
1583
  *  [-uid] => [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1584
  *  [-away] => [client_away] => 0
1585
  *  [-away] => [client_away_message] => 
1586
  *  [-voice] => [client_flag_talking] => 0
1587
  *  [-voice] => [client_input_muted] => 0
1588
  *  [-voice] => [client_output_muted] => 0
1589
  *  [-voice] => [client_input_hardware] => 0
1590
  *  [-voice] => [client_output_hardware] => 0
1591
  *  [-voice] => [client_talk_power] => 0
1592
  *  [-voice] => [client_is_talker] => 0
1593
  *  [-voice] => [client_is_priority_speaker] => 0
1594
  *  [-voice] => [client_is_recording] => 0
1595
  *  [-voice] => [client_is_channel_commander] => 0
1596
  *  [-times] => [client_idle_time] => 1714
1597
  *  [-times] => [client_created] => 1361027850
1598
  *  [-times] => [client_lastconnected] => 1361042955
1599
  *  [-groups] => [client_servergroups] => 6,7
1600
  *  [-groups] => [client_channel_group_id] => 8
1601
  *  [-groups] => [client_channel_group_inherited_channel_id] => 1
1602
  *  [-info] => [client_version] => 3.0.9.2 [Build: 1351504843]
1603
  *  [-info] => [client_platform] => Windows
1604
  *  [-icon] => [client_icon_id] => 0
1605
  *  [-country] => [client_country] => 
1606
  *  [-ip] => [connection_client_ip] => 127.0.0.1
1607
  *  [-badges] => [client_badges] => Overwolf=0
1608
  * }
1609
  * 
1610
  * <b>Usage:</b>
1611
  * 
1612
  * $ts3->clientList(); //No parameters
1613
  * $ts3->clientList("-uid"); //Single parameter
1614
  * $ts3->clientList("-uid -away -voice -times -groups -info -country -icon -ip -badges"); //Multiple parameters
1615
  * </pre>
1616
  *
1617
  * @author     Par0noid Solutions
1618
  * @param		string	$params	additional parameters [optional]
1619
  * @return     array clientList 
1620
  */
1621
	function clientList($params = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1622
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1623
		
1624
		if(!empty($params)) { $params = ' '.$params; }
1625
		
1626
		return $this->getData('multi', 'clientlist'.$params);
1627
	}
1628
1629
/**
1630
  * clientMove
1631
  * 
1632
  * Moves one or more clients specified with clid to the channel with ID cid. If the target channel has a password, it needs to be specified with cpw. If the channel has no password, the parameter can be omitted.
1633
  *
1634
  * @author     Par0noid Solutions
1635
  * @param		integer $clid	clientID
1636
  * @param		integer $cid	channelID
1637
  * @param		string	$cpw	channelPassword [optional]
1638
  * @return     boolean success
1639
  */
1640
	function clientMove($clid, $cid, $cpw = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1641
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1642
		return $this->getData('boolean', 'clientmove clid='.$clid.' cid='.$cid.(!empty($cpw) ? ' cpw='.$this->escapeText($cpw) : ''));
1643
	}
1644
1645
/**
1646
  * clientPermList
1647
  * 
1648
  * Displays a list of permissions defined for a client.
1649
  *
1650
  * <b>Output:</b>
1651
  * <pre>
1652
  * Array
1653
  * {
1654
  *  [permid] => 20654 //with permsid = false
1655
  *  [permsid] => b_client_ignore_bans //with permsid = true
1656
  *  [permvalue] => 1
1657
  *  [permnegated] => 0
1658
  *  [permskip] => 0
1659
  * }
1660
  * </pre>
1661
  *
1662
  * @author     Par0noid Solutions
1663
  * @param		intege		$cldbid 	clientDBID
1664
  * @param		boolean		$permsid	set true to add -permsid param [optional]
1665
  * @return     array clientPermList
1666
  */
1667
	function clientPermList($cldbid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1668
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
1669
		return $this->getData('multi', 'clientpermlist cldbid='.$cldbid.($permsid ? ' -permsid' : ''));
1670
	}
1671
1672
/**
1673
  * clientPoke
1674
  * 
1675
  * Sends a poke message to the client specified with clid.
1676
  *
1677
  * @author     Par0noid Solutions
1678
  * @param		integer $clid	clientID
1679
  * @param		string 	$msg 	pokeMessage
1680
  * @return     boolean success
1681
  */
1682
	function clientPoke($clid, $msg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1683
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1684
		return $this->getData('boolean', 'clientpoke clid='.$clid.' msg='.$this->escapeText($msg));
1685
	}
1686
1687
/**
1688
  * clientSetServerQueryLogin
1689
  * 
1690
  * Updates your own ServerQuery login credentials using a specified username. The password will be auto-generated.
1691
  * 
1692
  * <b>Output:</b>
1693
  * <pre>
1694
  * Array
1695
  * {
1696
  *  [client_login_password] => +r\/TQqvR
1697
  * }
1698
  * </pre>
1699
  *
1700
  * @author     Par0noid Solutions
1701
  * @param		string	$username	username
1702
  * @return     array userInfomation
1703
  */
1704
	function clientSetServerQueryLogin($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1705
		return $this->getData('array', 'clientsetserverquerylogin client_login_name='.$this->escapeText($username));
1706
	}
1707
1708
/**
1709
  * clientUpdate
1710
  * 
1711
  * Change your ServerQuery clients settings using given properties.
1712
  * 
1713
  * <b>Input-Array like this:</b>
1714
  * <pre>
1715
  * $data = array();
1716
  * $data['property'] = 'value';
1717
  * $data['property'] = 'value';
1718
  * </pre>
1719
  *
1720
  * @author     Par0noid Solutions
1721
  * @param		array	$data	clientProperties
1722
  * @return     boolean success
1723
  */
1724
	function clientUpdate($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1725
		$settingsString = '';
1726
		
1727
		foreach($data as $key => $value) {
1728
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
1729
		}
1730
		
1731
		return $this->getData('boolean', 'clientupdate '.$settingsString);
1732
	}
1733
1734
/**
1735
  * complainAdd
1736
  *
1737
  * Submits a complaint about the client with database ID tcldbid to the server.
1738
  *
1739
  * @author     Par0noid Solutions
1740
  * @param		integer $tcldbid	targetClientDBID
1741
  * @param		string	$msg		complainMessage
1742
  * @return     boolean success
1743
  */
1744
	function complainAdd($tcldbid, $msg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1745
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1746
		return $this->getData('boolean', 'complainadd tcldbid='.$tcldbid.' message='.$this->escapeText($msg));
1747
	}
1748
1749
/**
1750
  * complainDelete
1751
  * 
1752
  * Deletes the complaint about the client with ID tcldbid submitted by the client with ID fcldbid from the server.
1753
  *
1754
  * @author     Par0noid Solutions
1755
  * @param		integer $tcldbid targetClientDBID
1756
  * @param		integer $fcldbid fromClientDBID
1757
  * @return     boolean success
1758
  */
1759
	function complainDelete($tcldbid, $fcldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1760
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1761
		return $this->getData('boolean', 'complaindel tcldbid='.$tcldbid.' fcldbid='.$fcldbid);
1762
	}
1763
1764
/**
1765
  * complainDeleteAll
1766
  * 
1767
  * Deletes all complaints about the client with database ID tcldbid from the server.
1768
  *
1769
  * @author     Par0noid Solutions
1770
  * @param		integer $tcldbid targetClientDBID
1771
  * @return     boolean success
1772
  */
1773
	function complainDeleteAll($tcldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1774
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1775
		return $this->getData('boolean', 'complaindelall tcldbid='.$tcldbid);
1776
	}
1777
1778
/**
1779
  * complainList
1780
  * 
1781
  * Displays a list of complaints on the selected virtual server. If tcldbid is specified, only complaints about the targeted client will be shown.
1782
  *
1783
  * <b>Output:</b>
1784
  * <pre>
1785
  * Array
1786
  * {
1787
  *  [tcldbid] => 2
1788
  *  [tname] => par0noid
1789
  *  [fcldbid] => 1
1790
  *  [fname] => serveradmin from 127.0.0.1:6814
1791
  *  [message] => Steals crayons
1792
  *  [timestamp] => 1361044090
1793
  * }
1794
  * </pre>
1795
  *
1796
  * @author     Par0noid Solutions
1797
  * @param		string $tcldbid	targetClientDBID [optional]
1798
  * @return     array complainList
1799
  */
1800
	function complainList($tcldbid = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1801
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1802
		if(!empty($tcldbid)) { $tcldbid = ' tcldbid='.$tcldbid; }
1803
		return $this->getData('multi', 'complainlist'.$tcldbid);
1804
	}
1805
	
1806
1807
/**
1808
  * customInfo
1809
  * 
1810
  * Displays a list of custom properties for the client specified with cldbid.
1811
  *
1812
  * <b>Output:</b>
1813
  * <pre>
1814
  * Array
1815
  * {
1816
  * 	[0] => Array
1817
  *  	{
1818
  *  		[cldbid] => 1
1819
  *			[ident] => abc
1820
  *			[value] => def
1821
  *	  	}
1822
  * 	[1] => Array
1823
  *  	{
1824
  *			[ident] => ghi
1825
  *			[value] => jkl
1826
  *	  	}
1827
  * }
1828
  * </pre>
1829
  *
1830
  * @author     Par0noid Solutions
1831
  * @param		string $cldbid	clientDBID
1832
  * @return     array customInfos
1833
  */
1834
	function customInfo($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1835
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1836
		return $this->getData('multi', 'custominfo cldbid='.$cldbid);
1837
	}
1838
1839
/**
1840
  * customSearch
1841
  * 
1842
  * Searches for custom client properties specified by ident and value. The value parameter can include regular characters and SQL wildcard characters (e.g. %).
1843
  *
1844
  * <b>Output: (ident=abc, pattern=%)</b>
1845
  * <pre>
1846
  * Array
1847
  * {
1848
  * 	[0] => Array
1849
  *  	{
1850
  *  		[cldbid] => 1
1851
  *			[ident] => abc
1852
  *			[value] => def
1853
  *	  	}
1854
  * 	[1] => Array
1855
  *  	{
1856
  *  		[cldbid] => 2
1857
  *			[ident] => abc
1858
  *			[value] => def
1859
  *	  	}
1860
  * }
1861
  * </pre>
1862
  *
1863
  * @author     Par0noid Solutions
1864
  * @param		string	$ident		customIdent
1865
  * @param		string	$pattern	searchpattern
1866
  * @return     array	customSearchInfos
1867
  */
1868
	function customSearch($ident, $pattern) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1869
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1870
		return $this->getData('multi', 'customsearch ident='.$this->escapeText($ident).' pattern='.$this->escapeText($pattern));
1871
	}
1872
1873
/**
1874
  * execOwnCommand
1875
  * 
1876
  * executes a command that isn't defined in class and returns data like your propose
1877
  * 
1878
  * <b>Modes:</b>
1879
  * <ul>
1880
  * 	<li><b>0:</b> execute -> return boolean</li>
1881
  * 	<li><b>1:</b> execute -> return normal array</li>
1882
  * 	<li><b>2:</b> execute -> return multidimensional array</li>
1883
  * 	<li><b>3:</b> execute -> return plaintext serverquery</li>
1884
  * </ul>
1885
  *
1886
  * @author     Par0noid Solutions
1887
  * @param		string	$mode		executionMode
1888
  * @param		string	$command	command
1889
  * @return     mixed result
1890
  */
1891
	function execOwnCommand($mode, $command) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1892
		if($mode == '0') {
1893
			return $this->getData('boolean', $command);
1894
		}
1895
		if($mode == '1') {
1896
			return $this->getData('array', $command);
1897
		}
1898
		if($mode == '2') {
1899
			return $this->getData('multi', $command);
1900
		}
1901
		if($mode == '3') {
1902
			return $this->getData('plain', $command);
1903
		}
1904
	}
1905
1906
/**
1907
  * ftCreateDir
1908
  * 
1909
  * Creates new directory in a channels file repository.
1910
  *
1911
  * @author     Par0noid Solutions
1912
  * @param		string	$cid		channelId
1913
  * @param		string	$cpw		channelPassword (leave blank if not needed)
1914
  * @param		string	$dirname	dirPath
1915
  * @return     boolean success
1916
  */
1917
	function ftCreateDir($cid, $cpw = null, $dirname) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1918
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1919
		return $this->getData('boolean', 'ftcreatedir cid='.$cid.' cpw='.$this->escapeText($cpw).' dirname='.$this->escapeText($dirname));
1920
	}
1921
1922
/**
1923
  * ftDeleteFile
1924
  * 
1925
  * Deletes one or more files stored in a channels file repository.
1926
  *
1927
  * <b>Input-Array like this:</b>
1928
  * <pre>
1929
  * $files = array();
1930
  *	
1931
  * $files[] = '/pic1.jpg';
1932
  * $files[] = '/dokumente/test.txt';
1933
  * $files[] = '/dokumente';
1934
  * </pre>
1935
  *
1936
  * @author     Par0noid Solutions
1937
  * @param		string	$cid	channelID
1938
  * @param		string	$cpw	channelPassword (leave blank if not needed)
1939
  * @param		array	$files	files
1940
  * @return     boolean success
1941
  */
1942 View Code Duplication
	function ftDeleteFile($cid, $cpw = '', $files) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1943
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1944
		$fileArray = array();
1945
		
1946
		if(count($files) > 0) {
1947
			foreach($files AS $file) {
1948
				$fileArray[] = 'name='.$this->escapeText($file);
1949
			}
1950
			return $this->getData('boolean', 'ftdeletefile cid='.$cid.' cpw='.$this->escapeText($cpw).' '.implode('|', $fileArray));
1951
		}else{
1952
			$this->addDebugLog('no files given');
1953
			return $this->generateOutput(false, array('Error: no files given'), false);
1954
		}
1955
	}
1956
1957
/**
1958
  * ftDownloadFile
1959
  * 
1960
  * Ddownloads a file and returns its contents
1961
  *
1962
  * @author     Par0noid Solutions
1963
  * @param		array	$data	return of ftInitDownload
1964
  * @return     array downloadedFile
1965
  */
1966
	function ftDownloadFile($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1967
		$errnum = null;
1968
		$errstr = null;
1969
  		$this->runtime['fileSocket'] = @fsockopen($this->runtime['host'], $data['data']['port'], $errnum, $errstr, $this->runtime['timeout']);
1970
  		if($this->runtime['fileSocket']) {
1971
  			$this->ftSendKey($data['data']['ftkey']);
1972
  			$content = $this->ftRead($data['data']['size']);
1973
  			@fclose($this->runtime['fileSocket']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1974
  			$this->runtime['fileSocket'] = '';
1975
  			return $content;
1976 View Code Duplication
  		}else{
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1977
  			$this->addDebugLog('fileSocket returns '.$errnum. ' | '.$errstr);
1978
  			return $this->generateOutput(false, array('Error in fileSocket: '.$errnum. ' | '.$errstr), false);
1979
  		}
1980
	}
1981
	
1982
/**
1983
  * ftGetFileInfo
1984
  * 
1985
  * Displays detailed information about one or more specified files stored in a channels file repository.
1986
  * 
1987
  *
1988
  * @author     Par0noid Solutions
1989
  * @param		string	$cid	channelID
1990
  * @param		string	$cpw	channelPassword (leave blank if not needed)
1991
  * @param		string 	$file	path to file
1992
  * @return     boolean success
1993
  */
1994
	function ftGetFileInfo($cid, $cpw = '', $file) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1995
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1996
1997
		return $this->getData('multi', 'ftgetfileinfo cid='.$cid.' cpw='.$this->escapeText($cpw).' name='.$this->escapeText($file));
1998
	}
1999
2000
/**
2001
  * ftGetFileList
2002
  *
2003
  * Displays a list of files and directories stored in the specified channels file repository.
2004
  *
2005
  * <b>Output:</b>
2006
  * <pre>
2007
  * Array
2008
  * {
2009
  *  [cid] => 231
2010
  *  [path] => /
2011
  *  [name] => Documents
2012
  *  [size] => 0
2013
  *  [datetime] => 1286633633
2014
  *  [type] => 0
2015
  * }
2016
  * </pre>
2017
  *
2018
  * @author     Par0noid Solutions
2019
  * @param		string	$cid	channelID
2020
  * @param		string	$cpw	channelPassword (leave blank if not needed)
2021
  * @param		string	$path	filePath
2022
  * @return     array	fileList
2023
  */
2024
	function ftGetFileList($cid, $cpw = '', $path) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2025
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2026
		return $this->getData('multi', 'ftgetfilelist cid='.$cid.' cpw='.$this->escapeText($cpw).' path='.$this->escapeText($path));
2027
	}
2028
	
2029
/**
2030
  * ftInitDownload
2031
  * 
2032
  * Initializes a file transfer download. clientftfid is an arbitrary ID to identify the file transfer on client-side. On success, the server generates a new ftkey which is required to start downloading the file through TeamSpeak 3's file transfer interface.
2033
  *
2034
  * <b>Output:</b>
2035
  * <pre>
2036
  * Array
2037
  * {
2038
  *  [clientftfid] => 89
2039
  *  [serverftfid] => 3
2040
  *  [ftkey] => jSzWiRmFGdZnoJzW7BSDYJRUWB2WAUhb
2041
  *  [port] => 30033
2042
  *  [size] => 94
2043
  * }
2044
  * </pre>
2045
  *
2046
  * @author     Par0noid Solutions
2047
  * @param		string	$name			filePath
2048
  * @param		string	$cid			channelID
2049
  * @param		string	$cpw			channelPassword (leave blank if not needed)
2050
  * @param		integer	$seekpos		seekpos (default = 0) [optional]
2051
  * @return     array	initDownloadFileInfo
2052
  */	
2053
	function ftInitDownload($name, $cid, $cpw = '', $seekpos = 0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2054
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2055
		return $this->getData('array', 'ftinitdownload clientftfid='.rand(1,99).' name='.$this->escapeText($name).' cid='.$cid.' cpw='.$this->escapeText($cpw).' seekpos='.$seekpos);
2056
	}
2057
2058
/**
2059
  * ftInitUpload
2060
  * 
2061
  * Initializes a file transfer upload. clientftfid is an arbitrary ID to identify the file transfer on client-side. On success, the server generates a new ftkey which is required to start uploading the file through TeamSpeak 3's file transfer interface.
2062
  *
2063
  * <b>Output:</b>
2064
  * <pre>
2065
  * Array
2066
  * {
2067
  *  [clientftfid] => 84
2068
  *  [serverftfid] => 41
2069
  *  [ftkey] => HCnXpunOdAorqj3dGqfiuLszX18O0PHP
2070
  *  [port] => 30033
2071
  *  [seekpos] => 0
2072
  * }
2073
  * </pre>
2074
  *
2075
  * @author     Par0noid Solutions
2076
  * @param		string	$filename	filePath
2077
  * @param		string	$cid		channelID
2078
  * @param		integer	$size		fileSize in bytes
2079
  * @param		string	$cpw		channelPassword (leave blank if not needed)
2080
  * @param		boolean	$overwrite	overwrite	[optional] (default = 0)
2081
  * @param		boolean	$resume		resume		[optional] (default = 0)
2082
  * @return     array	initUploadFileInfo
2083
  */	
2084
	function ftInitUpload($filename, $cid, $size, $cpw = '', $overwrite = false, $resume = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2085
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2086
		
2087
		if($overwrite) { $overwrite = ' overwrite=1'; }else{ $overwrite = ' overwrite=0'; }
2088
		if($resume) { $resume = ' resume=1'; }else{ $resume = ' resume=0'; }
2089
		
2090
		return $this->getData('array', 'ftinitupload clientftfid='.rand(1,99).' name='.$this->escapeText($filename).' cid='.$cid.' cpw='.$this->escapeText($cpw).' size='.($size + 1).$overwrite.$resume);
2091
	}
2092
	
2093
/**
2094
  * ftList
2095
  * 
2096
  * Displays a list of running file transfers on the selected virtual server. The output contains the path to which a file is uploaded to, the current transfer rate in bytes per second, etc
2097
  *
2098
  * <b>Output:</b>
2099
  * <pre>
2100
  * Array
2101
  * {
2102
  *  [clid] => 1
2103
  *  [cldbid] => 2019
2104
  *  [path] => files/virtualserver_11/channel_231
2105
  *  [name] => 1285412348878.png
2106
  *  [size] => 1161281
2107
  *  [sizedone] => 275888
2108
  *  [clientftfid] => 15
2109
  *  [serverftfid] => 52
2110
  *  [sender] => 0
2111
  *  [status] => 1
2112
  *  [current_speed] => 101037.4453
2113
  *  [average_speed] => 101037.4453
2114
  *  [runtime] => 2163
2115
  * }
2116
  * </pre>
2117
  *
2118
  * @author     Par0noid Solutions
2119
  * @return     array	fileTransferList
2120
  */
2121
	function ftList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2122
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2123
		return $this->getData('multi', 'ftlist');
2124
	}
2125
2126
/**
2127
  * ftRenameFile
2128
  * 
2129
  * Renames a file in a channels file repository. If the two parameters tcid and tcpw are specified, the file will be moved into another channels file repository.
2130
  *
2131
  * @author     Par0noid Solutions
2132
  * @param		integer	$cid		channelID
2133
  * @param		string	$cpw		channelPassword (leave blank if not needed)
2134
  * @param		string	$oldname	oldFilePath
2135
  * @param		string	$newname	newFilePath
2136
  * @param		string  $tcid		targetChannelID [optional]
2137
  * @param		string  $tcpw		targetChannelPassword [optional]
2138
  * @return     boolean success
2139
  */
2140
	function ftRenameFile($cid, $cpw = null, $oldname, $newname, $tcid = null,  $tcpw = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2141
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2142
		$newTarget = ($tcid != null ? ' tcid='.$tcid.' '.$tcpw : '');
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $tcid of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
2143
		return $this->getData('boolean', 'ftrenamefile cid='.$cid.' cpw='.$cpw.' oldname='.$this->escapeText($oldname).' newname='.$this->escapeText($newname).$newTarget);
2144
	}
2145
2146
/**
2147
  * ftStop
2148
  * 
2149
  * Stops the running file transfer with server-side ID serverftfid.
2150
  *
2151
  * @author     Par0noid Solutions
2152
  * @param		integer	$serverftfid	serverFileTransferID
2153
  * @param		boolean	$delete			delete incomplete file [optional] (default: true) 
2154
  * @return     boolean success
2155
  */
2156
	function ftStop($serverftfid, $delete = true) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2157
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
2158
		return $this->getData('boolean', 'ftstop serverftfid='.$serverftfid.' delete='.($delete ? '1' : '0'));
2159
	}
2160
2161
/**
2162
  * ftUploadFile
2163
  * 
2164
  * Uploads a file to server
2165
  * To check if upload was successful, you have to search for this file in fileList after
2166
  *
2167
  * @author     Par0noid Solutions
2168
  * @param		array	$data			return of ftInitUpload
2169
  * @param		string	$uploadData		data which should be uploaded
2170
  * @return     array response
2171
  */
2172
	function ftUploadFile($data, $uploadData) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2173
  		$this->runtime['fileSocket'] = @fsockopen($this->runtime['host'], $data['data']['port'], $errnum, $errstr, $this->runtime['timeout']);
2174
  		if($this->runtime['fileSocket']) {
2175
  			$this->ftSendKey($data['data']['ftkey'], "\n");
2176
  			$this->ftSendData($uploadData);
2177
  			@fclose($this->runtime['fileSocket']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
2178
  			$this->runtime['fileSocket'] = '';
2179
  			return $this->generateOutput(true, array(), true);
2180 View Code Duplication
  		}else{
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2181
  			$this->addDebugLog('fileSocket returns '.$errnum. ' | '.$errstr);
2182
  			return $this->generateOutput(false, array('Error in fileSocket: '.$errnum. ' | '.$errstr), false);
2183
  		}
2184
	}
2185
2186
/**
2187
  * gm
2188
  * 
2189
  * Sends a text message to all clients on all virtual servers in the TeamSpeak 3 Server instance.
2190
  *
2191
  * @author     Par0noid Solutions
2192
  * @param		string	$msg	message
2193
  * @return     boolean success
2194
  */
2195
	function gm($msg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2196 View Code Duplication
		if(empty($msg)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2197
			$this->addDebugLog('empty message given');
2198
			return $this->generateOutput(false, array('Error: empty message given'), false);
2199
		}
2200
		return $this->getData('boolean', 'gm msg='.$this->escapeText($msg));
2201
	}
2202
2203
/**
2204
  * hostInfo
2205
  * 
2206
  * Displays detailed connection information about the server instance including uptime, number of virtual servers online, traffic information, etc.
2207
  *
2208
  * <b>Output:</b>
2209
  * <pre>
2210
  * Array
2211
  * {
2212
  *  [instance_uptime] => 19038
2213
  *  [host_timestamp_utc] => 1361046825
2214
  *  [virtualservers_running_total] => 1
2215
  *  [virtualservers_total_maxclients] => 32
2216
  *  [virtualservers_total_clients_online] => 1
2217
  *  [virtualservers_total_channels_online] => 2
2218
  *  [connection_filetransfer_bandwidth_sent] => 0
2219
  *  [connection_filetransfer_bandwidth_received] => 0
2220
  *  [connection_filetransfer_bytes_sent_total] => 0
2221
  *  [connection_filetransfer_bytes_received_total] => 0
2222
  *  [connection_packets_sent_total] => 24853
2223
  *  [connection_bytes_sent_total] => 1096128
2224
  *  [connection_packets_received_total] => 25404
2225
  *  [connection_bytes_received_total] => 1153918
2226
  *  [connection_bandwidth_sent_last_second_total] => 82
2227
  *  [connection_bandwidth_sent_last_minute_total] => 81
2228
  *  [connection_bandwidth_received_last_second_total] => 84
2229
  *  [connection_bandwidth_received_last_minute_total] => 87
2230
  * }
2231
  * </pre>
2232
  *
2233
  * @author     Par0noid Solutions
2234
  * @return     array hostInformation
2235
  */
2236
	function hostInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2237
		return $this->getData('array', 'hostinfo');
2238
	}
2239
2240
/**
2241
  * instanceEdit
2242
  * 
2243
  * Changes the server instance configuration using given properties.
2244
  *
2245
  * <b>Input-Array like this:</b>
2246
  * <pre>
2247
  * $data = array();
2248
  *	
2249
  * $data['setting'] = 'value';
2250
  * $data['setting'] = 'value';
2251
  * </pre>
2252
  *
2253
  * @author     Par0noid Solutions
2254
  * @param		array	$data	instanceProperties
2255
  * @return     boolean success
2256
  */
2257
	function instanceEdit($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2258
		if(count($data) > 0) {
2259
			$settingsString = '';
2260
			
2261
			foreach($data as $key => $val) {
2262
				$settingsString .= ' '.$key.'='.$this->escapeText($val);
2263
			}
2264
			return $this->getData('boolean', 'instanceedit '.$settingsString);
2265
		}else{
2266
			$this->addDebugLog('empty array entered');
2267
			return $this->generateOutput(false, array('Error: You can \'t give an empty array'), false);
2268
		}
2269
	}
2270
2271
/**
2272
  * instanceInfo
2273
  * 
2274
  * Displays the server instance configuration including database revision number, the file transfer port, default group IDs, etc.
2275
  *
2276
  * <b>Output:</b>
2277
  * <pre>
2278
  * Array
2279
  * {
2280
  *  [serverinstance_database_version] => 20
2281
  *  [serverinstance_filetransfer_port] => 30033
2282
  *  [serverinstance_max_download_total_bandwidth] => 18446744073709551615
2283
  *  [serverinstance_max_upload_total_bandwidth] => 18446744073709551615
2284
  *  [serverinstance_guest_serverquery_group] => 1
2285
  *  [serverinstance_serverquery_flood_commands] => 10
2286
  *  [serverinstance_serverquery_flood_time] => 3
2287
  *  [serverinstance_serverquery_ban_time] => 600
2288
  *  [serverinstance_template_serveradmin_group] => 3
2289
  *  [serverinstance_template_serverdefault_group] => 5
2290
  *  [serverinstance_template_channeladmin_group] => 1
2291
  *  [serverinstance_template_channeldefault_group] => 4
2292
  *  [serverinstance_permissions_version] => 15
2293
  * }
2294
  * </pre>
2295
  *
2296
  * @author     Par0noid Solutions
2297
  * @return     array instanceInformation
2298
  */
2299
	function instanceInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2300
		return $this->getData('array', 'instanceinfo');
2301
	}
2302
2303
/**
2304
  * logAdd
2305
  * 
2306
  * Writes a custom entry into the servers log. Depending on your permissions, you'll be able to add entries into the server instance log and/or your virtual servers log. The loglevel parameter specifies the type of the entry.
2307
  *
2308
  * @author     Par0noid Solutions
2309
  * @param		integer	$logLevel	loglevel between 1 and 4
2310
  * @param		string	$logMsg		logMessage
2311
  * @return     boolean success
2312
  */
2313
	function logAdd($logLevel, $logMsg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2314
		if($logLevel >=1 and $logLevel <= 4) { 
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
2315
			if(!empty($logMsg)) {
2316
				return $this->getData('boolean', 'logadd loglevel='.$logLevel.' logmsg='.$this->escapeText($logMsg));
2317
			}else{
2318
				$this->addDebugLog('logMessage empty!');
2319
				return $this->generateOutput(false, array('Error: logMessage empty!'), false);
2320
			}
2321
		}else{
2322
			$this->addDebugLog('invalid logLevel!');
2323
			return $this->generateOutput(false, array('Error: invalid logLevel!'), false);
2324
		}
2325
	}
2326
2327
/**
2328
  * login
2329
  * 
2330
  * Authenticates with the TeamSpeak 3 Server instance using given ServerQuery login credentials.
2331
  *
2332
  * @author     Par0noid Solutions
2333
  * @param		string	$username	username
2334
  * @param		string	$password	password
2335
  * @return     boolean success
2336
  */
2337
	function login($username, $password) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2338
		return $this->getData('boolean', 'login '.$this->escapeText($username).' '.$this->escapeText($password));
2339
	}
2340
2341
/**
2342
  * logout
2343
  * 
2344
  * Deselects the active virtual server and logs out from the server instance.
2345
  *
2346
  * @author     Par0noid Solutions
2347
  * @return     boolean success
2348
  */
2349
	function logout() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2350
		$this->runtime['selected'] = false;
2351
		return $this->getData('boolean', 'logout');
2352
	}
2353
2354
/**
2355
  * logView
2356
  * 
2357
  * Displays a specified number of entries from the servers log. If instance is set to 1, the server will return lines from the master logfile (ts3server_0.log) instead of the selected virtual server logfile.
2358
  * 
2359
  * <b>Output:</b>
2360
  * <pre>
2361
  * Array
2362
  * {
2363
  *  [last_pos] => 0
2364
  *  [file_size] => 1085
2365
  *  [l] => 2012-01-10 20:34:31.379260|INFO    |ServerLibPriv |   | TeamSpeak 3 Server 3.0.1 (2011-11-17 07:34:30)
2366
  * }
2367
  * {
2368
  *  [l] => 2012-01-10 20:34:31.380260|INFO    |DatabaseQuery |   | dbPlugin name:    SQLite3 plugin, Version 2, (c)TeamSpeak Systems GmbH
2369
  * }
2370
  * {
2371
  *  [l] => 2012-01-10 20:34:31.380260|INFO    |DatabaseQuery |   | dbPlugin version: 3.7.3
2372
  * }
2373
  * </pre>
2374
  *
2375
  * @author     Par0noid Solutions
2376
  * @param		integer	$lines	between 1 and 100
2377
  * @param		integer	$reverse	{1|0} [optional]
2378
  * @param		integer	$instance	{1|0} [optional]
2379
  * @param		integer	$begin_pos	{1|0} [optional]
2380
  * @return     multidimensional-array logEntries
0 ignored issues
show
Documentation introduced by
The doc-type multidimensional-array could not be parsed: Unknown type name "multidimensional-array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
2381
  */
2382
	function logView($lines, $reverse = 0, $instance = 0, $begin_pos = 0) {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2383
		if($lines >=1 and $lines <=100) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
2384
			return $this->getData('multi', 'logview lines='.$lines.' reverse='.($reverse == 0 ? '0' : '1').' instance='.($instance == 0 ? '0' : '1').' begin_pos='.($begin_pos == 0 ? '0' : $begin_pos));
2385
		}else{
2386
			$this->addDebugLog('please choose a limit between 1 and 100');
2387
			$this->generateOutput(false, array('Error: please choose a limit between 1 and 100'), false);
0 ignored issues
show
Unused Code introduced by
The call to the method ts3admin::generateOutput() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
2388
		}
2389
	}
2390
2391
/**
2392
  * messageAdd
2393
  * 
2394
  * Sends an offline message to the client specified by cluid.
2395
  *
2396
  * @author     Par0noid Solutions
2397
  * @param		string	$cluid		clientUID
2398
  * @param		string	$subject	Subject of the message
2399
  * @param		string	$message	Text of the message
2400
  * @return     boolean success
2401
  */
2402
	function messageAdd($cluid, $subject, $message) {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2403
        if(!$this->runtime['selected']) { return $this->checkSelected(); }
2404
        return $this->getData('boolean', 'messageadd cluid='.$cluid.' subject='.$this->escapeText($subject).' message='.$this->escapeText($message)); 
2405
	}
2406
2407
/**
2408
  * messageDelete
2409
  * 
2410
  * Deletes an existing offline message with ID msgid from your inbox.
2411
  *
2412
  * @author     Par0noid Solutions
2413
  * @param		string	$messageID		messageID
2414
  * @return     boolean success
2415
  */
2416
	function messageDelete($messageID) {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2417
        if(!$this->runtime['selected']) { return $this->checkSelected(); }
2418
        return $this->getData('boolean', 'messagedel msgid='.$messageID); 
2419
	}
2420
2421
/**
2422
  * messageGet
2423
  * 
2424
  * Displays an existing offline message with ID msgid from your inbox. Please note that this does not automatically set the flag_read property of the message.
2425
  *
2426
  * @author     Par0noid Solutions
2427
  * @param		string	$messageID		messageID
2428
  * @return     array messageInformation
2429
  */
2430
	function messageGet($messageID) {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2431
        if(!$this->runtime['selected']) { return $this->checkSelected(); }
2432
        return $this->getData('array', 'messageget msgid='.$messageID); 
2433
	}
2434
2435
/**
2436
  * messageList
2437
  * 
2438
  * Displays a list of offline messages you've received. The output contains the senders unique identifier, the messages subject, etc.
2439
  *
2440
  * @author     Par0noid Solutions
2441
  * @return     array messageInformation
2442
  */
2443
	function messageList() {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2444
        if(!$this->runtime['selected']) { return $this->checkSelected(); }
2445
        return $this->getData('array', 'messagelist'); 
2446
	}
2447
2448
/**
2449
  * messageUpdateFlag
2450
  * 
2451
  * Updates the flag_read property of the offline message specified with msgid. If flag is set to 1, the message will be marked as read.
2452
  *
2453
  * @author     Par0noid Solutions
2454
  * @param		string	$messageID		messageID
2455
  * @param		integer	$flag			flag {1|0}
2456
  * @return     array messageInformation
2457
  */
2458
	function messageUpdateFlag($messageID, $flag = 1) {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2459
        if(!$this->runtime['selected']) { return $this->checkSelected(); }
2460
        return $this->getData('boolean', 'messageupdateflag msgid='.$messageID.' flag='.$flag); 
2461
	}
2462
2463
/**
2464
  * permFind
2465
  * 
2466
  * Displays detailed information about all assignments of the permission specified with permid. The output is similar to permoverview which includes the type and the ID of the client, channel or group associated with the permission. A permission can be specified by permid or permsid.
2467
  *
2468
  * <b>Output:</b>
2469
  * <pre>
2470
  * Array
2471
  * {
2472
  *  [token] => eKnFZQ9EK7G7MhtuQB6+N2B1PNZZ6OZL3ycDp2OW
2473
  * }
2474
  * </pre>
2475
  *
2476
  * @author     Par0noid Solutions
2477
  * @param		mixed	$perm	permid or permsid
2478
  * @return     array permissionInfoList
2479
  */
2480
	function permFind($perm) { 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2481
        if(!$this->runtime['selected']) { return $this->checkSelected(); }
2482
        return $this->getData('multi', 'permfind '.(is_int($perm) || ctype_digit($perm) ? 'permid=' : 'permsid=').$perm); 
2483
    }
2484
	
2485
	
2486
/**
2487
  * permGet
2488
  * 
2489
  * Displays the current value of the permission specified with permid or permsid for your own connection. This can be useful when you need to check your own privileges.
2490
  *
2491
  * The perm parameter can be used as permid or permsid, it will switch the mode automatically.
2492
  *
2493
  * <b>Output:</b>
2494
  * <pre>
2495
  * Array
2496
  * {
2497
  *		[permsid] => i_channel_create_modify_with_codec_maxquality
2498
  *     [permid] => 96
2499
  *     [permvalue] => 10	
2500
  * }
2501
  * </pre>
2502
  *
2503
  * @author     Par0noid Solutions
2504
  * @param		mixed	$perm	permid or permsid
2505
  * @return     array permissionInfo
2506
  */
2507
	function permGet($perm) { 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2508
        if(!$this->runtime['selected']) { return $this->checkSelected(); }
2509
        return $this->getData('array', 'permget '.(is_int($perm) || ctype_digit($perm) ? 'permid=' : 'permsid=').$perm); 
2510
    }	
2511
	
2512
/**
2513
  * permIdGetByName
2514
  * 
2515
  * Displays the database ID of one or more permissions specified by permsid.
2516
  *
2517
  * <b>Input-Array like this:</b>
2518
  * <pre>
2519
  * $permissions = array();
2520
  * $permissions[] = 'permissionName';
2521
  * </pre>
2522
  * <b>Output:</b>
2523
  * <pre>
2524
  * Array
2525
  * {
2526
  *  [permsid] => b_serverinstance_help_view
2527
  *  [permid] => 4353
2528
  * }
2529
  * </pre>
2530
  *
2531
  * @author     Par0noid Solutions
2532
  * @param		string	$permsids		permNames
2533
  * @return     array	permissionList 
2534
  */
2535
	function permIdGetByName($permsids) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2536
		$permissionArray = array();
2537
		
2538
		if(count($permsids) > 0) {
2539
			foreach($permsids AS $value) {
0 ignored issues
show
Bug introduced by
The expression $permsids of type string is not traversable.
Loading history...
2540
				$permissionArray[] = 'permsid='.$value;
2541
			}
2542
			return $this->getData('multi', 'permidgetbyname '.$this->escapeText(implode('|', $permissionArray)));
2543
		}else{
2544
			$this->addDebugLog('no permissions given');
2545
			return $this->generateOutput(false, array('Error: no permissions given'), false);
2546
		}
2547
		
2548
	}
2549
2550
2551
/**
2552
  * permissionList
2553
  * 
2554
  * Displays a list of permissions available on the server instance including ID, name and description.
2555
  * If the new parameter is set the permissionlist will return with the new output format.
2556
  *
2557
  * <b>Output: (with new parameter)</b>
2558
  * <pre>
2559
  * [0] => Array
2560
  *     (
2561
  *         [num] => 1
2562
  *         [group_id_end] => 0
2563
  *         [pcount] => 0
2564
  *     )
2565
  *
2566
  * [1] => Array
2567
  *     (
2568
  *         [num] => 2
2569
  *         [group_id_end] => 7
2570
  *         [pcount] => 7
2571
  *         [permissions] => Array
2572
  *             (
2573
  *                 [0] => Array
2574
  *                     (
2575
  *                         [permid] => 1
2576
  *                         [permname] => b_serverinstance_help_view
2577
  *                         [permdesc] => Retrieve information about ServerQuery commands
2578
  *                         [grantpermid] => 32769
2579
  *                     )
2580
  *
2581
  *                 [1] => Array
2582
  *                     (
2583
  *                         [permid] => 2
2584
  *                         [permname] => b_serverinstance_version_view
2585
  *                         [permdesc] => Retrieve global server version (including platform and build number)
2586
  *                         [grantpermid] => 32770
2587
  *                     )
2588
  *
2589
  *                 [2] => Array
2590
  *                     (
2591
  *                         [permid] => 3
2592
  *                         [permname] => b_serverinstance_info_view
2593
  *                         [permdesc] => Retrieve global server information
2594
  *                         [grantpermid] => 32771
2595
  *                     )
2596
  *
2597
  *                 [3] => Array
2598
  *                     (
2599
  *                         [permid] => 4
2600
  *                         [permname] => b_serverinstance_virtualserver_list
2601
  *                         [permdesc] => List virtual servers stored in the database
2602
  *                         [grantpermid] => 32772
2603
  *                     )
2604
  *
2605
  *                 [4] => Array
2606
  *                     (
2607
  *                         [permid] => 5
2608
  *                         [permname] => b_serverinstance_binding_list
2609
  *                         [permdesc] => List active IP bindings on multi-homed machines
2610
  *                         [grantpermid] => 32773
2611
  *                     )
2612
  *
2613
  *                [5] => Array
2614
  *                     (
2615
  *                         [permid] => 6
2616
  *                         [permname] => b_serverinstance_permission_list
2617
  *                         [permdesc] => List permissions available available on the server instance
2618
  *                         [grantpermid] => 32774
2619
  *                     )
2620
  *
2621
  *                 [6] => Array
2622
  *                     (
2623
  *                         [permid] => 7
2624
  *                         [permname] => b_serverinstance_permission_find
2625
  *                         [permdesc] => Search permission assignments by name or ID
2626
  *                         [grantpermid] => 32775
2627
  *                     )
2628
  *
2629
  *             )
2630
  *
2631
  *     )
2632
  * </pre>
2633
  *
2634
  * @author     Par0noid Solutions
2635
  * @param		boolean		$new		[optional] add new parameter
2636
  * @return     array permissionList
2637
  */
2638
	function permissionList($new = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2639
		if($new === true) {
2640
			$groups = array();
2641
			$permissions = array();
2642
			
2643
			$response = $this->getElement('data', $this->getData('multi', 'permissionlist -new'));
0 ignored issues
show
Bug introduced by
It seems like $this->getData('multi', 'permissionlist -new') targeting ts3admin::getData() can also be of type null; however, ts3admin::getElement() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
2644
			
2645
			$gc = 1;
2646
			
2647
			foreach($response as $field) {
2648
				if(isset($field['group_id_end'])) {
2649
					$groups[] = array('num' => $gc, 'group_id_end' => $field['group_id_end']);
2650
					$gc++;
2651
				}else{
2652
					$permissions[] = $field;
2653
				}
2654
			}
2655
			
2656
			$counter = 0;
2657
			
2658
			for($i = 0; $i < count($groups); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2659
				$rounds = $groups[$i]['group_id_end'] - $counter;
2660
				$groups[$i]['pcount'] = $rounds;
2661
				for($j = 0; $j < $rounds; $j++) {
2662
					$groups[$i]['permissions'][] = array('permid' => ($counter + 1), 'permname' => $permissions[$counter]['permname'], 'permdesc' => $permissions[$counter]['permdesc'], 'grantpermid' => ($counter + 32769));
2663
					$counter++;
2664
				}
2665
			}
2666
			
2667
			return $groups;
2668
			
2669
		}else{
2670
			return $this->getData('multi', 'permissionlist');
2671
		}
2672
	}
2673
2674
/**
2675
  * permOverview
2676
  * 
2677
  * Displays all permissions assigned to a client for the channel specified with cid. If permid is set to 0, all permissions will be displayed. A permission can be specified by permid or permsid.
2678
  *
2679
  * If you set the permsid parameter, the permid parameter will be ignored.
2680
  *
2681
  * <b>Output:</b>
2682
  * <pre>
2683
  * Array
2684
  * {
2685
  *  [t] => 0
2686
  *  [id1] => 2
2687
  *  [id2] => 0
2688
  *  [p] => 16777
2689
  *  [v] => 1
2690
  *  [n] => 0
2691
  *  [s] => 0
2692
  * }
2693
  * </pre>
2694
  *
2695
  * @author     Par0noid Solutions
2696
  * @param		integer		$cid		cchannelId
2697
  * @param		integer 	$cldbid		clientDbId
2698
  * @param		integer 	$permid		permId (Default: 0)
2699
  * @param		string	 	$permsid	permName
2700
  * @return     array permOverview
2701
  */
2702
	function permOverview($cid, $cldbid, $permid='0', $permsid=false ) { 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2703
        if(!$this->runtime['selected']) { return $this->checkSelected(); } 
2704
        if($permsid) { $additional = ' permsid='.$permsid; }else{ $additional = ''; } 
0 ignored issues
show
Bug Best Practice introduced by
The expression $permsid of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
2705
         
2706
        return $this->getData('multi', 'permoverview cid='.$cid.' cldbid='.$cldbid.($permsid == false ? ' permid='.$permid : '').$additional); 
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $permsid of type false|string against false; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
2707
    }
2708
2709
/**
2710
  * permReset
2711
  * 
2712
  * Restores the default permission settings on the selected virtual server and creates a new initial administrator token. Please note that in case of an error during the permreset call - e.g. when the database has been modified or corrupted - the virtual server will be deleted from the database.
2713
  *
2714
  * <b>Output:</b>
2715
  * <pre>
2716
  * Array
2717
  * {
2718
  *  [token] => eKnFZQ9EK7G7MhtuQB6+N2B1PNZZ6OZL3ycDp2OW
2719
  * }
2720
  * </pre>
2721
  *
2722
  * @author     Par0noid Solutions
2723
  * @return     array token
2724
  */
2725
	function permReset() { 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2726
        if(!$this->runtime['selected']) { return $this->checkSelected(); } 
2727
        return $this->getData('array', 'permreset'); 
2728
    }
2729
	
2730
/**
2731
  * privilegekeyAdd
2732
  * 
2733
  * Create a new token. If tokentype is set to 0, the ID specified with tokenid1 will be a server group ID. Otherwise, tokenid1 is used as a channel group ID and you need to provide a valid channel ID using tokenid2. The tokencustomset parameter allows you to specify a set of custom client properties. This feature can be used when generating tokens to combine a website account database with a TeamSpeak user. The syntax of the value needs to be escaped using the ServerQuery escape patterns and has to follow the general syntax of:
2734
  * ident=ident1 value=value1|ident=ident2 value=value2|ident=ident3 value=value3
2735
  *
2736
  * <b>Input-Array like this:</b>
2737
  * <pre>
2738
  * $customFieldSet = array();
2739
  *	
2740
  * $customFieldSet['ident'] = 'value';
2741
  * $customFieldSet['ident'] = 'value';
2742
  * </pre>
2743
  *
2744
  * @author     Par0noid Solutions
2745
  * @param		integer	$tokentype				token type
2746
  * @param		integer	$tokenid1				groupID
2747
  * @param		integer	$tokenid2				channelID
2748
  * @param		string	$description			token description [optional]
2749
  * @param		array	$customFieldSet			customFieldSet [optional]
2750
  * @return     array	tokenInformation
2751
  */
2752
	function privilegekeyAdd($tokentype, $tokenid1, $tokenid2, $description ='', $customFieldSet = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2753
		return $this->tokenAdd($tokentype, $tokenid1, $tokenid2, $description, $customFieldSet);
2754
	}
2755
2756
/**
2757
  * privilegekeyDelete
2758
  * 
2759
  * Deletes an existing token matching the token key specified with token.
2760
  *
2761
  * @author     Par0noid Solutions
2762
  * @param		string	$token	token
2763
  * @return     boolean success
2764
  */
2765
	function privilegekeyDelete($token) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2766
		return $this->tokenDelete($token);
2767
	}
2768
2769
/**
2770
  * privilegekeyList
2771
  * 
2772
  * Displays a list of privilege keys available including their type and group IDs. Tokens can be used to gain access to specified server or channel groups. A privilege key is similar to a client with administrator privileges that adds you to a certain permission group, but without the necessity of a such a client with administrator privileges to actually exist. It is a long (random looking) string that can be used as a ticket into a specific server group.
2773
  *
2774
  * <b>Output:</b>
2775
  * <pre>
2776
  * Array
2777
  * {
2778
  *  [token] => GdqedxSEDle3e9+LtR3o9dO09bURH+vymvF5hOJg
2779
  *  [token_type] => 0
2780
  *  [token_id1] => 71
2781
  *  [token_id2] => 0
2782
  *  [token_created] => 1286625908
2783
  *  [token_description] => for you
2784
  * }
2785
  * </pre>
2786
  *
2787
  * @author     Par0noid Solutions
2788
  * @return     array tokenListist 
2789
  */
2790
	function privilegekeyList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2791
		return $this->tokenList();
2792
	}
2793
2794
/**
2795
  * privilegekeyUse
2796
  * 
2797
  * Use a token key gain access to a server or channel group. Please note that the server will automatically delete the token after it has been used.
2798
  *
2799
  * @author     Par0noid Solutions
2800
  * @param		string	$token	token
2801
  * @return     boolean success
2802
  */
2803
	function privilegekeyUse($token) {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2804
		return $this->tokenUse($token);
2805
	}
2806
 
2807
/**
2808
  * quit closes the connection to host 
2809
  *
2810
  * @author     Par0noid Solutions
2811
  * @return 	none
2812
  */
2813
	private function quit() {
2814
		$this->logout();
2815
		@fputs($this->runtime['socket'], "quit\n");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
2816
		@fclose($this->runtime['socket']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
2817
	}
2818
2819
/**
2820
  * selectServer
2821
  * 
2822
  * Selects the virtual server specified with sid or port to allow further interaction. The ServerQuery client will appear on the virtual server and acts like a real TeamSpeak 3 Client, except it's unable to send or receive voice data. If your database contains multiple virtual servers using the same UDP port, use will select a random virtual server using the specified port.
2823
  *
2824
  * @author     Par0noid Solutions
2825
  * @param		integer	$value		Port or ID
2826
  * @param		string	$type		value type ('port', 'serverId') (default='port')
2827
  * @param		boolean	$virtual	set true to add -virtual param [optional]
2828
  * @return     boolean success
2829
  */
2830
	function selectServer($value, $type = 'port', $virtual = false) { 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2831
        if(in_array($type, array('port', 'serverId'))) { 
2832
            if($type == 'port') { 
2833
                if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; } 
2834
                $res = $this->getData('boolean', 'use port='.$value.$virtual); 
2835
                if($res['success']) { 
2836
                    $this->runtime['selected'] = true; 
2837
                } 
2838
                return $res; 
2839
            }else{ 
2840
                if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; } 
2841
                $res = $this->getData('boolean', 'use sid='.$value.$virtual); 
2842
                if($res['success']) { 
2843
                    $this->runtime['selected'] = true; 
2844
                } 
2845
                return $res; 
2846
            } 
2847
        }else{ 
2848
            $this->addDebugLog('wrong value type'); 
2849
            return $this->generateOutput(false, array('Error: wrong value type'), false); 
2850
        } 
2851
    }
2852
2853
/**
2854
  * sendMessage
2855
  * 
2856
  * Sends a text message a specified target. The type of the target is determined by targetmode while target specifies the ID of the recipient, whether it be a virtual server, a channel or a client.
2857
  * <b>Hint:</b> You can just write to the channel the query client is in. See link in description for details.
2858
  *
2859
  * <b>Modes:</b>
2860
  * <ul>
2861
  * 	<li><b>1:</b> send to client</li>
2862
  * 	<li><b>2:</b> send to channel</li>
2863
  * 	<li><b>3:</b> send to server</li>
2864
  * </ul>
2865
  * <b>Targets:</b>
2866
  * <ul>
2867
  * 	<li>clientID</li>
2868
  * 	<li>channelID</li>
2869
  * 	<li>serverID</li>
2870
  * </ul>
2871
  *
2872
  * @author     Par0noid Solutions
2873
  * @param		integer $mode
2874
  * @param		integer $target
2875
  * @param		string	$msg	Message
2876
  * @see		http://forum.teamspeak.com/showthread.php/84280-Sendtextmessage-by-query-client http://forum.teamspeak.com/showthread.php/84280-Sendtextmessage-by-query-client
2877
  * @return     boolean	success
2878
  */
2879
	function sendMessage($mode, $target, $msg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2880
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2881
		return $this->getData('boolean', 'sendtextmessage targetmode='.$mode.' target='.$target.' msg='.$this->escapeText($msg));
2882
	}
2883
2884
/**
2885
  * serverCreate
2886
  * 
2887
  * Creates a new virtual server using the given properties and displays its ID, port and initial administrator privilege key. If virtualserver_port is not specified, the server will test for the first unused UDP port. The first virtual server will be running on UDP port 9987 by default. Subsequently started virtual servers will be running on increasing UDP port numbers.
2888
  * 
2889
  * <b>Input-Array like this:</b>
2890
  * <pre>
2891
  * $data = array();
2892
  *	
2893
  * $data['setting'] = 'value';
2894
  * $data['setting'] = 'value';
2895
  * </pre>
2896
  *
2897
  * <b>Output:</b>
2898
  * <pre>
2899
  * Array
2900
  * {
2901
  *  [sid] => 2
2902
  *  [virtualserver_port] => 9988
2903
  *  [token] => eKnFZQ9EK7G7MhtuQB6+N2B1PNZZ6OZL3ycDp2OW
2904
  * }
2905
  * </pre>
2906
  *
2907
  * @author     Par0noid Solutions
2908
  * @param		array	$data	serverSettings	[optional]
2909
  * @return     array serverInfo
2910
  */
2911
	function serverCreate($data = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2912
		$settingsString = '';
2913
		
2914
		if(count($data) == 0) {	$data['virtualserver_name'] = 'Teamspeak 3 Server'; }
2915
		
2916
		
2917
		foreach($data as $key => $value) {
2918
			if(!empty($value)) { $settingsString .= ' '.$key.'='.$this->escapeText($value); }
2919
		}
2920
		
2921
		return $this->getData('array', 'servercreate'.$settingsString);
2922
	}
2923
2924
/**
2925
  * serverDelete
2926
  * 
2927
  * Deletes the virtual server specified with sid. Please note that only virtual servers in stopped state can be deleted.
2928
  *
2929
  * @author     Par0noid Solutions
2930
  * @param		integer	$sid	serverID
2931
  * @return     boolean success
2932
  */
2933
	function serverDelete($sid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2934
		$this->serverStop($sid);
2935
		return $this->getdata('boolean', 'serverdelete sid='.$sid);
2936
	}
2937
2938
/**
2939
  * serverEdit
2940
  * 
2941
  * Changes the selected virtual servers configuration using given properties. Note that this command accepts multiple properties which means that you're able to change all settings of the selected virtual server at once.
2942
  *
2943
  * <b>Input-Array like this:</b>
2944
  * <pre>
2945
  * $data = array();
2946
  *	
2947
  * $data['setting'] = 'value';
2948
  * $data['setting'] = 'value';
2949
  * </pre>
2950
  *
2951
  * @author     Par0noid Solutions
2952
  * @param		array	$data	serverSettings
2953
  * @return     boolean success
2954
  */
2955 View Code Duplication
	function serverEdit($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2956
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2957
		
2958
		$settingsString = '';
2959
		
2960
		foreach($data as $key => $value) {
2961
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
2962
		}
2963
		
2964
		return $this->getData('boolean', 'serveredit'.$settingsString);
2965
	}
2966
2967
/**
2968
  * serverGroupAdd
2969
  * 
2970
  * Creates a new server group using the name specified with name and displays its ID. The optional type parameter can be used to create ServerQuery groups and template groups. For detailed information, see
2971
  *
2972
  * <b>Output:</b>
2973
  * <pre>
2974
  * Array
2975
  * {
2976
  *  [sgid] => 86
2977
  * }
2978
  * </pre>
2979
  *
2980
  * @author     Par0noid Solutions
2981
  * @param		integer $name	groupName
2982
  * @param		integer	$type	groupDbType (0 = template, 1 = normal, 2 = query | Default: 1)
2983
  * @return     array groupId
2984
  */
2985
	function serverGroupAdd($name, $type = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2986
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2987
		return $this->getData('array', 'servergroupadd name='.$this->escapeText($name).' type='.$type);
2988
	}
2989
2990
/**
2991
  * serverGroupAddClient
2992
  * 
2993
  * Adds a client to the server group specified with sgid. Please note that a client cannot be added to default groups or template groups.
2994
  *
2995
  * @author     Par0noid Solutions
2996
  * @param		integer $sgid	serverGroupId
2997
  * @param		integer $cldbid	clientDBID
2998
  * @return     boolean success
2999
  */
3000
	function serverGroupAddClient($sgid, $cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3001
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3002
		return $this->getData('boolean', 'servergroupaddclient sgid='.$sgid.' cldbid='.$cldbid);
3003
	}
3004
3005
/**
3006
  * serverGroupAddPerm
3007
  * 
3008
  * Adds a set of specified permissions to the server group specified with sgid. Multiple permissions can be added by providing the four parameters of each permission. A permission can be specified by permid or permsid.
3009
  *
3010
  * <b>Input-Array like this:</b>
3011
  * <pre>
3012
  * $permissions = array();
3013
  * $permissions['permissionID'] = array('permissionValue', 'permskip', 'permnegated');
3014
  * //or you could use
3015
  * $permissions['permissionName'] = array('permissionValue', 'permskip', 'permnegated');
3016
  * </pre>
3017
  * 
3018
  * @author     Par0noid Solutions
3019
  * @param		integer $sgid	serverGroupID
3020
  * @param		array	$permissions	permissions
3021
  * @return     boolean success
3022
  */
3023 View Code Duplication
	function serverGroupAddPerm($sgid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3024
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3025
		
3026
		if(count($permissions) > 0) {
3027
			//Permissions given
3028
				
3029
			//Errorcollector
3030
			$errors = array();
3031
				
3032
			//Split Permissions to prevent query from overload
3033
			$permissions = array_chunk($permissions, 50, true);
3034
				
3035
			//Action for each splitted part of permission
3036
			foreach($permissions as $permission_part)
3037
			{
3038
				//Create command_string for each command that we could use implode later
3039
				$command_string = array();
3040
		
3041
				foreach($permission_part as $key => $value)
3042
				{
3043
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value[0].' permskip='.$value[1].' permnegated='.$value[2];
3044
				}
3045
		
3046
				$result = $this->getData('boolean', 'servergroupaddperm sgid='.$sgid.' '.implode('|', $command_string));
3047
		
3048
				if(!$result['success'])
3049
				{
3050
					foreach($result['errors'] as $error)
3051
					{
3052
						$errors[] = $error;
3053
					}
3054
				}
3055
			}
3056
				
3057
			if(count($errors) == 0)
3058
			{
3059
				return $this->generateOutput(true, array(), true);
3060
			}else{
3061
				return $this->generateOutput(false, $errors, false);
3062
			}
3063
				
3064
		}else{
3065
			// No permissions given
3066
			$this->addDebugLog('no permissions given');
3067
			return $this->generateOutput(false, array('Error: no permissions given'), false);
3068
		}
3069
	}
3070
3071
/**
3072
  * serverGroupAutoAddPerm
3073
  * 
3074
  * Adds a set of specified permissions to *ALL* regular server groups on all virtual servers. The target groups will be identified by the value of their i_group_auto_update_type permission specified with sgtype. Multiple permissions can be added at once. A permission can be specified by permid or permsid. The known values for sgtype are: 10: Channel Guest 15: Server Guest 20: Query Guest 25: Channel Voice 30: Server Normal 35: Channel Operator 40: Channel Admin 45: Server Admin 50: Query Admin
3075
  *
3076
  * <b>Input-Array like this:</b>
3077
  * <pre>
3078
  * $permissions = array();
3079
  * $permissions['permissionID'] = array('permissionValue', 'permskip', 'permnegated');
3080
  * //or you could use
3081
  * $permissions['permissionName'] = array('permissionValue', 'permskip', 'permnegated');
3082
  * </pre>
3083
  * 
3084
  * @author     Par0noid Solutions
3085
  * @param		integer	$sgtype			serverGroupType
3086
  * @param		array	$permissions	permissions
3087
  * @return     boolean success
3088
  */
3089 View Code Duplication
	function serverGroupAutoAddPerm($sgtype, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3090
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3091
		
3092
		if(count($permissions) > 0) {
3093
			//Permissions given
3094
				
3095
			//Errorcollector
3096
			$errors = array();
3097
				
3098
			//Split Permissions to prevent query from overload
3099
			$permissions = array_chunk($permissions, 50, true);
3100
				
3101
			//Action for each splitted part of permission
3102
			foreach($permissions as $permission_part)
3103
			{
3104
				//Create command_string for each command that we could use implode later
3105
				$command_string = array();
3106
		
3107
				foreach($permission_part as $key => $value)
3108
				{
3109
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value[0].' permskip='.$value[1].' permnegated='.$value[2];
3110
				}
3111
		
3112
				$result = $this->getData('boolean', 'servergroupautoaddperm sgtype='.$sgtype.' '.implode('|', $command_string));
3113
		
3114
				if(!$result['success'])
3115
				{
3116
					foreach($result['errors'] as $error)
3117
					{
3118
						$errors[] = $error;
3119
					}
3120
				}
3121
			}
3122
				
3123
			if(count($errors) == 0)
3124
			{
3125
				return $this->generateOutput(true, array(), true);
3126
			}else{
3127
				return $this->generateOutput(false, $errors, false);
3128
			}
3129
				
3130
		}else{
3131
			// No permissions given
3132
			$this->addDebugLog('no permissions given');
3133
			return $this->generateOutput(false, array('Error: no permissions given'), false);
3134
		}
3135
	}
3136
3137
/**
3138
  * serverGroupAutoDeletePerm
3139
  * 
3140
  * Removes a set of specified permissions from *ALL* regular server groups on all virtual servers. The target groups will be identified by the value of their i_group_auto_update_type permission specified with sgtype. Multiple permissions can be removed at once. A permission can be specified by permid or permsid. The known values for sgtype are: 10: Channel Guest 15: Server Guest 20: Query Guest 25: Channel Voice 30: Server Normal 35: Channel Operator 40: Channel Admin 45: Server Admin 50: Query Admin
3141
  *
3142
  * <b>Input-Array like this:</b>
3143
  * <pre>
3144
  * $permissions = array();
3145
  * $permissions[] = 'permissionID';
3146
  * //or you could use
3147
  * $permissions[] = 'permissionName';
3148
  * </pre>
3149
  *
3150
  * @author     Par0noid Solutions
3151
  * @param		integer		$sgtype				serverGroupType
3152
  * @param		array		$permissions		permissions
3153
  * @return     boolean success
3154
  */
3155 View Code Duplication
	function serverGroupAutoDeletePerm($sgtype, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3156
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3157
		$permissionArray = array();
3158
		
3159
		if(count($permissions) > 0) {
3160
			foreach($permissions AS $value) {
3161
				$permissionArray[] = is_numeric($value) ? 'permid='.$value : 'permsid='.$this->escapeText($value);
3162
			}
3163
			return $this->getData('boolean', 'servergroupautodelperm sgtype='.$sgtype.' '.implode('|', $permissionArray));
3164
		}else{
3165
			$this->addDebugLog('no permissions given');
3166
			return $this->generateOutput(false, array('Error: no permissions given'), false);
3167
		}
3168
	}
3169
3170
/**
3171
  * serverGroupClientList
3172
  * 
3173
  * Displays the IDs of all clients currently residing in the server group specified with sgid. If you're using the optional -names option, the output will also contain the last known nickname and the unique identifier of the clients.
3174
  *
3175
  * <b>Possible params:</b> -names
3176
  *
3177
  * <b>Output: (with -names param)</b>
3178
  * <pre>
3179
  * Array
3180
  * {
3181
  *  [cldbid] => 2017
3182
  *  [client_nickname] => Par0noid //with -names parameter
3183
  *  [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
3184
  * }
3185
  * </pre>
3186
  *
3187
  * @author     Par0noid Solutions
3188
  * @param		integer	$sgid		groupId
3189
  * @param		boolean	$names		set true to add -names param [optional]
3190
  * @return     multidimensional-array	serverGroupClientList
0 ignored issues
show
Documentation introduced by
The doc-type multidimensional-array could not be parsed: Unknown type name "multidimensional-array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
3191
  */
3192
	function serverGroupClientList($sgid, $names = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3193
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3194
		if($names) { $names = ' -names'; }else{ $names = ''; }
3195
		return $this->getData('multi', 'servergroupclientlist sgid='.$sgid.$names);
3196
	}
3197
3198
/**
3199
  * serverGroupCopy
3200
  * 
3201
  * Creates a copy of the server group specified with ssgid. If tsgid is set to 0, the server will create a new group. To overwrite an existing group, simply set tsgid to the ID of a designated target group. If a target group is set, the name parameter will be ignored.
3202
  *
3203
  * <b>Output:</b>
3204
  * <pre>
3205
  * Array
3206
  * {
3207
  *  [sgid] => 86
3208
  * }
3209
  * </pre>
3210
  *
3211
  * @author     Par0noid Solutions
3212
  * @param		integer	$ssgid	sourceGroupID
3213
  * @param		integer	$tsgid	targetGroupID
3214
  * @param		integer $name	groupName
3215
  * @param		integer	$type	groupDbType (0 = template, 1 = normal, 2 = query | Default: 1)
3216
  * @return     array groupId
3217
  */
3218
	function serverGroupCopy($ssgid, $tsgid, $name, $type = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3219
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3220
		return $this->getData('array', 'servergroupcopy ssgid='.$ssgid.' tsgid='.$tsgid.' name='.$this->escapeText($name).' type='.$type);
3221
	}
3222
3223
/**
3224
  * serverGroupDelete
3225
  * 
3226
  * Deletes the server group specified with sgid. If force is set to 1, the server group will be deleted even if there are clients within.
3227
  *
3228
  * @author     Par0noid Solutions
3229
  * @param		integer $sgid	serverGroupID
3230
  * @param		integer $force 	forces deleting group (Default: 1)
3231
  * @return     boolean success
3232
  */
3233
	function serverGroupDelete($sgid, $force = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3234
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3235
		return $this->getData('boolean', 'servergroupdel sgid='.$sgid.' force='.$force);
3236
	}
3237
3238
/**
3239
  * serverGroupDeleteClient
3240
  * 
3241
  * Removes a client specified with cldbid from the server group specified with sgid.
3242
  *
3243
  * @author     Par0noid Solutions
3244
  * @param		integer $sgid	groupID
3245
  * @param		integer $cldbid	clientDBID
3246
  * @return     boolean success
3247
  */
3248
	function serverGroupDeleteClient($sgid, $cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3249
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3250
		return $this->getData('boolean', 'servergroupdelclient sgid='.$sgid.' cldbid='.$cldbid);
3251
	}
3252
3253
/**
3254
  * serverGroupDeletePerm
3255
  * 
3256
  * Removes a set of specified permissions from the server group specified with sgid. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
3257
  *
3258
  * <b>Input-Array like this:</b>
3259
  * <pre>
3260
  * $permissions = array();
3261
  * $permissions[] = 'permissionID';
3262
  * //or you could use
3263
  * $permissions[] = 'permissionName';
3264
  * </pre>
3265
  *
3266
  * @author     Par0noid Solutions
3267
  * @param		integer		$sgid				serverGroupID
3268
  * @param		array		$permissionIds		permissionIds
3269
  * @return     boolean success
3270
  */
3271 View Code Duplication
	function serverGroupDeletePerm($sgid, $permissionIds) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3272
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3273
		$permissionArray = array();
3274
		
3275
		if(count($permissionIds) > 0) {
3276
			foreach($permissionIds AS $value) {
3277
				$permissionArray[] = is_numeric($value) ? 'permid='.$value : 'permsid='.$this->escapeText($value);
3278
			}
3279
			return $this->getData('boolean', 'servergroupdelperm sgid='.$sgid.' '.implode('|', $permissionArray));
3280
		}else{
3281
			$this->addDebugLog('no permissions given');
3282
			return $this->generateOutput(false, array('Error: no permissions given'), false);
3283
		}
3284
	}
3285
3286
/**
3287
  * serverGroupList
3288
  * 
3289
  * Displays a list of server groups available. Depending on your permissions, the output may also contain global ServerQuery groups and template groups.
3290
  *
3291
  * <b>Output:</b>
3292
  * <pre>
3293
  * Array
3294
  * {
3295
  *  [sgid] => 1
3296
  *  [name] => Guest Server Query
3297
  *  [type] => 2
3298
  *  [iconid] => 0
3299
  *  [savedb] => 0
3300
  * }
3301
  * </pre>
3302
  *
3303
  * @author     Par0noid Solutions
3304
  * @return     array serverGroupList
3305
  */
3306
	function serverGroupList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3307
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3308
		return $this->getData('multi', 'servergrouplist');
3309
	}
3310
3311
/**
3312
  * serverGroupPermList
3313
  * 
3314
  * Displays a list of permissions assigned to the server group specified with sgid. If the permsid option is specified, the output will contain the permission names instead of the internal IDs.
3315
  *
3316
  * <b>Output:</b>
3317
  * <pre>
3318
  * Array
3319
  * {
3320
  *  [permid] => 12876 (if permsid = false)
3321
  *  [permsid] => b_client_info_view (if permsid = true)
3322
  *  [permvalue] => 1
3323
  *  [permnegated] => 0
3324
  *  [permskip] => 0
3325
  * }
3326
  * </pre>
3327
  *
3328
  * @author     Par0noid Solutions
3329
  * @param		integer	$sgid		serverGroupID
3330
  * @param		boolean	$permsid	set true to add -permsid param [optional]
3331
  * @return     array serverGroupPermList
3332
  */
3333
	function serverGroupPermList($sgid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3334
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3335
		if($permsid) { $additional = ' -permsid'; }else{ $additional = ''; }
3336
		return $this->getData('multi', 'servergrouppermlist sgid='.$sgid.$additional);
3337
	}
3338
3339
/**
3340
  * serverGroupRename
3341
  * 
3342
  * Changes the name of the server group specified with sgid.
3343
  *
3344
  * @author     Par0noid Solutions
3345
  * @param		integer $sgid	serverGroupID
3346
  * @param		integer $name	groupName
3347
  * @return     boolean success
3348
  */
3349
	function serverGroupRename($sgid, $name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3350
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3351
		return $this->getData('boolean', 'servergrouprename sgid='.$sgid.' name='.$this->escapeText($name));
3352
	}
3353
3354
/**
3355
  * serverGroupsByClientID
3356
  * 
3357
  * Displays all server groups the client specified with cldbid is currently residing in.
3358
  *
3359
  * <b>Output:</b>
3360
  * <pre>
3361
  * Array
3362
  * {
3363
  *  [name] => Guest
3364
  *  [sgid] => 73
3365
  *  [cldbid] => 2
3366
  * }
3367
  * </pre>
3368
  *
3369
  * @author     Par0noid Solutions
3370
  * @param		integer	$cldbid	clientDBID
3371
  * @return     array serverGroupsByClientId
3372
  */
3373
	function serverGroupsByClientID($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3374
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3375
		return $this->getData('multi', 'servergroupsbyclientid cldbid='.$cldbid);
3376
	}
3377
3378
/**
3379
  * serverIdGetByPort
3380
  * 
3381
  * Displays the database ID of the virtual server running on the UDP port specified by virtualserver_port.
3382
  * 
3383
  * <b>Output:</b>
3384
  * <pre>
3385
  * Array
3386
  * {
3387
  *  [server_id] => 1
3388
  * }
3389
  * </pre>
3390
  *
3391
  * @author     Par0noid Solutions
3392
  * @param		integer $port	serverPort
3393
  * @return     array serverInfo
3394
  */
3395
	function serverIdGetByPort($port) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3396
		return $this->getData('array', 'serveridgetbyport virtualserver_port='.$port);
3397
	}
3398
3399
/**
3400
  * serverInfo
3401
  * 
3402
  * Displays detailed configuration information about the selected virtual server including unique ID, number of clients online, configuration, etc.
3403
  *	
3404
  * <b>Output:</b>
3405
  * <pre>
3406
  * Array
3407
  * {
3408
  *  [virtualserver_unique_identifier] => 1GvKR12fg/mY75flwN/u7pn7KIs=
3409
  *  [virtualserver_name] => TeamSpeak ]I[ Server
3410
  *  [virtualserver_welcomemessage] => Welcome to TeamSpeak, check [URL]www.teamspeak.com[/URL] for latest information
3411
  *  [virtualserver_platform] => Windows
3412
  *  [virtualserver_version] => 3.0.12.4 [Build: 1461597405]
3413
  *  [virtualserver_maxclients] => 32
3414
  *  [virtualserver_password] => 
3415
  *  [virtualserver_clientsonline] => 2
3416
  *  [virtualserver_channelsonline] => 1
3417
  *  [virtualserver_created] => 0
3418
  *  [virtualserver_uptime] => 6517
3419
  *  [virtualserver_codec_encryption_mode] => 0
3420
  *  [virtualserver_hostmessage] => 
3421
  *  [virtualserver_hostmessage_mode] => 0
3422
  *  [virtualserver_filebase] => files\\virtualserver_1
3423
  *  [virtualserver_default_server_group] => 11
3424
  *  [virtualserver_default_channel_group] => 12
3425
  *  [virtualserver_flag_password] => 0
3426
  *  [virtualserver_default_channel_admin_group] => 9
3427
  *  [virtualserver_max_download_total_bandwidth] => 18446744073709551615
3428
  *  [virtualserver_max_upload_total_bandwidth] => 18446744073709551615
3429
  *  [virtualserver_hostbanner_url] => 
3430
  *  [virtualserver_hostbanner_gfx_url] => 
3431
  *  [virtualserver_hostbanner_gfx_interval] => 0
3432
  *  [virtualserver_complain_autoban_count] => 5
3433
  *  [virtualserver_complain_autoban_time] => 1200
3434
  *  [virtualserver_complain_remove_time] => 3600
3435
  *  [virtualserver_min_clients_in_channel_before_forced_silence] => 100
3436
  *  [virtualserver_priority_speaker_dimm_modificator] => -18.0000
3437
  *  [virtualserver_id] => 1
3438
  *  [virtualserver_antiflood_points_tick_reduce] => 5
3439
  *  [virtualserver_antiflood_points_needed_command_block] => 150
3440
  *  [virtualserver_antiflood_points_needed_ip_block] => 250
3441
  *  [virtualserver_client_connections] => 1
3442
  *  [virtualserver_query_client_connections] => 54
3443
  *  [virtualserver_hostbutton_tooltip] => 
3444
  *  [virtualserver_hostbutton_url] => 
3445
  *  [virtualserver_hostbutton_gfx_url] => 
3446
  *  [virtualserver_queryclientsonline] => 1
3447
  *  [virtualserver_download_quota] => 18446744073709551615
3448
  *  [virtualserver_upload_quota] => 18446744073709551615
3449
  *  [virtualserver_month_bytes_downloaded] => 0
3450
  *  [virtualserver_month_bytes_uploaded] => 16045
3451
  *  [virtualserver_total_bytes_downloaded] => 0
3452
  *  [virtualserver_total_bytes_uploaded] => 16045
3453
  *  [virtualserver_port] => 9987
3454
  *  [virtualserver_autostart] => 1
3455
  *  [virtualserver_machine_id] => 
3456
  *  [virtualserver_needed_identity_security_level] => 8
3457
  *  [virtualserver_log_client] => 0
3458
  *  [virtualserver_log_query] => 0
3459
  *  [virtualserver_log_channel] => 0
3460
  *  [virtualserver_log_permissions] => 1
3461
  *  [virtualserver_log_server] => 0
3462
  *  [virtualserver_log_filetransfer] => 0
3463
  *  [virtualserver_min_client_version] => 1445512488
3464
  *  [virtualserver_name_phonetic] => 
3465
  *  [virtualserver_icon_id] => 0
3466
  *  [virtualserver_reserved_slots] => 0
3467
  *  [virtualserver_total_packetloss_speech] => 0.0000
3468
  *  [virtualserver_total_packetloss_keepalive] => 0.0000
3469
  *  [virtualserver_total_packetloss_control] => 0.0000
3470
  *  [virtualserver_total_packetloss_total] => 0.0000
3471
  *  [virtualserver_total_ping] => 0.0000
3472
  *  [virtualserver_ip] => 
3473
  *  [virtualserver_weblist_enabled] => 1
3474
  *  [virtualserver_ask_for_privilegekey] => 0
3475
  *  [virtualserver_hostbanner_mode] => 0
3476
  *  [virtualserver_channel_temp_delete_delay_default] => 0
3477
  *  [virtualserver_min_android_version] => 1407159763
3478
  *  [virtualserver_min_ios_version] => 1407159763
3479
  *  [virtualserver_status] => online
3480
  *  [connection_filetransfer_bandwidth_sent] => 0
3481
  *  [connection_filetransfer_bandwidth_received] => 0
3482
  *  [connection_filetransfer_bytes_sent_total] => 0
3483
  *  [connection_filetransfer_bytes_received_total] => 0
3484
  *  [connection_packets_sent_speech] => 0
3485
  *  [connection_bytes_sent_speech] => 0
3486
  *  [connection_packets_received_speech] => 0
3487
  *  [connection_bytes_received_speech] => 0
3488
  *  [connection_packets_sent_keepalive] => 12959
3489
  *  [connection_bytes_sent_keepalive] => 531319
3490
  *  [connection_packets_received_keepalive] => 12959
3491
  *  [connection_bytes_received_keepalive] => 544277
3492
  *  [connection_packets_sent_control] => 396
3493
  *  [connection_bytes_sent_control] => 65555
3494
  *  [connection_packets_received_control] => 397
3495
  *  [connection_bytes_received_control] => 44930
3496
  *  [connection_packets_sent_total] => 13355
3497
  *  [connection_bytes_sent_total] => 596874
3498
  *  [connection_packets_received_total] => 13356
3499
  *  [connection_bytes_received_total] => 589207
3500
  *  [connection_bandwidth_sent_last_second_total] => 81
3501
  *  [connection_bandwidth_sent_last_minute_total] => 92
3502
  *  [connection_bandwidth_received_last_second_total] => 83
3503
  *  [connection_bandwidth_received_last_minute_total] => 88
3504
  * }
3505
  * </pre>
3506
  *
3507
  * @author     Par0noid Solutions
3508
  * @return     array serverInformation
3509
  */
3510
	function serverInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3511
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3512
		return $this->getData('array', 'serverinfo');
3513
	}
3514
3515
/**
3516
  * serverList
3517
  * 
3518
  * Displays a list of virtual servers including their ID, status, number of clients online, etc. If you're using the -all option, the server will list all virtual servers stored in the database. This can be useful when multiple server instances with different machine IDs are using the same database. The machine ID is used to identify the server instance a virtual server is associated with. The status of a virtual server can be either online, offline, deploy running, booting up, shutting down and virtual online. While most of them are self-explanatory, virtual online is a bit more complicated. Please note that whenever you select a virtual server which is currently stopped, it will be started in virtual mode which means you are able to change its configuration, create channels or change permissions, but no regular TeamSpeak 3 Client can connect. As soon as the last ServerQuery client deselects the virtual server, its status will be changed back to offline.
3519
  *
3520
  * <b>Possible params:</b> [-uid] [-short] [-all] [-onlyoffline]
3521
  *
3522
  * <b>Output:</b>
3523
  * <pre>
3524
  * Array
3525
  * {
3526
  *  [virtualserver_id] => 1 //displayed on -short
3527
  *  [virtualserver_port] => 9987 //displayed on -short
3528
  *  [virtualserver_status] => online //displayed on -short
3529
  *  [virtualserver_clientsonline] => 2
3530
  *  [virtualserver_queryclientsonline] => 1
3531
  *  [virtualserver_maxclients] => 32
3532
  *  [virtualserver_uptime] => 3045
3533
  *  [virtualserver_name] => TeamSpeak ]I[ Server
3534
  *  [virtualserver_autostart] => 1
3535
  *  [virtualserver_machine_id] =>
3536
  *  [-uid] => [virtualserver_unique_identifier] => bYrybKl/APfKq7xzpIJ1Xb6C06U= 
3537
  * }
3538
  * </pre>
3539
  *
3540
  * @author     Par0noid Solutions
3541
  * @param		string		$options		optional parameters
3542
  * @return     array serverList
3543
  */
3544
	function serverList($options = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3545
		return $this->getData('multi', 'serverlist'.(!empty($options) ? ' '.$options : ''));
3546
	}
3547
3548
/**
3549
  * serverProcessStop
3550
  * 
3551
  * Stops the entire TeamSpeak 3 Server instance by shutting down the process.
3552
  *
3553
  * @author     Par0noid Solutions
3554
  * @return     boolean success
3555
  */
3556
	function serverProcessStop() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3557
		return $this->getData('boolean', 'serverprocessstop');
3558
	}
3559
3560
/**
3561
  * serverRequestConnectionInfo
3562
  * 
3563
  * Displays detailed connection information about the selected virtual server including uptime, traffic information, etc.
3564
  *
3565
  * <b>Output:</b>
3566
  * <pre>
3567
  * Array
3568
  * {
3569
  *  [connection_filetransfer_bandwidth_sent] => 0
3570
  *  [connection_filetransfer_bandwidth_received] => 0
3571
  *  [connection_filetransfer_bytes_sent_total] => 0
3572
  *  [connection_filetransfer_bytes_received_total] => 0
3573
  *  [connection_packets_sent_total] => 3333
3574
  *  [connection_bytes_sent_total] => 149687
3575
  *  [connection_packets_received_total] => 3333
3576
  *  [connection_bytes_received_total] => 147653
3577
  *  [connection_bandwidth_sent_last_second_total] => 123
3578
  *  [connection_bandwidth_sent_last_minute_total] => 81
3579
  *  [connection_bandwidth_received_last_second_total] => 352
3580
  *  [connection_bandwidth_received_last_minute_total] => 87
3581
  *  [connection_connected_time] => 3387
3582
  *  [connection_packetloss_total] => 0.0000
3583
  *  [connection_ping] => 0.0000
3584
  * }
3585
  * </pre>
3586
  *
3587
  * @author     Par0noid Solutions
3588
  * @return     array serverRequestConnectionInfo
3589
  */
3590
	function serverRequestConnectionInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3591
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3592
		return $this->getData('array', 'serverrequestconnectioninfo');
3593
	}
3594
3595
/**
3596
  * serverSnapshotCreate
3597
  * 
3598
  * Displays a snapshot of the selected virtual server containing all settings, groups and known client identities. The data from a server snapshot can be used to restore a virtual servers configuration, channels and permissions using the serversnapshotdeploy command.
3599
  *
3600
  * @author     Par0noid Solutions
3601
  * @return     string snapshot
3602
  */
3603
	function serverSnapshotCreate() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3604
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3605
		return $this->getData('plain', 'serversnapshotcreate');
3606
	}
3607
3608
/**
3609
  * serverSnapshotDeploy
3610
  * 
3611
  * Restores the selected virtual servers configuration using the data from a previously created server snapshot. Please note that the TeamSpeak 3 Server does NOT check for necessary permissions while deploying a snapshot so the command could be abused to gain additional privileges.
3612
  *
3613
  * + added "-mapping" to the serversnapshotdeploy command. This optional parameters will add a mapping of the old and new channelid's in the return
3614
  *
3615
  * @author     Par0noid Solutions
3616
  * @param		string	$snapshot	snapshot
3617
  * @param		bool	$mapping	mapping [optional]
3618
  * @return     boolean success
3619
  */
3620
	function serverSnapshotDeploy($snapshot, $mapping = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3621
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3622
		return $this->getData('boolean', 'serversnapshotdeploy '.($mapping ? '-mapping ' : '').$snapshot);
3623
	}
3624
	
3625
/**
3626
  * serverStart
3627
  * 
3628
  * Starts the virtual server specified with sid. Depending on your permissions, you're able to start either your own virtual server only or all virtual servers in the server instance.
3629
  *
3630
  * @author     Par0noid Solutions
3631
  * @param		integer $sid	serverID
3632
  * @return     boolean success
3633
  */
3634
	function serverStart($sid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3635
		return $this->getdata('boolean', 'serverstart sid='.$sid);
3636
	}	
3637
3638
/**
3639
  * serverStop
3640
  * 
3641
  * Stops the virtual server specified with sid. Depending on your permissions, you're able to stop either your own virtual server only or all virtual servers in the server instance.
3642
  *
3643
  * @author     Par0noid Solutions
3644
  * @param		integer $sid	serverID
3645
  * @return     boolean success
3646
  */
3647
	function serverStop($sid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3648
		return $this->getdata('boolean', 'serverstop sid='.$sid);
3649
	}
3650
3651
/**
3652
  * serverTemppasswordAdd
3653
  * 
3654
  * Sets a new temporary server password specified with pw. The temporary password will be valid for the number of seconds specified with duration. The client connecting with this password will automatically join the channel specified with tcid. If tcid is set to 0, the client will join the default channel.
3655
  *
3656
  * @author     Par0noid Solutions
3657
  * @param		string	$pw				temporary password
3658
  * @param		string	$duration		durations in seconds
3659
  * @param		string	$desc			description [optional]
3660
  * @param		string	$tcid			cid user enters on connect (0 = Default channel) [optional]
3661
  * @param		string	$tcpw			channelPW
3662
  * @return     boolean success
3663
  */
3664
	function serverTempPasswordAdd($pw, $duration, $desc = 'none', $tcid = 0, $tcpw = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3665
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3666
		return $this->getdata('boolean', 'servertemppasswordadd pw='.$this->escapeText($pw).' desc='.(!empty($desc) ? $this->escapeText($desc) : 'none').' duration='.$duration.' tcid='.$tcid.(!empty($tcpw) ? ' tcpw='.$this->escapeText($tcpw) : ''));
3667
	}
3668
3669
/**
3670
  * serverTemppasswordDel
3671
  * 
3672
  * Deletes the temporary server password specified with pw.
3673
  * 
3674
  * @author     Par0noid Solutions
3675
  * @param		string	$pw		temporary password
3676
  * @return     boolean success
3677
  */	
3678
	function serverTempPasswordDel($pw) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3679
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3680
		return $this->getdata('boolean', 'servertemppassworddel pw='.$this->escapeText($pw));
3681
	}
3682
3683
/**
3684
  * serverTemppasswordList
3685
  * 
3686
  * Returns a list of active temporary server passwords. The output contains the clear-text password, the nickname and unique identifier of the creating client.
3687
  *
3688
  * <b>Output:</b>
3689
  * <pre>
3690
  * Array
3691
  * {
3692
  *  [nickname] => serveradmin
3693
  *  [uid] => 1
3694
  *  [desc] => none
3695
  *  [pw_clear] => test
3696
  *  [start] => 1334996838
3697
  *  [end] => 1335000438
3698
  *  [tcid] => 0
3699
  * }
3700
  * </pre>
3701
  *
3702
  * @author     Par0noid Solutions
3703
  * @return     array	serverTemppasswordList
3704
  */
3705
	function serverTempPasswordList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3706
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3707
		return $this->getData('multi', 'servertemppasswordlist');
3708
	}
3709
	
3710
3711
/**
3712
  *	setClientChannelGroup
3713
  *
3714
  * Sets the channel group of a client to the ID specified with cgid.
3715
  *
3716
  * @author     Par0noid Solutions
3717
  * @param		integer $cgid	groupID
3718
  * @param		integer $cid	channelID
3719
  * @param		integer $cldbid	clientDBID
3720
  * @return     boolean success
3721
  */
3722
	function setClientChannelGroup($cgid, $cid, $cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3723
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3724
		return $this->getData('boolean', 'setclientchannelgroup cgid='.$cgid.' cid='.$cid.' cldbid='.$cldbid);
3725
	}
3726
3727
/**
3728
  * setName
3729
  * 
3730
  * Sets your nickname in server query
3731
  *
3732
  * @author     Par0noid Solutions
3733
  * @param		string	$newName	new name in server query
3734
  * @return     boolean success
3735
  */
3736
	function setName($newName) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3737
		return $this->getData('boolean', 'clientupdate client_nickname='.$this->escapeText($newName));
3738
	}
3739
3740
/**
3741
  * tokenAdd
3742
  * 
3743
  * Create a new token. If tokentype is set to 0, the ID specified with tokenid1 will be a server group ID. Otherwise, tokenid1 is used as a channel group ID and you need to provide a valid channel ID using tokenid2. The tokencustomset parameter allows you to specify a set of custom client properties. This feature can be used when generating tokens to combine a website account database with a TeamSpeak user. The syntax of the value needs to be escaped using the ServerQuery escape patterns and has to follow the general syntax of:
3744
  * ident=ident1 value=value1|ident=ident2 value=value2|ident=ident3 value=value3
3745
  *
3746
  * <b>Input-Array like this:</b>
3747
  * <pre>
3748
  * $customFieldSet = array();
3749
  *	
3750
  * $customFieldSet['ident'] = 'value';
3751
  * $customFieldSet['ident'] = 'value';
3752
  * </pre>
3753
  *
3754
  * @author     Par0noid Solutions
3755
  * @param		integer	$tokentype				token type
3756
  * @param		integer	$tokenid1				groupID
3757
  * @param		integer	$tokenid2				channelID
3758
  * @param		string	$description			token description [optional]
3759
  * @param		array	$customFieldSet			customFieldSet [optional]
3760
  * @return     array	tokenInformation
3761
  */
3762
	function tokenAdd($tokentype, $tokenid1, $tokenid2, $description ='', $customFieldSet = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3763
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3764
		
3765
		if(!empty($description)) { $description = ' tokendescription=' . $this->escapeText($description); }
3766
3767
		if($tokentype == '0') { $tokenid2 = '0'; }
3768
		
3769
		if(count($customFieldSet)) {
3770
			$settingsString = array();
3771
		
3772
			foreach($customFieldSet as $key => $value) {
3773
				$settingsString[] = 'ident='.$this->escapeText($key).'\svalue='.$this->escapeText($value);
3774
			}
3775
			
3776
			$customFieldSet = ' tokencustomset='.implode('\p', $settingsString);
3777
		}else{
3778
			$customFieldSet = '';
3779
		}
3780
		
3781
		return $this->getData('array', 'privilegekeyadd tokentype='.$tokentype.' tokenid1='.$tokenid1.' tokenid2='.$tokenid2.$description.$customFieldSet);
3782
	}
3783
3784
/**
3785
  * tokenDelete
3786
  * 
3787
  * Deletes an existing token matching the token key specified with token.
3788
  *
3789
  * @author     Par0noid Solutions
3790
  * @param		string	$token	token
3791
  * @return     boolean success
3792
  */
3793
	function tokenDelete($token) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3794
		if(!$this->runtime['selected']) { return $this->checkSelected(); }			
3795
		return $this->getData('boolean', 'privilegekeydelete token='.$token);
3796
	}
3797
3798
/**
3799
  * tokenList
3800
  * 
3801
  * Displays a list of privilege keys available including their type and group IDs. Tokens can be used to gain access to specified server or channel groups. A privilege key is similar to a client with administrator privileges that adds you to a certain permission group, but without the necessity of a such a client with administrator privileges to actually exist. It is a long (random looking) string that can be used as a ticket into a specific server group.
3802
  *
3803
  * <b>Output:</b>
3804
  * <pre>
3805
  * Array
3806
  * {
3807
  *  [token] => GdqedxSEDle3e9+LtR3o9dO09bURH+vymvF5hOJg
3808
  *  [token_type] => 0
3809
  *  [token_id1] => 71
3810
  *  [token_id2] => 0
3811
  *  [token_created] => 1286625908
3812
  *  [token_description] => for you
3813
  * }
3814
  * </pre>
3815
  *
3816
  * @author     Par0noid Solutions
3817
  * @return     array tokenListist 
3818
  */
3819
	function tokenList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3820
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3821
3822
		return $this->getData('multi', 'privilegekeylist');
3823
	}
3824
3825
/**
3826
  * tokenUse
3827
  * 
3828
  * Use a token key gain access to a server or channel group. Please note that the server will automatically delete the token after it has been used.
3829
  *
3830
  * @author     Par0noid Solutions
3831
  * @param		string	$token	token
3832
  * @return     boolean success
3833
  */
3834
	function tokenUse($token) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3835
		if(!$this->runtime['selected']) { return $this->checkSelected(); }			
3836
		return $this->getData('boolean', 'privilegekeyuse token='.$token);
3837
	}
3838
3839
/**
3840
  * version
3841
  * 
3842
  * Displays the servers version information including platform and build number.
3843
  *
3844
  * <b>Output:</b>
3845
  * <pre>
3846
  * Array
3847
  * {
3848
  *  [version] => 3.0.6.1
3849
  *  [build] => 1340956745
3850
  *  [platform] => Windows
3851
  * }
3852
  * </pre>
3853
  *
3854
  * @author     Par0noid Solutions
3855
  * @return     array versionInformation
3856
  */
3857
	function version() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3858
		return $this->getData('array', 'version');
3859
	}
3860
3861
/**
3862
  * whoAmI
3863
  * 
3864
  * Displays information about your current ServerQuery connection including your loginname, etc.
3865
  *
3866
  * <b>Output:</b>
3867
  * <pre>
3868
  * Array
3869
  * {
3870
  *  [virtualserver_status] => online
3871
  *  [virtualserver_id] => 1
3872
  *  [virtualserver_unique_identifier] => bYrybKl/APfKq7xzpIJ1Xb6C06U=
3873
  *  [virtualserver_port] => 9987
3874
  *  [client_id] => 5
3875
  *  [client_channel_id] => 1
3876
  *  [client_nickname] => serveradmin from 127.0.0.1:15208
3877
  *  [client_database_id] => 1
3878
  *  [client_login_name] => serveradmin
3879
  *  [client_unique_identifier] => serveradmin
3880
  *  [client_origin_server_id] => 0
3881
  * }
3882
  * </pre>
3883
  *
3884
  * @author     Par0noid Solutions
3885
  * @return     array clientinformation
3886
  */
3887
	function whoAmI() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3888
		return $this->getData('array', 'whoami');
3889
	}
3890
3891
//*******************************************************************************************	
3892
//************************************ Helper Functions ************************************
3893
//*******************************************************************************************
3894
3895
/**
3896
  * checkSelected throws out 2 errors
3897
  *
3898
  * <b>Output:</b>
3899
  * <pre>
3900
  * Array
3901
  * {
3902
  *  [success] => false
3903
  *  [errors] => Array 
3904
  *  [data] => false
3905
  * }
3906
  * </pre>
3907
  *
3908
  * @author     Par0noid Solutions
3909
  * @return     array error
3910
  */
3911
	private function checkSelected() {
3912
		$backtrace = debug_backtrace();
3913
		$this->addDebugLog('you can\'t use this function if no server is selected', $backtrace[1]['function'], $backtrace[0]['line']);
3914
		return $this->generateOutput(false, array('you can\'t use this function if no server is selected'), false);
3915
	}
3916
3917
/**
3918
  * convertSecondsToStrTime
3919
  * 
3920
  * Converts seconds to a strTime (bsp. 5d 1h 23m 19s)
3921
  *
3922
  * @author     Par0noid Solutions
3923
  * @param		integer	$seconds	time in seconds
3924
  * @return     string strTime
3925
  */
3926
 	public function convertSecondsToStrTime($seconds) {
3927
		$conv_time = $this->convertSecondsToArrayTime($seconds);
3928
    	return $conv_time['days'].'d '.$conv_time['hours'].'h '.$conv_time['minutes'].'m '.$conv_time['seconds'].'s';
3929
	}
3930
3931
/**
3932
  * convertSecondsToArrayTime
3933
  * 
3934
  * Converts seconds to a array: time
3935
  *
3936
  * <b>Output:</b>
3937
  * <pre>
3938
  * Array
3939
  * {
3940
  *  [days] => 3
3941
  *  [hours] => 9
3942
  *  [minutes] => 45
3943
  *  [seconds] => 17
3944
  * }
3945
  * </pre>
3946
  *
3947
  * @author     Par0noid Solutions
3948
  * @param		integer	$seconds	time in seconds
3949
  * @return     array time
3950
  */
3951
 	public function convertSecondsToArrayTime($seconds) {
3952
		$conv_time = array();
3953
		$conv_time['days']=floor($seconds / 86400);
3954
		$conv_time['hours']=floor(($seconds - ($conv_time['days'] * 86400)) / 3600);
3955
		$conv_time['minutes']=floor(($seconds - (($conv_time['days'] * 86400)+($conv_time['hours']*3600))) / 60);
3956
		$conv_time['seconds']=floor(($seconds - (($conv_time['days'] * 86400)+($conv_time['hours']*3600)+($conv_time['minutes'] * 60))));
3957
		return $conv_time;
3958
	}
3959
3960
/**
3961
  * getElement
3962
  * 
3963
  * Returns the given associated element from an array
3964
  * This can be used to get a result in a one line operation
3965
  * 
3966
  * For example you got this array:
3967
  * <pre>
3968
  * Array
3969
  * {
3970
  *  [success] => false
3971
  *  [errors] => Array 
3972
  *  [data] => false
3973
  * }
3974
  * </pre>
3975
  * Now you can grab the element like this:
3976
  * <pre>
3977
  * $ts = new ts3admin('***', '***');
3978
  * 
3979
  * if($ts->getElement('success', $ts->connect())) {
3980
  *  //operation
3981
  * }
3982
  * </pre>
3983
  *
3984
  * @author     Par0noid Solutions
3985
  * @param		string	$element	key of element
3986
  * @param		array	$array		array
3987
  * @return     mixed
3988
  */
3989
	public function getElement($element, $array) {
3990
		return $array[$element];
3991
	}
3992
3993
/**
3994
  * succeeded
3995
  * 
3996
  * Succeeded will check the success element of a return array
3997
  * <pre>
3998
  * $ts = new ts3admin('***', '***');
3999
  * 
4000
  * if($ts->succeeded($ts->connect())) {
4001
  *  //operation
4002
  * }
4003
  * </pre>
4004
  *
4005
  * @author     Par0noid Solutions
4006
  * @param		array	$array	result
4007
  * @return     boolean
4008
  */
4009
	public function succeeded($array) {
4010
		if(isset($array['success'])) {
4011
			return $array['success'];
4012
		}else{
4013
			return false;
4014
		}
4015
	}
4016
	
4017
	
4018
4019
//*******************************************************************************************	
4020
//*********************************** Internal Functions ************************************
4021
//*******************************************************************************************
4022
4023
/**
4024
 * __construct
4025
 * 
4026
 * @author	Par0noid Solutions
4027
 * @param	string	$host		ts3host
4028
 * @param	integer	$queryport	ts3queryport
4029
 * @param	integer	$timeout	socket timeout (default = 2) [optional]
4030
 * @return	void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
4031
*/
4032
	function __construct($host, $queryport, $timeout = 2) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4033
		if($queryport >= 1 and $queryport <= 65536) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
4034
			if($timeout >= 1) {
4035
				$this->runtime['host'] = $host;
4036
				$this->runtime['queryport'] = $queryport;
4037
				$this->runtime['timeout'] = $timeout;
4038
			}else{
4039
				$this->addDebugLog('invalid timeout value');
4040
			}
4041
		}else{
4042
			$this->addDebugLog('invalid queryport');
4043
		}
4044
	}
4045
4046
/**
4047
 * __destruct
4048
 * 
4049
 * @author	Par0noid Solutions
4050
 * @return	void
4051
*/
4052
	function __destruct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4053
		$this->quit();
4054
	}
4055
4056
/**
4057
 * __call
4058
 * 
4059
 * prevents your website from php errors if you want to execute a method which doesn't exists
4060
 * 
4061
 * @author	Par0noid Solutions
4062
 * @param	string	$name	method name
4063
 * @param	array	$args	method arguments
4064
 * @return	void
4065
*/
4066
	function __call($name, $args) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4067
		$this->addDebugLog('Method '.$name.' doesn\'t exist', $name, 0);
4068
		return $this->generateOutput(false, array('Method '.$name.' doesn\'t exist'), false);
4069
	}
4070
4071
/**
4072
  * isConnected
4073
  * 
4074
  * Checks if the connection is established
4075
  *
4076
  * @author     Par0noid Solutions
4077
  * @return     boolean connected
4078
  */
4079
	private function isConnected() {
4080
		if(empty($this->runtime['socket'])) {
4081
			return false;
4082
		}else{
4083
			return true;
4084
		}
4085
	}
4086
4087
/**
4088
  * generateOutput
4089
  * 
4090
  * Builds a method return as array
4091
  *
4092
  * @author     Par0noid Solutions
4093
  * @param		boolean		$success	true/false
4094
  * @param		array		$errors		all errors which occured while executing a method
4095
  * @param		mixed		$data		parsed data from server
4096
  * @return     array output
4097
  */
4098
	private function generateOutput($success, $errors, $data) {
4099
		return array('success' => $success, 'errors' => $errors, 'data' => $data);
4100
	}
4101
4102
/**
4103
  * unEscapeText
4104
  * 
4105
  * Turns escaped chars to normals
4106
  *
4107
  * @author     Par0noid Solutions
4108
  * @param		string	$text	text which should be escaped
4109
  * @return     string	text
4110
  */
4111
 	private function unEscapeText($text) {
4112
 		$escapedChars = array("\t", "\v", "\r", "\n", "\f", "\s", "\p", "\/");
4113
 		$unEscapedChars = array('', '', '', '', '', ' ', '|', '/');
4114
		$text = str_replace($escapedChars, $unEscapedChars, $text);
4115
		return $text;
4116
	}
4117
4118
/**
4119
  * escapeText
4120
  * 
4121
  * Escapes chars that we can use it in the query
4122
  *
4123
  * @author     Par0noid Solutions
4124
  * @param		string	$text	text which should be escaped
4125
  * @return     string	text
4126
  */
4127
 	private function escapeText($text) {
4128
 		$text = str_replace("\t", '\t', $text);
4129
		$text = str_replace("\v", '\v', $text);
4130
		$text = str_replace("\r", '\r', $text);
4131
		$text = str_replace("\n", '\n', $text);
4132
		$text = str_replace("\f", '\f', $text);
4133
		$text = str_replace(' ', '\s', $text);
4134
		$text = str_replace('|', '\p', $text);
4135
		$text = str_replace('/', '\/', $text);
4136
		return $text;
4137
	}
4138
4139
/**
4140
  * splitBanIds
4141
  * 
4142
  * Splits banIds to array
4143
  *
4144
  * @author     Par0noid Solutions
4145
  * @param		string	$text	plain text server response
4146
  * @return     string	text
4147
  */
4148
 	private function splitBanIds($text) {
4149
		$data = array();
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
4150
		$text = str_replace(array("\n", "\r"), '', $text);
4151
		$ids = explode("banid=", $text);
4152
		unset($ids[0]);
4153
		return $ids;
4154
	}
4155
4156
//*******************************************************************************************	
4157
//************************************ Network Functions ************************************
4158
//*******************************************************************************************
4159
4160
/**
4161
  * connect
4162
  * 
4163
  * Connects to a ts3instance query port
4164
  *
4165
  * @author     Par0noid Solutions
4166
  * @return		boolean success
4167
  */
4168
	function connect() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4169
		if($this->isConnected()) { 
4170
			$this->addDebugLog('Error: you are already connected!');
4171
			return $this->generateOutput(false, array('Error: the script is already connected!'), false);
4172
		}
4173
		$socket = @fsockopen($this->runtime['host'], $this->runtime['queryport'], $errnum, $errstr, $this->runtime['timeout']);
4174
4175
		if(!$socket) {
4176
			$this->addDebugLog('Error: connection failed!');
4177
			return $this->generateOutput(false, array('Error: connection failed!', 'Server returns: '.$errstr), false);
4178
		}else{
4179
			if(strpos(fgets($socket), 'TS3') !== false) {
4180
				$tmpVar = fgets($socket);
0 ignored issues
show
Unused Code introduced by
$tmpVar is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
4181
				$this->runtime['socket'] = $socket;
4182
				return $this->generateOutput(true, array(), true);
4183
			}else{
4184
				$this->addDebugLog('host isn\'t a ts3 instance!');
4185
				return $this->generateOutput(false, array('Error: host isn\'t a ts3 instance!'), false);
4186
			}
4187
		}
4188
	}
4189
4190
/**
4191
  * executeCommand
4192
  * 
4193
  * Executes a command and fetches the response
4194
  *
4195
  * @author     Par0noid Solutions
4196
  * @param		string	$command	command which should be executed
4197
  * @param		array	$tracert	array with information from first exec
4198
  * @return     mixed data
4199
  */
4200
	private function executeCommand($command, $tracert) {
4201
		if(!$this->isConnected()) {
4202
			$this->addDebugLog('script isn\'t connected to server', $tracert[1]['function'], $tracert[0]['line']);
4203
			return $this->generateOutput(false, array('Error: script isn\'t connected to server'), false);
4204
		}
4205
		
4206
		$data = '';
4207
4208
		
4209
		$splittedCommand = str_split($command, 1024);
4210
		
4211
		$splittedCommand[(count($splittedCommand) - 1)] .= "\n";
4212
		
4213
		foreach($splittedCommand as $commandPart) {
4214
			fputs($this->runtime['socket'], $commandPart);
4215
		}
4216
4217
		do {
4218
			$data .= fgets($this->runtime['socket'], 4096);
4219
			
4220
			if(strpos($data, 'error id=3329 msg=connection') !== false) {
4221
				$this->runtime['socket'] = '';
4222
				$this->addDebugLog('You got banned from server. Socket closed.', $tracert[1]['function'], $tracert[0]['line']);
4223
				return $this->generateOutput(false, array('You got banned from server. Connection closed.'), false);
4224
			}
4225
			
4226
		} while(strpos($data, 'msg=') === false or strpos($data, 'error id=') === false);
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
4227
4228
		if(strpos($data, 'error id=0 msg=ok') === false) {
4229
			$splittedResponse = explode('error id=', $data);
4230
			$chooseEnd = count($splittedResponse) - 1;
4231
			
4232
			$cutIdAndMsg = explode(' msg=', $splittedResponse[$chooseEnd]);
4233
			
4234
			$this->addDebugLog('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1]), $tracert[1]['function'], $tracert[0]['line']);
4235
			
4236
			return $this->generateOutput(false, array('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1])), false);
4237
		}else{
4238
			return $this->generateOutput(true, array(), $data);
4239
		}
4240
	}
4241
4242
/**
4243
 * getData
4244
 * 
4245
 * Parses data from query and returns an array
4246
 * 
4247
 * @author		Par0noid Solutions
4248
 * @access		private
4249
 * @param		string	$mode		select return mode ('boolean', 'array', 'multi', 'plain')
4250
 * @param		string	$command	command which should be executed
4251
 * @return		mixed data
4252
 */
4253
	private function getData($mode, $command) {
4254
	
4255
		$validModes = array('boolean', 'array', 'multi', 'plain');
4256
	
4257
		if(!in_array($mode, $validModes)) {
4258
			$this->addDebugLog($mode.' is an invalid mode');
4259
			return $this->generateOutput(false, array('Error: '.$mode.' is an invalid mode'), false);
4260
		}
4261
		
4262 View Code Duplication
		if(empty($command)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4263
			$this->addDebugLog('you have to enter a command');
4264
			return $this->generateOutput(false, array('Error: you have to enter a command'), false);
4265
		}
4266
		
4267
		$fetchData = $this->executeCommand($command, debug_backtrace());
4268
		
4269
		
4270
		$fetchData['data'] = str_replace(array('error id=0 msg=ok', chr('01')), '', $fetchData['data']);
4271
		
4272
		
4273
		if($fetchData['success']) {
4274
			if($mode == 'boolean') {
4275
				return $this->generateOutput(true, array(), true);
4276
			}
4277
			
4278
			if($mode == 'array') {
4279
				if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
4280
				$datasets = explode(' ', $fetchData['data']);
4281
				
4282
				$output = array();
4283
				
4284 View Code Duplication
				foreach($datasets as $dataset) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4285
					$dataset = explode('=', $dataset);
4286
					
4287
					if(count($dataset) > 2) {
4288
						for($i = 2; $i < count($dataset); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
4289
							$dataset[1] .= '='.$dataset[$i];
4290
						}
4291
						$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
4292
					}else{
4293
						if(count($dataset) == 1) {
4294
							$output[$this->unEscapeText($dataset[0])] = '';
4295
						}else{
4296
							$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
4297
						}
4298
						
4299
					}
4300
				}
4301
				return $this->generateOutput(true, array(), $output);
4302
			}
4303
			if($mode == 'multi') {
4304
				if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
4305
				$datasets = explode('|', $fetchData['data']);
4306
				
4307
				$output = array();
4308
				
4309
				foreach($datasets as $datablock) {
4310
					$datablock = explode(' ', $datablock);
4311
					
4312
					$tmpArray = array();
4313
					
4314 View Code Duplication
					foreach($datablock as $dataset) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4315
						$dataset = explode('=', $dataset);
4316
						if(count($dataset) > 2) {
4317
							for($i = 2; $i < count($dataset); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
4318
								$dataset[1] .= '='.$dataset[$i];
4319
							}
4320
							$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
4321
						}else{
4322
							if(count($dataset) == 1) {
4323
								$tmpArray[$this->unEscapeText($dataset[0])] = '';
4324
							}else{
4325
								$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
4326
							}
4327
						}					
4328
					}
4329
					$output[] = $tmpArray;
4330
				}
4331
				return $this->generateOutput(true, array(), $output);
4332
			}
4333
			if($mode == 'plain') {
4334
				return $fetchData;
4335
			}
4336
		}else{
4337
			return $this->generateOutput(false, $fetchData['errors'], false);
4338
		}
4339
	}
4340
4341
/**
4342
  * ftSendKey
4343
  * 
4344
  * Sends down/upload-key to ftHost
4345
  * 
4346
  * @author     Par0noid Solutions
4347
  * @param		string	$key
4348
  * @param		string $additional
4349
  * @return     none
4350
 */
4351
	private function ftSendKey($key, $additional = NULL) {
4352
		fputs($this->runtime['fileSocket'], $key.$additional);
4353
	}
4354
4355
/**
4356
  * ftSendData
4357
  * 
4358
  * Sends data to ftHost
4359
  * 
4360
  * @author     Par0noid Solutions
4361
  * @param		mixed	$data
4362
  * @return     none
4363
 */
4364
	private function ftSendData($data) {
4365
		$data = str_split($data, 4096);
4366
		foreach($data as $dat) {
4367
			fputs($this->runtime['fileSocket'], $dat);
4368
		}
4369
	}
4370
4371
/**
4372
  * ftRead
4373
  * 
4374
  * Reads data from ftHost
4375
  * 
4376
  * @author     Par0noid Solutions
4377
  * @param		int	$size
4378
  * @return     string data
4379
 */
4380
	private function ftRead($size) {
4381
		$data = '';
4382
		while(strlen($data) < $size) {		
4383
			$data .= fgets($this->runtime['fileSocket'], 4096);
4384
		}
4385
		return $data;
4386
	}
4387
4388
//*******************************************************************************************	
4389
//************************************* Debug Functions *************************************
4390
//*******************************************************************************************
4391
4392
/**
4393
  * getDebugLog
4394
  * 
4395
  * Returns the debug log
4396
  *
4397
  * <b>Output:</b>
4398
  * <pre>
4399
  * Array
4400
  * {
4401
  *  [0] => Error in login() on line 1908: ErrorID: 520 | Message: invalid loginname or password
4402
  *  [1] => Error in selectServer() on line 2044: ErrorID: 1540 | Message: convert error
4403
  * }
4404
  * </pre>
4405
  *
4406
  * @author     Par0noid Solutions
4407
  * @return     array debugLog
4408
  */
4409
 	public function getDebugLog() {
4410
		return $this->runtime['debug'];
4411
	}
4412
4413
/**
4414
  * addDebugLog
4415
  * 
4416
  * Adds an entry to debugLog
4417
  *
4418
  * @author     Par0noid Solutions
4419
  * @param		string	$text			text which should added to debugLog
4420
  * @param		string	$methodName		name of the executed method [optional]
4421
  * @param		string	$line			line where error triggered [optional]
4422
  * @return     array debugLog
4423
  */
4424
	private function addDebugLog($text, $methodName = '', $line = '') {
4425
		if(empty($methodName) and empty($line)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
4426
			$backtrace = debug_backtrace();
4427
			$methodName = $backtrace[1]['function'];
4428
			$line = $backtrace[0]['line'];
4429
		}
4430
		$this->runtime['debug'][] = 'Error in '.$methodName.'() on line '.$line.': '.$text;	
4431
	}
4432
}
4433
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...