• Welcome to Valhalla Legends Archive.
 

Safelist/Shitlist

Started by dodge, January 18, 2005, 10:42 AM

Previous topic - Next topic

dodge

(First off, thanks to Arta, your articles are helpful )

I searched around in some posts to see if someone had answered it, my guess is yes but I can't find it and my internet keeps going out. Right now, I am just coming up with the theory of how to make a bot, then working it out and making it work. Right now I was questioning the safelist. I came up with two possible ways to do it but I am not sure which one would be effective.

First, is a list view effecitve? I was thinking about when you load the bot to add everyone in a file called Safelist and everytime you accessed the file the Listview would update then when someone tries to ban to check that listview

Second, an array. Same idea just using an array

Which way is more pratical?

shout

I am guessing your using vB...

I would say an array.

Reading the file from start up and keeping it in a gloabal array might me more efficent. So...
(Pseudocode)

banuser(username)
if username = safelisted[any]
     donothing
else
     ban username


If you were to add a person to the safelist while the bot is running (thru the bot), simply add the person to the array and when the bot is exiting, write the array to the file.

You could also have your bot update from the file every minute or so, and keep the ones added via the bot in a seperate array. Then when the bot closes, update the file, and check for any doubles.

dodge

heh yes im using vb sorry about that :)

thanks for answering my question :-D

Mephisto

Here's what I do which in a generic sense is more efficient than just creating a data structure dedicated to safe listed users.  Keep in mind I will demonstrate code examples in C++ but you should be able to convert it mentally into VB as you go along.

First, I have many structs that I use to hold data values.  On such is called DatabaseUserData and it has public members like username and flags (keep in mind this info is derived from the database not from dynamic Battle.net activities, that's for ChannelUserData).

I store all my database users into a data structure called a map (refer to STL -> std::map).  Each time I want to add a user I add it to my map after filling out a DatabaseUserData struct object.

Here's an example:
struct DatabaseUserData {
    std::string _username;
    ULONG _flags;
};

std::map<std::string, DatabaseUserData> DatabaseUserMap;

DatabaseUserData user;
user._username = "Mephisto";
user._flags = FLAG_A|FLAG_B|FLAG_C; // can add more flags if you want...
DatabaseUserMap["Mephisto"] = user; // added a user to the database which I can access with the key "Mephisto"

Now, when you want to check the safelist (probably to determine whether to kick/ban/ignore someone you can do something like this):
if(DatabaseUserMap[user]._flags & FLAG_S) { // mask out all their flags but S
    // take action resulting if the user is safelisted
} else if((DatabaseUserMap[user]._flags & FLAG_S) == 0) { // == is evaluated first, so we use parenthesis (and you could just use an else instead of an else if here)
    // ban target
}

Zakath

Umm...why check that the user doesn't have S when you just barely checked if they DID have S? It's fairly plain that if you even get to the second conditional that they don't have the S flag, so why are you checking?
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

Kp

Also, unless the compiler is extremely smart, it's going to assemble that into multiple lookups of the flags.  You should instead retrieve the flags into a local variable and do all computations with that variable.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

tA-Kane

Quote from: Kp on January 19, 2005, 07:05 PM
Also, unless the compiler is extremely smart, it's going to assemble that into multiple lookups of the flags. You should instead retrieve the flags into a local variable and do all computations with that variable.
eww--! Compilers should *never* cache results from functions!! Suppose you do something that would cause a different result to be returned, even with the very exact same data being passed to it? For example, an encryption function that takes only the data to be encrypted and returns different results each time would either get the encryption key itself, or generate random data for the result. Regardless of whether or not the result is validly-encrypted (*cough*), the result is still different. Subsequent use of that data, if using cached data, would generate invalid data!
Macintosh programmer and enthusiast.
Battle.net Bot Programming: http://www.bash.org/?240059
I can write programs. Can you right them?

http://www.clan-mac.com
http://www.eve-online.com

dxoigmn

Quote from: tA-Kane on January 20, 2005, 01:32 PM
eww--! Compilers should *never* cache results from functions!! Suppose you do something that would cause a different result to be returned, even with the very exact same data being passed to it? For example, an encryption function that takes only the data to be encrypted and returns different results each time would either get the encryption key itself, or generate random data for the result. Regardless of whether or not the result is validly-encrypted (*cough*), the result is still different. Subsequent use of that data, if using cached data, would generate invalid data!

That's why he said "extremely smart."

MyndFyre

Quote from: dxoigmn on January 20, 2005, 01:36 PM
Quote from: tA-Kane on January 20, 2005, 01:32 PM
eww--! Compilers should *never* cache results from functions!! Suppose you do something that would cause a different result to be returned, even with the very exact same data being passed to it? For example, an encryption function that takes only the data to be encrypted and returns different results each time would either get the encryption key itself, or generate random data for the result. Regardless of whether or not the result is validly-encrypted (*cough*), the result is still different. Subsequent use of that data, if using cached data, would generate invalid data!

That's why he said "extremely smart."

So smart, in fact, that it knows how to code what the programmer meant, instead of what he said. :P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Quote from: tA-Kane on January 20, 2005, 01:32 PM
Quote from: Kp on January 19, 2005, 07:05 PMAlso, unless the compiler is extremely smart, it's going to assemble that into multiple lookups of the flags. You should instead retrieve the flags into a local variable and do all computations with that variable.
eww--! Compilers should *never* cache results from functions!!

Of course they should.  However, it should be limited to functions which are marked as being pure or const.  That is, if the programmer notes that the function can safely be called fewer times than the code says, the compiler should take that hint and reduce the number of calls.  If you have a function which produces changing results, just don't mark it as pure.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Mephisto

I did the else if conditional for demonstration purposes.  Besides which, I don't see what's wrong with doing that anyways, seems to be more illustrative to and clearer to anyone else who would read the code, and I don't think it causes much overhead at all (or does it?).

As for not storing the flags into a local variable...I didn't know that you should do this.  I thought it was perfectly fine to retrieve it from the object each time you needed to access it.

Kp

Quote from: Mephisto on January 20, 2005, 05:36 PMAs for not storing the flags into a local variable...I didn't know that you should do this.  I thought it was perfectly fine to retrieve it from the object each time you needed to access it.

From a correctness perspective, you're right.  The program should get the same answer whether you fetch to a local or keep requerying the data.  However, from a performance perspective, there's a potential hit if the query is expensive (which depends on how efficiently the STL you're using has implemented operator[], how big your map is, etc.).
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Mephisto

Makes sense.  I'm not sure either; but I'm assuming since STL is specifically modified for performance, and with the compiler optimizations it should be as *good* as it can be.  :)

Kp

Quote from: Mephisto on January 20, 2005, 08:34 PMMakes sense.  I'm not sure either; but I'm assuming since STL is specifically modified for performance, and with the compiler optimizations it should be as *good* as it can be.  :)

As I recall, you use Microsoft's C compiler.  If so, it's not as good as it can be: afaik, it doesn't support the concept of a pure function, so the compiler cannot make the optimization I described.  The lookup may be fast, but it won't be optimized out.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!