Last active
January 9, 2024 05:11
-
-
Save SmileYzn/98f2a8e1fb9353074436783983832974 to your computer and use it in GitHub Desktop.
LogAPI Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class LogAPI | |
{ | |
/** | |
* Called when a unknow function is received | |
* | |
* @param string $name Function name | |
* @param type $arguments Function argument list | |
*/ | |
function __call($name, $arguments) | |
{ | |
// Do nothing here | |
} | |
/** | |
* On Receive Event | |
*/ | |
function OnEvent() | |
{ | |
// Parse request as json event | |
$request = json_decode(file_get_contents('php://input'), true); | |
// If event is not empty | |
if(!empty($request['Event'])) | |
{ | |
// If method exists | |
if(method_exists($this, $request['Event'])) | |
{ | |
// Process paramemeters as array | |
$parameters = array_values($request); | |
// Return from function call | |
return $this->{$request['Event']}(...$parameters); | |
} | |
} | |
// Return null | |
return null; | |
} | |
/** | |
* Find player using the list of players and target string | |
* | |
* @param array $Players Array of players of event | |
* @param string $Target String to find player | |
* | |
* @return array Return Player found by search | |
*/ | |
protected function FindPlayer($Players, $Target) | |
{ | |
foreach($Players as $AuthId => $Player) | |
{ | |
if($Target[0] == '#') | |
{ | |
if($Player['UserId'] == substr($Target, 1)) | |
{ | |
return $Player; | |
} | |
} | |
else if(stripos($Player['Name'], $Target) !== false) | |
{ | |
return $Player; | |
} | |
} | |
// | |
return null; | |
} | |
/** | |
* On Server Activate Event | |
* | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param string $EdictCount Entity Count in Server (Number of edict) | |
* @param string $ClientMax Number of maximum allowed clients in server | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ServerActivate($Event, $Server, $EdictCount, $ClientMax) | |
{ | |
return null; | |
} | |
/** | |
* On Server Deactivate Event | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ServerDeactivate($Event, $Server) | |
{ | |
return null; | |
} | |
/** | |
* On Server Alert Message | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param string $Type Alert Mesasge Type (Always 5 at_logged) | |
* @param string $Message Log string | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ServerAlertMessage($Event, $Server, $Type, $Message) | |
{ | |
return null; | |
} | |
/** | |
* On Server Update Information | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ServerInfo($Event, $Server) | |
{ | |
(new Servidor)->atualizar($Server); | |
return null; | |
} | |
/** | |
* On Client Connect | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param int $EntityId Entity Index | |
* @param string $UserId User Index | |
* @param string $Name Client Name | |
* @param string $AuthId Client AuthId | |
* @param string $Address Client IP Address | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ClientConnect($Event, $Server, $EntityId, $UserId, $Name, $AuthId, $Address) | |
{ | |
(new Servidor)->atualizar($Server); | |
return null; | |
} | |
/** | |
* On Client Put In Server | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param int $EntityId Entity Index | |
* @param string $UserId User Index | |
* @param string $Name Client Name | |
* @param string $AuthId Client AuthId | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ClientPutInServer($Event, $Server, $EntityId, $UserId, $Name, $AuthId) | |
{ | |
(new Servidor)->atualizar($Server); | |
return null; | |
} | |
/** | |
* On Client Disconnect | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param int $EntityId Entity Index | |
* @param string $UserId User Index | |
* @param string $Name Client Name | |
* @param string $AuthId Client AuthId | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ClientDisconnect($Event, $Server, $EntityId, $UserId, $Name, $AuthId) | |
{ | |
(new Servidor)->atualizar($Server); | |
return null; | |
} | |
/** | |
* On Client Killed | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param int $EntityId Entity Index | |
* @param string $UserId User Index | |
* @param string $Name Client Name | |
* @param string $AuthId Client AuthId | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ClientKill($Event, $Server, $EntityId, $UserId, $Name, $AuthId) | |
{ | |
(new Servidor)->atualizar($Server); | |
return null; | |
} | |
/** | |
* On Client Information Changed | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param int $EntityId Entity Index | |
* @param string $UserId User Index | |
* @param string $Name Client Name | |
* @param string $AuthId Client AuthId | |
* @param string $InfoBuffer KeyInfoBuffer | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ClientUserInfoChanged($Event, $Server, $EntityId, $UserId, $Name, $AuthId, $InfoBuffer) | |
{ | |
return null; | |
} | |
/** | |
* On Client Command | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param int $EntityId Entity Index | |
* @param string $UserId User Index | |
* @param string $Name Client Name | |
* @param string $AuthId Client AuthId | |
* @param string $Command Command | |
* @param string $Args Command Arguments | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ClientCommand($Event, $Server, $EntityId, $UserId, $Name, $AuthId, $Command, $Args) | |
{ | |
return null; | |
} | |
/** | |
* On Client say or say_team commands | |
* | |
* @param string $Event Event Name | |
* @param array $Server Server information data | |
* @param int $EntityId Entity Index | |
* @param string $UserId User Index | |
* @param string $Name Client Name | |
* @param string $AuthId Client AuthId | |
* @param string $Type Type (say or say_team) | |
* @param string $Message Message sent | |
* | |
* @return mixed Array containing ServerExecute commands or null | |
*/ | |
protected function ClientSay($Event, $Server, $EntityId, $UserId, $Name, $AuthId, $Type, $Message) | |
{ | |
(new Servidor)->atualizar($Server); | |
if (strpos($Message, '.menu1') === 0) | |
{ | |
$menu = $this->Menu1($EntityId); | |
return ["ServerMenu" => $menu]; | |
} | |
else if (strpos($Message, '.menu') === 0) | |
{ | |
$menu = | |
[ | |
"EntityId" => $EntityId, | |
"Title" => "Lista de Players:", | |
"Exit" => true, | |
"Callback" => "PlayerMenuHandle", | |
]; | |
// (int Info, std::string Text, bool Disabled, int Extra); | |
foreach ($Server['Players'] as $Auth => $Player) | |
{ | |
$menu["Items"][] = | |
[ | |
"Info" => $Player['Auth'], | |
"Text" => $Player['Name'], | |
"Disabled" => false, | |
"Extra" => "{$Player['UserId']}" | |
]; | |
} | |
$resultado = | |
[ | |
"ServerMenu" => $menu, | |
"ServerExecute" => | |
[ | |
"log_psay #$UserId [LOGAPI] Escolha o jogador." | |
], | |
]; | |
return $resultado; | |
} | |
return null; | |
} | |
protected function Menu1($EntityId) | |
{ | |
$menu = | |
[ | |
"EntityId" => $EntityId, | |
"Title" => "Menu Exemplo 1", | |
"Exit" => true, | |
"Callback" => "Menu1Handle", | |
"Items" => | |
[ | |
[ | |
"Info" => "0", | |
"Text" => "Opção 0", | |
"Disabled" => false, | |
"Extra" => "Opção 0" | |
], | |
[ | |
"Info" => "1", | |
"Text" => "Acessar website", | |
"Disabled" => false, | |
"Extra" => "Opção 0" | |
], | |
[ | |
"Info" => "2", | |
"Text" => "Opção 2", | |
"Disabled" => false, | |
"Extra" => "Opção 2" | |
], | |
] | |
]; | |
return $menu; | |
} | |
protected function Menu1Handle($Event, $Server, $EntityId, $UserId, $Name, $AuthId, $Callback, $Info, $Text, $Disabled, $Extra) | |
{ | |
switch($Info) | |
{ | |
case 0: | |
{ | |
$menu = $this->Menu2($EntityId); | |
return ["ServerMenu" => $menu]; | |
} | |
case 1: | |
{ | |
return ["ServerExecute" => "log_motd #{$UserId} http://pugbr.net/"]; | |
} | |
case 2: | |
{ | |
return ["ServerConsoleLog" => ["EntityId" => $EntityId, "Message" => "LINHA QUEBRADA\nLINHA QUEBRADA\nLINHA QUEBRADA"]]; | |
} | |
} | |
} | |
protected function Menu2($EntityId) | |
{ | |
$menu = | |
[ | |
"EntityId" => $EntityId, | |
"Title" => "Menu Exemplo 2", | |
"Exit" => true, | |
"Callback" => "Menu2Handle", | |
"Items" => | |
[ | |
[ | |
"Info" => "0", | |
"Text" => "Opção 0", | |
"Disabled" => false, | |
"Extra" => "Opção 0" | |
], | |
[ | |
"Info" => "1", | |
"Text" => "Opção 1", | |
"Disabled" => false, | |
"Extra" => "Opção 0" | |
], | |
[ | |
"Info" => "2", | |
"Text" => "Opção 2", | |
"Disabled" => true, | |
"Extra" => "Opção 2" | |
], | |
] | |
]; | |
return $menu; | |
} | |
protected function Menu2Handle($Event, $Server, $EntityId, $UserId, $Name, $AuthId, $Callback, $Info, $Text, $Disabled, $Extra) | |
{ | |
switch($Info) | |
{ | |
case 0: | |
{ | |
$menu = $this->Menu1($EntityId); | |
return ["ServerMenu" => $menu]; | |
} | |
case 1: | |
{ | |
break; | |
} | |
case 2: | |
{ | |
break; | |
} | |
} | |
} | |
protected function PlayerMenuHandle($Event, $Server, $EntityId, $UserId, $Name, $AuthId, $Callback, $Info, $Text, $Disabled, $Extra) | |
{ | |
(new Servidor)->atualizar($Server); | |
return ["ServerExecute" => "kick #{$Extra} BYE"]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment