-
Notifications
You must be signed in to change notification settings - Fork 3
/
adr_party.php
400 lines (377 loc) · 14.5 KB
/
adr_party.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?php
/***************************************************************************
* adr_party.php
* ------------------------
* copyright : LagunaCid
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
***************************************************************************/
define('IN_PHPBB', true);
define('IN_ADR_CHARACTER', true);
define('IN_ADR_BATTLE', true);
define('IN_ADR_SHOPS', true);
define('IN_ADR_VAULT', true);
$phpbb_root_path = './';
include_once($phpbb_root_path . 'extension.inc');
include_once($phpbb_root_path . 'common.'.$phpEx);
$loc = 'character';
$sub_loc = 'adr_character';
//
// Start session management
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
// End session management
//
include_once($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
// Sorry , only logged users ...
if ( !$userdata['session_logged_in'] )
{
$redirect = "adr_character.$phpEx";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}
// V: basic checks
$adr_general = adr_get_general_config();
// Includes the tpl and the header
include_once($phpbb_root_path . 'includes/page_header.'.$phpEx);
include_once($phpbb_root_path . 'adr/includes/adr_header.'.$phpEx);
// Who is looking at this page ?
$user_id = $userdata['user_id'];
//V: wtf is $searchid?? or $view_userdata??
//$searchid = $view_userdata['user_id'];
$points = $userdata['user_points'];
$char = adr_get_user_infos($user_id);
adr_enable_check();
adr_ban_check($user_id);
adr_character_created_check($user_id);
// V: Guilds Mod Integration
// Get clan user belongs to!
$guild_id = adr_guild_get_by_user($user_id);
if ($guild_id) $guild = adr_guild_get($guild_id);
if (!$guild_id || empty($guild))
{
message_die(GENERAL_MESSAGE, 'Adr_Must_be_in_clan_to_party');
}
// Guilds mod END
?>
<table width=90% border=0 align="center" valign="center" bordercolor=black cellpadding="0" cellspacing="0">
<tr><td class="row2" align="center" valign="center">
<?php
// Actions
$action = !empty($_GET['action']) ? $_GET['action'] : '';
if($action == 'leave')
{
$can = 0;
// User is a Leader?
if($char['character_leader'] == 2)
{
// Is there any other leaders?
// V: exclude us...
$sql = 'SELECT character_id FROM '.ADR_CHARACTERS_TABLE.'
WHERE character_leader = 2
AND character_party = '.$char['character_party'].'
AND character_id != '.$char['character_id'];
$re = $db->sql_query($sql);
$row = $db->sql_fetchrow($re);
if($row['character_id']){$can = 1;}else{$can = 0;}
}
if($can == 1)
{
$sql = 'UPDATE '.ADR_CHARACTERS_TABLE.' SET character_party = 0, character_leader = 0 WHERE character_id = '.$user_id;
$re = $db->sql_query($sql) or die('Error on SQL Syntax');
$message = 'Vous avez quitté votre groupe avec succès';
$char['character_party'] = 0;
}
else
{
$message = 'Vous devez choisir un nouveau chef de groupe avant de partir !';
}
}
if($action == 'disband')
{
// User is a Leader?
if($char['character_leader'] == 2)
{
$can = 1;
}
if($can == 1)
{
$sql = 'UPDATE '.ADR_CHARACTERS_TABLE.'
SET character_party = 0, character_leader = 0
WHERE character_party = '.$char['character_party'];
$re = $db->sql_query($sql) or die('Error on SQL Syntax');
$message = 'Groupe dissout avec succès !';
$char['character_party'] = 0;
}
else
{
$message = 'Vous devez être le chef du groupe pour dissoudre votre groupe.';
}
}
if($action == 'create')
{
$can = 1;
// User is in a party?
if($char['character_party'] != 0)
{
$message = 'Vous devez d\'abord quitter votre groupe';
$can = 0;
}
// Lets Create.
$sql = "SELECT character_party FROM ".ADR_CHARACTERS_TABLE." ORDER BY character_party DESC LIMIT 1";
$re = $db->sql_query($sql) or die('SQL Error on line '.__LINE__);
$row = $db->sql_fetchrow($re);
$party_id = $row['character_party'] + 1;
if ($can)
{
$sql = 'UPDATE '.ADR_CHARACTERS_TABLE.'
SET character_party = '.$party_id.', character_leader = 2 WHERE character_id = '.$user_id;
$re = $db->sql_query($sql) or die('SQL Error on line '.__LINE__);
$char['character_party'] = $party_id;
$message = 'Votre groupe a été créé avec succès.';
}
}
if($action == 'invite')
{
$id = intval($_GET['id']);
$invite_guild_id = adr_guild_get_by_user($id);
if ($invite_guild_id != $guild_id)
{
message_die(GENERAL_MESSAGE, 'Adr_party_invite_only_clan');
}
$row = adr_get_user_infos($id);
if (!$row)
{
message_die(GENERAL_MESSAGE, 'Adr_party_no_such_char');
}
if (in_array($char['character_party'], explode('#', $row['character_invites'])))
{
$message = $lang['Adr_party_already_invited'];
}
else if ($row['character_party'] == $char['character_party'])
{
$message = $lang['Adr_party_already_member'];
}
else
{
$newstring = $row['character_invites'].'#'.$char['character_party'];
$sql = 'UPDATE '.ADR_CHARACTERS_TABLE.' SET character_invites = "'.$newstring.'" WHERE character_id = '.$id;
$re = $db->sql_query($sql) or die('SQL Query Error on line '.__LINE__);
$message = 'Vous avez invité '.$row['character_name'].' à rejoindre votre équipe. '.$row['character_name'].' recevra une notification en arrivant sur cette page.';
}
}
if($action == 'join')
{
$party_id = intval($_GET['party']);
// V: first, check we were invited...
$invites = $char['character_invites'];
$has_invite = in_array($party_id, explode('#', $invites));
if (!$has_invite)
{
message_die(GENERAL_MESSAGE, 'Adr_party_not_invited');
}
$sql = 'UPDATE '.ADR_CHARACTERS_TABLE.'
SET character_party = '.$party_id.',
character_invites = "",
character_leader = 0
WHERE character_id = '.$user_id;
$re = $db->sql_query($sql) or die('SQL Error on line '.__LINE__);
$message = 'Bienvenue dans le groupe !';
$char = adr_get_user_infos($user_id);
}
if($action == 'refuse')
{
$id = $_GET['party'];
$invites = $char['character_invites'];
$invites = explode('#',$invites);
for($i=0;$i<count($invites);$i++)
{
if($invites[$i] != $id){$newstring .= $invites[$i].'#';}
}
$newstring = substr($newstring,0,(strlen($newstring)-1));
$sql = 'UPDATE '.ADR_CHARACTERS_TABLE.' SET character_invites = "'.$newstring.'" WHERE character_id = '.$user_id;
$re = $db->sql_query($sql) or die('SQL Error on line '.__LINE__);
$message = 'Invitation refusée.';
$char['character_party'] = $id;
$char['character_leader'] = 0;
$char['character_invites'] = $newstring;
}
if($action == 'promote')
{
$id = $_GET['id'];
$sql = 'SELECT character_leader, character_name FROM '.ADR_CHARACTERS_TABLE.' WHERE character_id = '.$id.' AND character_party = '.$char['character_party'];
$re = $db->sql_query($sql);
$row = $db->sql_fetchrow($re);
if($char['character_leader'] > $row['character_leader'] && $char['character_leader'] > 0)
{
if($row['character_leader'] > 1){$plus = 2;}else{$plus = $row['character_leader'] + 1;}
$sql = 'UPDATE '.ADR_CHARACTERS_TABLE.' SET character_leader = '.$plus.' WHERE character_id = '.$id;
$re = $db->sql_query($sql) or die('SQL Error on line '.__LINE__);
$message = $row['character_name'].' a été promu.';
}
else
{
$message = 'Impossible de promulguer cet utilisateur.';
}
}
if($action == 'kick')
{
$sql = 'SELECT character_leader, character_name FROM '.ADR_CHARACTERS_TABLE.' WHERE character_id = '.intval($_GET['id']);
$re = $db->sql_query($sql);
$row = $db->sql_fetchrow($re);
if($char['character_leader'] > 0
&& ($char['character_leader'] > $rowset[$i]['character_leader'] || $guild['guild_leader_id'] == $user_id)
&& $adr_user['character_id'] != $rowset[$i]['character_id'])
{
$sql = 'UPDATE '.ADR_CHARACTERS_TABLE.' SET character_leader = 0, character_party = 0 WHERE character_id = '.$id.' AND character_party = '.$char['character_party'];
$re = $db->sql_query($sql) or die('SQL Error on line '.__LINE__);
$message = $row['character_name'].' a été renvoyé avec succès.';
}
else
{
$message = 'Impossible de renvoyer cet utilisateur.';
}
}
// Message Table
if (!empty($message))
{
?>
<table width=100% border=0 bordercolor=black cellpadding="0" cellspacing="0">
<tr><td class=row2><a name=party></a><span class=gen><center><b><?=$message?></td></tr>
</table>
<?php
}//end message table
// User is in a party?
if($char['character_party'] == 0)
{
?>
<table width=100% bordercolor=black border=0 cellpadding="0" cellspacing="0">
<th colspan=3>Vous n'êtes pas dans un groupe.</th>
<tr><td class="row1" colspan=3><center><input type=button class=liteoption value="Créer un groupe" onClick="window.location.href='./adr_party.php?action=create#party'"></td></tr>
<?php
?>
</table>
<?php
}
if($char['character_party'] != 0)
{
?><table width=100% border=0 bordercolor=black cellpadding="0" cellspacing="0">
<th colspan=3>Vous êtes dans un groupe.</th>
<tr><td class="row1" colspan=3><center><input type=button class=liteoption value="Quitter" onClick="window.location.href='./adr_party.php?action=leave#party'">
<?php if($char['character_leader'] == 2){ ?>
<input type=button class=liteoption value="Dissoudre" onClick="window.location.href='./adr_party.php?action=disband#party'">
<?php } ?></td></tr>
<th colspan=3>Membres :</th>
<?php
$sql = 'SELECT character_name, character_id, character_leader, character_level
FROM '.ADR_CHARACTERS_TABLE.'
WHERE character_party = '.$char['character_party'].'
ORDER BY character_leader DESC';
$re = $db->sql_query($sql);
$rowset = $db->sql_fetchrowset($re);
$party_level = 0; // sum of all the members level
$party_count = count($rowset);
for($i=0;$i<$party_count;$i++)
{
$party_level = $party_level + $rowset[$i]['character_level'];
if($char['character_leader'] > 0
&& ($char['character_leader'] > $rowset[$i]['character_leader'] || $guild['guild_leader_id'] == $user_id)
&& $adr_user['character_id'] != $rowset[$i]['character_id'])
{
$kick = '<td class="row1"><center><span class=gen><input type=button class=liteoption value="Renvoyer" onClick="window.location.href=\'./adr_party.php?action=kick&id='.$rowset[$i]['character_id'].'#party\'"></td>';
}
else if($char['character_leader'] > 0)
{
$kick = '<td class="row1"><center><span class=gen> </td>';
}
if($char['character_leader'] >= $rowset[$i]['character_leader']
&& $rowset[$i]['character_leader'] < 2
&& $char['character_leader'] != 0)
{
$promote = '<td class="row1"><center><span class=gen><input class=liteoption type=button value="Promouvoir" onClick="window.location.href=\'./adr_party.php?action=promote&id='.$rowset[$i]['character_id'].'\'"></td>';
}
else if($char['character_leader'] > 0)
{
$promote = '<td class="row1"><center><span class=gen> </td>';
}
if($rowset[$i]['character_leader'] == 0){$rank = '<span class=gen> (Membre)';}
if($rowset[$i]['character_leader'] == 1){$rank = '<span class=gen><i> (Officier)';}
if($rowset[$i]['character_leader'] == 2){$rank = '<span class=gen><b> (Chef)';}
?>
<tr><td class="row1"><span class=gen><center><?=$rowset[$i]['character_name']?> - Niveau: <?=$rowset[$i]['character_level']?> <?=$rank?></td><?=$kick?><?=$promote?></tr>
<?php
} // end for members
?><tr><td class="row1" colspan=3><span class=gen><center>Niveau total : <?=$party_level?> | Nombre de membres : <?=$party_count?> | Niveau moyen : <?=round($party_level/$party_count)?></td></tr></table><?php
if($char['character_leader'] > 0)
{
$sql = 'SELECT * FROM '.ADR_CHARACTERS_TABLE.'
INNER JOIN '.ADR_GUILD_MEMBER_TABLE.' gm
ON gm.guild_member_user_id = character_id
AND gm.guild_member_guild_id = '.$guild_id.'
WHERE character_party != '.$char['character_party'].'
ORDER BY character_name';
$result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Cannot query members', '', __LINE__, __FILE__, $sql);
$user_list = '';
foreach ($db->sql_fetchrowset($result) as $invitable_char)
{
$already_invited = in_array($char['character_party'], explode('#', $invitable_char['character_invites']));
if (!$already_invited)
{
$user_list .= '<option value='.$invitable_char['character_id'].'>'.$invitable_char['character_name'].' (ID: '.$invitable_char['character_id'].')</option>';
}
}
if ($user_list)
{
$user_list = '<select name=members>' . $user_list . '</select>';
?>
<table width=100% border=0 bordercolor=black cellpadding="0" cellspacing="0">
<th colspan=3>Inviter un compagnon de votre guilde.</th><th>Actions</th>
<tr><td class="row1" colspan=3><span class=gen><center><form name=form><?=$user_list?></td><td class="row1" colspan=3><input type=button class=liteoption value="Inviter !" onClick="window.location.href='./adr_party.php?action=invite&id='+form.members.value+'#party'"></form></td></tr>
</table>
<?php
}
}
}
else if($char['character_invites'] != '')
{
$invites = split('#',$char['character_invites']);
for($i=0;$i<count($invites);$i++)
{
if($invites[$i] != '')
{
$sql = 'SELECT character_name FROM '.ADR_CHARACTERS_TABLE.' WHERE character_party = '.$invites[$i].' AND character_leader = 2 LIMIT 1';
$re = $db->sql_query($sql);
$row = $db->sql_fetchrow($re);
$party_leader = $row['character_name'];
?>
<table width=100% border=0 bordercolor=black cellpadding="0" cellspacing="0"><th colspan=3>Invitations</th>
<tr>
<td class="row1" width="100%">Groupe de <?=$party_leader?></td>
<td class="row1">
<input type=button class=liteoption value="Accepter"
onClick="window.location.href='./adr_party.php?action=join&party=<?=$invites[$i]?>#party'">
</td>
<td class="row1">
<input type=button class=liteoption value="Refuser"
onClick="window.location.href='./adr_party.php?action=refuse&party=<?=$invites[$i]?>#party'">
</td></tr>
</table>
<script>alert('You have invitation(s) to join your party!');</script>
<?php
}
}
}
?>
</td></tr>
</table>
<?php
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);