Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and are struggling to install it? Cronwerks now installs mods for only $3/$2.50 here.


AuthorTopic: Delete Inactive Users.  (Read 356 times)

Maketextgames.com

  • Active Member
  • **
  • Reputation Power: 112
  • Maketextgames.com is working their way up.Maketextgames.com is working their way up.Maketextgames.com is working their way up.
  • Offline Offline
  • Posts: 204
    • MSN Messenger - immortalthug4ever@hotmail.com
    • View Profile
    • WWW
Delete Inactive Users.
« on: February 13, 2010, 12:26:17 PM »
Simple Make-Up here, probably could have used the laston column in users but my math is bleh so doing the calculations would be a pain.

This is much simpler.


All this does is check an active type column that is updated + 1 daily.

When that column is > 30 it deletes the user.  If the user Logs in that column goes back to 0.

Nothing major.  Quick inserts.


First add the SQL

ALTER TABLE `users` ADD `oncheck` INT(11) NOT NULL DEFAULT 0;

Then open up Authenticate.php

find.
Code: [Select]
$IP = $_SERVER['REMOTE_ADDR'];
$db->query("UPDATE users SET lastip_login='$IP',last_login=unix_timestamp() WHERE userid={$mem['userid']}");

Note**** IF your IP isnt set like the above, or mysql_real_escaped change it for security reasons.

Below the code above add
Code: [Select]
$db->query("UPDATE `users` SET `oncheck` = 0 WHERE `userid`=".$mem['userid']."");

Close/Save.

Next open up Cron Day.

Above ?>

Add the following

Code: [Select]
$checkout = $db->query("SELECT u.`userid`,us.`userid` FROM `users` u LEFT JOIN `userstats` us ON u.`userid`=us.`userid` WHERE `oncheck`>30");
while($check = $db->fetch_row($checkout))
{
$db->query("DELETE FROM `users` WHERE `userid`={$check['userid']}");
$db->query("DELETE FROM `userstats` WHERE `userid`={$check['userid']}");
}

Save.  Done.


Simple really.=)


Jordan

  • Active Member
  • **
  • Reputation Power: 55
  • Jordan has no influence.
  • Offline Offline
  • Posts: 103
  • Website Developer for hire;
    • MSN Messenger - Pudda2008@hotmail.co.uk
    • View Profile
    • WWW
    • Email
Re: Delete Inactive Users.
« Reply #1 on: February 14, 2010, 07:42:48 AM »
>,< stupid (N)
Logged

Pudda2008@hotmail.co.uk - Feel free to add me on MSN

Spudinski

  • Basic Member
  • *
  • Reputation Power: 42
  • Spudinski has no influence.
  • Offline Offline
  • Posts: 52
  • I have cookies!
    • View Profile
    • WWW
    • Email
Re: Delete Inactive Users.
« Reply #2 on: February 14, 2010, 11:05:34 AM »
It's not really that hard math, though.

SQL Query:
Code: [Select]
DELETE FROM `users` WHERE `laston` <= (`laston` - 2592000)
I'm pretty sure that does just as well a job.
Logged
If you see a post that just doesn't just seem right, send me a PM.
Offering services for small-type games and websites, send me a PM if you want/need something done.

Jordan

  • Active Member
  • **
  • Reputation Power: 55
  • Jordan has no influence.
  • Offline Offline
  • Posts: 103
  • Website Developer for hire;
    • MSN Messenger - Pudda2008@hotmail.co.uk
    • View Profile
    • WWW
    • Email
Re: Delete Inactive Users.
« Reply #3 on: February 14, 2010, 11:33:11 AM »
Deleting user's because there inactive is STUPID

Although Spuds right.. All that code when you all ya need is one query really >,<
Logged

Pudda2008@hotmail.co.uk - Feel free to add me on MSN

Maketextgames.com

  • Active Member
  • **
  • Reputation Power: 112
  • Maketextgames.com is working their way up.Maketextgames.com is working their way up.Maketextgames.com is working their way up.
  • Offline Offline
  • Posts: 204
    • MSN Messenger - immortalthug4ever@hotmail.com
    • View Profile
    • WWW
Re: Delete Inactive Users.
« Reply #4 on: February 14, 2010, 05:19:06 PM »
I wasn't entirely sure how the last-on bit worked as it's several integers even if I just logged in, so wasnt grapsing the concept.

@Pudda, someone wanted this, i just slapped it together for them and then threw on here "shrug"

code isnt largely shorter ^

As you still need 2 db queries one to remove from userstats and one from users :p

The only thing differant is you wouldnt need

$checkout = $db->query("SELECT u.`userid`,us.`userid` FROM `users` u LEFT JOIN `userstats` us ON u.`userid`=us.`userid` WHERE `oncheck`>30");
while($check = $db->fetch_row($checkout))
{

and you wouldnt need

$db->query("UPDATE `users` SET `oncheck` = 0 WHERE `userid`=".$mem['userid']."");

really not a huge differance as far as "speed" clutter" goes.

Zeddicus

  • Basic Member
  • *
  • Reputation Power: 0
  • Zeddicus is looked down upon.Zeddicus is looked down upon.
  • Offline Offline
  • Posts: 41
    • View Profile
    • WWW
Re: Delete Inactive Users.
« Reply #5 on: February 14, 2010, 06:01:00 PM »
If you use this, make sure *everything* user related is deleted aswell. (Gangs,items) ect ect. :)
Logged
New Forums http://McAddons.com.
Sign up for all the latest security updates and modifications!

Maketextgames.com

  • Active Member
  • **
  • Reputation Power: 112
  • Maketextgames.com is working their way up.Maketextgames.com is working their way up.Maketextgames.com is working their way up.
  • Offline Offline
  • Posts: 204
    • MSN Messenger - immortalthug4ever@hotmail.com
    • View Profile
    • WWW
Re: Delete Inactive Users.
« Reply #6 on: February 14, 2010, 09:17:30 PM »
Aye it all depends on what mods etc they have.  (:

Good point.

I will post queries you may need such as delete from mail, inventory, etc.

Spudinski

  • Basic Member
  • *
  • Reputation Power: 42
  • Spudinski has no influence.
  • Offline Offline
  • Posts: 52
  • I have cookies!
    • View Profile
    • WWW
    • Email
Re: Delete Inactive Users.
« Reply #7 on: February 14, 2010, 11:44:48 PM »
Yea, I still want to make a bot for that type of thing.
Based on the userID, it search all tables for that userID, and delete the related row - but since mod' developers aren't always correct in the way they do things, it's difficult as the column name that holds the userID isn't always the same.

Not even a regex search can do. :(
Logged
If you see a post that just doesn't just seem right, send me a PM.
Offering services for small-type games and websites, send me a PM if you want/need something done.

Maketextgames.com

  • Active Member
  • **
  • Reputation Power: 112
  • Maketextgames.com is working their way up.Maketextgames.com is working their way up.Maketextgames.com is working their way up.
  • Offline Offline
  • Posts: 204
    • MSN Messenger - immortalthug4ever@hotmail.com
    • View Profile
    • WWW
Re: Delete Inactive Users.
« Reply #8 on: February 14, 2010, 11:49:30 PM »
Hm, Would definitely be a resourceful idea.

CrimGame.com

  • Basic Member
  • *
  • Reputation Power: 21
  • CrimGame.com has no influence.
  • Offline Offline
  • Posts: 42
  • Play with me baby!
    • View Profile
    • WWW
Re: Delete Inactive Users.
« Reply #9 on: February 15, 2010, 06:26:48 AM »
$db->query("DELETE FROM `users` WHERE `userid`={$check['userid']}");
$db->query("DELETE FROM `userstats` WHERE `userid`={$check['userid']}");


Wow reminds me of code from 2 years back on MWG, you forgot afew tables, events, mail, logs, .... and so on

Maketextgames.com

  • Active Member
  • **
  • Reputation Power: 112
  • Maketextgames.com is working their way up.Maketextgames.com is working their way up.Maketextgames.com is working their way up.
  • Offline Offline
  • Posts: 204
    • MSN Messenger - immortalthug4ever@hotmail.com
    • View Profile
    • WWW
Re: Delete Inactive Users.
« Reply #10 on: February 15, 2010, 09:32:01 AM »
Everything Reminds you of everything, considering a dummy could code this up with minimal knowledge of PHP I sure hope you aren't implying that i actually took time to go through mwg and find something that does something so simple

You really are on yourself arent you?

CrimGame.com

  • Basic Member
  • *
  • Reputation Power: 21
  • CrimGame.com has no influence.
  • Offline Offline
  • Posts: 42
  • Play with me baby!
    • View Profile
    • WWW
Re: Delete Inactive Users.
« Reply #11 on: February 15, 2010, 10:35:14 AM »
Immortal in no way did i imply you stole any code i just simply said it reminds me of code from 2 years ago, Same discussion i participated in on MWG/CE two years ago came up with similar conclusions. I then offered my help with giving you a idea of advancing it further.

I didn't mean any disrespect, im sorry if you misinterpreted it.