Pages: [1]   Go Down
  Print  
Author Topic: IPBan plugin error  (Read 597 times) Bookmark and Share
Newbie
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: COD4
Posts: 5
Offline Offline
« on: December 26, 2011, 01:11:34 PM »

So I'm making a plugin that will ban by IPs and I'm getting messed up in my code inserting the banned ips into the SQL table I created. This is the code I have so far, the command works but SQL doesn't.

    def cmd_ipban(self, data, client=None, cmd=None):
   input = self._adminPlugin.parseUserCmd(data)
   cursor = self.console.storage.query( "INSERT INTO ippens VALUES (0,%s)" % input[0])
   cursor.close()

Thank you! Cheesy
Logged

Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #1 on: December 26, 2011, 02:25:50 PM »

you are not telling what the error message is
Logged

Newbie
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: COD4
Posts: 5
Offline Offline
« Reply #2 on: December 26, 2011, 03:27:49 PM »

you are not telling what the error message is
i get a warning, can't handle func or something like that. the important thing is that the command looks like it works except nothing shows up when i look in the sql browser
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #3 on: December 26, 2011, 03:37:53 PM »

this is not helping much. maybe post your full plugin
Logged

Newbie
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: COD4
Posts: 5
Offline Offline
« Reply #4 on: December 26, 2011, 04:06:56 PM »

I'll upload it when I get on my pc, but from eyeballing it, can you see any mistakes with the query line?
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #5 on: December 26, 2011, 05:12:11 PM »

it looks all right (as any not working code by the way). That's why context and error messages are important.

If you can't still see what's wrong by looking at the code, then run your code with a debugger (Eclipse pydev has an easy one to use)
Logged

Newbie
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: COD4
Posts: 5
Offline Offline
« Reply #6 on: December 27, 2011, 02:48:30 PM »

Here's the full code. If you need the SQL create statement too, I can give that



Code: python
#Set the command level on line 21. Should be fairly obvious.

__version__ = 'infinity.0'
__author__  = 'Megak'

import b3
import b3.events
# Import the necessary libaries you need here, for example, I need random for the randomization of answers part of it.

#--------------------------------------------------------------------------------------------------
#This lot doesn't need to be changed for simple commands, it gets the admin plugin and registers commands.
class MegakPlugin(b3.plugin.Plugin):
   _adminPlugin = None
   requiresConfigFile = False

   def onStartup(self):  
       self._adminPlugin = self.console.getPlugin('admin')  
       if not self._adminPlugin:  
           return False  
       #SET COMMAND LEVEL HERE
       self._adminPlugin.registerCommand(self, 'getip', 90, self.cmd_getip)
       self._adminPlugin.registerCommand(self, 'banip', 90, self.cmd_ipban)


       self.registerEvent(b3.events.EVT_CLIENT_SAY)  
       self.registerEvent(b3.events.EVT_CLIENT_TEAM_SAY)  
       self.registerEvent(b3.events.EVT_CLIENT_AUTH)  
       self.registerEvent(b3.events.EVT_CLIENT_CONNECT)
 
       def onEvent(self, event):
           """\
           Handle intercepted events
           """
           if event.type == b3.events.EVT_CLIENT_CONNECT:
               cursor = self.console.storage.query( "SELECT * FROM ippens WHERE ip= %s" % event.client.ip)
               if cursor.rowcount >=1:
                   self.console.kick(event.client.cid, "Banned IP", None, True)
               cursor.close()


   def cmd_getip(self, data, client=None, cmd=None):
input = self._adminPlugin.parseUserCmd(data)
cursor = self.console.storage.query( "SELECT ip, name FROM clients WHERE id= %s" % input[0])
r = cursor.getRow()
client.message('%s IP: %s' % (r['name'], r['ip']))
cursor.close()

   def cmd_ipban(self, data, client=None, cmd=None):
input = self._adminPlugin.parseUserCmd(data)
cursor = self.console.storage.query( "INSERT INTO ippens VALUES (0,%s)" % input[0])
cursor.close()



Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #7 on: December 27, 2011, 03:24:36 PM »

probably because an IP is a string and as such needs to be wrapped with quotes in your SQL statement. Try

Code: python
"SELECT * FROM ippens WHERE ip= '%s'" % event.client.ip
Logged

Newbie
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: COD4
Posts: 5
Offline Offline
« Reply #8 on: December 28, 2011, 06:02:10 PM »

But that should be regardless of the insert command, right?
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #9 on: December 29, 2011, 01:19:27 AM »

I don't get what you mean, sorry :s

Try your sql queries in phpmyadmin or MySQL Workbench before you use them in your code, it will save you time.
Logged

Tags:
Pages: [1]   Go Up
  Print  
 
Jump to:  


Rate this page +1 at Google Search


SimplePortal 2.3.1 © 2008-2009, SimplePortal