Discord Logger !!EXPERIMENTAL!!

This commit is contained in:
kotyara 2022-04-30 21:07:32 +00:00 • committed by GitHub
parent 046d8e9fca
commit 0d53ce1889
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 5 deletions

View file

@ -305,8 +305,9 @@ class Player{
if($msg === true and $this->username != "" and $this->spawned !== false){
$this->server->api->chat->broadcast($this->username." left the game");
}
$this->spawned = false;
$this->spawned = false;
console("[INFO] ".FORMAT_AQUA.$this->username.FORMAT_RESET."[/".$this->ip.":".$this->port."] logged out due to ".$reason);
$this->server->send2Discord($this->username . " left the game: ".$reason);
$this->windows = array();
$this->armor = array();
$this->inventory = array();
@ -1348,6 +1349,8 @@ class Player{
return;
}
$this->server->send2Discord($this->username . " joined the game");
$this->auth = true;
if(!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01){
if(($this->gamemode & 0x01) === 0x01){
@ -2016,6 +2019,7 @@ class Player{
}else{
$data = array("player" => $this, "message" => $message);
if($this->server->api->handle("player.chat", $data) !== false){
$this->server->send2Discord("<" . $this->username . "> " . $message);
if(isset($data["message"])){
$this->server->api->chat->send($this, $data["message"]);
}else{

View file

@ -73,11 +73,26 @@ class PocketMinecraftServer{
}
console("[INFO] Loading extra.properties...");
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, array(
"version" => "2",
"save-player-data" => true,
"save-console-data" => true
"save-console-data" => true,
"discord-msg" => false,
"discord-webhook-url" => "none",
"discord-bot-name" => "NostalgiaCore Logger"
));
$dolog = $this->extraprops->get("save-console-data");
if($this->extraprops->get("discord-msg") == true){
if($this->extraprops->get("discord-webhook-url") !== "none"){
console("[INFO] Discord Logger is enabled.");
} else {
console("[WARNING] Discord Logger is enabled in extra.properties,");
console("[WARNING] but you didn't put the webhook url, so it won't work.");
}
} elseif($this->extraprops->get("version") == null){
console("[WARNING] Your extra.properties file is corrupted!");
console("To fix it - just remove it! Server will generate it automatically.");
}
$dolog = $this->extraprops->get("save-console-data");
}
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
@ -695,5 +710,21 @@ class PocketMinecraftServer{
}
}
}
public function send2Discord($msg){
if($this->extraprops->get("discord-msg") == true and $this->extraprops->get("discord-webhook-url") !== "none"){
$url = $this->extraprops->get("discord-webhook-url");
$name = $this->extraprops->get("discord-bot-name");
$headers = [ 'Content-Type: application/json; charset=utf-8' ];
$POST = [ 'username' => $name, 'content' => $msg];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($POST));
$response = curl_exec($ch);
}
}
}