Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: BaDDBLooD on March 07, 2004, 09:32 PM

Title: Channel Type's?
Post by: BaDDBLooD on March 07, 2004, 09:32 PM


Public Function GetChannelType(ByVal Flags As Long) As String

   Select Case Flags
       Case CHANNEL_PUBLIC&
           GetChannelType = "Public Channel"
       Case CHANNEL_MODERATED&
           GetChannelType = "Moderated channel"
       Case CHANNEL_RESTRICTED&
           GetChannelType = "Restricted Channel"
       Case CHANNEL_SILENT&
           GetChannelType = "Silent Channel"
       Case CHANNEL_SYSTEM&
           GetChannelType = "System CHannel"
       Case CHANNEL_PRODUCTSPECIFIC&
           GetChannelType = "Product Specific"
       Case CHANNEL_GLOBAL&
           GetChannelType = "Global Channel"
   End Select
   
End Function



Not sure if those are correct or not...
i tested a few of them out, it shows it shows clan, and op channels as public.  Although it showed channels like clan recruitment, kbk info etc.. as Nothing..

Little help? ;o
Title: Re:Channel Type's?
Post by: MyndFyre on March 07, 2004, 09:41 PM
For future reference, when making words plural, you don't need to add an apostrophe.  "Types" is the correct transcription, not "type's."
Title: Re:Channel Type's?
Post by: o.OV on March 07, 2004, 09:45 PM
I never thought anyone would care about channel flags.
Use zDS bot to compare..
I think zDS shows channel flag when you join a channel.

Add-On:
Where did you get that anyways.
I hate Constants.
You should comment the constants with actual value.
And have the channel flag display on screen
when you enter a channel.
Title: Re:Channel Type's?
Post by: BaDDBLooD on March 07, 2004, 09:54 PM
i don't have a zds bot lol

i got them at bnetdoc's..

anyone else have Input?
Title: Re:Channel Type's?
Post by: Eric on March 07, 2004, 09:57 PM
Quote from: BaDDBLooD on March 07, 2004, 09:54 PM
i don't have a zds bot lol
Quote from: BaDDBLooD on March 07, 2004, 09:55 PM
all i have to say is... bnet doc's
Learn how to use the edit button.
Title: Re:Channel Type's?
Post by: Fr0z3N on March 07, 2004, 10:35 PM

Public Function ChannelFlags(ByVal Flags As Long) As String
   Dim Result As String
   Dim StrFlags As String
   StrFlags = DecToBin(Flags)
   StrFlags = Right(StrFlags, Len(StrFlags) - 1)
   Do While Len(StrFlags) < 16
       StrFlags = "0" & StrFlags
   Loop
   
   If IsBit(StrFlags, 0) Then Result = "Public"
   If IsBit(StrFlags, 1) Then Result = Result & "Moderated"
   If IsBit(StrFlags, 2) Then Result = Result & "Restricted"
   If IsBit(StrFlags, 3) Then Result = Result & "Silent"
   If IsBit(StrFlags, 4) Then Result = Result & "System"
   If IsBit(StrFlags, 5) Then Result = Result & "Product-Specific"
   If IsBit(StrFlags, 11) Then Result = Result & "Globally-Accessible"
   If Flags = &H0 Then Result = "Private"
   
   ChannelFlags = Result
End Function


That works for me.
Title: Re:Channel Type's?
Post by: Grok on March 07, 2004, 10:48 PM
Quote from: o.OV on March 07, 2004, 09:45 PMAdd-On:
Where did you get that anyways.
I hate Constants.
You should comment the constants with actual value.

Ack.  CompSci 101.  Use Named Constants for repeated-use literal constants.  This significantly improves readability of code and maintainability.  If one of the constants changes values, you only have to change the definition.
Title: Re:Channel Type's?
Post by: Soul Taker on March 08, 2004, 05:47 AM
You both are missing the redirecting channel flag, 0x4000.
Title: Re:Channel Type's?
Post by: Fr0z3N on March 08, 2004, 06:49 AM
Quote from: Fr0z3N on March 07, 2004, 10:35 PM

   If IsBit(StrFlags, 4) Then Result = Result & "System"




I don't think I am.
Title: Re:Channel Type's?
Post by: Arta on March 08, 2004, 08:33 AM
0x4 != 0x4000.
Title: Re:Channel Type's?
Post by: iago on March 08, 2004, 09:28 AM
Quote from: Grok on March 07, 2004, 10:48 PM
Quote from: o.OV on March 07, 2004, 09:45 PMAdd-On:
Where did you get that anyways.
I hate Constants.
You should comment the constants with actual value.

Ack.  CompSci 101.  Use Named Constants for repeated-use literal constants.  This significantly improves readability of code and maintainability.  If one of the constants changes values, you only have to change the definition.

Agreed, I take off more and more marks on each assignment for using Literal constants.  But people still do it, so obviously they aren't reading my comments of WHY they lost marks.

Anyway, your problem is that you're using a case for flags.  I would recommend looking up the right way to do flags, and why it works, but, basically, use bitwise operations.

Instead of this:
select Flags
       Case CHANNEL_PUBLIC&
           GetChannelType = "Public Channel"

do this:

if((Flags AND CHANNEL_PUBLIC) <> 0)
   returnString = returnString + "public"

Or something like that.  Keep in mind it can be >1 type.
Title: Better flag string creation, and additional flags
Post by: tA-Kane on March 08, 2004, 01:54 PM
In case you find a channel that has flags that you aren't supporting, it would be a good idea to make a note of it. The codes I see here aren't making use of that, so I'll make an example:

Function ChannelFlagsToFlagString(Value As Integer, DoUnknown As Boolean, DoPrivate As Boolean) As String
 Dim FlagString As String
 Dim Flags As Integer
 
 CONST kChannelFlags_Public = 1//0x1
 CONST kChannelFlags_Moderated = 2//0x2
 CONST kChannelFlags_Restricted = 4//0x4
 CONST kChannelFlags_Silent = 8//0x8
 CONST kChannelFlags_System = 16//0x10
 CONST kChannelFlags_ProductSpecific = 32//0x20
 CONST kChannelFlags_Global = 4096//0x1000
 
 Flags = Value//set temporary usage to the channel's flags value
 
 //get all the flag strings
 //rules: check for a specific flag
 //if that flag doesn't exist (not 1), then move on
 //else, add ", " and the name of the flag to the flag string
 //then, remove the flag from the temporary buffer
 //why remove? allows to check for unknown flags at the end of the function
 If BitwiseAnd(Flags,kChannelFlags_Global) = kBnetGame_ChannelFlags_Global Then
   FlagString = FlagString + ", Global"
   Flags = BitwiseXOr(Flags,kChannelFlags_Global)
 End If
 If BitwiseAnd(Flags,kChannelFlags_ProductSpecific) = kBnetGame_ChannelFlags_ProductSpecific Then
   FlagString = FlagString + ", Product Specific"
   Flags = BitwiseXOr(Flags,kChannelFlags_ProductSpecific)
 End If
 If BitwiseAnd(Flags,kChannelFlags_System) = kBnetGame_ChannelFlags_System Then
   FlagString = FlagString + ", System"
   Flags = BitwiseXOr(Flags,kChannelFlags_System)
 End If
 If BitwiseAnd(Flags,kChannelFlags_Silent) = kBnetGame_ChannelFlags_Silent Then
   FlagString = FlagString + ", Silent"
   Flags = BitwiseXOr(Flags,kChannelFlags_Silent)
 End If
 If BitwiseAnd(Flags,kChannelFlags_Restricted) = kBnetGame_ChannelFlags_Restricted Then
   FlagString = FlagString + ", Restricted"
   Flags = BitwiseXOr(Flags,kChannelFlags_Restricted)
 End If
 If BitwiseAnd(Flags,kChannelFlags_Moderated) = kBnetGame_ChannelFlags_Moderated Then
   FlagString = FlagString + ", Moderated"
   Flags = BitwiseXOr(Flags,kChannelFlags_Moderated)
 End If
 If BitwiseAnd(Flags,kChannelFlags_Public) = kBnetGame_ChannelFlags_Public Then
   FlagString = FlagString + ", Public"
   Flags = BitwiseXOr(Flags,kChannelFlags_Public)
 End If
 
 //check for unknown flags
 If Flags <> 0 Then
   //check to make sure that the calling function wants to see the unknown flags
   If DoUnknown = True Then
     FlagString = ", Unknown ("+MyHex(Flags)+")"  
   End If
 End If
 
 //check for no flags at all (flags = 0 and flagstring is empty)
 If Flags = 0 And FlagString = "" Then
   //check to make sure calling function wants private channel string
   If DoPrivate = True Then
     FlagString = FlagString + ", Private"
   End If
 End If
 
 //return the string, without the first ", "
 Return Mid(FlagString,3)


Then, in the calling function, you would pass the channel's flags in the first parameter. If you want to display any unknown flags, pass true for the second parameter. And then if you want to display private channels (eg, no flags), pass true for the third.

Hopefully with this you'll be able to notice that BnetDocs is incomplete with regards to channel flags; there are 3 channel flags that BnetDocs does not document that are easily findable:

kChannelFlags_TechSupport
kChannelFlags_ChatAccessible
kChannelFlags_LoadBalanced (aka kChannelFlags_Redirected)

Title: Re:Better flag string creation, and additional flags
Post by: Eli_1 on March 08, 2004, 02:03 PM
Quote from: tA-Kane on March 08, 2004, 01:54 PM
In case you find a channel that has flags that you aren't supporting, it would be a good idea to make a note of it. The codes I see here aren't making use of that, so I'll make an example:

Function ChannelFlagsToFlagString(Value As Integer, DoUnknown As Boolean, DoPrivate As Boolean) As String
 Dim FlagString As String
 Dim Flags As Integer
 
 CONST kChannelFlags_Public = 1//0x1
 CONST kChannelFlags_Moderated = 2//0x2
 CONST kChannelFlags_Restricted = 4//0x4
 CONST kChannelFlags_Silent = 8//0x8
 CONST kChannelFlags_System = 16//0x10
 CONST kChannelFlags_ProductSpecific = 32//0x20
 CONST kChannelFlags_Global = 4096//0x1000

 

btw, // won't work as comments with VB  :P
Title: Re:Channel Type's?
Post by: hismajesty on March 08, 2004, 02:19 PM
Seeing as how Kane doesn't use VB they may be the comment character used in his language (I forget the name, but it's said to be similar to VB). I guess, the Mac version of VB. :P
Title: Re:Channel Type's?
Post by: BaDDBLooD on March 08, 2004, 03:44 PM
Quote from: Fr0z3N on March 07, 2004, 10:35 PM

Public Function ChannelFlags(ByVal Flags As Long) As String
   Dim Result As String
   Dim StrFlags As String
   StrFlags = DecToBin(Flags)
   StrFlags = Right(StrFlags, Len(StrFlags) - 1)
   Do While Len(StrFlags) < 16
       StrFlags = "0" & StrFlags
   Loop
   
   If IsBit(StrFlags, 0) Then Result = "Public"
   If IsBit(StrFlags, 1) Then Result = Result & "Moderated"
   If IsBit(StrFlags, 2) Then Result = Result & "Restricted"
   If IsBit(StrFlags, 3) Then Result = Result & "Silent"
   If IsBit(StrFlags, 4) Then Result = Result & "System"
   If IsBit(StrFlags, 5) Then Result = Result & "Product-Specific"
   If IsBit(StrFlags, 11) Then Result = Result & "Globally-Accessible"
   If Flags = &H0 Then Result = "Private"
   
   ChannelFlags = Result
End Function


That works for me.


Now i just need the IsBit, and DecToBin functions :P
Title: Re:Channel Type's?
Post by: Kp on March 08, 2004, 03:46 PM
Quote from: hismajesty on March 08, 2004, 02:19 PM
Seeing as how Kane doesn't use VB they may be the comment character used in his language (I forget the name, but it's said to be similar to VB). I guess, the Mac version of VB. :P

Kane uses REALBasic, iirc.  (Yes, that's the capitalization it uses too.)
Title: Re:Channel Type's?
Post by: Eli_1 on March 08, 2004, 03:49 PM
Quote from: hismajesty on March 08, 2004, 02:19 PM
Seeing as how Kane doesn't use VB they may be the comment character used in his language (I forget the name, but it's said to be similar to VB). I guess, the Mac version of VB. :P

I wasn't trying to criticise Kane about it, was just trying to make aware that the value of the constants like kChannelFlags_Public wasn't 1//0x1, it was 1 with a comment of 0x1...  :P

I think he uses Real Basic REALBasic btw
Title: Re:Channel Type's?
Post by: BaDDBLooD on March 09, 2004, 09:50 PM
Frozen, where can i get those 2 Functions?
Title: Re:Channel Type's?
Post by: tA-Kane on March 10, 2004, 12:15 PM
Quote from: Kp on March 08, 2004, 03:46 PMKane uses REALBasic, iirc.  (Yes, that's the capitalization it uses too.)
Actually, it's not. It's REALbasic (note the lowercase 'b').

Quote from: Eli_1 on March 08, 2004, 03:49 PMI wasn't trying to criticise Kane about it, was just trying to make aware that the value of the constants like kChannelFlags_Public wasn't 1//0x1, it was 1 with a comment of 0x1...
Yes. What does VB use for comments? /**/? Or single-quote?

REALbasic uses double-slash (//) and single-quote (') for comments identification.

I prefer to use double-slash since it's also used in C and C++, but REALbasic's method for commenting (eg, you select some code and select the "Comment" menu item, it checks to see if the beginning of the line is a comment-identifier, and if it is, then it removes it, if not, then it adds a single-quote to the beginning of the line.

Quote from: BaDDBLooD on March 09, 2004, 09:50 PMwhere can i get those 2 Functions?

You can make GetBit by using your language's "raise to the nth power" function, or if your language doesn't have that, you can use multiplication and an if statement.

There's an even easier way if your language has a bitshift function.

I'll list examples in C here, but I don't remember the keyword in C to "raise to the nth power"... porhaps Yoni might? :P
unsigned long GetBitByMultiplication(int BitNum){
 int i;
 unsigned long rVal;
 
 for (i = 0, rVal = 1; i < BitNum; i++){
   rVal *= 2;
 }
 return rVal;
}

#define GetBitByBitShift(BitNum)  (1 << BitNum)
//now to clean up, we should define GetBit as either of these... since GetBitByBitShift is the cleanest (and the fastest), we'll use that...
#define GetBit GetBitByBitShift

I haven't tested this code; I wrote it from memory, but it should work. Shame on me if that's not the case.

edit: actually, you don't even need the if statement.
Title: Re:Channel Type's?
Post by: Adron on March 10, 2004, 02:16 PM
Quote from: tA-Kane on March 10, 2004, 12:15 PM
I'll list examples in C here, but I don't remember the keyword in C to "raise to the nth power"... porhaps Yoni might? :P

You don't raise to the nth power with a C keyword... You may call pow, which uses floating point math and the fpu, but normally you'd use bitshifts where possible.
Title: Re:Channel Type's?
Post by: Fr0z3N on March 10, 2004, 02:49 PM


Private Function IsBit(ByVal BitString As String, ByVal BitNumber As Integer) As Boolean
   If Mid(BitString, 16 - BitNumber, 1) = "1" Then
       IsBit = True
   Else
       IsBit = False
   End If
End Function

Private Function DecToBin(ByVal Dec As Long) As String
   Dim Temp As String, Retrn As String ' as string so that we don't Get number limitations


   Do
       Temp = str(Dec Mod 2)
       Retrn = Temp & Retrn
       Dec = IIf(Right(str(Dec), 2) = ".5", Dec - 0.5, IIf(Dec Mod 2 > 0, Dec - 1, Dec)) / 2
   Loop Until Dec = 0
   DecToBin = Replace(Retrn, " ", "")
End Function


Title: Re:Channel Type's?
Post by: tA-Kane on March 10, 2004, 03:17 PM
Quote from: Adron on March 10, 2004, 02:16 PMYou don't raise to the nth power with a C keyword... You may call pow, which uses floating point math and the fpu
My mistake.
Title: Re:Channel Type's?
Post by: BaDDBLooD on March 10, 2004, 03:34 PM
Why don't clan recruitment, and kbk info show up?
Title: Re:Channel Type's?
Post by: Eric on March 10, 2004, 03:38 PM
Quote from: BaDDBLooD on March 10, 2004, 03:34 PM
Why don't clan recruitment, and kbk info show up?
[13:37:45] Joining public channel: Clan Recruitment
[13:37:48] Joining public channel: KBK Info

Perhaps you forgot to add or incorrectly added the public channel flag.
Title: Re:Channel Type's?
Post by: Eli_1 on March 10, 2004, 03:39 PM
Quote from: tA-Kane on March 10, 2004, 12:15 PM
Yes. What does VB use for comments? /**/? Or single-quote?


VB uses single-quote also
Title: Re:Channel Type's?
Post by: tA-Kane on March 10, 2004, 04:03 PM
Someone slap me for not paying attention, I feel embarassed. :-[

Sorry for any confusion I made for GetBit instead of IsBit. It's still good code though.
Title: Re:Channel Type's?
Post by: BaDDBLooD on March 10, 2004, 05:19 PM
Lord, would you post your Flag function?