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;
}
}
}
}
?>
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}