• Welcome to Valhalla Legends Archive.
 

Help with a flags access system.

Started by LackLuster), November 04, 2005, 09:06 PM

Previous topic - Next topic

LackLuster)

Ok, so my bot is using a flags system, and I am having trouble with having users added remotely...

The flags are currently strings (Least efficient method, I know, but it's the easiest, and my bot isn't meant to be super fast or anything!), KBSXMT, and I can't have somebody added unless they are added with their flags in the same order... Any ideas on how to fix it?

Kp

Stop using a string.  A bitmask will implicitly solve your problem, as well as looking nicer. :)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

LackLuster)

Thank you... I'm a newb, so hopefully I can figure out how to make a bitmask work. :x

Networks

Create a function that orders the letters in the beginning? I don't see why it has to be that way, maybe you should change the method in which your bot checks for flags.

Kp is extremely correct, bitwise is far more efficient and powerful and is well worth learning it.

Warrior

Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

Joe[x86]

#5
I'm not quite sure what you're trying to do, but I think its see if they have a specific flag. You need to use InStr() and see if it returns a non-zero.

An example of how this is done is modAccess from prjJoeBotRGE. You'll obviously need to change the variables referencing the position of the data, but whatever.

Public Function GetFlags(Username As String) As String
    Let GetFlags = CStr(modINI.ReadINI("JoeBotRGE-DB", Username, "config.ini"))
End Function

Public Function HasFlag(Username As String, Flag As String) As Boolean
    Let HasFlag = CBool(InStr(1, modINI.ReadINI("JoeBotRGE-DB", Username, "config.ini"), Flag))
End Function

Public Sub AddFlag(Username As String, Flag As String)
    Dim CurFlag As String: Let CurFlag = UCase(modINI.ReadINI("JoeBotRGE-DB", Username, "config.ini"))
    Call modINI.WriteINI("JoeBotRGE-DB", Username, IIf(InStr(1, CurFlag, Flag) <> 0, CurFlag, CurFlag & Flag), "config.ini")
End Sub

Public Sub RemFlag(Username As String, Flag As String)
    Dim CurFlag As String: Let CurFlag = UCase(modINI.ReadINI("JoeBotRGE-DB", Username, "config.ini"))
    Call modINI.WriteINI("JoeBotRGE-DB", Username, Replace(CurFlag, Flag, vbNullString), "config.ini")
End Sub


You'll also need modINI for using INI files.

Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long

Public Sub WriteINI(sSection As String, sKey As String, sValue As String, sFile As String)
    Call WritePrivateProfileString(sSection, sKey, sValue, App.Path & "\" & sFile)
End Sub

Public Function ReadINI$(riSection$, riKey$, riFile$)
    Dim sRiBuffer$, sRiValue$, sRiLong$

    riFile$ = (App.Path & "\" & riFile$)
    If Dir(riFile$) <> "" Then
        sRiBuffer = String(255, vbNull)
        sRiLong = GetPrivateProfileString(riSection, riKey, Chr(1), sRiBuffer, 255, riFile)
        If Left(sRiBuffer, 1) <> Chr(1) Then
            sRiValue = Left(sRiBuffer, sRiLong)
            ReadINI = sRiValue
        End If
    Else
        ReadINI = ""
    End If
End Function





A bitwise flags system would be a bit harder to implement, but probably faster to use. I'd code this for you, but I'm pretty lazy right now. =p.
A = 0x01
B = 0x02
C = 0x04
D = 0x08
E = 0x10
F = 0x20
G = 0x40
H = 0x80
F = 0x100
..and so on, doubling each time, until you get to Z = whatever Z equals.
To check it for a flag, say A
If lFlags And A = A Then
  'Flag = True
Else
  'Flag = False
End If
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Networks

A BitWise flag system isn't at all harder, it's just one more thing to learn. If anything it takes up far less space in your computer's memory opposed to literal strings which is why anyone should look into it.