-
Notifications
You must be signed in to change notification settings - Fork 0
/
adr_global_chat.php
291 lines (240 loc) · 11.1 KB
/
adr_global_chat.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
<?php
/***************************************************************************
* adr_global_chat.php
* ---------------------
* Version : 1.0.0
* Authors : aUsTiN
* [ ([email protected]) (http://phpbb-amod.com) ]
* Seteo-Bloke
* [ ([email protected]) (http://www.phpbb-adr.com) ]
*
***************************************************************************************/
define('IN_PHPBB', true);
define('IN_ADR_BATTLE', true);
define('IN_ADR_CHARACTER', true);
define('IN_ADR_SHOPS', true);
$phpbb_root_path = './';
include_once($phpbb_root_path . 'extension.inc');
include_once($phpbb_root_path . 'common.'.$phpEx);
include_once($phpbb_root_path . 'includes/bbcode.'. $phpEx);
$loc = 'battle_community';
$sub_loc = 'battle_community';
//
// Start session management
$userdata = session_pagestart($user_ip, PAGE_ADR);
init_userprefs($userdata);
// End session management
//
$user_id = $userdata['user_id'];
$user_points = $userdata['user_points'];
include_once($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
include_once($phpbb_root_path . 'adr/includes/adr_functions_global_chat.'.$phpEx);
// Sorry , only logged users
if(!$userdata['session_logged_in']){
$redirect = "adr_battle_community.$phpEx";
$redirect .= (isset($user_id)) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}
// Get the general config
$adr_general = adr_get_general_config();
$adr_user = adr_get_user_infos($user_id);
// Load the headers
$gen_simple_header = TRUE;
//include_once($phpbb_root_path .'includes/page_header.'. $phpEx);
adr_template_file('adr_global_chat_body.tpl');
$mode = ($_POST['mode']) ? $_POST['mode'] : $_POST['mode'];
if(!$mode)
$mode = ($_GET['mode']) ? $_GET['mode'] : $_GET['mode'];
$todays_chat_info = GC_GetTodaysChat();
$todays_chat = $todays_chat_info['chat_text'];
// Basic error checks before postings
$error_['1'] ='<i><font color="#FF0000">'.$lang['Adr_global_shout_error_1'].'</font></i><br><br>';
$error_['2'] ='<i><font color="#FF0000">'.$lang['Adr_global_shout_error_2'].'</font></i><br><br>';
$error_['3'] ='<i><font color="#FF0000">'.$lang['Adr_global_shout_error_3'].'</font></i><br><br>';
$error_['4'] ='<i><font color="#FF0000">'.$lang['Adr_global_shout_incorrect_user'].'</font></i><br><br>';
if($mode == 'archives'){
$template->assign_block_vars('archives', array(
'MSG' => 'Setup the archives here, with the header & footer included!'
));
}
if($mode == 'add')
{
$msg = ($_POST['msg']) ? $_POST['msg'] : $_POST['msg'];
#==== Check: did they post all spaces? ======================== |
$msg = trim($msg);
#==== Check: did they post? =================================== |
if(empty($msg)) $error_messages = '1';
#==== Check: max characters exceeded? ========================= |
$some_number = 250; # Make this a config value!
if(strlen($msg) > $some_number){
$over = ($some_number - $msg);
$error_messages = '2';
}
#==== Check: admin has posted a command sequence ========================= |
if($userdata['user_level'] == ADMIN){
// Checks if admin wants to instant kill a user.
// First 5 characters are '/kill', sixth is a space ' ' and then from 7 onwards we have the username
// Remember [0] is the first letter in the array
if(substr($msg, 0, 5) == '/kill'){
$username = substr($msg, 6);
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.adr_gc_admin_cmd_kill($username).'</i></font>';
}
// Revive user with full HP
elseif(substr($msg, 0, 7) == '/revive'){
$username = substr($msg, 8);
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.adr_gc_admin_cmd_revive($username).'</i></font>';
}
// Finish a users monster battle
elseif(substr($msg, 0, 10) == '/endallmon'){
$username = substr($msg, 11);
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.adr_admin_cmd_endallmon($username).'</i></font>';
}
// Finish a users all current PvP battles
elseif(substr($msg, 0, 10) == '/endallpvp'){
$username = substr($msg, 11);
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.adr_admin_cmd_endallpvp($username).'</i></font>';
}
// Finish one PvP battle. Pass battle_pvp_id for success
elseif(substr($msg, 0, 7) == '/endpvp'){
$battle_id = intval(substr($msg, 8));
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.adr_admin_cmd_endpvp($battle_id).'</i></font>';
}
// Instant ban a user from participating in ADR/RPG
elseif(substr($msg, 0, 4) == '/ban'){
// Find first instance of '?' within cmd to grab ban reason
$pos = strpos($msg, '?');
// Check if a '?' is present. If not show error msg
if(strpos($msg, '?')){
$reason = trim(substr(($pos + 1)));
$username = substr($msg, 5, ($pos - 6));
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.adr_admin_cmd_ban($username, $reason).'</i></font>';
}
else{
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.$lang['Adr_global_shout_error_3'].'</i></font>';
}
}
// Instant UNban a user from participating in ADR/RPG
elseif(substr($msg, 0, 6) == '/unban')
{
// Find first instance of '?' within cmd to grab ban reason
$pos = strpos($msg, '?');
// Check if a '?' is present. If not show error msg
if(strpos($msg, '?')){
$reason = trim(substr(($pos + 1)));
$username = trim(substr($msg, 7, ($pos - 8)));
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.adr_admin_cmd_unban($username, $reason).'</i></font>';
}
else{
$msg = '<font color="purple"><i><b>'.$lang['Adr_global_shout_adm_cmd'].' </b>'.$lang['Adr_global_shout_error_3'].'</i></font>';
}
}
}
#==== Check: wordwrapping the message? ======================== |
# This is so the kids can't stretch the page!
$msg = wordwrap($msg, 25, ' ', 1);
#==== Check for admin global shout ================================= |
$admin_shout = ((substr($msg, 0, 1) == '!') && ($userdata['user_level'] == ADMIN)) ? TRUE : FALSE;
$msg = ($admin_shout) ? substr_replace($msg, '', 0, 1) : $msg;
$msg = ($admin_shout) ? '<font color="#FF0000"><b>'.$msg.'</b></font>' : $msg;
$msg = ($admin_shout) ? strtoupper($msg) : $msg;
#==== Get Username To add to Message ================================= |
$umsg = ($admin_shout == FALSE) ? '<a href="profile.'. $phpEx .'?mode=viewprofile&u='. $adr_user['character_id'] .'" target="_blank">'. $adr_user['character_name'] .'</a>' : '<font color="#FF0000"><b>'.$lang['Adr_global_shout_announcer'].'</b></font>';
#==== check if shouter is a GM (admin)========|
$umsg = ($userdata['user_level'] == ADMIN) ? '<b>'. $umsg .'</b>' : $umsg;
#==== Check for emotes ================================= |
$emote_= (substr($msg, 0, 3) != "/me") ? FALSE : TRUE;
$clear_text_= ((substr($msg, 0, 6) == "/clear") && ($userdata['user_level'] == ADMIN)) ? TRUE : FALSE;
$killme_ = (substr($msg, 0, 7) != "/killme") ? FALSE : TRUE;
$pvpme_ = (substr($msg, 0, 6) != "/pvpme") ? FALSE : TRUE;
$vitals = (substr($msg, 0, 6) != '/stats') ? FALSE : TRUE;
if($emote_){
$msg = '<i>'.$umsg.' '.substr($msg, 4).'</i>';
}
elseif($clear_text_){
GC_clear_today_chat();
$error_messages = $lang['Adr_global_shout_error_no_log'];
}
elseif($killme_){
$killme_msg = substr($msg, 8);
$msg = '<i>'.sprintf($lang['Adr_global_shout_killme'], $adr_user['character_name'], $killme_msg).'</i>';
}
elseif($pvpme_){
$msg = '<font color="red"><b>'.sprintf($lang['Adr_global_shout_pvpme'], $adr_user['character_name']).'</b></font>';
}
elseif($vitals){
$username = substr($msg, 7);
$msg = '<i>'.adr_gc_admin_cmd_vitals($username).'</i>';
}
elseif(substr($msg, 0, 9) == '/realname'){
// Not complete
$character_name = substr($msg, 10);
$msg = sprintf($lang['Adr_global_shout_realname'], '<font color="purple"><i>', '<b>'.$character_name.'</b>', '<b>'.$username.'</b>', '</i></font>');
}
else{
$msg = $umsg.": ".'<font color="#0000FF">'.$msg.'</font>';
}
$msg = str_replace("\'", "''", $msg);
#==== Add Beginning & End To Message ========================== |
$msg = '%S%'. $msg;
$msg = $msg .'%E%';
#==== Escape ' ========================== |
$msg = addslashes($msg);
if($error_messages == "")
GC_AddChat($msg);
redirect('adr_global_chat.'. $phpEx.'?err='.$error_messages, TRUE);
exit;
}
// Include page header now to prevent redirect errors
include_once($phpbb_root_path .'includes/page_header.'. $phpEx);
if(!$mode){
if(!$todays_chat)
$todays_chat = '%S%*'.$lang['Adr_global_shout_error_no_log'].'*%E%';
#==== Word Censor Pass ======================================== |
$q = "SELECT * FROM ". WORDS_TABLE;
if(!$r = $db->sql_query($q))
message_die(GENERAL_ERROR, "Error Selecting Censored Word List.", "", __LINE__, __FILE__, $q);
while($row = $db->sql_fetchrow($r)){
if(eregi(quotemeta($row['word']), $todays_chat))
$todays_chat = str_replace($row['word'], $row['replacement'], $todays_chat);
}
#==== Generic BBCode Pass ===================================== |
# Did it this way so i wouldn't have to use bbcode_uid for each post
$todays_chat = str_replace('[b]', '<b>', $todays_chat);
$todays_chat = str_replace('[/b]', '</b>', $todays_chat);
$todays_chat = str_replace('[i]', '<i>', $todays_chat);
$todays_chat = str_replace('[/i]', '</i>', $todays_chat);
#==== HTML Block Pass ========================================= |
# This is done to prevent stretching the page or a redirect exploit.
$allowed = '<b><i><a><font>';
$todays_chat = strip_tags($todays_chat, $allowed);
#==== Starting Pass =========================================== |
$todays_chat = str_replace('%S%', '<tr><td class="row2" align="left" width="100%"><span class="genmed">', $todays_chat);
#==== Closing Pass ============================================ |
$todays_chat = str_replace('%E%', '</span></td></tr>', $todays_chat);
#==== Smilies Pass ============================================ |
if ($board_config['allow_smilies'])
$todays_chat = smilies_pass($todays_chat);
#==== Unquote where necessary ===================================== |
$todays_chat = stripslashes($todays_chat);
$chat_session = $todays_chat;
$error_messages = ($_POST['err']) ? $_POST['err'] : $_POST['err'];
if (!$error_messages)
$error_messages = ($_GET['err']) ? $_GET['err'] : $_GET['err'];
$error_messages = (!$error_messages) ? '' : $error_[$error_messages];
$template->assign_block_vars('chat_body', array(
'FORM' => append_sid("adr_global_chat.$phpEx"),
'TOP_L' => sprintf($lang['Adr_shoutbox_archive'], date('Y-m-d')),
'TOP_M' => ' : ',
'TOP_R' => '<a href="'. append_sid('adr_global_chat.'. $phpEx .'?mode=archives') .'">Archives</a>',
'MSG' => $lang['Adr_shoutbox_enter'],
'BUTTON' => $lang['Adr_shoutbox_shout'],
'ERROR' => $error_messages,
'TXT' => $chat_session,
'U_CHAT_VIEW' => append_sid("adr_global_chat.$phpEx")
));
}
$template->assign_vars(array(
'U_CHAT_VIEW' => append_sid("adr_global_chat.$phpEx")
));
$template->pparse('body');
?>