· 8 years ago · Jan 16, 2018, 06:44 AM
1<?php
2/*******************************************************************
3To jest przykład zastowania API TS3 do generowania banera oraz czasu
4na serwerze z wykorzystaniem odświeżania banera przez wywołania
5klienta ts3 przebywajÄ…cego na serwerze.
6TimeBot wymaga utworzenie 4 kanałów trwałych które będą edytowane przez
7wywołania API.
8
9Aby sprawdzić ID kanałów wymagane dla timebot można użyć opcji API channellist
10
11Jako link do banera w edycji serwera TeamSpeak3 podaje siÄ™ link do pliku:
12Banner GFX URL: http://moja_strona/timebot_baner/create.php
13Interwał GFX: 60 sekund
14*******************************************************************/
15
16error_reporting(E_ALL ^ (E_NOTICE | E_DEPRECATED));
17ini_set('session.bug_compat_warn','off');
18
19$secret_key = '26c3b4ded06eb7cf08a9c69dbf9bf69653615c26';
20$channel_id_1 = '19323';
21$channel_id_2 = '19324';
22$channel_id_3 = '19325';
23$channel_id_4 = '19326';
24
25$post_data = array(
26 'api_key' => $secret_key,
27 'channel_id_1' => '1',
28 'channel_id_2' => '2',
29 'channel_id_3' => '3',
30 'channel_id_4' => '4',
31 'command' => 'api_timebot_baner'
32 );
33$url ="https://net-speak.pl/api_client/api_client.php";
34
35$ch = curl_init();
36
37curl_setopt($ch, CURLOPT_URL, $url) or die("error");
38curl_setopt($ch, CURLOPT_POST, 1);
39curl_setopt($ch, CURLOPT_TIMEOUT, 20);
40curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
41curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
42curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
43curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
44curl_setopt($ch, CURLOPT_HEADER, 0);
45curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
46curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
47
48$curl_response = curl_exec($ch);
49curl_close($ch);
50
51$response = json_decode($curl_response);
52$response_data=$response->{'response'};
53$result=$response_data->{'result'};
54
55if($result=="success")
56 {
57 $virtualserver_name=$response_data->{'virtualserver_name'};
58 $virtualserver_clientsonline=$response_data->{'virtualserver_clientsonline'};
59 $virtualserver_queryclientsonline=$response_data->{'virtualserver_queryclientsonline'};
60 $virtualserver_maxclients=$response_data->{'virtualserver_maxclients'};
61 $virtualserver_uptime=$response_data->{'virtualserver_uptime'};
62
63
64$text = "GameProject"; //---------------- wstaw własny tekst
65
66$data = date('d.m.Y');
67$godzina = date('H:i');
68
69
70function LoadJpeg($imgname)
71{
72 $im = @imagecreatefromjpeg($imgname);
73
74 if(!$im)
75 {
76 $im = imagecreatetruecolor(525, 80);
77 $bgc = imagecolorallocate($im, 255, 255, 255);
78 $tc = imagecolorallocate($im, 0, 0, 0);
79
80 imagefilledrectangle($im, 0, 0, 525, 80, $bgc);
81
82 imagestring($im, 1, 5, 5, 'Nierozpoznana grafika: ' . $imgname, $tc);
83 }
84
85 return $im;
86}
87
88
89$font = './EncodeSansCompressed-SemiBold.ttf';
90$fonta = './arial.ttf';
91$fontc = './verdanai.ttf';
92$img = LoadJpeg('background.jpg');
93
94$white=ImageColorAllocate($img,10 ,10 ,10);
95$green=ImageColorAllocate($img,223 ,223 ,223);
96$red=ImageColorAllocate($img,237 ,42 ,33);
97$fsize_text='';
98$ile_text=strlen($text);
99if($ile_text > 27)$fsize_text=16;
100if($ile_text < 27)$fsize_text=19;
101
102$bbox = imagettfbbox(26, 0, $font, $virtualserver_name);
103$center1 = (imagesx($img) / 2) - (($bbox[2] - $bbox[0]) / 2);
104
105$bbox2 = imagettfbbox($fsize_text, 0, $font, $text);
106$center2 = (imagesx($img) / 2) - (($bbox2[2] - $bbox2[0]) / 2);
107
108$this_image1=explode("-",$imga);
109$this_image=$this_image1[1];
110
111imagettftext($img, 26, 0, $center1 +4, 50 +4, $white, $font, $virtualserver_name);
112imagettftext($img, 26, 0, $center1, 50, $green, $font, $virtualserver_name);
113imagettftext($img, 18, 0, 785, 180, $white, $fonta, $godzina);
114imagettftext($img, 19, 0, 786, 185, $white, $fonta, $godzina);
115imagettftext($img, 18.5, 0, 785, 183, $green, $fonta, $godzina);
116imagettftext($img, 18, 0, 70, 180, $white, $fonta, $data);
117imagettftext($img, 19, 0, 67, 185, $white, $fonta, $data);
118imagettftext($img, 18.5, 0, 70, 183, $green, $fonta, $data);
119imagettftext($img, $fsize_text, 0, $center2 +4, 200 +4, $white, $font, $text);
120imagettftext($img, $fsize_text, 0, $center2, 200, $green, $font, $text);
121imagettftext($img, 18, 0, 440, 240, $white, $fonta, $virtualserver_clientsonline);
122imagettftext($img, 17.5, 0, 443, 238, $green, $fonta, $virtualserver_clientsonline);
123imagettftext($img, 18, 0, 485, 240, $white, $fonta, $virtualserver_maxclients);
124imagettftext($img, 17.5, 0, 488, 238, $green, $fonta, $virtualserver_maxclients);
125
126
127$url = "baner/baner.jpg";
128chmod($url,0755);
129header('Content-Type: image/png');
130
131imagejpeg($img, $url, 100);
132imagejpeg($img);
133imagedestroy($img);
134
135
136}
137else
138 {
139function LoadJpeg($imgname)
140{
141 $im = @imagecreatefromjpeg($imgname);
142
143 if(!$im)
144 {
145 $im = imagecreatetruecolor(525, 80);
146 $bgc = imagecolorallocate($im, 255, 255, 255);
147 $tc = imagecolorallocate($im, 0, 0, 0);
148
149 imagefilledrectangle($im, 0, 0, 525, 80, $bgc);
150
151 imagestring($im, 1, 5, 5, 'Nierozpoznana grafika: ' . $imgname, $tc);
152 }
153
154 return $im;
155}
156
157$img = LoadJpeg("baner/baner.jpg");
158
159header('Content-Type: image/png');
160imagejpeg($img);
161imagedestroy($img);
162
163 }
164?>