• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Removing inactive players

Ralle Bre

New Member
Joined
Oct 9, 2010
Messages
25
Reaction score
3
Code:
<?php
	class clean extends MySQLi
	{
		//private $connected = false;

		public function __construct($host, $user, $pw, $db)
		{
			parent::__construct($host, $user, $pw, $db);

			if(mysqli_connect_error())
				die("Connection Error #".mysqli_connect_errno());

			//$this->connected = true;
			return true;
		}

		public function __destruct()
		{
			//if($this->connected)
			if($thread = $this->thread_id)
			{
				$this->kill($thread);
				$this->close();
			}

			return true;
		}

		function getPlayers($days = 30)
		{
			$query = $this->query("SELECT `players`.`id` FROM `players` WHERE `players`.`lastlogin` <= ".(time() - $days * 24 * 3600).";");
			$players = array();

			if($query->rowCount())
				while($f = $query->fetch())
					$players[] = $f[0];

			return $players;
		}

		function getAccounts()
		{
			$query = $this->query("SELECT `accounts`.`id` FROM `accounts` WHERE `accounts`.`id` NOT IN(SELECT `players`.`account_id` FROM `players`);");
			$accounts = array();

			if($query->rowCount())
				while($f = $query->fetch())
					$accounts[] = $f[0];

			return $accounts;
		}

		function deletePlayers($players)
		{
			if(!$players)
				return false;

			$query = "DELETE FROM `players` WHERE `players`.`id` = '{$players[0]}'";

			if(count($players) > 1)
				for($i = 1; $i < count($players); $i++)
					$query .= " OR `players`.`id` = '{$players[$i]}'";

			$this->query($query.";");

			return true;
		}

		function deleteAccounts($accounts)
		{
			if(!$accounts)
				return false;

			$query = "DELETE FROM `accounts` WHERE `accounts`.`id` = '{$accounts[0]}'";

			if(count($accounts) > 1)
				for($i = 1; $i < count($accounts); $i++)
					$query .= " OR `accounts`.`id` = '{$accounts[$i]}'";

			$this->query($query.";");

			return true;
		}
	}

	$clean = new clean("host", "user", "pw", "db");

	$players = $clean->getPlayers();
	$accounts = $clean->getAccounts();

	if($players)
	{
		echo count($players)." players<br />\n";
		$clean->deletePlayers($players);
	}

	if($accounts)
	{
		echo count($accounts)." accounts<br />\n";
		$clean->deleteAccounts($accounts);
	}

	unset($clean);
?>

NOTE: It's untested and I have no clue if it works, if you dont know how to use it, you don't deserve to have it.
 
retard. have begginers in this forum.
if u don't know how to explain dont post.
 
Nice.. time to show people they won't receive everything ready-to-use in their lives.

Thank you, Ralle Bre.
 
nice script but atm i dont host a server so i dont really need it.
but maby you can upgrade your script to make it like when ppl are inactive for 2 weeks it put there account + characters in detention room and if the players are still not logged in for 1 week then it would be deleted.
 
nice script but atm i dont host a server so i dont really need it.
but maby you can upgrade your script to make it like when ppl are inactive for 2 weeks it put there account + characters in detention room and if the players are still not logged in for 1 week then it would be deleted.

Detention room ? What are we in elementary school now ?
 
Back
Top