• Welcome to Valhalla Legends Archive.
 

[RESOLVED] Bitwize Flag Check

Started by Eric, November 20, 2004, 11:57 PM

Previous topic - Next topic

Eric

For some odd reason, my bitwize flag comparison always returns false when checking for USER_FLAG_B (0x04), but returns properly for all of the other flags and I can't figure out why.

// User Flags
#define USER_FLAG_A 0x01 // A - Access Management
#define USER_FLAG_a 0x02 // a - Restricted Access Management
#define USER_FLAG_B         0x04 // B - Auto-Banned
#define USER_FLAG_C 0x08 // C - Connection
#define USER_FLAG_D 0x10 // D - Connection
#define USER_FLAG_G 0x20 // G - General Function Control
#define USER_FLAG_J 0x40 // J - Join
#define USER_FLAG_M 0x80 // M - Bot Master
#define USER_FLAG_O 0x100 // O - Channel Operator
#define USER_FLAG_o 0x200   // o - Restricted Channel Operator
#define USER_FLAG_P 0x400   // P - Protected
#define USER_FLAG_S 0x800   // S - Safe
#define USER_FLAG_s 0x1000  // s - Low-Level Safe
#define USER_FLAG_T 0x2000 // T - Talk



dbuUsers[0].Flags = (USER_FLAG_A|
USER_FLAG_B|
USER_FLAG_C|
USER_FLAG_D|
USER_FLAG_G|
USER_FLAG_J|
USER_FLAG_M|
USER_FLAG_O|
USER_FLAG_S|
USER_FLAG_T);


inline void CBNCS::OnJoin(const DWORD *dwFlags, const DWORD *dwPing, const char *sUsername, const char *sStatstring)
{
#ifdef DEBUG
AppendConsole("%s:%i:%X has joined the channel.\n", sUsername, *dwPing, *dwFlags);
#endif

unsigned int iUsrBFlags = Database.GetUserFlags(sUsername);

if (iUsrBFlags != 0xFFFFFFFF)
{
if ((iUsrBFlags & USER_FLAG_B) == USER_FLAG_B)
SendChatCommand("/ban %s Autoban", sUsername);
}
}

drivehappy

#1
What does iUsrBFlags equal when it's supposed to SendChatCommand() ?
BTW, it's not called bitwise, rather bit masking.

Eric

#2
Quote from: drivehappy on November 21, 2004, 02:05 AM
What does iUsrBFlags equal when it's supposed to SendChatCommand() ?
BTW, it's not called bitwise, rather bit masking.
0x14F9 (5369)

Edit: Problem solved.  For some odd reason, the entry being loaded from the database was incorrect.

Mephisto

if ((iUsrBFlags & USER_FLAG_B) == USER_FLAG_B)

That's a bit redundant.  Just use if ((iUsrBFlags & FLAG_B) { ... }

Eric

Quote from: Mephisto on November 21, 2004, 12:26 PM
if ((iUsrBFlags & USER_FLAG_B) == USER_FLAG_B)

That's a bit redundant.  Just use if ((iUsrBFlags & FLAG_B) { ... }

It helps to give me a more visual perspective.

Eibro

Also note that if you're ANDing with a mask rather than a flag you need the extra == to check if the entire mask was set.
Eibro of Yeti Lovers.