Advertisement
Guest User

Reports.

a guest
Oct 8th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.87 KB | None | 0 0
  1. sub EVENT_SAY
  2. {
  3.     if($text=~/^Report/i && !defined $qglobals{Report})
  4.     {
  5.         $dbh = DBI_CONNECT();
  6.         quest::setglobal("Report", 1, 5, "M30");
  7.         my $time = localtime;
  8.         my $split = substr($text, 7);
  9.         quest::gmsay("$name ($time): $split", 331, 1, 0, 80);
  10.         $sth = $dbh->prepare("SELECT max(id) FROM messaging");
  11.         $sth->execute();
  12.         my $id = $sth->fetchrow_array()+1;
  13.         $query = "INSERT INTO messaging VALUES ('$id', '$name', '$split', '$time')";
  14.         $sth = $dbh->do($query);
  15.         $sth->finish();
  16.         $dbh->disconnect();
  17.     }  
  18.     elsif($text=~/^Report/i && defined $qglobals{Report})
  19.     {
  20.         $client->Message(327, "You have sent in a report in the last 30 minutes, try again later.");
  21.     }
  22.  
  23.     if($status >= 80)
  24.     {
  25.         if($text=~/^ViewMessages/i)
  26.         {
  27.             $dbh = DBI_CONNECT();
  28.             $query = "SELECT id, name, message, time FROM messaging ORDER BY id ASC LIMIT 0,1000";
  29.             $sth = $dbh->prepare($query);
  30.             $sth->execute();
  31.             $query2 = "SELECT COUNT(id) FROM messaging";
  32.             $sth2 = $dbh->prepare($query2);
  33.             $sth2->execute();
  34.             my $results = $sth2->fetchrow_array();
  35.             if($results > 0)
  36.             {
  37.                 while(my($pid, $pname, $pmessage, $ptime) = $sth->fetchrow_array())
  38.                 {
  39.                     $client->Message(327, "Message $pid - $pname ($ptime): $pmessage");
  40.                 }
  41.                 $sth->finish();
  42.                 $dbh->disconnect();
  43.             }
  44.             else
  45.             {
  46.                 $client->Message(327, "There are currently no reports.");
  47.             }
  48.         }
  49.     }
  50.  
  51.     if($status >= 200)
  52.     {
  53.         if($text=~/^ClearMessages/i)
  54.         {
  55.             $dbh = DBI_CONNECT();
  56.             $query = "TRUNCATE TABLE messaging";
  57.             $sth = $dbh->do($query);
  58.             quest::gmsay("All reports have been cleared by $name.", 331, 1, 0, 80);
  59.         }
  60.     }
  61. }
  62.  
  63. sub DBI_CONNECT
  64. {
  65.     use DBI;
  66.     $database = "CHANGEME";
  67.     $host = "CHANGEME";
  68.     $username = "CHANGEME";
  69.     $password = "CHANGEME";
  70.     $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", "$username", "$password", {RaiseError => 1});
  71.     return $dbh;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement