You are here: Big Brother Bot ForumCommunity DevelopersPlugin DevelopersAdd Ban Into Database Without Kicking Client?
Pages: 1 [2]   Go Down
  Print  
Author Topic: Add Ban Into Database Without Kicking Client?  (Read 1229 times) Bookmark and Share
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #15 on: September 16, 2011, 01:22:04 PM »

Ah, I guess that means my idea won't work then lol.  I tried enabling PB in b3, but it still gives the same error
Code:
110916 15:12:13 ERROR "handler WidebanxtremePlugin could not handle event Client Authenticated: TypeError: object of type 'NoneType' has no len() [('b3\\\\parser.pyo', 973, 'handleEvents', None), ('b3\\\\plugin.pyo', 158, 'parseEvent', None), ('G:\\\\UserFiles\\\\NinjaNife\\\\GameServers\\\\TC30418520720240387106885\\\\b3\\\\extplugins\\\\widebanxtreme.py', 68, 'onEvent', None)]"
    keep in mind we were discussing earlier about B3 and not about the widebanxtreme plugin. The error you code comes from that plugin. Try to fix the plugin first. Make sure that plugin is meant to work with your game. Try to contact his author for support and advice.

    Quote
    Now, there is no PB on the server itself, so I guess that could still be the problem..  Not sure; I will try to check later.
    check the widebanxtreme plugin code and see what it tries to do with the b3 event data.

    Quote
    If b3 doesn't find a PBID when a player connects, what does it send in the EVT_CLIENT_AUTH event?  Just 'None' or something else?
    See my previous post. EVT_CLIENT_AUTH event data is the Client object for the authenticated player.

    Quote
    As for the "sleep()" thing, I actually have found that in several of the plugins I use, and if it causes all of b3 to sleep then I should try to fix that.  Is there a guide available that explains how to exchange "sleep(5)" for something that won't harm b3's core functions (only sleep the plugin/section of code)?  Thanks for all the help!
    There are plenty of cases where you can use sleep. Just don't use it in onEvent() in your plugins. Here how B3 dispatches an event :

    Thread 1 - read game log :
    • B3 read a line from the game server log file and create a B3 event which is queued
    • B3 reads an other game log line,  etc

    Thread 2 - dispatches events to plugins :
    • Take a B3 event off the queue
    • If event is too old, log error "'**** Event sat in queue too long", discard and get an other one
    • Find out the list of plugins interested in that event
    • Sort that list given the plugin priority (defined by the order plugins are read from b3.xml)
    • For all plugins in that list :
    •     * if plugin is disable, discard and go to the next one
    •     * call the plugin onEvent() method with the B3 event as a parameter
    •     * wait for the plugin onEvent() method to return
    • once all plugins have made their action on that event, go get an other one off the queue
    You see that if a plugin is too long to treat an event then this same event is passed to the next plugin late.
    Only when all plugins listening for that event have finished does Thread 2 start working on the next event, in the meantime Thread 1 continues to pile up new fresh event into the queue.
    That's why it is important to return from plugin onEvent() method as soon as the plugin can.
    It is a race of Thread 2 against Thread 1. Thread 2 must keep up with the rythme of Thread 1 or some events will be discarded

    Quote
    Here is the code that handles the pbid after it is received:

    Code: python
    if len(event.client.pbid) > 0 and event.client.pbid is not None and event.client.pbid != 'None':
    I assume this is code from the widebanxtrem plugin ? Given the error
    Code:
    110914 21:35:20 ERROR   "handler WidebanxtremePlugin could not handle event Client Authenticated: TypeError: object of type 'NoneType' has no len() [('b3\\\\parser.pyo', 973, 'handleEvents', None), ('b3\\\\plugin.pyo', 158, 'parseEvent', None), ('G:\\\\UserFiles\\\\MW2\\\\GameServers\\\\TC37353467860442667146473\\\\b3\\\\extplugins\\\\widebanxtreme.py', 79, 'onEvent', None)]"
    It is safe to say that python does not like when one asks him to compute the length of something which is None. If we know that in some cases it is normal to find a None value, then we should first check that that value is not None before computing the length. Try this change :
    Code: python
    if event.client.pbid is not None and len(event.client.pbid) > 0 and event.client.pbid != 'None':
    « Last Edit: September 16, 2011, 01:27:21 PM by Courgette » Logged


    Full Member
    ***
    OS: Windows
    Type: Owner dedicated server(s)
    Gameservers: CoD4, CoD6, CoD7
    Posts: 80
    Offline Offline
    Currently hosting 40+ b3 Bots!!!
    WWW
    « Reply #16 on: September 16, 2011, 01:52:35 PM »

    O_O

    That fixed it!  I feel like an idiot for not noticing that before..wow my bad for asking all the wrong questions Courgette :/  I completely missed that (I kept trying to change the variables it checked; never thought that was the issue because only PBID crashed it..probably because the others were all used).  Thank you so much for your help, and sorry for all the trouble.  Thanks again, and have a great night.

    Brendan "NinjaNife" West

    *EDIT*
    I am taking this as a lesson to never assume that someone else's code is correct (in cases such as these anyway)..although it was a great plugin besides that problem lol.
    « Last Edit: September 16, 2011, 01:57:45 PM by NinjaNife » Logged
    Senior Dev.
    *
    OS: Linux
    Type: Home user
    Posts: 3484
    Offline Offline
    WWW
    Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
    « Reply #17 on: September 16, 2011, 02:18:17 PM »

    wow my bad for asking all the wrong questions Courgette :/  I completely missed that (I kept trying to change the variables it checked; never thought that was the issue because only PBID crashed it..probably because the others were all used).  Thank you so much for your help, and sorry for all the trouble.  Thanks again, and have a great night.
    no problem, no we are looking forward to try your future plugins Wink

    Quote
    I am taking this as a lesson to never assume that someone else's code is correct
    That is very true. Don't forget to include your own code in "someone else's code".

    Proving that an algorithm is bug proof is quite expensive to achieve and most of the time never done (because not asked for / paid by the client). For B3, one would have to test its plugin for all B3 supported games x the number of B3 supported releases x the number of different game actions the plugins acts on x the different game modes x ....  Well you can be sure no B3 plugin developer does test all those cases. When the plugin works for the game the dev used to develop, it is enough to assume the code works for most frequent cases. Of course when a unusual case happens, shit comes along. The code was correct but for the other use cases Smiley
    Quality is then : what % of all different cases was the plugin tested with ?

    One way to guestimate how OK a B3 plugin is for your game server is to look for :
    • how long does this plugin exists
    • how much support has been provided in the forums for that plugin (the more problem discussed, the more fixed)
    • how many versions of the plugin have been released
    • how many servers running the same game as me are also using this plugin
    Logged

    Full Member
    ***
    OS: Windows
    Type: Owner dedicated server(s)
    Gameservers: CoD4, CoD6, CoD7
    Posts: 80
    Offline Offline
    Currently hosting 40+ b3 Bots!!!
    WWW
    « Reply #18 on: September 16, 2011, 08:59:41 PM »

    I will be sure to remember that Smiley  What is the best thing to use instead of "sleep()"?  I have that in several plugins (ones I made and others) and figure I might as well change it out while I can..  Is there a good guide for converting them, or is it pretty easy?  Thanks again for the help!

    Brendan "NinjaNife" West
    Logged
    Senior Dev.
    *
    OS: Linux
    Type: Home user
    Posts: 3484
    Offline Offline
    WWW
    Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
    « Reply #19 on: September 16, 2011, 09:53:26 PM »

    Look at your b3.log, every minutes B3 reports statistics about plugins to highlight plugins that would be slow at working on events.

    If you feel like your plugin is way slower than other plugins, then consider using threads in your plugin. One example is the banlist plugin. The onEvent method does a first check to discard some of the events, then it calls onPlayerConnect which runs checkClient in a new thread
    Logged

    Full Member
    ***
    OS: Windows
    Type: Owner dedicated server(s)
    Gameservers: CoD4, CoD6, CoD7
    Posts: 80
    Offline Offline
    Currently hosting 40+ b3 Bots!!!
    WWW
    « Reply #20 on: September 17, 2011, 06:02:31 AM »

    Look at your b3.log, every minutes B3 reports statistics about plugins to highlight plugins that would be slow at working on events.

    If you feel like your plugin is way slower than other plugins, then consider using threads in your plugin. One example is the banlist plugin. The onEvent method does a first check to discard some of the events, then it calls onPlayerConnect which runs checkClient in a new thread

    I am not sure it is slower than most (seems pretty fast to me), but when it finds something that meets the criteria, it sends 3 messages separated by "sleep(5)" (this is the part I am worried about), and what I understood you said before is that "sleep(5)" doesn't just pause until the next message, but actually pauses all of b3's functions.  Is this correct or did I misunderstand?  Here's an example:

    Code:
                        time.sleep(5)
        event.client.message(self.config.get('messages', 'privatemsg1'))
                        time.sleep(5)
        event.client.message(self.config.get('messages', 'privatemsg2'))
                        time.sleep(5)
        event.client.message(self.config.get('messages', 'privatemsg3'))
                        time.sleep(5)

    My plugins already use "onEvent" to trigger it, but I was just meaning that if "sleep(5)" pauses b3 that I should probably change it (you mentioned using "threads" or cron-something).  Thanks for the help.

    Brendan "NinjaNife" West

    P.S.
    After re-reading your post and looking more at your example, I am still confused on how I would implement that..  Do you mean I should make the main part of the code into a function and then start the function in the "thread.start_new_thread()" instead of just having a ton of code under teh "def onEvent()" statement?  So "def onEvent()" would hold the trigger, and then pass it onto the function in a new thread?  Or am I completely mixed up lol.  Example (if the same thing as the banlist plugin can be utilized here):

    Code:
        def onEvent(self, event):
            if (event.type == b3.events.EVT_CLIENT_AUTH):
                self.onPlayerConnect(event.client)

        def onPlayerConnect(self, client):
            thread.start_new_thread(self.checkClient, (client,))

        def checkClient(self, client):
            **my plugin data (everything under the EVT_CLIENT_AUTH trigger event)**

    *EDIT*
    I forgot to mention that the entire plugin is under "onEvent()", so this definitely qualifies as a problem from what you said before..plugin modification is complicated :s
    « Last Edit: September 17, 2011, 06:48:22 AM by NinjaNife » Logged
    Senior Dev.
    *
    OS: Linux
    Type: Home user
    Posts: 3484
    Offline Offline
    WWW
    Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
    « Reply #21 on: September 17, 2011, 02:50:03 PM »

    Code: python
    thread.start_new_thread(self.checkClient, (client,))
    means : call the function self.checkClient with client as a parameter in a new thread.
    Logged

    Full Member
    ***
    OS: Windows
    Type: Owner dedicated server(s)
    Gameservers: CoD4, CoD6, CoD7
    Posts: 80
    Offline Offline
    Currently hosting 40+ b3 Bots!!!
    WWW
    « Reply #22 on: September 17, 2011, 04:33:32 PM »

    Code: python
    thread.start_new_thread(self.checkClient, (client,))
    means : call the function self.checkClient with client as a parameter in a new thread.

    That should work for me correct?  Except the function would be different of course; but the parameter should be the same since all the plugin does is check the client info and compare it to the penalties database.  I will give it a try and let you know what I find.

    Brendan "NinjaNife" West

    *EDIT*
    Success!  I have successfully (as far as I can tell) reconfigured the plugin, and it now is much faster if it finds an offending client.  Here are examples of before and after:

    Before:
    Code:
    110917 21:26:26 VERBOS2 'Client Authenticated event handled by WidebanxtremePlugin in 20807.981 ms'
    After:
    Code:
    110917 21:24:00 VERBOS2 'Client Authenticated event handled by WidebanxtremePlugin in 1.619 ms'
    As you can see, there is a HUGE improvement now that I implemented the threads function.  Thanks for the help!
    « Last Edit: September 17, 2011, 05:30:47 PM by NinjaNife » Logged
    Tags: plugin event thread 
    Pages: 1 [2]   Go Up
      Print  
     
    Jump to:  


    Rate this page +1 at Google Search


    SimplePortal 2.3.1 © 2008-2009, SimplePortal