1 <?php
2 /**
3 * XLRstats : Real Time Player Stats (http://www.xlrstats.com)
4 * (CC) BY-NC-SA 2005-2013, Mark Weirath, Özgür Uysal
5 *
6 * Licensed under the Creative Commons BY-NC-SA 3.0 License
7 * Redistributions of files must retain the above copyright notice.
8 *
9 * @link http://www.xlrstats.com
10 * @license Creative Commons BY-NC-SA 3.0 License (http://creativecommons.org/licenses/by-nc-sa/3.0/)
11 * @package app.Controller
12 * @since XLRstats v3.0
13 * @version 0.1
14 */
15
16 class IpAliasesController extends AppController {
17
18 /**
19 * Models used
20 *
21 * @var array
22 */
23 public $uses = array('PlayerStat', 'IpAlias');
24
25 /**
26 * Helpers
27 *
28 * @var array
29 */
30 public $helpers = array(
31 'Js' => array('Jquery'),
32 );
33
34 /**
35 * Components
36 *
37 * @var array
38 */
39 public $components = array(
40 'GeoIP',
41 'RequestHandler',
42 'DataTable',
43 'Paginator',
44 );
45
46 //-------------------------------------------------------------------
47
48 /**
49 * Displays player's Ip aliases via dataTables.
50 *
51 * @param int $playerID is passed to the dataTable script's "sAjaxSource".
52 */
53 public function view($playerID = null) {
54 /* Prevent direct access to this method */
55 if (!$this->request->is('ajax')) {
56 $this->Session->setFlash(__('That was not a valid request...'), null, null, 'error');
57 $this->redirect(array('plugin' => null, 'admin' => false, 'controller' => 'pages', 'action' => 'display', 'server' => Configure::read('server_id'), 'home'));
58 }
59
60 $this->set('playerID', $playerID);
61 $this->layout = 'ajax';
62 }
63
64 //-------------------------------------------------------------------
65
66 /**
67 * Queries player IPs and pass data to view file json/ip_aliases_json.ctp
68 * to be processed by dataTables.
69 *
70 * Sample data returned:
71 * Array
72 * (
73 * [sEcho] => 1
74 * [iTotalRecords] => 2613
75 * [iTotalDisplayRecords] => 89
76 * [aaData] => Array
77 * (
78 * [0] => Array
79 * (
80 * [0] => Array
81 * (
82 * [0] => Array
83 * (
84 * [0] => gb //country code
85 * [1] => United Kingdom //country
86 * )
87 * [1] => 94.13.38.240 //ip
88 * )
89 * [1] => 1 //times used
90 * [2] => 1319984292 //time add
91 * [3] => 1319984292 //time edit
92 * )
93 * )
94 * )
95 *
96 * @param null $playerID player id
97 * @return mixed
98 */
99 public function ipAliasesJson($playerID = null) {
100 // Find correct B3 client ID ($b3ID) belonging to XLRstats player ID
101 $player = $this->PlayerStat->find('first', array(
102 'conditions' => array(
103 'PlayerStat.id' => $playerID,
104 )
105 )
106 );
107 $b3ID = $player['Player']['id'];
108
109 // Build conditions for player's Ipaliases
110 $conditions = array(
111 'IpAlias.client_id' => $b3ID,
112 //'IpAlias.inactive !=' => 1,
113 );
114
115 $this->paginate = array(
116 'fields' => array (
117 'IpAlias.ip',
118 'IpAlias.num_used',
119 'IpAlias.time_add',
120 'IpAlias.time_edit',
121 ),
122 'conditions' => $conditions,
123 );
124
125 $data = $this->DataTable->getResponse('IpAlias');
126
127 //Add flag information to the array
128 foreach ($data['aaData'] as $k => &$v) {
129 $v[0] = array($this->XlrFunctions->getFlag($v[0]), $v[0]);
130 }
131
132 //pr($data);
133
134 if ($this->request->is('requested')) {
135 return $data;
136 } else {
137 $this->set('ipAliases', $data);
138 }
139 return null;
140 }
141
142 }
143