1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: Jake
5+ * Date: 16/09/2016
6+ * Time: 06:18
7+ */
8+
9+ namespace Plugin ;
10+
11+ use App \Plugin ;
12+ use TeamSpeak3 \Ts3Exception ;
13+
14+ class GlobalBan extends Plugin implements PluginContract
15+ {
16+
17+ public $ server ;
18+
19+ public function isTriggered ()
20+ {
21+ if (!isset ($ this ->info ['text ' ])) {
22+ $ this ->sendOutput ($ this ->CONFIG ['usage ' ]);
23+
24+ return ;
25+ }
26+
27+ $ this ->server = $ this ->teamSpeak3Bot ->node ;
28+
29+ list ($ name , $ reason ) = $ this ->info ['text ' ]->split (' ' );
30+
31+ try {
32+ $ client = current ($ this ->server ->clientFind ($ name ));
33+ $ client = $ this ->server ->clientGetById ($ client ['clid ' ]);
34+ }catch (Ts3Exception $ e ){
35+ $ message = $ e ->getMessage ();
36+ if ($ message === "invalid clientID " ) {
37+ $ this ->sendOutput ("[COLOR=red][b] There are no users online by that name " );
38+
39+ return ;
40+ }
41+ }
42+
43+ $ curl = curl_init ();
44+
45+ $ fields = [
46+ 'key ' => $ this ->CONFIG ['key ' ],
47+ 'uid ' => $ client ['client_unique_identifier ' ]->toString (),
48+ 'ip ' => $ client ['connection_client_ip ' ],
49+ 'banned_by ' => $ this ->info ['invokername ' ],
50+ 'banned_by_uid ' => $ this ->info ['invokeruid ' ],
51+ 'reason ' => $ reason ,
52+ 'server_name ' => $ this ->server ->toString (),
53+ 'server_uid ' => $ this ->server ['virtualserver_unique_identifier ' ],
54+ 'h ' => hash_pbkdf2 ('sha1 ' , sprintf ("%s-%s-%s " , $ this ->CONFIG ['key ' ], $ client ['client_unique_identifier ' ]->toString (),$ this ->info ['invokeruid ' ]),$ this ->server ['virtualserver_unique_identifier ' ], 1 , 8 ),
55+
56+ ];
57+
58+ curl_setopt ($ curl , CURLOPT_URL , 'http://127.0.0.1/bans/submit ' );
59+ curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
60+ curl_setopt ($ curl , CURLOPT_POSTFIELDS , $ fields );
61+ curl_setopt ($ curl , CURLOPT_CONNECTTIMEOUT , 1 );
62+ curl_setopt ($ curl , CURLOPT_TIMEOUT , 5 );
63+
64+ $ response = json_decode (curl_exec ($ curl ));
65+ if (curl_errno ($ curl ) != 0 ) {
66+ $ this ->sendOutput (sprintf ("There was a error with the request: %s " , curl_error ($ curl )));
67+ return ;
68+ }
69+
70+ curl_close ($ curl );
71+
72+ if ($ response ->success === true ) {
73+ try {
74+ $ id = hash_pbkdf2 ("sha1 " , $ client ['client_unique_identifier ' ]->toString (), '' , 1 , 8 );
75+ $ client ->poke ("[b][color=red]You are global banned by Nimda ID: # {$ id }" );
76+ $ client ->poke ("[b][color=red]Visit [url=http://support.mxgaming.com/]Global Ban Support[/url]. " );
77+ $ client ->ban (1 , "Global Ban ID # {$ id } ( {$ reason }) " );
78+ }catch (Ts3Exception $ e ){
79+ return ;
80+ }
81+
82+ $ this ->sendOutput (sprintf ("[b][color=green] Client %s successfully global banned ID #%s " , $ client , $ id ));
83+ } elseif ($ response ->success === false && $ response ->err === 0x02 ) {
84+ $ this ->sendOutput ("[COLOR=red][b]This server is not authorized to global ban, email support@mxgaming.com " );
85+ }
86+ }
87+
88+ }
0 commit comments