Overview

Namespaces

  • aliuly
    • common
      • selectors
    • loader
  • xPaw

Classes

  • aliuly\common\ArmorItems
  • aliuly\common\BasicCli
  • aliuly\common\BasicHelp
  • aliuly\common\BasicPlugin
  • aliuly\common\ChatSession
  • aliuly\common\Cmd
  • aliuly\common\CmdSelector
  • aliuly\common\ExpandVars
  • aliuly\common\FastTransfer
  • aliuly\common\FileUtils
  • aliuly\common\FreezeSession
  • aliuly\common\GetMotd
  • aliuly\common\GetMotdAsyncTask
  • aliuly\common\InvisibleSession
  • aliuly\common\InvUtils
  • aliuly\common\ItemName
  • aliuly\common\mc
  • aliuly\common\mc2
  • aliuly\common\MoneyAPI
  • aliuly\common\MPMU
  • aliuly\common\Npc
  • aliuly\common\PermUtils
  • aliuly\common\PluginAsyncTask
  • aliuly\common\PluginCallbackTask
  • aliuly\common\PMScript
  • aliuly\common\QueryAsyncTask
  • aliuly\common\Rcon
  • aliuly\common\RconTask
  • aliuly\common\selectors\All
  • aliuly\common\selectors\AllEntity
  • aliuly\common\selectors\BaseSelector
  • aliuly\common\selectors\Random
  • aliuly\common\Session
  • aliuly\common\ShieldSession
  • aliuly\common\ShoppingCart
  • aliuly\common\SignUtils
  • aliuly\common\SkinUtils
  • aliuly\common\SpySession
  • aliuly\common\SubCommandMap
  • aliuly\common\TPUtils
  • aliuly\loader\Main
  • xPaw\MinecraftQuery

Exceptions

  • xPaw\MinecraftQueryException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace aliuly\common;
  4: use aliuly\common\Session;
  5: use pocketmine\plugin\PluginBase;
  6: use pocketmine\event\player\PlayerCommandPreprocessEvent;
  7: use pocketmine\event\server\RemoteServerCommandEvent;
  8: use pocketmine\event\server\ServerCommandEvent;
  9: use pocketmine\event\player\PlayerJoinEvent;
 10: use pocketmine\Player;
 11: use aliuly\common\MPMU;
 12: 
 13: //use aliuly\common\MPMU;
 14: 
 15: /**
 16:  * Spying/logging session
 17:  */
 18: class SpySession extends Session {
 19:   const RCON = "*RCON*";
 20:   const CONSOLE = "*CONSOLE*";
 21:   protected $conlog;
 22:   protected $privacy;
 23:   protected $exPerms;
 24:   protected $notice;
 25: 
 26:   /**
 27:    * @param PluginBase $owner - plugin that owns this session
 28:    */
 29:   public function __construct(PluginBase $owner, $privacy= null, $exPerms = null, $notice = null) {
 30:     parent::__construct($owner);    // We do it here so to prevent the registration of listeners
 31:     $this->conlog = null;
 32:     $this->privacy = $privacy;
 33:     $this->exPerms = $exPerms;
 34:     $this->notice = is_null($notice) || is_array($notice) ? $notice :  [ $notice ];
 35:   }
 36:   /**
 37:    * Enable/disable console logging
 38:    * @param callable $cb - Callback to execute when logging, otherwise null to disable
 39:    */
 40:   public function setLogging($cb) {
 41:     $this->conlog = is_callable($cb) ? $cb : null;
 42:   }
 43:   /**
 44:    * Return if logging is enabled or not...
 45:    * @return bool
 46:    */
 47:   public function isLogging() {
 48:     return is_callable($this->conlog);
 49:   }
 50:   /**
 51:    * Enable/disable tapping
 52:    * @param Player $pl - Player that will receive taps
 53:    * @param callable $cb - Player being spied upon, either a string or Player instance
 54:    */
 55:   public function configTap(Player $pl, $cb) {
 56:     $n = MPMU::iName($pl);
 57:     if (is_callable($cb)) {
 58:       if (!isset($this->state[$n])) {
 59:         $this->state[$n] = [];
 60:       }
 61:       $this->state[$n]["callback"] = $cb;
 62:     } else {
 63:       if (isset($this->state[$n])) unset($this->state[$n]);
 64:     }
 65:   }
 66:   /**
 67:    * Check if a player is Spying
 68:    * @param Player $pl - Player that is tapping
 69:    * @return bool
 70:    */
 71:   public function isTapping(Player $pl) {
 72:     $n = MPMU::iName($pl);
 73:     return isset($this->state[$n]);
 74:   }
 75:   /**
 76:    * Return taps
 77:    * @param Player $pl - Player that will receive taps
 78:    * @return str[]
 79:    */
 80:   public function getTaps(Player $pl) {
 81:     $n = MPMU::iName($pl);
 82:     if (!isset($this->state[$n])) return null;
 83:     if (!isset($this->state[$n]["taps"])) return null;
 84:     return array_keys($this->state[$n]["taps"]);
 85:   }
 86: 
 87:   /**
 88:    * Start/Stop tapping
 89:    * @param Player $pl - Player that will receive taps
 90:    * @param Player|str|null $n - Start tapping a player, console, everything, etc...
 91:    */
 92:   public function setTap(Player $pl,$v,$ena = true) {
 93:     $v = MPMU::iName($v);
 94:     $n = MPMU::iName($pl);
 95:     if ($v === null) {
 96:       // Global tap!
 97:       if ($ena) {
 98:         if (isset($this->state[$n]["taps"])) unset($this->state[$n]["taps"]);
 99:       } else {
100:         $this->state[$n]["taps"] = [];
101:       }
102:       return;
103:     }
104:     if (!isset($this->state[$n]["taps"])) $this->state[$n]["taps"] = [];
105:     if ($ena) {
106:       $this->state[$n]["taps"][$v] = $v;
107:     } else {
108:       if (isset($this->state[$n]["taps"][$v])) unset($this->state[$n]["taps"][$v]);
109:     }
110:   }
111: 
112: 
113:   protected function logEvent($n,$msg) {
114:     //
115:         // First we apply hard-coded white-washing rules
116:         //
117:         foreach ([
118:             // SimpleAuth related commands
119:             '/\/login\s*.*/' => '/login **CENSORED**',
120:             '/\/register\s*.*/' => '/register **CENSORED**',
121:             '/\/unregister\s*.*/' => '/register **CENSORED**',
122:             // SimpleAuthHelper related commands
123:             '/\/chpwd\s*.*/' => '/chpwd **CENSORED**',
124:         ] as $re => $txt) {
125:             $msg = preg_replace($re,$txt,$msg);
126:         }
127:     if (is_array($this->privacy)) {
128:       foreach ($this->privacy as $re => $txt) {
129:         $msg = preg_replace($re,$txt,$msg);
130:       }
131:     }
132: 
133:     if ($this->conlog !== null) {
134:       $log = $this->conlog;
135:       $log($n,$msg);
136:     }
137:     foreach ($this->state as $ls=>&$tt) {
138:       if (isset($tt["taps"]) && !isset($tt["taps"][$n])) continue;
139:       $log = $tt["callback"];
140:       $log($ls,$n,$msg);
141:     }
142:   }
143:     /**
144:      * @priority MONITOR
145:      */
146:     public function onPlayerCmd(PlayerCommandPreprocessEvent $ev) {
147:         if ($ev->isCancelled()) return;
148:     if ($this->exPerms !== null && $ev->getPlayer()->hasPermission($this->exPerms)) return;
149:     $this->logEvent(MPMU::iName($ev->getPlayer()),$ev->getMessage());
150:     }
151:     /**
152:      * @priority MONITOR
153:      */
154:     public function onRconCmd(RemoteServerCommandEvent $ev) {
155:     $this->logEvent(self::RCON,$ev->getMessage());
156:     }
157:     /**
158:      * @priority MONITOR
159:      */
160:     public function onConsoleCmd(ServerCommandEvent $ev) {
161:         $this->logEvent(self::CONSOLE,$ev->getCommand());
162:     }
163:   public function onJoin(PlayerJoinEvent $ev) {
164:     if ($this->notice === null) return;
165:     foreach ($this->notice as $ln) {
166:       $ev->getPlayer()->sendMessage($ln);
167:     }
168:   }
169: }
170: 
API documentation generated by ApiGen