Clan x86

Technical (Development, Security, etc.) => General Programming => Botdev => Topic started by: MyndFyre on August 08, 2008, 03:29:48 AM

Title: BN# - Beta 1
Post by: MyndFyre on August 08, 2008, 03:29:48 AM
BN# (that's "BN-Sharp") has reached Beta 1!

If you haven't yet heard of BN#, it's a Microsoft .NET Framework-based utility library meant for simplifying the process of connecting to Battle.net.  It's a highly-optimized, highly efficient, object-oriented, and extensible drop-in for most Battle.net projects.  Oh, and I almost forgot to mention -- it's open-source (http://jinxbot.googlecode.com).


What's new in Beta 1?
New Features
Breaking Changes
Non-Breaking Changes
Bug fixes
Get BN# from the above link and check out the online documentation (http://www.jinxbot.net/bns/)!
Title: Re: BN# - Beta 1
Post by: Chavo on August 08, 2008, 11:52:51 AM
Funny, I was about to pm you saying I had some time to help with this.  Do you have your JinxBot preview that uses BN# working as well?
Title: Re: BN# - Beta 1
Post by: MyndFyre on August 08, 2008, 11:57:06 AM
Quote from: Chavo on August 08, 2008, 11:52:51 AM
Funny, I was about to pm you saying I had some time to help with this.  Do you have your JinxBot preview that uses BN# working as well?

Yes, I have it working, but it's not ready to make a full release just yet.
Title: Re: BN# - Beta 1
Post by: Camel on August 09, 2008, 06:06:32 AM
Packet prioritization? That sounds like a disaster waiting to unfold!
Title: Re: BN# - Beta 1
Post by: iago on August 09, 2008, 11:43:35 AM
Quote from: Camel on August 09, 2008, 06:06:32 AM
Packet prioritization? That sounds like a disaster waiting to unfold!
I did something similar to that in JavaOp2, and it worked perfectly.

Explain the "disaster"?
Title: Re: BN# - Beta 1
Post by: MyndFyre on August 09, 2008, 03:41:07 PM
Quote from: Camel on August 09, 2008, 06:06:32 AM
Packet prioritization? That sounds like a disaster waiting to unfold!

How so?

Threads of execution:
* Receive() loop - gets data one packet at a time from Bnet, puts packets into a priority queue
* Parse() loop - gets packets out of the priority queue, hands them off to the parsing handler function, calls the high-priority event handlers, and enqueues the event for lower-priority handlers.
* Normal- and Low-priority event handler loops - fire the normal- and low-priority event handlers.

The idea is that you can say something like, SID_USERJOINED is higher priority that SID_CHATEVENT.  So the handlers for SID_USERJOINED will always be processed first.

Why does that sound like the potential for disaster?
Title: Re: BN# - Beta 1
Post by: Camel on August 11, 2008, 12:09:01 AM
Why would you want to process the packets out of order? You shouldn't display a user joining before a user chatting unless that's the order that you recived the packets in, otherwise the user could be mislead to think that the person who joined saw the chat.

I can't think of any case where it's advantageous to prioritize packets, but I can think of several cases where it could lead to invalid state - for example, if you parse a user leaving the channel before entering, then the bot will show the user in the channel when he isn't.
Title: Re: BN# - Beta 1
Post by: MyndFyre on August 11, 2008, 03:13:48 AM
Quote from: Camel on August 11, 2008, 12:09:01 AM
Why would you want to process the packets out of order? You shouldn't display a user joining before a user chatting unless that's the order that you recived the packets in, otherwise the user could be mislead to think that the person who joined saw the chat.

I can't think of any case where it's advantageous to prioritize packets, but I can think of several cases where it could lead to invalid state - for example, if you parse a user leaving the channel before entering, then the bot will show the user in the channel when he isn't.
Since the EID_SHOW/EID_JOIN/EID_LEAVE packets are all handled as SID_CHATEVENT (0x0e) they can't be processed out of order.  Looking at my previous post, I misspoke to say that within-packet-ID events could be handled out-of-order.

I envision a moderation plugin where things like SID_CHATEVENT are infinitely more important to be parsed than, say, SID_CLANMEMBERSTATUSCHANGED, SID_FRIENDUPDATE, or other miscellaneous packets of that nature.  I'd certainly want moderation events to have higher priority than things that aren't important to a client whose sole purpose was moderation.
Title: Re: BN# - Beta 1
Post by: Camel on August 11, 2008, 04:38:35 AM
Why would a moderation plugin process friend updates?

I don't see any condition where the prioritization could ever potentially be useful.
Title: Re: BN# - Beta 1
Post by: MyndFyre on August 11, 2008, 09:53:31 AM
Quote from: Camel on August 11, 2008, 04:38:35 AM
Why would a moderation plugin process friend updates?
The core processes every packet.  It doesn't just say "Oh look, a packet, but fuck it!"  But a moderation plugin might want the core to process that packet a little bit further down the pipe - you know, when all of the chat events are done being processed?

I don't understand why you're being such a hard-ass about it.  It's optional, the default setting is "everything-normal," and nobody's making you use this.
Title: Re: BN# - Beta 1
Post by: Camel on August 11, 2008, 11:24:29 AM
The moderation plugin doesn't process friend updates, and therefore doesn't care whether friend updates are processed before or after chat events.

I don't think I'm being a hardass, and I'm certainly not trying to depreciate the cool factor of it - it is something that is interesting and probably useful to someone somewhere; not in this context, though. There is, IMO, no valid argument for processing BNCS packets out of the order from which they came off the wire. It simply doesn't have the potential to be useful, as guaranteed by the fact that the only packet that requires any substantial amount of power to process is ineligible for a variable priority.

Don't take what I'm saying the wrong way, I am genuinely interested in this kind of thing. Hopefully I'll have some time soon to sit down and actually take a look at how you did it, since I can think of at least one application I'm working on where it would be advantageous to do something similar (that is, prioritizing a potentially large queue of packets).
Title: Re: BN# - Beta 1
Post by: MyndFyre on August 11, 2008, 02:15:27 PM
Quote from: Camel on August 11, 2008, 11:24:29 AM
The moderation plugin doesn't process friend updates, and therefore doesn't care whether friend updates are processed before or after chat events.
You're not hearing me.  The core by default fires off each event as it is retrieved from the wire.  If a plugin wants to make a connection highly moderation-centric, then it could tell the core to process the packets out-of-order.  The processing of every packet happens regardless of whether event handlers are registered to listen to the relevant events.

The ultimate goal for this is that a JinxBot application can be as rich as any typical client without sacrificing potential security features such as channel flood handling.  I don't know whether that will become an issue.  But I don't really see this becoming dangerous, which was, as I feel obliged to point out, your original criticism.
Title: Re: BN# - Beta 1
Post by: Camel on August 11, 2008, 02:37:38 PM
Are you saying that the core processes internally the packets as they come off the wire, but then might fire the events out of order to one particular plugin? As long as the core's internal state is modified in the order that packets come in off the wire, that seems reasonable; I must have misunderstood how you are doing it.

I don't recall using the word dangerous :)


[edit] After looking back at your original post, it sure does sound like you're parsing packets out of order upon request. What happens if one plugin requests that packets are parsed out of order, but another plugin doesn't properly handle some corner case like a user being promoted on the friends list before he's added to the friends list?
Title: Re: BN# - Beta 1
Post by: MyndFyre on August 12, 2008, 11:29:37 AM
Quote from: Camel on August 11, 2008, 02:37:38 PM
[edit] After looking back at your original post, it sure does sound like you're parsing packets out of order upon request. What happens if one plugin requests that packets are parsed out of order, but another plugin doesn't properly handle some corner case like a user being promoted on the friends list before he's added to the friends list?
Then something breaks.

It's up to the user to handle these situations.  The core can certainly get out of state by handling a FriendRemoved event before a FriendAdded event if FriendAdded is set to low priority and FriendRemoved is set to high priority, and somehow the messages to add and remove a friend are sent to Battle.net in rapid enough succession that the core has to enqueue them.  I'd hope that someone wouldn't be stupid enough to do that, but if you really want to......
Title: BN# - Beta 2
Post by: MyndFyre on August 15, 2008, 05:05:43 AM
I released Beta 2; it was a bugfix release and offers a new utility class that gets about halfway there to the full implementation of Warden.  This functionality will be rolled into MBNCSUtil proper soon as well.

New Features
What's coming for Beta 3
Title: Re: BN# - Beta 1
Post by: Joe on September 30, 2008, 09:05:37 PM
Two quick bugs.. looks like BattleNetClient.Channel isn't emptied on channel switches, and as I told you over AIM, there's a typo in the event WardentUnhandled.
Title: Re: BN# - Beta 1
Post by: MyndFyre on October 01, 2008, 12:30:05 AM
Good catch on channel join!  Please report bugs here (http://code.google.com/p/jinxbot/issues/list).