Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: OuTLawZGoSu on January 28, 2004, 04:09 PM

Title: Why isn't this working?
Post by: OuTLawZGoSu on January 28, 2004, 04:09 PM
 

Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If


Can you tell me why this isnt working?

FLAGS = 0 works fine. It gets all the user's icons. Only game icons, not squelch or gravel.

The rest dont do anything. Am I doing something wrong?
Title: Re:Why isn't this working?
Post by: ObsidianWolf on January 28, 2004, 04:11 PM
Have you checked your ImageList to see that the Appropriate Keys Have been set for those Icons?
Title: Re:Why isn't this working?
Post by: warz on January 28, 2004, 04:12 PM
I'd suggest Switch (FLAGS) { } also
Title: Re:Why isn't this working?
Post by: Kp on January 28, 2004, 04:12 PM
Quote from: OuTLawZGoSu on January 28, 2004, 04:09 PMCan you tell me why this isnt working?

Yes.

Quote from: OuTLawZGoSu on January 28, 2004, 04:09 PMThe rest dont do anything. Am I doing something wrong?

Yes.

Thus spake the Oracle.
Title: Re:Why isn't this working?
Post by: Zakath on January 28, 2004, 04:21 PM
I'm going to do something I don't normally do and just drop some code on you, because you've completely missed a critical aspect of the flags bitmask. Hopefully you'll learn something from this.


void CheckFlags( DWORD dwFlags, int *lpnStatImg, int *lpnLagImg ) {
   if ( dwFlags & 0x10 )
      *lpnLagImg = ICON_PLUG;
   if ( dwFlags & 0x20 )
      *lpnStatImg = ICON_SQUELCH;
   if ( dwFlags & 0x04 )
      *lpnStatImg = ICON_MEGAPHONE;
   if ( dwFlags & 0x02 )
      *lpnStatImg = ICON_GAVEL;
   if ( dwFlags & 0x08 )
      *lpnStatImg = ICON_BNET;
   if ( dwFlags & 0x01 )
      *lpnStatImg = ICON_BLIZZARD;
}


There are three key concepts in that function that you've missed. See if you can figure out what they are.
Title: Re:Why isn't this working?
Post by: OuTLawZGoSu on January 28, 2004, 04:25 PM
I got no idea what that does. I dont know C++ :/
Title: Re:Why isn't this working?
Post by: hismajesty on January 28, 2004, 05:32 PM
QuoteFLAGS = 0 works fine. It gets all the user's icons. Only game icons, not squelch or gravel.

gravel eh? Is that a new flag? :P

QuoteI got no idea what that does. I dont know C++ :/
My C++ knowledge is limited but it's not too hard to figure out what that means.
Title: Re:Why isn't this working?
Post by: R.a.B.B.i.T on January 28, 2004, 05:47 PM
Switch(Value){} is the same as Select Case Value:Case Value:EndSelect.
Title: Re:Why isn't this working?
Post by: MyndFyre on January 28, 2004, 06:09 PM
You'd better raise my karma for this one.

The following code:

Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If

determines if the flags value equals EXACTLY the value that you're looking for.  

I can see two things that you are doing wrong.

First, part of the entire point of using flags is to allow for several boolean values within a single numeric value.  Because data is stored ultimately in bits, a 1 can represent a true value, and a 0 a false value.

So, if you wanted a user to have the regular icon, no special icon flags are set.  Hence, the flags value is 0.

An example 8-bit number like the ones that are used in this case might be 01001010b = 0x4A (hex), or in Visual Basic, &H4A, the decimal equivalent being 74.

On Battle.net, it is possible (for example) for a squelched user to have the gavel.  Thus, you need to be able to check each individual BIT for its truth value.

Zakath posted some C-style code that lets you do this.  In your case, perhaps try modifying your code to utilize the bitwise operators AND and OR.


Case ID_JOIN

If FLAGS = 0 Then
 Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
 If FLAGS And &H2 = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
 ElseIf FLAGS And &H20 = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
 End If
End If


These code modifications do two things....

First, it completely removes conditional checking of the second case (special icons) if the first (standard game icon) turns out being the case.

Second, it changes your flags tests to ensure that 1.) you are using HEX values and not DECIMAL values (checking for decimal 20 would never work, because it's the bitwise combination of 16 and 4 -- you'd get megaphone if that was in there), and 2.) that you are actually doing BITWISE FLAGS tests and not direct numeric comparisons.

Make sure to have them in the correct order; I believe a squelched gavel holder has the squelched icon.

Cheers
--Rob
Title: Re:Why isn't this working?
Post by: o.OV on January 29, 2004, 06:28 AM
Quote from: Myndfyre on January 28, 2004, 06:09 PM
You'd better raise my karma for this one.

The following code:

Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If

determines if the flags value equals EXACTLY the value that you're looking for.  

I can see two things that you are doing wrong.

First, part of the entire point of using flags is to allow for several boolean values within a single numeric value.  Because data is stored ultimately in bits, a 1 can represent a true value, and a 0 a false value.

So, if you wanted a user to have the regular icon, no special icon flags are set.  Hence, the flags value is 0.

An example 8-bit number like the ones that are used in this case might be 01001010b = 0x4A (hex), or in Visual Basic, &H4A, the decimal equivalent being 74.

On Battle.net, it is possible (for example) for a squelched user to have the gavel.  Thus, you need to be able to check each individual BIT for its truth value.

Zakath posted some C-style code that lets you do this.  In your case, perhaps try modifying your code to utilize the bitwise operators AND and OR.


Case ID_JOIN

If FLAGS = 0 Then
 Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
 If FLAGS And &H2 = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
 ElseIf FLAGS And &H20 = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
 End If
End If


These code modifications do two things....

First, it completely removes conditional checking of the second case (special icons) if the first (standard game icon) turns out being the case.

Second, it changes your flags tests to ensure that 1.) you are using HEX values and not DECIMAL values (checking for decimal 20 would never work, because it's the bitwise combination of 16 and 4 -- you'd get megaphone if that was in there), and 2.) that you are actually doing BITWISE FLAGS tests and not direct numeric comparisons.

Make sure to have them in the correct order; I believe a squelched gavel holder has the squelched icon.

Cheers
--Rob

Here is another modification..


Case ID_JOIN

If FLAGS = 0 Then
 Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
 If (FLAGS And &H2) = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
 ElseIf (FLAGS And &H20) = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
 End If
End If


If you plan on a moderation bot with a feature to unignore safelisted users you will have to setup another check to detect for a squelched ops..
Assuming you will use this example in other cases.
Title: Re:Why isn't this working?
Post by: DarkMinion on January 29, 2004, 08:08 AM
Never ever ever check a bitmask with =
Title: Re:Why isn't this working?
Post by: o.OV on January 29, 2004, 12:15 PM
Quote from: DarkMinion on January 29, 2004, 08:08 AM
Never ever ever check a bitmask with =

Well I only did a minor fix on it.. and I'm not even sure exactly what you mean by that.. lol

I could do the fix like this..


If (flags And &H2) = &H2 Then
   Form1.ChannelList.ListItems.Add 1, , Username, , ICON_GAVEL
ElseIf (flags And &H20) = &H20 Then
   Form1.ChannelList.ListItems.Add 1, , Username, , ICON_SQUELCH
Else
   Form1.ChannelList.ListItems.Add 1, , Username, , GetIcon
End If
Title: Re:Why isn't this working?
Post by: Networks on January 29, 2004, 01:27 PM
did u make columns in the list box? so that the icons go where they're supposed to.
Title: Re:Why isn't this working?
Post by: UserLoser. on January 29, 2004, 01:43 PM
Quote from: Networks on January 29, 2004, 01:27 PM
did u make columns in the list box? so that the icons go where they're supposed to.

Subclassing, or you can just use a ListView if you want columns and icons (which is a lot easier)
Title: Re:Why isn't this working?
Post by: MyndFyre on January 29, 2004, 09:02 PM
Quote from: DarkMinion on January 29, 2004, 08:08 AM
Never ever ever check a bitmask with =

Well thanks, I'm not a VB programmer, I do C/Java/C#, so I wouldn't know.  It was intended more to point him in the right direction.  :)  When I check bitmasks in C#, I go:


if ( (flags & (int)UserFlags.Squelched) == UserFlags.Squelched)
 // assign squelched icon
else if ( (flags & (int)UserFlags.Moderator) == UserFlags.Moderator)
 // give it the gavel.

etc.
Title: Re:Why isn't this working?
Post by: Spht on January 29, 2004, 10:00 PM
Quote from: Myndfyre on January 29, 2004, 09:02 PM
Quote from: DarkMinion on January 29, 2004, 08:08 AM
Never ever ever check a bitmask with =

Well thanks, I'm not a VB programmer, I do C/Java/C#, so I wouldn't know.  It was intended more to point him in the right direction.  :)  When I check bitmasks in C#, I go:


if ( (flags & (int)UserFlags.Squelched) == UserFlags.Squelched)
 // assign squelched icon
else if ( (flags & (int)UserFlags.Moderator) == UserFlags.Moderator)
 // give it the gavel.

etc.

Same concept...