Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.45 KB | None | 0 0
  1. <?php
  2.  
  3. class player {
  4. private $mod;
  5. private $rcon;
  6. private $players;
  7. private $logging;
  8. private $guid;
  9. private $pid;
  10. private $name;
  11. private $customvars = array();
  12. private $lastkiller = false;
  13. private $lastvictim = false;
  14. private $team = "none";
  15. public $joined = 0;
  16. public $lastweaponkill = false;
  17. public $lastweapondeath = false;
  18. public $kills = 0;
  19. public $deaths = 0;
  20. public $teamkills = 0;
  21. public $teamdeaths = 0;
  22. public $selfkills = 0;
  23. public $headshots = 0;
  24. public $lastdeathwastk = false;
  25. public $lastkillwastk = false;
  26. public $lastCommand = 0;
  27. public $damagegiven = 0;
  28. public $teamdamagegiven = 0;
  29. public $damagetaken = 0;
  30. public $vehicledamagegiven = 0;
  31. public $teamvehicledamagegiven = 0;
  32. public $actorsdamagegiven = 0;
  33. public $teamactorsdamagegiven = 0;
  34.  
  35. public function __construct($guid, $pid, $name) {
  36. $this->mod = & $GLOBALS['mod'];
  37. $this->rcon = & $GLOBALS['rcon'];
  38. $this->logging = & $GLOBALS['logging'];
  39. $this->players = & $GLOBALS['players'];
  40. $this->guid = $guid;
  41. $this->pid = $pid;
  42. $this->name = $name;
  43. $this->joined = time();
  44. }
  45.  
  46. public function __destruct() {}
  47.  
  48. public function __set($name, $value) {
  49.  
  50. //Abw�rtskompatiblit�t
  51. if ($name == "team") {
  52. $this->setTeam($value);
  53. }
  54.  
  55. $this->customvars[$name] = $value;
  56. }
  57.  
  58. public function __get($name) {
  59.  
  60. //Abw�rtskompatiblit�t
  61. if ($name == "team") {
  62. return $this->getTeam();
  63. }
  64.  
  65. return $this->customvars[$name];
  66. }
  67.  
  68. public function __isset($name) {
  69. return array_key_exists($name, $this->customvars);
  70. }
  71.  
  72. public function __unset($name) {
  73. unset($this->customvars[$name]);
  74. }
  75.  
  76. public function dumpUser() {
  77. $return = $this->rcon->rcon("dumpuser \"$this->name\"");
  78. if (preg_match('|^Player .+ is not on the server\s?$|', $return)) return false;
  79. $return = explode("\n", $return);
  80. $info = array();
  81. foreach ($return as $value) {
  82. if (preg_match('|^([a-z0-9_]+)\s+(.*)$|i', $value, $subpatterns)) {
  83. $info[$subpatterns[1]] = $subpatterns[2];
  84. }
  85. }
  86. return $info;
  87. }
  88.  
  89. public function say($msg) {
  90. $msg = str_replace("{{br}}", "\n", $msg);
  91. $msg = wordwrap($msg, 140 - strlen($this->mod->getCV("main", "pmprefix")), "\n", true);
  92. $split = explode("\n", $msg);
  93. foreach ($split as $value) {
  94. $value = $this->mod->getCV("main", "pmprefix") . $value;
  95. $this->rcon->rcon("tell $this->pid $value");
  96. }
  97. }
  98.  
  99. public function update($pid, $name = false) {
  100. if ($name != false && $name != $this->name) {
  101. $this->logging->write(MOD_NOTICE, "Player '$this->name' changed name to '$name', PID: $this->pid, GUID: $this->guid");
  102. $oldname = $this->name;
  103. $this->name = $name;
  104. $this->mod->triggerEvent("playerNameChange", array($this->guid, $oldname, $name));
  105. }
  106. if ($pid != $this->pid) {
  107. $this->logging->write(MOD_NOTICE, "Player '$this->name's PID was changed from $this->pid to $pid, GUID: $this->guid");
  108. $oldpid = $this->pid;
  109. $this->pid = $pid;
  110. $this->mod->triggerEvent("playerPIDChange", array($this->guid, $oldpid, $pid));
  111. }
  112. }
  113.  
  114. public function getGroup() {
  115. $admin = $this->mod->getAdminByGuid($this->guid);
  116. if (!$admin) return "default";
  117. return $admin["group"];
  118. }
  119.  
  120. public function getName() {
  121. return $this->name;
  122. }
  123.  
  124. public function getPID() {
  125. return $this->pid;
  126. }
  127.  
  128. public function getGuid() {
  129. return $this->guid;
  130. }
  131.  
  132. public function setTeam($team) {
  133. if ($team != $this->team) {
  134. $oldteam = $this->team;
  135. $this->team = $team;
  136. $this->mod->triggerEvent("playerTeamChange", array($this->guid, $oldteam));
  137. }
  138. }
  139.  
  140. public function getTeam() {
  141. return $this->team;
  142. }
  143.  
  144. public function isAllowedToExec($command) {
  145. return in_array($command, $this->mod->getGroupCommands($this->getGroup()));
  146. }
  147.  
  148. public function resetTeam() {
  149. $this->team = "none";
  150. }
  151.  
  152. public function kick($reason = false, $kicker = false) {
  153. if (!$reason) {
  154. $reason = $this->mod->getCV("kickban", "defaultkickreason");
  155. }
  156.  
  157. if ($this->mod->getCV("kickban", "usepb")) {
  158. /*$dump = $this->dumpUser();
  159. if (!$dump) {
  160. $this->logging->write(MOD_WARNING, "Couldn't dump user '".$this->name."', can't kick him with pb_sv_kick, using clientkick, PID: ".$this->pid.", GUID:".$this->guid);
  161. $this->rcon->rcon("clientkick " . $this->pid);
  162. }*/
  163. $result = $this->rcon->rcon("pb_sv_kick ".$this->getPbid()." 0 $reason^7");
  164. // ^3PunkBuster Server: Matched: ^1FN^0! ^2manu (slot #1)
  165. // 0:^1FN^0! ^2manu PunkBuster kicked player '^1FN^0! ^2manu' (for 0 minutes) ... Kicked by Admin [Admin Decision]
  166. // ^3PunkBuster Server: Kick Command Issued (Kicked by Admin [Admin Decision]) for (slot#1) 192.168.2.21:28960 c90dc162f630049cec0cb632e5e0aa50 ^1FN^0! ^2manu
  167. if (stripos($result, "Kick Command Issued") === false) {
  168. $this->logging->write(MOD_WARNING, "Error kicking player '".$this->name."' with pb_sv_kick, using clientkick, PID: ".$this->pid.", GUID:".$this->guid);
  169. $this->rcon->rcon("clientkick " . $this->pid);
  170. }
  171.  
  172.  
  173. }
  174. else {
  175. $this->say($this->mod->getLngString("playerKickReasonNoPb", array("<REASON>"), array($reason)));
  176. $this->say($this->mod->getLngString("playerKickReasonNoPb", array("<REASON>"), array($reason)));
  177.  
  178. sleep(1);
  179.  
  180. $this->rcon->rcon("clientkick " . $this->pid);
  181. }
  182.  
  183. $kickerlog = ($kicker !== false) ? $this->players[$kicker]->getName() : "MOD";
  184. $this->logging->write(MOD_NOTICE, "Player '$this->name' got kicked (by: $kickerlog), reason: $reason, PID: $this->pid, GUID: $this->guid");
  185.  
  186.  
  187. if ($this->mod->getCV("kickban", "announce")) {
  188. if ($kicker !== false) {
  189. $search = array("<PLAYER>", "<KICKER>", "<REASON>");
  190. $replace = array($this->getName(), $this->players[$kicker]->getName(), $reason ? $reason : $this->mod->getCV("kickban", "defaultkickreason"));
  191. $this->mod->rconSay($this->mod->getLngString("playerKickedPublicMsg", $search, $replace));
  192. }
  193. else {
  194. $search = array("<PLAYER>", "<REASON>");
  195. $replace = array($this->getName(), $reason ? $reason : $this->mod->getCV("kickban", "defaultkickreason"));
  196. $this->mod->rconSay($this->mod->getLngString("playerKickedPublicMsgAuto", $search, $replace));
  197. }
  198. }
  199.  
  200. $this->mod->triggerEvent("playerKicked", array($this->guid, $reason, $kicker));
  201.  
  202. return true;
  203. }
  204.  
  205. public function ban($reason = false, $kicker = false) {
  206. if (!$reason) {
  207. $reason = $this->mod->getCV("kickban", "defaultbanreason");
  208. }
  209. if ($this->mod->getCV("kickban", "usepb")) {
  210. /*$dump = $this->dumpUser();
  211. if (!$dump) {
  212. $this->logging->write(MOD_WARNING, "Couldn't dump user '".$this->name."', can't ban him with pb_sv_ban, using banclient, PID: ".$this->pid.", GUID:".$this->guid);
  213. $this->rcon->rcon("banClient " . $this->pid);
  214. }*/
  215. $result = $this->rcon->rcon("pb_sv_ban ".$this->getPbid()." $reason^7");
  216. if (stripos($result, "Kick/Ban Command Issued") === false) {
  217. $this->logging->write(MOD_WARNING, "Error kicking player '".$this->name."' with pb_sv_kick, using clientkick, PID: ".$this->pid.", GUID:".$this->guid);
  218. $this->rcon->rcon("banClient " . $this->pid);
  219. }
  220. }
  221. else {
  222. $this->say($this->mod->getLngString("playerBanReasonNoPb", array("<REASON>"), array($reason)));
  223. $this->say($this->mod->getLngString("playerBanReasonNoPb", array("<REASON>"), array($reason)));
  224.  
  225. sleep(1);
  226.  
  227. $this->rcon->rcon("banClient " . $this->pid);
  228. }
  229.  
  230. $kickerlog = ($kicker !== false) ? $this->players[$kicker]->getName() : "MOD";
  231. $this->logging->write(MOD_NOTICE, "Player '$this->name' got banned (by: $kickerlog), reason: $reason, PID: $this->pid, GUID: $this->guid");
  232.  
  233. if ($this->mod->getCV("kickban", "announce")) {
  234. if ($kicker !== false) {
  235. $search = array("<PLAYER>", "<KICKER>", "<REASON>");
  236. $replace = array($this->getName(), $this->players[$kicker]->getName(), $reason ? $reason : $this->mod->getCV("kickban", "defaultbanreason"));
  237. $this->mod->rconSay($this->mod->getLngString("playerBannedPublicMsg", $search, $replace));
  238. }
  239. else {
  240. $search = array("<PLAYER>", "<REASON>");
  241. $replace = array($this->getName(), $reason ? $reason : $this->mod->getCV("kickban", "defaultbanreason"));
  242. $this->mod->rconSay($this->mod->getLngString("playerBannedPublicMsgAuto", $search, $replace));
  243. }
  244. }
  245.  
  246. $this->mod->triggerEvent("playerBanned", array($this->guid, $reason, $kicker));
  247.  
  248. return true;
  249. }
  250.  
  251. public function tempBan($reason = false, $time = false, $kicker = false) {
  252. if (!$reason) {
  253. $reason = $this->mod->getCV("kickban", "defaultbanreason");
  254. }
  255. if ($this->mod->getCV("kickban", "usepb")) {
  256. if (!$time || !is_numeric($time) || $time < 0) {
  257. $time = $this->mod->getCV("kickban", "pbtempbanduration");
  258. }
  259. else {
  260. $time = (int)$time;
  261. }
  262. $result = $this->rcon->rcon("pb_sv_kick ".$this->getPbid()." $time $reason^7");
  263. if (stripos($result, "Kick Command Issued") === false) {
  264. $this->logging->write(MOD_WARNING, "Error kicking player '".$this->name."' with pb_sv_kick, using clientkick, PID: ".$this->pid.", GUID:".$this->guid);
  265. $this->rcon->rcon("tempBanClient " . $this->pid);
  266. }
  267. }
  268. else {
  269. $this->say($this->mod->getLngString("playerBanReasonNoPb", array("<REASON>"), array($reason)));
  270. $this->say($this->mod->getLngString("playerBanReasonNoPb", array("<REASON>"), array($reason)));
  271.  
  272. sleep(1);
  273.  
  274. $this->rcon->rcon("tempBanClient " . $this->pid);
  275. }
  276.  
  277. $kickerlog = ($kicker !== false) ? $this->players[$kicker]->getName() : "MOD";
  278. $this->logging->write(MOD_NOTICE, "Player '$this->name' got temporarily banned for $time minutes (by: $kickerlog), reason: $reason, PID: $this->pid, GUID: $this->guid");
  279.  
  280. if ($this->mod->getCV("kickban", "announce")) {
  281. if ($kicker !== false) {
  282. $search = array("<PLAYER>", "<KICKER>", "<REASON>", "<TIME>");
  283. $replace = array($this->getName(), $this->players[$kicker]->getName(), $reason ? $reason : $this->mod->getCV("kickban", "defaultbanreason"), ($time) ? $time : $this->mod->getCV("kickban", "pbtempbanduration"));
  284. $this->mod->rconSay($this->mod->getLngString("playerTempBannedPublicMsg", $search, $replace));
  285. }
  286. else {
  287. $search = array("<PLAYER>", "<REASON>", "<TIME>");
  288. $replace = array($this->getName(), $reason ? $reason : $this->mod->getCV("kickban", "defaultbanreason"), ($time) ? $time : $this->mod->getCV("kickban", "pbtempbanduration"));
  289. $this->mod->rconSay($this->mod->getLngString("playerTempBannedPublicMsgAuto", $search, $replace));
  290. }
  291. }
  292.  
  293. $this->mod->triggerEvent("playerTempBanned", array($this->guid, $reason, $time ? $time : $this->mod->getCV("kickban", "pbtempbanduration"), $kicker));
  294.  
  295. return true;
  296. }
  297.  
  298. public function isProtected() {
  299. $admin = $this->mod->getAdminByGuid($this->guid);
  300. if (!$admin) return false;
  301. return (bool) $admin["protected"];
  302. }
  303.  
  304. public function getAllowedCommands() {
  305. return $this->mod->getGroupCommands($this->getGroup());
  306. }
  307.  
  308. public function setProtection($bool) {
  309. $bool = (bool)$bool;
  310. if ($this->isProtected() && $bool) {
  311. return true;
  312. }
  313. if (!$this->isProtected() && !$bool) {
  314. return true;
  315. }
  316. return $this->mod->updateAdmin($this->guid, array("protected" => (int)$bool));
  317.  
  318. }
  319.  
  320. public function getLastVictim() {
  321. if (!$this->lastvictim || !array_key_exists($this->lastvictim, $this->players)) {
  322. return false;
  323. }
  324. return $this->lastvictim;
  325. }
  326.  
  327. public function getLastKiller() {
  328. if (!$this->lastkiller || !array_key_exists($this->lastkiller, $this->players)) {
  329. return false;
  330. }
  331. return $this->lastkiller;
  332. }
  333.  
  334. public function setGroup($group) {
  335. if ($group == $this->getGroup()) {
  336. return true;
  337. }
  338. if ($group == "default" && $this->getGroup() != "default") {
  339. $this->mod->deleteAdmin($this->guid);
  340. }
  341. elseif ($group != "default" && $this->getGroup() == "default") {
  342. $this->mod->addAdmin($this->guid, $group, $this->name, false);
  343. }
  344. else {
  345. $this->mod->updateAdmin($this->guid, array("group"=>$group));
  346. }
  347. }
  348.  
  349. public function death($type, $killer, $weapon, $damage, $bodypart) {
  350. $this->lastkiller = $killer;
  351. $this->lastweapondeath = $weapon;
  352. $this->deaths ++;
  353. $this->damagetaken += $damage;
  354. $this->lastdeathwastk = false;
  355.  
  356. if ($type == "teamkill") {
  357. $this->teamdeaths ++;
  358. $this->lastdeathwastk = true;
  359. $this->mod->triggerEvent("playerTeamDeath", array($this->guid, $killer, $weapon, $damage, $bodypart));
  360. }
  361. elseif ($type == "selfkill") {
  362. $this->selfkills ++;
  363. $this->lastkiller = $this->guid;
  364. $this->lastvictim = $this->guid;
  365. $this->lastweaponkill = $weapon;
  366. $this->lastkillwastk = false;
  367. $this->mod->triggerEvent("playerSelfKill", array($this->guid, $weapon, $damage, $bodypart));
  368. }
  369. else {
  370. $this->mod->triggerEvent("playerDeath", array($this->guid, $killer, $weapon, $damage, $bodypart));
  371. }
  372. }
  373.  
  374. public function kill($type, $victim, $weapon, $damage, $bodypart) {
  375. $this->lastvictim = $victim;
  376. $this->lastweaponkill = $weapon;
  377. $this->lastkillwastk = false;
  378.  
  379. if ($type == "kill") {
  380. $this->kills ++;
  381. $this->damagegiven += $damage;
  382. if ($weapon[1] == "MOD_HEAD_SHOT") {
  383. $this->headshots ++;
  384. }
  385. $this->mod->triggerEvent("playerKill", array($this->guid, $victim, $weapon, $damage, $bodypart));
  386. }
  387. elseif ($type == "teamkill") {
  388. $this->teamdamagegiven += $damage;
  389. $this->teamkills ++;
  390. $this->lastkillwastk = true;
  391. $this->mod->triggerEvent("playerTeamKill", array($this->guid, $victim, $weapon, $damage, $bodypart));
  392.  
  393. }
  394. }
  395.  
  396. public function damageTaken($type, $attacker, $weapon, $damage, $bodypart) {
  397. $this->damagetaken += $damage;
  398. if ($type == "teamdamage") {
  399. $this->mod->triggerEvent("playerTeamDamageTaken", array($this->guid, $attacker, $weapon, $damage, $bodypart));
  400. }
  401. elseif ($type == "damage") {
  402. $this->mod->triggerEvent("playerDamageTaken", array($this->guid, $attacker, $weapon, $damage, $bodypart));
  403. }
  404. elseif ($type == "selfdamage") {
  405. $this->mod->triggerEvent("playerSelfDamage", array($this->guid, $weapon, $damage, $bodypart));
  406. }
  407. }
  408.  
  409. public function damageGiven($type, $victim, $weapon, $damage, $bodypart) {
  410. if ($type == "teamdamage") {
  411. $this->teamdamagegiven += $damage;
  412. $this->mod->triggerEvent("playerTeamDamageGiven", array($this->guid, $victim, $weapon, $damage, $bodypart));
  413. }
  414. elseif ($type == "damage") {
  415. $this->damagegiven += $damage;
  416. $this->mod->triggerEvent("playerDamageGiven", array($this->guid, $victim, $weapon, $damage, $bodypart));
  417. }
  418.  
  419. }
  420.  
  421. public function vehicleDamageGiven($type, $entityid, $weapon, $damage, $bodypart) {
  422. if ($type == "teamdamage") {
  423. $this->teamvehicledamagegiven += $damage;
  424. $this->mod->triggerEvent("playerTeamVehicleDamageGiven", array($this->guid, $entityid, $weapon, $damage, $bodypart));
  425. }
  426. elseif ($type == "damage") {
  427. $this->vehicledamagegiven += $damage;
  428. $this->mod->triggerEvent("playerVehicleDamageGiven", array($this->guid, $entityid, $weapon, $damage, $bodypart));
  429. }
  430. }
  431.  
  432. public function actorsDamageGiven($type, $entityid, $weapon, $damage, $bodypart) {
  433. if ($type == "teamdamage") {
  434. $this->teamactorsdamagegiven += $damage;
  435. $this->mod->triggerEvent("playerTeamActorsDamageGiven", array($this->guid, $entityid, $weapon, $damage, $bodypart));
  436. }
  437. elseif ($type == "damage") {
  438. $this->actorsdamagegiven += $damage;
  439. $this->mod->triggerEvent("playerActorsDamageGiven", array($this->guid, $entityid, $weapon, $damage, $bodypart));
  440. }
  441. }
  442.  
  443. public function getPbid() {
  444. return $this->pid + 1;
  445. }
  446. }
  447.  
  448.  
  449.  
  450. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement