-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsig.php
380 lines (337 loc) · 15.1 KB
/
sig.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
<?php
/***************************************************************************
*
* 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.
*
* Portions of this program are derived from publicly licensed software
* projects including, but not limited to phpBB, Magelo Clone,
* EQEmulator, EQEditor, and Allakhazam Clone.
*
* Author:
* Maudigan(Airwalking)
*
* February 24, 2014 - Changed items to png files (Maudigan c/o Warmonger)
* September 26, 2014 - Maudigan
* made STR/STA/DEX/etc lowercase to match the db column names
* Updated character table name
* rewrote the code that pulls guild name/rank
* altered character profile initialization to remove redundant query
***************************************************************************/
define('INCHARBROWSER', true);
include_once("include/config.php");
include_once("include/debug.php");
include_once("include/sql.php");
include_once("include/global.php");
include_once("include/language.php");
include_once("include/functions.php");
include_once("include/profile.php");
include_once("include/itemclass.php");
include_once("include/statsclass.php");
include_once("include/calculatestats.php");
global $game_db;
//exit now and post message if server doesnt have GD installed
if (!SERVER_HAS_GD) {
print $language['MESSAGE_NO_GD'];
exit();
}
//paths where files are saved
$path = array(
'BACKGROUND' => 'images/signatures/backgrounds/%s.png',
'BORDER' => 'images/signatures/borders/%s.png',
'SCREEN' => 'images/signatures/screens/%s.png',
'STATBORDER' => 'images/signatures/statborders/%s.png',
'EPICBORDER' => 'images/signatures/epicborders/%s.png',
//'EPIC' => 'images/items/item_%s.gif', //removed 2/24/2014
'EPIC' => 'images/items/item_%s.png', //added 2/24/2014
'FONT' => (SERVER_HAS_FREETYPE) ? 'fonts/%s.ttf' : 'fontsold/%s.gdf'
);
//convert passed hex color to RGB
function HexToRGB($hex) {
$hex = ereg_replace("#", "", $hex);
$color = array();
if(strlen($hex) == 3) {
$color['r'] = hexdec(substr($hex, 0, 1) . $r);
$color['g'] = hexdec(substr($hex, 1, 1) . $g);
$color['b'] = hexdec(substr($hex, 2, 1) . $b);
}
else if(strlen($hex) == 6) {
$color['r'] = hexdec(substr($hex, 0, 2));
$color['g'] = hexdec(substr($hex, 2, 2));
$color['b'] = hexdec(substr($hex, 4, 2));
}
return $color;
}
//get our starting values from _GET or presets
// several parameters are '-' delimited since mod_rewrite can only handle 9 parameters
$defaultcolor = array( 'r'=>255, 'g'=>255, 'b'=>255 );
$getone = explode("-", $_GET['one']);
$gettwo = explode("-", $_GET['two']);
$getstat = explode("-", $_GET['stat']);
$getbackground = explode("-", $_GET['background']);
$fontone = ($getone[0]) ? sprintf($path['FONT'], $getone[0]) : sprintf($path['FONT'], "roman") ;
$sizeone = ($getone[1]) ? $getone[1] : 20;
$colorone = ($getone[2]) ? HexToRGB($getone[2]) : $defaultcolor;
$shadowone = ($getone[3]) ? 1 : 0;
$fonttwo = ($gettwo[0]) ? sprintf($path['FONT'], $gettwo[0]) : sprintf($path['FONT'], "roman") ;
$sizetwo = ($gettwo[1]) ? $gettwo[1] : 10;
$colortwo = ($gettwo[2]) ? HexToRGB($gettwo[2]) : $defaultcolor;
$shadowtwo = ($gettwo[3]) ? 1 : 0;
$epicbg = ($_GET['epic']) ? sprintf($path['EPICBORDER'], $_GET['epic']) : false ;
$statdisplay = array();
$statdisplay[0] = ($getstat[2]) ? $getstat[2] : false ;
$statdisplay[1] = ($getstat[3]) ? $getstat[3] : false ;
$statdisplay[2] = ($getstat[4]) ? $getstat[4] : false ;
$statdisplay[3] = ($getstat[5]) ? $getstat[5] : false ;
$statdisplay[4] = ($getstat[6]) ? $getstat[6] : false ;
$statcolor = ($getstat[1]) ? HexToRGB($getstat[1]) : $defaultcolor;
$statbg = ($getstat[0]) ? sprintf($path['STATBORDER'], $getstat[0]) : false ;
$background = ($getbackground[1]) ? sprintf($path['BACKGROUND'], $getbackground[1]) : false;
$bgcolor = ($getbackground[0]) ? HexToRGB($getbackground[0]) : $defaultcolor;
$screen = ($getbackground[2]) ? sprintf($path['SCREEN'], $getbackground[2]) : false;
$border = ($_GET['border']) ? sprintf($path['BORDER'], $_GET['border']) : false;
//starting points of text
$line_start_x = 15;
$line_start_y = 12;
//stats constants, starting points, etc
$stat_start_x = 16;
$stat_start_y = 70;
$stat_step_x = 97;
$stat_width = 80;
$stat_height = 18;
$stat_text_y = 2;
$stat_text_x = 8;
//epic constants
$epic_x = 420;
$epic_y = 15;
$epic_icon_offset = 0;
$epic_width_height = 40;
$epic_icon_width_height = 40;
$signaturewidth = 500;
$signatureheight = 100;
//used for outputting errors since any text output will cause broken image links
//should be similar to message_die in functions.php
function png_message_die($error, $message) {
global $signaturewidth, $signatureheight, $defaultcolor;
$error_image = imagecreatetruecolor($signaturewidth, $signatureheight);
$error_color = imagecolorallocate($error_image, $defaultcolor['r'], $defaultcolor['g'], $defaultcolor['b']);
imagestring($error_image, 5, 10, 30, $error, $error_color);
imagestring($error_image, 2, 10, 50, $message, $error_color);
header("Content-Type: image/png");
imagepng($error_image);
ImageDestroy($error_image);
}
//if character name isnt provided post error message and exit
if(!$_GET['char']) png_message_die($language['MESSAGE_ERROR'],$language['MESSAGE_NO_CHAR']);
else $charName = $_GET['char'];
//character initializations - rewritten 9/28/2014
$char = new profile($charName); //the profile class will sanitize the character name
$charID = $char->char_id();
$mypermission = GetPermissions($char->GetValue('gm'), $char->GetValue('anon'), $char->char_id());
//block view if user level doesnt have permission
if ($mypermission['signatures'] && !isAdmin()) png_message_die($language['MESSAGE_ERROR'],$language['MESSAGE_ITEM_NO_VIEW']);
//load profile information for the character
$name = $char->GetValue('name');
$last_name = $char->GetValue('last_name');
$title = $char->GetValue('title');
$level = $char->GetValue('level');
$deity = $char->GetValue('deity');
$baseSTR = $char->GetValue('str'); //changed stats to lowercase 9/26/2014
$baseSTA = $char->GetValue('sta');
$baseAGI = $char->GetValue('agi');
$baseDEX = $char->GetValue('dex');
$baseWIS = $char->GetValue('wis');
$baseINT = $char->GetValue('int');
$baseCHA = $char->GetValue('cha');
$defense = $char->GetValue('defense'); //TODO multi row table
$offense = $char->GetValue('offense'); //TODO multi row table
$race = $char->GetValue('race');
$class = $char->GetValue('class');
$pp = $char->GetValue('platinum');
$gp = $char->GetValue('gold');
$sp = $char->GetValue('silver');
$cp = $char->GetValue('copper');
$bpp = $char->GetValue('platinum_bank');
$bgp = $char->GetValue('gold_bank');
$bsp = $char->GetValue('silver_bank');
$bcp = $char->GetValue('copper_bank');
//load guild name
$guild_name = '';
$guild_rank = '';
//rewritten because the guild id was removed from the profile 9/26/2014
$query = "SELECT guilds.name, guild_members.rank
FROM guilds
JOIN guild_members
ON guilds.id = guild_members.guild_id
WHERE guild_members.char_id = $charID LIMIT 1";
if (defined('DB_PERFORMANCE')) dbp_query_stat('query', $query); //added 9/28/2014
$results = $game_db->query($query);
if(numRows($results) != 0)
{
$row = fetchRows($results);
$guild_name = $row[0]['name'];
$guild_rank = $guildranks[$row[0]['rank']];
}
//place where all the items stats are added up
$itemstats = new stats();
// pull characters inventory slotid is loaded as
// "myslot" since items table also has a slotid field.
$query = "SELECT items.*, character_inventory.augslot1, character_inventory.augslot2, character_inventory.augslot3, character_inventory.augslot4, character_inventory.augslot5, character_inventory.slotid AS myslot from items, character_inventory where character_inventory.id = '$charID' AND items.id = character_inventory.itemid";
if (defined('DB_PERFORMANCE')) dbp_query_stat('query', $query); //added 9/28/2014
$results = $game_db->query($query);
foreach($results AS $row) {
$tempitem = new item($row);
for ($i = 1; $i <= 5; $i++) {
if ($row["augslot".$i]) {
$query = "SELECT * from items where id = ".$row["augslot".$i]." LIMIT 1";
if (defined('DB_PERFORMANCE')) dbp_query_stat('query', $query); //added 9/28/2014
$augresults = $game_db->query($query);
$augrow = fetchRows($augresults);
$itemstats->additem($augrow);
}
}
if ($tempitem->type() == EQUIPMENT)
$itemstats->additem($row);
}
$epicicon = '';
if ($epicbg) {
$query = "SELECT items.icon, items.id FROM items
JOIN titles ON items.id = titles.item_id
JOIN character_inventory ON items.id = character_inventory.itemid
WHERE character_inventory.id = $charID
AND titles.class = $class
ORDER BY items.id DESC
LIMIT 0, 1;";
if (defined('DB_PERFORMANCE')) dbp_query_stat('query', $query); //added 9/28/2014
$results = $game_db->query($query);
if ($row = fetchRows($results)) $epicicon = sprintf($path['EPIC'], $row[0]['icon']);
}
$chardata = array(
'FIRST_NAME' => $name,
'LAST_NAME' => $last_name,
'TITLE' => $title,
'GUILD_NAME' => $guild_name,
'GUILD_RANK' => $guild_rank,
'LEVEL' => $level,
'CLASS' => $dbclassnames[$class],
'RACE' => $dbracenames[$race],
'DEITY' => $dbdeities[$deity],
);
$stats = array(
'REGEN' => $itemstats->regen(),
'FT' => $itemstats->FT(),
'DS' => $itemstats->DS(),
'HASTE' => $itemstats->haste()."%",
'HP' => GetMaxHP($level,$class,($baseSTA+$itemstats->STA()),$itemstats->hp()),
'MANA' => GetMaxMana($level,$class,($baseINT+$itemstats->INT()),($baseWIS+$itemstats->WIS()),+$itemstats->mana()),
'ENDR' => GetMaxEndurance(($baseSTR+$itemstats->STR()),($baseSTA+$itemstats->STA()),($baseDEX+$itemstats->DEX()),($baseAGI+$itemstats->AGI()),$level,$itemstats->endurance()),
'AC' => GetMaxAC(($baseAGI+$itemstats->AGI()), $level, $defense, $class, $itemstats->AC(), $race),
'ATK' => GetMaxAtk($itemstats->attack(), ($baseSTR+$itemstats->STR()), $offense),
'STR' => ($baseSTR+$itemstats->STR()),
'STA' => ($baseSTA+$itemstats->STA()),
'DEX' => ($baseDEX+$itemstats->DEX()),
'AGI' => ($baseAGI+$itemstats->AGI()),
'INT' => ($baseINT+$itemstats->INT()),
'WIS' => ($baseWIS+$itemstats->WIS()),
'CHA' => ($baseCHA+$itemstats->CHA()),
'PR' => (PRbyRace($race)+$PRbyClass[$class]+$itemstats->PR()),
'FR' => (FRbyRace($race)+$FRbyClass[$class]+$itemstats->FR()),
'MR' => (MRbyRace($race)+$MRbyClass[$class]+$itemstats->MR()),
'DR' => (DRbyRace($race)+$DRbyClass[$class]+$itemstats->DR()),
'CR' => (CRbyRace($race)+$CRbyClass[$class]+$itemstats->CR()),
'WT' => round($itemstats->WT()/10)
);
/**************************************************
** DO NOT USE png_message_die past this point **
**************************************************/
//create image
$image = imagecreatetruecolor($signaturewidth, $signatureheight);
//apply background color
$bgcolor = imagecolorallocate($image, $bgcolor['r'], $bgcolor['g'], $bgcolor['b']);
imagefilledrectangle($image, 0, 0, $signaturewidth - 1, $signatureheight - 1, $bgcolor);
//apply background image
if ($background) {
$tempimage = imagecreatefrompng($background);
imagecopy($image, $tempimage, 0, 0, 0, 0, $signaturewidth, $signatureheight);
imagedestroy($tempimage);
}
//aply alpha screen to bg
if ($screen) {
$tempimage = imagecreatefrompng($screen);
imagecopy($image, $tempimage, 0, 0, 0, 0, $signaturewidth, $signatureheight);
imagedestroy($tempimage);
}
//drop epic on if an icon was set earlier
if($epicbg && $epicicon) {
$tempimage = imagecreatefrompng($epicbg);
imagecopy($image, $tempimage, $epic_x, $epic_y, 0, 0, $epic_width_height, $epic_width_height);
imagedestroy($tempimage);
//$tempimage = imagecreatefromgif($epicicon); //removed 2/24/2014
$tempimage = imagecreatefrompng($epicicon); //added 2/24/2014
imagecopy($image, $tempimage, $epic_x + $epic_icon_offset, $epic_y + $epic_icon_offset, 0, 0, $epic_icon_width_height , $epic_icon_width_height );
imagedestroy($tempimage);
}
// for drawing the 3 lines of text
$black = imagecolorallocate($image, 0, 0, 0);
function drawtext( $image, $text, $size, $font, $color, $offsetx, $offsety, $shadow) {
global $black;
$color = imagecolorallocate($image, $color['r'], $color['g'], $color['b']);
if (SERVER_HAS_FREETYPE) {
$bbox = imagettfbbox($size, 0, $font, $text);
$height = abs($bbox[1]) + abs($bbox[5]);
$width = abs($bbox[4]) + abs($bbox[0]);
$x = $offsetx + abs($bbox[0]);
$y = $offsety + abs($bbox[5]);
if ($shadow) imagettftext($image, $size, 0, $x+1, $y+1, $black, $font, $text);
imagettftext($image, $size, 0, $x, $y, $color, $font, $text);
}
else {
$hfont = ImageLoadFont($font);
$width = ImageFontWidth($hfont) * strlen($text);
$height = ImageFontHeight($hfont);
if ($shadow) imagestring($image, $hfont, $offsetx+1, $offsety+1, $text, $black);
imagestring($image, $hfont, $offsetx, $offsety, $text, $color);
}
return array( 'HEIGHT' => $height, 'WIDTH' => $width );
}
//draw line one
$ttftext = $chardata['FIRST_NAME']." ".$chardata['LAST_NAME'];
$ttfreturn = drawtext( $image, $ttftext, $sizeone, $fontone, $colorone, $line_start_x, $line_start_y, $shadowone);
$line_start_y += $ttfreturn['HEIGHT'];
//draw line two
$ttftext = $chardata['LEVEL']." ".$chardata['RACE']." ".$chardata['CLASS'];
$ttfreturn = drawtext( $image, $ttftext, $sizetwo, $fonttwo, $colortwo, $line_start_x, $line_start_y, $shadowtwo);
$line_start_y += $ttfreturn['HEIGHT'];
//draw line three
if ($chardata['GUILD_NAME']) {
$ttftext = $chardata['GUILD_RANK']." of ".$chardata['GUILD_NAME'];
$ttfreturn = drawtext( $image, $ttftext, $sizetwo, $fonttwo, $colortwo, $line_start_x, $line_start_y, $shadowtwo);
$line_start_y += $ttfreturn['HEIGHT'];
}
// draw stats and boxes
if ($statbg) {
$i = 0;
$statcolor = imagecolorallocate($image, $statcolor['r'], $statcolor['g'], $statcolor['b']);
foreach ($statdisplay as $key => $value) {
if ($value > "")
if (array_key_exists($value, $stats)) {
$stattext = $value." ".$stats[$value];
$tempimage = imagecreatefrompng($statbg);
imagecopy($image, $tempimage, $stat_start_x + $stat_step_x * $i , $stat_start_y, 0, 0, $stat_width, $stat_height);
imagestring($image, 2, $stat_text_x + $stat_start_x + $stat_step_x * $i , $stat_text_y + $stat_start_y, $stattext, $statcolor);
imagedestroy($tempimage);
}
$i++;
}
}
if ($border) {
$tempimage = imagecreatefrompng($border);
imagecopy($image, $tempimage, 0, 0, 0, 0, $signaturewidth, $signatureheight);
imagedestroy($tempimage);
}
header("Content-Type: image/png");
imagepng($image);
ImageDestroy($image);
?>