Example #1
0
 public function __construct(PluginBase $owner, $target)
 {
     $this->owner = $owner;
     switch (strtolower($target)) {
         case "emergency":
             $this->level = LogLevel::EMERGENCY;
             break;
         case "alert":
             $this->level = LogLevel::ALERT;
             break;
         case "critical":
             $this->level = LogLevel::CRITICAL;
             break;
         case "error":
             $this->level = LogLevel::ERROR;
             break;
         case "warning":
             $this->level = LogLevel::WARNING;
             break;
         case "notice":
             $this->level = LogLevel::NOTICE;
             break;
         case "info":
             $this->level = LogLevel::INFO;
             break;
         case "debug":
             $this->level = LogLevel::DEBUG;
             break;
         default:
             $owner->getServer()->getLogger()->error(mc::_("Invalid log target %1%", $target));
             $owner->getServer()->getLogger()->error(mc::_("Using \"debug\""));
             $this->level = LogLevel::DEBUG;
     }
 }
Example #2
0
 public function logMsg(CommandSender $pl, $msg)
 {
     $txt = date(mc::_("Y-m-d H:i:s"), time()) . " " . "[" . $pl->getName() . "]: " . $msg . "\n";
     file_put_contents($this->file, $txt, FILE_APPEND);
 }
Example #3
0
 private function cmdLog(CommandSender $sender, array $args)
 {
     if (count($args) == 0) {
         $sender->sendMessage($this->logging ? mc::_("Logging ON") : mc::_("Logging OFF"));
         return true;
     }
     if (count($args) != 1) {
         return false;
     }
     switch (strtolower($args[0])) {
         case "on":
             $sender->sendMessage(mc::_("Logging starting"));
             $this->logging = true;
             $this->logMsg($sender, mc::_(">>>Logging started"), true);
             break;
         case "off":
             $this->logMsg($sender, mc::_(">>>Logging stopped"), true);
             $sender->sendMessage(mc::_("Logging stopping"));
             $this->logging = false;
             break;
         default:
             return false;
     }
     return true;
 }
Example #4
0
 public function onCmd($sender, $args)
 {
     if (!MPMU::inGame($sender)) {
         return true;
     }
     if (count($args) == 0) {
         $args = ["ls"];
     }
     $m = strtolower($sender->getName());
     switch ($scmd = strtolower(array_shift($args))) {
         case "stop":
             $sender->sendMessage(mc::_("Stopping tapping"));
             if (count($args) == 0) {
                 $this->stopSpying($sender);
             } else {
                 foreach ($args as $n) {
                     $n = strtolower($n);
                     if (isset($this->sessions[$n][$m])) {
                         unset($this->sessions[$n][$m]);
                     }
                 }
             }
             return true;
         case "start":
             $sender->sendMessage(mc::_("Starting tapping"));
             if (count($args) == 0) {
                 return false;
             }
             foreach ($args as $n) {
                 $pl = $this->owner->getServer()->getPlayer($n);
                 if ($pl == null) {
                     $sender->sendMessage(mc::_("%1% cannot be found", $n));
                     continue;
                 }
                 if ($pl->hasPermission("chatscribe.privacy")) {
                     $sender->sendMessage(mc::_("%1% has privacy, cannot be spied", $n));
                     continue;
                 }
                 $pl->sendMessage(mc::_("%1% is now tapping you", $n));
                 $n = strtolower($pl->getName());
                 if (!isset($this->sessions[$n])) {
                     $this->sessions[$n] = [];
                 }
                 $this->sessions[$n][$m] = $sender;
             }
             return true;
         case "ls":
         case "sess":
             if (count($args) != 0) {
                 return false;
             }
             $str = "";
             foreach ($this->sessions as $i => &$j) {
                 if (!isset($j[$m])) {
                     continue;
                 }
                 $str .= (strlen($str) == 0 ? "" : ", ") . $i;
             }
             if ($str == "") {
                 $sender->sendMessage(mc::_("No sessions found"));
             } else {
                 $sender->sendMessage(mc::_("Spying on:"));
                 $sender->sendMessage($str);
             }
             return true;
     }
     return false;
 }