mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2003
Posts: 14
P
Pikka bird
OP Offline
Pikka bird
P
Joined: Oct 2003
Posts: 14
Alright...
This is what I want to do - and its really the only way I want to do it, for certain reasons. I want to store sets of information in an ini file or a txt file. I'm not sure which one would work best for this.
Now the kind of info I want to hold in here is like a users list... I want it so it would look something like this in a txt file:

Proselyte Commander password123
GeneralLee StaffSgt peepee123

Now... what I would want is a command to pull this up... a script that like...
Code:
on 1:JOIN:#-=SL=-,#-=SL=-o-club,#testing:{ 
 

Then after this... an indentifer or something that reads users.txt.

So basically... if I join the channel, the bot notices me and says - You are in the user list under the name Proselyte as a Commander. Please verify your account log in by giving me your password. So then I'd private message the bot with password123, and it would log me in. Now what I need help with is an identifier or whatever that checks a txt file for a certain data piece.

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
You have a great many options you can choose from.
  1. You can use a .txt file and store the lines as you presented them.

    Using this method, you would use $read(filename.txt, sn, Proselyte) to save Commander password123 in a variable, and just have your script use $gettok on that variable to retrieve the first or second parameters, separated by the space character (32).

    var %info = $read(filename.txt, sn, $nick)
    var %rank = $gettok(%info, [color:orange]1
    , 32)
    var %password = $gettok(%info, 2, 32)
    [/color]
  2. You can store them in an INI file with each option on its own line. To do this, you will want to use $encode($nick, m) to get rid of the problem of nicks like [Proselyte] or [Hammer]. mIRC would change those to ~Proselyte~ and ~Hammer~ so that when they are stored in the INI file, they would look like [~Proselyte~] instead of [[Proselyte]], which doesn't work.

    [UHJvc2VseXRl]
    rank=Commander
    password=password123

    [R2VuZXJhbExlZQ==]
    rank=StaffSgt
    password=peepee123

    var %rank = $readini(filename.ini, $encode($nick, m), rank)
    var %password = $readini(filename.ini, $encode($nick, m), password)
  3. You can store them in a hash table in either of the ways already mentioned, either by storing each nick's data in one item, or by building an item name for each parameter.

    var %rank = $gettok($hget(htable, $encode($nick, m)), 1, 32)
    var %password = $gettok($hget(htable, $encode($nick, m)), 2, 32)

    or, if you are building the item names for the hash table:

    var %rank = $hget(htable, $+(rank., $encode($nick, m)))
    var %password = $hget(htable, $+(password., $encode($nick, m)))
The easiest method, most likely, for most cases such as this is the $read(filename.txt, sn, $nick) since it does not require you to "escape" odd characters like [ ] out of nicknames when you're searching an INI file (or hash table, really, depending on how you hsave the hash table to disk).

Each method has its advantages and disadvantages.
  1. Text files are very handy and don't have the "odd characters in nicks" problem that INI files and some hash tables do, but mIRC can have trouble with the lines if they get too long, if you're not careful.
  2. INI files are fantastic for storing lots of different kinds of individual pieces of data in their own items, but mIRC can sometimes have problems with INI files if they get to large (over 64KB), so they are not so good at large numbers of nicks and their data, for instance.
  3. Hash tables can store almost unlimited amounts of data, active in memory, so they don't need to do any disk reads - very fast data access! - to get at your results, but they also have the same line size limitation that text files do (around 940 characters). Once you are very familiar with how hash tables work, they are definitely the way to go for almost all applications...but learning how to use them effectively is not as easy as using a straight TXT file or INI file.
There are also a lot of other data storage choices you might choose, but most of them are quite a bit more esoteric and probably wouldn't fit the simple needs you have described. Databases (through $com), for instance, can store large amounts of data and can be accessible to multiple programs, and even over the web to large numbers of people, but they are not at all easy to learn. Nor is setting up such a script trivial; however, for some applications, this solution is ideal.

The best choice is whichever you feel best suits your needs (for your current level of scripting).


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C

Link Copied to Clipboard