Re: PocketMine Plugin - Anti Fake Request

From iLuke_x, 5 Months ago, written in PHP, viewed 62 times. This paste is a reply to PocketMine Plugin - Anti Fake Request from NAT - go back
URL https://code.nat.moe/view/251acad3/diff Embed
Viewing differences between PocketMine Plugin - Anti Fake Request and Re: PocketMine Plugin - Anti Fake Request
<?php
/*
<?php
/*
__PocketMine Plugin__
Plugin__
name=Anti Fake Request
Request
description=Block fake player request.
request.
version=0.1
author=NAT
class=AntiFakeRQ
apiversion=12
*/
1
author=NAT
class=AntiFakeRQ
apiversion=12
*/
class AntiFakeRQ implements Plugin{
        
Plugin{
        
private $api,$server;
        
$api,$server;
        
public function __construct(ServerAPI $api, $server = false){
                
false){
                
$this->api = $api;
                
$api;
                
$this->server = ServerAPI::request();
        }
        
ServerAPI::request();
        }
        
public function init(){
        }
        
init(){
        }
        
public function __destruct(){
        }
        
__destruct(){
        }
        
public function packetHandler(Packet $packet){
                
$packet){
                
$data =& $packet;
                
$packet;
                
$CID = PocketMinecraftServer::clientID($packet->ip, $packet->port);
                if(isset($this->clients[$CID])){
                        $this->clients[$CID]->handlePacket($packet);
                }else{
$packet->port);
                if(isset($this->clients[$CID])){
                        $this->clients[$CID]->handlePacket($packet);
                }else{
                        if($this->handle("server.noauthpacket.".$packet->pid(), $packet) === false){
                                return;
                        }
                        switch($packet->pid()){
                                
false){
                                return;
                        }
                        switch($packet->pid()){
                                
case RakNetInfo::UNCONNECTED_PING:
                                
RakNetInfo::UNCONNECTED_PING:
                                
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
                                        
RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
                                        
if($this->invisible === true){
                                                
true){
                                                
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
                                                
RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
                                                
$pk->pingID = $packet->pingID;
                                                
$packet->pingID;
                                                
$pk->serverID = $this->serverID;
                                                
$this->serverID;
                                                
$pk->serverType = $this->serverType;
                                                
$this->serverType;
                                                
$pk->ip = $packet->ip;
                                                
$packet->ip;
                                                
$pk->port = $packet->port;
                                                $this->send($pk);
                                                break;
                                        }
$packet->port;
                                                $this->send($pk);
                                                break;
                                        }
                                        if(!isset($this->custom["times_".$CID])){
$CID])){
                                                $this->custom["times_".$CID] = 0;
                                        }
                                        
0;
                                        }
                                        
$ln = 15;
                                        
15;
                                        
if($this->description == "" or substr($this->description, -1) != " "){                                                
"){                                                
                                                $this->description .= " ";
                                        }
";
                                        }
                                        $txt = substr($this->description, $this->custom["times_".$CID], $ln);
$ln);
                                        $txt .= substr($this->description, 0, $ln - strlen($txt));
                                        
strlen($txt));
                                        
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
                                        
RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
                                        
$pk->pingID = $packet->pingID;
                                        
$packet->pingID;
                                        
$pk->serverID = $this->serverID;
$this->serverID;
                                        $pk->serverType = $this->serverType . $this->name . " [".count($this->clients)."/".$this->maxClients."] ".$txt;
                                        
$txt;
                                        
$pk->ip = $packet->ip;
                                        
$packet->ip;
                                        
$pk->port = $packet->port;
                                        $this->send($pk);
$packet->port;
                                        $this->send($pk);
                                        $this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
                                        break;
                                
strlen($this->description);
                                        break;
                                
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
                                        
RakNetInfo::OPEN_CONNECTION_REQUEST_1:
                                        
if($packet->structure !== RakNetInfo::STRUCTURE){
RakNetInfo::STRUCTURE){
                                                console("[DEBUG] Incorrect structure #".$packet->structure." from ".$packet->ip.":".$packet->port, true, true, 2);
                                                
2);
                                                
$pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
                                                
RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
                                                
$pk->serverID = $this->serverID;
                                                
$this->serverID;
                                                
$pk->ip = $packet->ip;
                                                
$packet->ip;
                                                
$pk->port = $packet->port;
                                                $this->send($pk);
                                        }else{
                                                
$packet->port;
                                                $this->send($pk);
                                        }else{
                                                
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
                                                
RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
                                                
$pk->serverID = $this->serverID;
                                                
$this->serverID;
                                                
$pk->mtuSize = strlen($packet->buffer);
                                                
strlen($packet->buffer);
                                                
$pk->ip = $packet->ip;
                                                
$packet->ip;
                                                
$pk->port = $packet->port;
                                                $this->send($pk);
                                        }
                                        break;
                                
$packet->port;
                                                $this->send($pk);
                                        }
                                        break;
                                
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
                                        
RakNetInfo::OPEN_CONNECTION_REQUEST_2:
                                        
if($this->invisible === true){
                                                break;
                                        }
        if(!isset($this->blacklist[$packet->ip])){
                
true){
                                                break;
                                        }
        if(!isset($this->blacklist[$packet->ip])){
                
$this->blacklist[$packet->ip] = array(
                 
array(
                 
'last' => 0,
          
0,
          
'count' => 0,
          );
        }
        
0,
          );
        }
        
$bl = &$this->blacklist[$packet->ip];
        
&$this->blacklist[$packet->ip];
        
if(time() - $bl['last'] < 3){
                $bl['count']++;
                
3){
                $bl['count']++;
                
if($bl['count'] % 500==0){
500==0){
                        console("[AntiFakeRQ] Block fake request attack from {$packet->ip}, total {$bl['count']}.");
          }
        }
        
");
          }
        }
        
$bl['last'] = time();
        if($bl['count']<3)
        
time();
        if($bl['count']<3)
        
$this->clients[$CID] = new Player($packet->clientID, $packet->ip, $packet->port, $packet->mtuSize);
                                        
$packet->mtuSize);
                                        
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_2);
                                        
RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_2);
                                        
$pk->serverID = $this->serverID;
                                        
$this->serverID;
                                        
$pk->port = $this->port;
                                        
$this->port;
                                        
$pk->mtuSize = $packet->mtuSize;
                                        
$packet->mtuSize;
                                        
$pk->ip = $packet->ip;
                                        
$packet->ip;
                                        
$pk->port = $packet->port;
                                        $this->send($pk);
                                        break;
                        }
                }
        }
}
$packet->port;
                                        $this->send($pk);
                                        break;
                        }
                }
        }
}
?>

Reply to "Re: PocketMine Plugin - Anti Fake Request"

Here you can reply to the paste above

captcha