Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!

Author Topic: bantopic creator miniplugin  (Read 12443 times)

Offline wurst

  • Jr. Member
  • **
  • Posts: 22
bantopic creator miniplugin
« on: October 08, 2011, 05:09:11 PM »
he, im a bit lost with re-writing a little plugin for b3.
im having the v 1.50 on win32 running utr41 serwer.
i want to sent a http request to my webserver.
in order to create a topic about the banner/banned in forums.
i just need to pass some get variables.

unclefragger once made a mumble channel switcher, using matched player/phpbb/mumble users.
this is a very early version of his script, kicking out the http request on team change:

Code: python [Select]

__version__ = '0.0.1'
__author__  = 'Unclefragger'

import b3, time, threading, re
from b3 import clients
import b3.events
import b3.plugin
import b3.cron
import datetime, string
import urllib2

#--------------------------------------------------------------------------------------------------
class ChanswitcherPlugin(b3.plugin.Plugin):
  
  def startup(self):
    """\
    Initialize plugin settings
    """
    # listen for client events
    self.registerEvent(b3.events.EVT_CLIENT_TEAM_CHANGE)

  def onEvent(self, event):
    """\
    Handle intercepted events
    """
    if not event.client or event.client.cid == None:
      return
    
    # start that call ...
    client_id = event.client.id
    client_name = event.client.name
    client_team = event.data

    urlStr = 'http://192.168.*.*/cgi-bin/move_player.cgi?guid=' + str(client_id) + '&team=' + str(client_team)
    try:
   fileHandle = urllib2.urlopen(urlStr)
   fileHandle.close()
    except IOError:
   self.plugin.warn("http request failed")





now i tried to do something like:

Code: python [Select]

__version__ = '0.0.1'
__author__  = 'plz'

import b3, time, threading, re
from b3 import clients
import b3.events
import b3.plugin
import b3.cron
import datetime, string
import urllib2

#--------------------------------------------------------------------------------------------------
class BantopicPlugin(b3.plugin.Plugin):
  
  def startup(self):

    # listen for client events
    self.registerEvent(b3.events.EVT_CLIENT_BAN)
    
    # (b3.events.Event(b3.events.EVT_CLIENT_BAN, reason, client))

  def onEvent(self, event):

    client = event.client
    reason = event.reason

    urlStr = 'http://192.168.*.*/old/dswp_tools/bantopic/bantopic.php?client=' + str(client) + '&reason=' + str(reason)
    
    try:
   fileHandle = urllib2.urlopen(urlStr)
   fileHandle.close()
    except IOError:
   self.plugin.warn("http request failed")



http://www.dswp.de/old/dswp_tools/bantopic/bantopic.php?clientid=123&name=haxor&reason=fufufurrrr must be .htaccessed later (or i make some webdir in lan)

can someone explain me whats going on and howto behave?

thx in advance
« Last Edit: October 09, 2011, 07:00:14 PM by wurst »

Offline wurst

  • Jr. Member
  • **
  • Posts: 22
Re: bantopic creator miniplugin
« Reply #1 on: October 09, 2011, 09:39:12 PM »

::BUMP::


He, i changed the BAN to BAN_TEMP, i set Log Level to 10, i removed the variables for testing:

Code: python [Select]

__version__ = '0.0.1'
__author__  = 'plz'

import b3, time, threading, re
from b3 import clients
import b3.events
import b3.plugin
import b3.cron
import datetime, string
import urllib2

#--------------------------------------------------------------------------------------------------
class BantopicPlugin(b3.plugin.Plugin):

  def startup(self):

    # listen for !ban events
   self.registerEvent(b3.events.EVT_CLIENT_BAN_TEMP)

    # (b3.events.Event(b3.events.EVT_CLIENT_BAN_TEMP, reason, client))

  def onEvent(self, event):
   # if not event.client or event.client.cid == None:
    # return

    #client_id = event.client
    # client_id = event.data
    # reason_id = event.reason
    #reason_id = event.client

    urlStr = 'http://192.168.*.*/old/dswp_tools/bantopic/bantopic.php?client=123&reason=fufufu'
    
    try:
     fileHandle = urllib2.urlopen(urlStr)
     fileHandle.close()
    except IOError:
     self.plugin.warn("http request failed")


all seem ok here:

Code: [Select]
111009 21:34:33	BOT    	Loading Plugin #20 bantopic [G:\gameservers\UrbanTerror\b3_22225\b3\extplugins\conf\bantopic.xml]
111009 21:34:33 INFO Could not load built in plugin bantopic (No module named bantopic)
111009 21:34:33 INFO trying external plugin directory : G:\gameservers\UrbanTerror\b3_22225\b3\extplugins
111009 21:34:33 BOT     BantopicPlugin: Loading config G:\gameservers\UrbanTerror\b3_22225\b3\extplugins\conf\bantopic.xml for BantopicPlugin
111009 21:34:33 DEBUG Register Event: Stop Process: BantopicPlugin
111009 21:34:33 DEBUG Register Event: Program Exit: BantopicPlugin
111009 21:34:33 BOT     Plugin bantopic (0.0.1 - plz) loaded

...and here

Code: [Select]
111009 21:34:34	BOT    	Starting Plugin bantopic
111009 21:34:34 DEBUG Register Event: Client Temp Banned: BantopicPlugin


but it keeps telling me this when i !ban:

Code: [Select]
111009 21:35:43	ERROR	handler BantopicPlugin could not handle event Client Temp Banned: AttributeError: BantopicPlugin instance has no attribute 'plugin' [('G:\\gameservers\\UrbanTerror\\b3_22225\\b3\\parser.py', 933, 'handleEvents', 'hfunc.parseEvent(event)'), ('G:\\gameservers\\UrbanTerror\\b3_22225\\b3\\plugin.py', 157, 'parseEvent', 'self.onEvent(event)'), ('G:\\gameservers\\UrbanTerror\\b3_22225\\b3\\extplugins\\bantopic.py', 37, 'onEvent', 'self.plugin.warn("http request failed")')]
0:0:26
111009 21:35:43 CONSOLE 1:20 ClientDisconnect: 5

AttributeError: BantopicPlugin instance has no attribute 'plugin'.

im kinda lost...
« Last Edit: October 09, 2011, 09:47:11 PM by wurst »

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: bantopic creator miniplugin
« Reply #2 on: October 10, 2011, 06:25:04 PM »
would it not just be easier to make a .php page that pulls active bans from the sql and makes an appeal system like i have here http://ehdgaming.co.uk/viewbans.php

Offline MordyT

  • Support Hero
  • Hero Member
  • *
  • Posts: 3644
  • Over $300 Donated to B3!
    • MordyT
Re: bantopic creator miniplugin
« Reply #3 on: October 10, 2011, 06:54:37 PM »
Care to share that PHP script spoon? It looks awesome as always!
Help will be given to those with a b3.log

If drop off the map it is due to RL becoming busy :)

System: Python 2.7.3 - Deb 7 - B3 Source Code - 128MB RAM box (rented at $5 a year) - remote MySQL - Remote Web Services

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: bantopic creator miniplugin
« Reply #4 on: October 10, 2011, 08:21:06 PM »
It was made by Seven it runs though our forum and i dont know it works for phpbb3 its coded in a wired way. But the main idea is just a sql query
SELECT * FROM cleints WHERE penaltie = 'ban' AND inactive = '0'
then display the info in a table with and appeal ban button that submits all the data into another table with the users reason to unban them.

Offline wurst

  • Jr. Member
  • **
  • Posts: 22
Re: bantopic creator miniplugin
« Reply #5 on: October 27, 2011, 10:12:41 AM »
ah, thix for the tips, in between i got it running.
i think its always useful when u can shoot urls with GET_variables.
maybe its noobish.

the thing in my case is: im having more information cause the admin is always a phpbb user.
ingame rights are in fact hooked to phpbb groups, from phpbb integrates mumble, irc and teh rest.
so i have a user that posts, its the admin. that user can attach a demo, a poll is automatically started.
here u can see a (srv very) old "dswp cheatsheet" (05-2009)

oki first the result...
http://www.dswp.de/old/lamas-corner/
(all posts with red name are auto- generated)

now i have 2 scripts...
1.) B3 Linkshooter
Code: python [Select]

#
# BanTopic Plugin for BigBrotherBot(B3) (www.bigbrotherbot.net)
# Copyright (C) 2011 <[dswp]Wursti>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# Changelog:
# version 0.0.1: 10.10.2011 Basic functionality by sending banned clients ID via http request PHP $_GET variable
#
#
#
__version__ = '0.0.1'
__author__  = 'plz'

import b3, time, threading, re
from b3 import clients
import b3.events
import b3.plugin
import b3.cron
import datetime, string
import urllib


class BantopicPlugin(b3.plugin.Plugin):

  def startup(self):

    # listen for !ban events
   self.registerEvent(b3.events.EVT_CLIENT_BAN_TEMP)


  def onEvent(self, event):

    clientid = event.client.id

    urlStr = 'http://www.dswp.de/old/dswp_tools/bantopic/bantopic.php?srvport=22222&clientid=' + str(clientid)
   
    try:
     fileHandle = urllib.urlopen(urlStr)
     fileHandle.close()
    except IOError:
     self.plugin.warn("http request failed")


2.) PhpBB Poster

Code: php [Select]


<?php
// know that phpbb has its own posting api, this is cheap hax.
// maden 10-2011 by wursti && do not try this at home! :P

include '../../config.php' ;

$testmode = 0;
$sqllog   = 0;

//who let the dogs in?

if ($testmode == 0) {
$ip = $_SERVER['REMOTE_ADDR'];
if ( $ip != '192.168.9.1' ) {echo "$ip must go home now!"; die; }
                    }



$clientid = $_GET['clientid'];
$srvport = $_GET['srvport'];

if ($clientid == '') {echo 'hello world?'; die; }
if ($srvport == '') {echo 'forgot some serwer port?'; die; }


//debug $clientid = 7900; $srvport = 22225;


//Grab corresponting Admin and Userdata
$db = mysql_connect ($dbhost, $dbuser, $dbpasswd) or die(mysql_error());

mysql_select_db($dbname, $db) or die('Cannot select database');

$sql_banned = "SELECT
pu.user_id AS admin_phpbb_id,
pe.admin_id AS admin_b3_id,
pu.username AS admin_phpbb_name,
cla.name AS admin_b3_name,
sta.id AS admin_xlr_id,
cl.id AS client_b3_id,
stc.id AS client_xlr_id,
cl.name AS client_name,
FROM_UNIXTIME(pe.time_add) AS time_add_normal,
pe.time_add,
UNIX_TIMESTAMP(now()) as time_now,
FROM_UNIXTIME(pe.time_edit) AS time_edit_normal,
FROM_UNIXTIME(pe.time_expire) AS time_expire_normal,
pe.duration,
pe.reason,
pe.id AS penalty_id

FROM
phpbb_users pu

INNER JOIN bot$srvport.penalties pe          on pu.b3_id_$srvport = pe.admin_id
INNER JOIN bot$srvport.clients cl            on pe.client_id = cl.id
INNER JOIN bot$srvport.clients cla           on pe.admin_id = cla.id
INNER JOIN bot$srvport.xlr_playerstats sta   on pe.admin_id = sta.client_id
LEFT  JOIN bot$srvport.xlr_playerstats stc   on pe.client_id = stc.client_id  -- maybe victim has no stats yet...

where pe.client_id = $clientid
order by pe.time_add desc
limit 0,1;"
;

//debug echo $sql_banned;

$query=mysql_query($sql_banned, $db);
$row=mysql_fetch_assoc($query);

// htmlentities($str, ENT_QUOTES)

$admin_phpbb_id =      $row['admin_phpbb_id'];
$admin_b3_id =         $row['admin_b3_id'];
$admin_phpbb_name  =   htmlentities($row['admin_phpbb_name'], ENT_QUOTES);
$admin_b3_name  =      htmlentities($row['admin_b3_name'], ENT_QUOTES);
$admin_xlr_id  =       $row['admin_xlr_id'];
$client_b3_id  =       $row['client_b3_id'];
$client_xlr_id  =      $row['client_xlr_id'];
$client_name  =        htmlentities($row['client_name'], ENT_QUOTES);
$time_add_normal  =    $row['time_add_normal'];
$time_add  =           $row['time_add'];
$time_now  =           $row['time_now'];
$time_edit_normal  =   $row['time_edit_normal'];
$time_expire_normal  = $row['time_expire_normal'];
$duration  =           $row['duration'];
$reason  =             htmlentities($row['reason'], ENT_QUOTES);
$penalty_id  =         $row['penalty_id'];

//logging excel- compatible csv omg
$logfile = "./autobanlog.csv";
if (file_exists($logfile)) { $logexist = 1; }
$linebreak = "\n";

$firstline = "admin_phpbb_id ; admin_b3_id ;admin_phpbb_name ; admin_b3_name ; admin_xlr_id ; client_b3_id ; client_xlr_id ; client_name ; time_add_normal ; time_add ; time_now ; time_edit_normal ; time_expire_normal ; duration ; reason ; penalty_id ;";
$logline = "$admin_phpbb_id ; $admin_b3_id ;$admin_phpbb_name ; $admin_b3_name ; $admin_xlr_id ; $client_b3_id ; $client_xlr_id ; $client_name ; $time_add_normal ; $time_add ; $time_now ; $time_edit_normal ; $time_expire_normal ; $duration ; $reason ; $penalty_id ;";



$fh = fopen($logfile, 'a') or die("can't open $logfile");


if ($logexist != 1)  {
                     fwrite($fh, $firstline);
                     fwrite($fh, $linebreak);
                     }
                     fwrite($fh, $logline);
                     fwrite($fh, $linebreak);
                     
if ($sqllog == 1)    {
                     fwrite($fh, $linebreak);
                     fwrite($fh, $sql_banned);
                     fwrite($fh, $linebreak);
                     fwrite($fh, $linebreak);
                     }
                     
                     fclose($fh);




$duration_days = $duration / ( 1440 );
$time_add_ago = $time_now - $time_add ;

//die on several reasons^^

if ($testmode == 0) {
                      if ($duration == 0 )        {echo 'kick only?'; die; }
                      if ($duration < 4319 )      {echo 'shorter then 3d ban.'; die; }
                      if ($admin_b3_id == 0 )     {echo 'b3 generated penalty. ciao.'; die; }
                      if ($reason == '' )         {echo 'admin must give a reason lol.'; die; }
                      if ( $time_add_ago > 3 )    {echo "that ban is $time_add_ago seconds old. 3 seconds is maximum"; die; }
                    }



if ($srvport == 22222)     {$statspath = "[url=http://www.dswp.de/old/tdm-player$client_xlr_id:359wpamd] $client_xlr_id [/url:359wpamd]";
                            $echlonpath = "[url=http://www.dswp.de/echelon/clientdetails.php?game=1&id=$client_b3_id:359wpamd] $client_b3_id [/url:359wpamd]";
                           }
elseif ($srvport == 22223) {$statspath = "[url=http://www.dswp.de/old/bomb-player$client_xlr_id:359wpamd] $client_xlr_id [/url:359wpamd]";
                            $echlonpath = "[url=http://bomb.dswp.de/echelon/clientdetails.php?game=1&id=$client_b3_id:359wpamd] $client_b3_id [/url:359wpamd]";
                           }
elseif ($srvport == 22225) {$statspath = "[url=http://www.dswp.de/old/ts-player$client_xlr_id:359wpamd] $client_xlr_id [/url:359wpamd]";
                            $echlonpath = "[url=http://teamsurvivor.dswp.de/echelon/clientdetails.php?game=1&id=$client_b3_id:359wpamd] $client_b3_id [/url:359wpamd]";
                           }

if ($client_xlr_id == ''){   $statspath  = "No Stats collected yet.";  }



                         
//create topic in lamas corner
// post a new topic, post, edit forums

//setup post text
$post_text= <<<ENDE

$client_name banned cause $reason

XLR ID: $statspath
B3  ID: $echlonpath

Ban Added: $time_add_normal
TempBan Expires: $time_expire_normal

Duration: $duration_days days
Penalty ID: $penalty_id

ENDE;


$new_cyc_time = time();

// new post
mysql_query("INSERT INTO phpbb_posts (forum_id,poster_id,post_time,post_subject,post_text,bbcode_bitfield,bbcode_uid)
VALUES ('16','$admin_phpbb_id','$new_cyc_time','$client_name banned [$reason]','$post_text','EA==','359wpamd')");

$cyc_postid = mysql_insert_id();


// new topic with poll
mysql_query("INSERT INTO phpbb_topics
            (forum_id,topic_title,topic_poster,topic_time,topic_first_post_id,topic_first_poster_name,topic_first_poster_colour,topic_last_post_id,topic_last_poster_id,topic_last_poster_name,topic_last_poster_colour,topic_last_post_subject,topic_last_post_time,topic_auto_created,poll_title,poll_start,poll_max_options,poll_vote_change)
     VALUES ('16','[BANNED] $client_name BY [$admin_b3_name] CAUSE [$reason]','$admin_phpbb_id','$new_cyc_time','$cyc_postid','$admin_phpbb_name','FC0204','$cyc_postid','$admin_phpbb_id','$admin_phpbb_name','FC0204','$client_name banned [$reason]','$new_cyc_time','1','Extend Ban?','$new_cyc_time','1','1')");

$cyc_topicid = mysql_insert_id();

//new poll with topic id
mysql_query("INSERT INTO phpbb_poll_options
             (poll_option_id,topic_id,poll_option_text,poll_option_total)
       VALUES('1','$cyc_topicid','Extend Ban!','1')");
       
mysql_query("INSERT INTO phpbb_poll_options
             (poll_option_id,topic_id,poll_option_text,poll_option_total)
       VALUES('2','$cyc_topicid','Drop Ban!','0')");
       
//store a vote for the admin as Extend!       
mysql_query("INSERT INTO phpbb_poll_votes
             (topic_id,poll_option_id,vote_user_id,vote_user_ip)
       VALUES('$cyc_topicid','1','$admin_phpbb_id','192.168.9.1')");


// topic_id into post
mysql_query("UPDATE phpbb_posts SET topic_id=$cyc_topicid WHERE post_id=$cyc_postid");

// edit forum
mysql_query("UPDATE phpbb_forums SET forum_posts=forum_posts+1,forum_topics=forum_topics+1,
forum_topics_real=forum_topics_real+1,forum_last_post_id='$cyc_postid',forum_last_poster_id='$admin_phpbb_id',
forum_last_post_subject='$client_name banned [$reason]',forum_last_post_time='$new_cyc_time',
forum_last_poster_name='$admin_phpbb_name',forum_last_poster_colour='FC0204' WHERE forum_id='16'");


// +1 post for the admin :)
mysql_query("UPDATE phpbb_users SET user_posts=user_posts+1 WHERE user_id=$admin_phpbb_id");


?>


ill post the thing again when its finished.
i dunno how big the need of other people is, its everything dependent on phpbb.
the b3 1.70 should have more variables coming with the CLIENT_TEMP_BAN, so the query and filtering could be less intensively done (for exampe get wether a human or B3 bans before shooting mysql)

 


Rate this page +1 at Google Search