-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathcharacter.php
126 lines (98 loc) · 2.53 KB
/
character.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
<?php
/**
* @fileoverview character.php, display character
* @author Vincent Thibault (alias KeyWorld - Twitter: @robrowser)
* @version 1.0.0
*/
// Avoid direct access
defined("__ROOT__") OR die();
// Include Render class
require_once( __ROOT__ . 'render/class.CharacterRender.php' );
class Character_Controller extends Controller {
/**
* Load database, specify where to cache things
*/
public function __construct()
{
parent::loadDatabase();
Cache::setNamespace('character');
}
/**
* Process entry
*/
public function process($pseudo, $action = -1, $animation = -1)
{
header('Content-type:image/png');
header('Cache-Control: max-age='. Cache::$time .', public');
Cache::setFilename($pseudo . ".png");
$content = "";
// Load the cache file ?
if( Cache::get($content) ) {
die( $content );
}
// Find and render
$data = $this->getPlayerData($pseudo);
$this->render($data, $action, $animation);
// Cache
Cache::save();
}
/**
* Get player data from SQL
*/
private function getPlayerData($pseudo)
{
$data = $this->query("
SELECT
char.class, char.clothes_color,
char.hair, char.hair_color,
char.head_top, char.head_mid, char.head_bottom,
char.robe, char.weapon, char.shield,
char.option,
login.sex
FROM `char`
LEFT JOIN `login` ON login.account_id = char.account_id
WHERE char.name = ?
LIMIT 1",
array($pseudo)
);
// No character found ? Load a default character ?
if( empty($data) ) {
// Store file, not needed to recalculate it each time
Cache::setFilename("[notfound].png");
$content = "";
if( Cache::get($content) ) {
die($content);
}
return array(
"class" => 0,
"clothes_color" => 0,
"hair" => 2,
"hair_color" => 0,
"head_top" => 0,
"head_mid" => 0,
"head_bottom" => 0,
"robe" => 0,
"weapon" => 0,
"shield" => 0,
"sex" => "M"
);
}
return $data[0];
}
/**
* Render avatar
*/
private function render($data, $action, $animation)
{
// Load Class and set parameters
$chargen = new CharacterRender();
$chargen->action = $action == -1 ? CharacterRender::ACTION_READYFIGHT : intval($action);
$chargen->direction = $animation == -1 ? CharacterRender::DIRECTION_SOUTHEAST : intval($animation);
$chargen->body_animation = 4;
$chargen->doridori = 0;
// Generate Image
$chargen->loadFromSqlData($data);
$img = $chargen->render();
imagepng($img);
}
}