Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!
Echelon v2 is not yet officially released! If you cannot get this dev-version installed, revert to version 1 as available in our download section.

Author Topic: Cross server ban plugin possible?  (Read 9786 times)

Offline Glock

  • Sr. Member
  • ****
  • Posts: 172
  • Running B3 on 4 busy BF3 servers myself! B3 FTW!
Re: Cross server ban plugin possible?
« Reply #30 on: June 21, 2013, 12:04:59 AM »
Doesn't work at all mate, sorry..
Every time, I get 'permission denied'

So frustrating, I'm trying everything I can and I don't want to keep coming back saying ' no, doesn't work'....

Probably summat so simple, but I'm not able to code like this
« Last Edit: June 21, 2013, 12:07:25 AM by Glock »
Need B3 Bot Hosting for your gameservers in the UK & Europe?
Take a look at Rcon-Admin.com
Cheap + reliable B3 Bot hosting in the UK and Europe

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: Cross server ban plugin possible?
« Reply #31 on: June 21, 2013, 12:17:26 AM »
have you tried connecting with root as it should have no permission problems

Offline Glock

  • Sr. Member
  • ****
  • Posts: 172
  • Running B3 on 4 busy BF3 servers myself! B3 FTW!
Re: Cross server ban plugin possible?
« Reply #32 on: June 21, 2013, 12:18:54 AM »
Ok will try now :)
Need B3 Bot Hosting for your gameservers in the UK & Europe?
Take a look at Rcon-Admin.com
Cheap + reliable B3 Bot hosting in the UK and Europe

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: Cross server ban plugin possible?
« Reply #33 on: June 21, 2013, 12:21:03 AM »
if that fails try using the servers ip instead of localhost or 127.0.0.1 make sure the servers ip is allowed in the mysql

Offline Glock

  • Sr. Member
  • ****
  • Posts: 172
  • Running B3 on 4 busy BF3 servers myself! B3 FTW!
Re: Cross server ban plugin possible?
« Reply #34 on: June 21, 2013, 12:23:45 AM »
Hi,
Yeah I've tried local host, 127.0.1 etc..

Now, I've used root and we have a different error this time;

Code: [Select]
130620 23:21:38	ERROR	'Query failed - <class \'_mysql_exceptions.OperationalError\'>: (1136, "Column count doesn\'t match value count at row 1")'
130620 23:21:38 ERROR "handler AdminPlugin could not handle event Say: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' [('b3\\\\parser.pyo', 1066, 'handleEvents', None), ('b3\\\\plugin.pyo', 176, 'parseEvent', None), ('b3\\\\plugin.pyo', 194, 'onEvent', None), ('b3\\\\plugins\\\\admin.pyo', 401, 'handle', None), ('b3\\\\plugins\\\\admin.pyo', 545, 'OnSay', None), ('b3\\\\plugins\\\\admin.pyo', 2431, 'execute', None), ('C:\\\\B3\\\\WGG\\\\Server_3_176.57.145.118\\\\extplugins\\\\globalban.py', 117, 'cmd_globalban', None)]"
130620 23:21:38 DEBUG "getCommand: ('admin.yell', '(WGG): [pm] There was an error processing your command', '6', 'player', 'G1ock')"
Need B3 Bot Hosting for your gameservers in the UK & Europe?
Take a look at Rcon-Admin.com
Cheap + reliable B3 Bot hosting in the UK and Europe

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: Cross server ban plugin possible?
« Reply #35 on: June 21, 2013, 12:31:27 AM »
Try this

Code: [Select]
__version__ = '1.0'
__author__  = 'Spoon'

from b3.querybuilder import QueryBuilder
import b3, re, threading, MySQLdb
import b3, thread, time, string, datetime
import b3.events
import b3, re

class GlobalbanPlugin(b3.plugin.Plugin):
    _adminPlugin = None

    def onStartup(self):
      self.registerEvent(b3.events.EVT_CLIENT_AUTH)
      """\
      Initialize plugin settings
      """

      self._adminPlugin = self.console.getPlugin('admin')
      if not self._adminPlugin:
        self.error('Could not find admin plugin')
        return False
   
      if 'commands' in self.config.sections():
        for cmd in self.config.options('commands'):
          level = self.config.get('commands', cmd)
          sp = cmd.split('-')
          alias = None
          if len(sp) == 2:
            cmd, alias = sp

          func = self.getCmd(cmd)
          if func:
            self._adminPlugin.registerCommand(self, cmd, level, func, alias)

      self.debug('Started')

    def getCmd(self, cmd):
      cmd = 'cmd_%s' % cmd
      if hasattr(self, cmd):
        func = getattr(self, cmd)
        return func

      return None

    def dbconnect(self):
        self._db = MySQLdb.connect(self.config.get('db','host'),self.config.get('db','username'),self.config.get('db','password'),self.config.get('db','db'))

    def _query(self, query):
        c = self._db.cursor()
        c.execute(query)
        return c

    def query(self, query):
        if self._db or self.dbconnect():
            try:
                return self._query(query)
            except Exception as e:

                if e[0] == 2013 or e[0] == 2006:
                    self.console.error('Query failed, trying to reconnect - %s: %s' % (type(e), e))

                    if self.dbconnect():
                        try:
                            return self._query(query)
                        except Exception as e:
                            pass

                self.console.error('Query failed - %s: %s' % (type(e), e))

    def onEvent(self, event):
        if not event.client:
            return
        if event.type == b3.events.EVT_CLIENT_AUTH:
            self.checkBan(event.client)

    def checkBan(self, client):
        self.dbconnect()
       
        cursor = self.query("""SELECT reason FROM globalbans WHERE guid = '%s' AND inactive = '0' """ % (client.pbid))
        if cursor.rowcount > 0:
            r = cursor.fetchone()
            client.ban('%s ^7(Enforced Global ^1Ban^7)' % r[0])
        else:
        return False
           
       
    def cmd_globalban(self, data, client=None, cmd=None):
        """\
        <name> [<reason>] - Adds a player to the global ban list.
        """
        m = self._adminPlugin.parseUserCmd(data)
        if not m:
            client.message('^7Invalid parameters')
            return False

        cid, keyword = m
        reason = self._adminPlugin.getReason(keyword)

        if not reason and client.maxLevel < self._adminPlugin._noreason_level:
            client.message('^1ERROR: ^7You must supply a reason')
            return False

        sclient = self._adminPlugin.findClientPrompt(cid, client)
        if sclient:
            if sclient.cid == client.cid:
                self.console.say(self._adminPlugin.getMessage('ban_self', client.exactName))
                return True
            elif sclient.maxLevel >= client.maxLevel:
                if sclient.maskGroup:
                    client.message('^7%s ^7is a masked higher level player, can\'t ban' % sclient.exactName)
                else:
                    self.console.say(self._adminPlugin.getMessage('ban_denied', client.exactName, sclient.exactName))
                return True
            else:
                self.dbconnect()
                cursor = self.query("INSERT INTO globalban ( name, guid, reason, inactive ) VALUES ('%s', '%s', '%s', '0')") % (sclient.exactName, sclient.pbid, reason)
                self.checkBan(sclient)
                return True

Offline Glock

  • Sr. Member
  • ****
  • Posts: 172
  • Running B3 on 4 busy BF3 servers myself! B3 FTW!
Re: Cross server ban plugin possible?
« Reply #36 on: June 21, 2013, 12:42:27 AM »
Ok,
Progress!

But, new errors.. good sign I always say :P

Code: [Select]
130620 23:39:45	DEBUG	'AdminPlugin: Handle command !globalban shumil'
130620 23:39:45 ERROR 'STDERR "C:\\\\B3\\\\WGG\\\\Server_3_176.57.145.118\\\\extplugins\\\\globalban.py:51: Warning: Incorrect integer value: \'%s\' for column \'Name\' at row 1\\n"'
130620 23:39:45 ERROR 'STDERR "C:\\\\B3\\\\WGG\\\\Server_3_176.57.145.118\\\\extplugins\\\\globalban.py:51: Warning: Incorrect integer value: \'%s\' for column \'GUID\' at row 1\\n"'
130620 23:39:45 ERROR 'STDERR "C:\\\\B3\\\\WGG\\\\Server_3_176.57.145.118\\\\extplugins\\\\globalban.py:51: Warning: Incorrect integer value: \'%s\' for column \'Reason\' at row 1\\n"'
130620 23:39:45 ERROR "handler AdminPlugin could not handle event Say: TypeError: unsupported operand type(s) for %: 'Cursor' and 'tuple' [('b3\\\\parser.pyo', 1066, 'handleEvents', None), ('b3\\\\plugin.pyo', 176, 'parseEvent', None), ('b3\\\\plugin.pyo', 194, 'onEvent', None), ('b3\\\\plugins\\\\admin.pyo', 401, 'handle', None), ('b3\\\\plugins\\\\admin.pyo', 545, 'OnSay', None), ('b3\\\\plugins\\\\admin.pyo', 2431, 'execute', None), ('C:\\\\B3\\\\WGG\\\\Server_3_176.57.145.118\\\\extplugins\\\\globalban.py', 117, 'cmd_globalban', None)]"
130620 23:39:45 DEBUG "getCommand: ('admin.yell', '(WGG): [pm] There was an error processing your command', '6', 'player', 'G1ock')"

Need B3 Bot Hosting for your gameservers in the UK & Europe?
Take a look at Rcon-Admin.com
Cheap + reliable B3 Bot hosting in the UK and Europe

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: Cross server ban plugin possible?
« Reply #37 on: June 21, 2013, 12:43:58 AM »
are the columns set to integer?

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: Cross server ban plugin possible?
« Reply #38 on: June 21, 2013, 12:48:54 AM »
Try this

Code: [Select]
__version__ = '1.0'
__author__  = 'Spoon'

from b3.querybuilder import QueryBuilder
import b3, re, threading, MySQLdb
import b3, thread, time, string, datetime
import b3.events
import b3, re

class GlobalbanPlugin(b3.plugin.Plugin):
    _adminPlugin = None

    def onStartup(self):
      self.registerEvent(b3.events.EVT_CLIENT_AUTH)
      """\
      Initialize plugin settings
      """

      self._adminPlugin = self.console.getPlugin('admin')
      if not self._adminPlugin:
        self.error('Could not find admin plugin')
        return False
   
      if 'commands' in self.config.sections():
        for cmd in self.config.options('commands'):
          level = self.config.get('commands', cmd)
          sp = cmd.split('-')
          alias = None
          if len(sp) == 2:
            cmd, alias = sp

          func = self.getCmd(cmd)
          if func:
            self._adminPlugin.registerCommand(self, cmd, level, func, alias)

      self.debug('Started')

    def getCmd(self, cmd):
      cmd = 'cmd_%s' % cmd
      if hasattr(self, cmd):
        func = getattr(self, cmd)
        return func

      return None

    def dbconnect(self):
        self._db = MySQLdb.connect(self.config.get('db','host'),self.config.get('db','username'),self.config.get('db','password'),self.config.get('db','db'))

    def _query(self, query):
        c = self._db.cursor()
        c.execute(query)
        return c

    def query(self, query):
        if self._db or self.dbconnect():
            try:
                return self._query(query)
            except Exception as e:

                if e[0] == 2013 or e[0] == 2006:
                    self.console.error('Query failed, trying to reconnect - %s: %s' % (type(e), e))

                    if self.dbconnect():
                        try:
                            return self._query(query)
                        except Exception as e:
                            pass

                self.console.error('Query failed - %s: %s' % (type(e), e))

    def onEvent(self, event):
        if not event.client:
            return
        if event.type == b3.events.EVT_CLIENT_AUTH:
            self.checkBan(event.client)

    def checkBan(self, client):
        self.dbconnect()
       
        cursor = self.query("""SELECT reason FROM globalbans WHERE guid = '%s' AND inactive = '0' """ % (client.pbid))
        if cursor.rowcount > 0:
            r = cursor.fetchone()
            client.ban('%s ^7(Enforced Global ^1Ban^7)' % r[0])
        else:
        return False
           
       
    def cmd_globalban(self, data, client=None, cmd=None):
        """\
        <name> [<reason>] - Adds a player to the global ban list.
        """
        m = self._adminPlugin.parseUserCmd(data)
        if not m:
            client.message('^7Invalid parameters')
            return False

        cid, keyword = m
        reason = self._adminPlugin.getReason(keyword)

        if not reason and client.maxLevel < self._adminPlugin._noreason_level:
            client.message('^1ERROR: ^7You must supply a reason')
            return False

        sclient = self._adminPlugin.findClientPrompt(cid, client)
        if sclient:
            if sclient.cid == client.cid:
                self.console.say(self._adminPlugin.getMessage('ban_self', client.exactName))
                return True
            elif sclient.maxLevel >= client.maxLevel:
                if sclient.maskGroup:
                    client.message('^7%s ^7is a masked higher level player, can\'t ban' % sclient.exactName)
                else:
                    self.console.say(self._adminPlugin.getMessage('ban_denied', client.exactName, sclient.exactName))
                return True
            else:
                self.dbconnect()
                cursor = self.query("INSERT INTO globalban ( name, guid, reason, inactive ) VALUES ('%s', '%s', '%s', '0')" % (sclient.exactName, sclient.pbid, reason))
                self.checkBan(sclient)
                return True

Offline Glock

  • Sr. Member
  • ****
  • Posts: 172
  • Running B3 on 4 busy BF3 servers myself! B3 FTW!
Re: Cross server ban plugin possible?
« Reply #39 on: June 21, 2013, 12:49:59 AM »
Yeah,
I made a small SQL and it's as you would expect it..[I think lol]

But yeah it is.
I don't know what's stopping it from going through..
I will be heading off shortly, early starts late nights take it out of you  ;)

I seriously do appreciate all the help you have given so far, not only am I really grateful, I know, that in the long run, the B3 community will be too as this is a huge chuck of server banning that seems to be 'lost' when using multiple servers.

This will be a superb plugin if you can get it working and the community will definitely be thankful for it.

I can provide an environment if you need it - if there is anything I can do, please ask.
Many thanks so far
Need B3 Bot Hosting for your gameservers in the UK & Europe?
Take a look at Rcon-Admin.com
Cheap + reliable B3 Bot hosting in the UK and Europe

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: Cross server ban plugin possible?
« Reply #40 on: June 21, 2013, 12:52:42 AM »
Make the columns VARCHAR and try that last code i posted.
Glad to help, doing this cause i'm bored have to go soon too got to get up at 5am uk time 5 hours sleep :)

Offline Glock

  • Sr. Member
  • ****
  • Posts: 172
  • Running B3 on 4 busy BF3 servers myself! B3 FTW!
Re: Cross server ban plugin possible?
« Reply #41 on: June 21, 2013, 12:57:42 AM »
Same here, but a bit more sleep  07:00, when the kids wake me by jumping on my face while I'm kipping  ;D

Need B3 Bot Hosting for your gameservers in the UK & Europe?
Take a look at Rcon-Admin.com
Cheap + reliable B3 Bot hosting in the UK and Europe

Offline Glock

  • Sr. Member
  • ****
  • Posts: 172
  • Running B3 on 4 busy BF3 servers myself! B3 FTW!
Re: Cross server ban plugin possible?
« Reply #42 on: June 21, 2013, 12:59:43 AM »
I need 'values' for VARCHAR mate
 :-\
Need B3 Bot Hosting for your gameservers in the UK & Europe?
Take a look at Rcon-Admin.com
Cheap + reliable B3 Bot hosting in the UK and Europe

Offline Spoon

  • Sr. Member
  • ****
  • Posts: 255
    • EHD Gaming
Re: Cross server ban plugin possible?
« Reply #43 on: June 21, 2013, 01:02:38 AM »
might be that theres no id column try that.

Offline Glock

  • Sr. Member
  • ****
  • Posts: 172
  • Running B3 on 4 busy BF3 servers myself! B3 FTW!
Re: Cross server ban plugin possible?
« Reply #44 on: June 21, 2013, 01:12:20 AM »
Ok

it's authenticating clients, it's also checking for bans!
Result!

Then I had the following;
130621 00:04:24   ERROR   'Query failed - <class \'_mysql_exceptions.ProgrammingError\'>: (1146, "Table \'b31.globalban\' doesn\'t exist")'

So I probably need to do some cleaning.
My B3 backup DB is, b31, IN B31 is table 'globalbans' with colums name, guid, reason, inactive..

So she's logging, checking, looking for bans then stopping due to a table error of some sorts, it says it doesn't exist but perhaps I've missed something.

Progress, a headway.
I hope this helps?

Cheers and thanks again
Need B3 Bot Hosting for your gameservers in the UK & Europe?
Take a look at Rcon-Admin.com
Cheap + reliable B3 Bot hosting in the UK and Europe

 


Rate this page +1 at Google Search

anything