|
Joined: Mar 2005
Posts: 74
Babel fish
|
OP
Babel fish
Joined: Mar 2005
Posts: 74 |
can i make a hash table with a user lvl? if not, can you teach me how to make a hashtable where ppl can register their username and password so they can access the command script in my bot
Thx
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Any information can be stored in a hash table. Here's a suggestion for a code on *:start:{
if !$hget(Register) { .hmake Register 10 }
if $exists(Register.hsh) { .hload Register register.hsh }
}
on *:load:{
if !$hget(Register) { .hmake Register 10 }
if $exists(Register.hsh) { .hload Register register.hsh }
}
on *:exit:{ .hsave -o Register Register.hsh }
on *:disconnectt:{ .hsave -o Register Register.hsh }
on *:text:!register*:?:{
if !$hget(Register,$+(Password.,$address)) {
.hadd -m Register $+(Password.,$address) $md5($2)
}
else .msg $nick You are already registered
}
on *:text:!login*:?:{
if $md5($2) === $hget(Register,$+(Password.,$address)) {
.auser -a $hget(Register,$+(Levels.,$address)) $nick
}
else .msg $nick Invalid password
}
on *:part:#: .ruser $nick
on *:quit: .ruser $nick
on *:kick: .ruser $knick
on *:text:!addlevel*:?:{
var %a = $comchan($nick,0)
while (%a) {
if ($nick isop $comchan($nick,%a)) && ($$2 ison $comchan($nick,%a)) {
var %address = $right($address($$2,0),-2)
var %levels = $replace($3-,$chr(44),$chr(32))
var %levels = $replace(%levels,$chr(32),$chr(44))
.hadd -m Register $+(Levels.,%address) $addtok($hget(Register,$+(Levels.,%address)),%levels,44)
}
}
dec %a
}
}
To register: /msg <botnick> !register <PaSsWoRd> To login: /msg <botnick> !login <PaSsWoRd> To add levels, the person must have ops in the channel and the person they are adding levels to must be in the same channel: /msg <botnick> !addlevel <nick> <levels> <levels> can have multiple entries separated by spaces or commas Code is untested as written, but I use a similar code on one of my bots, and it works fine
|
|
|
|
Joined: Mar 2005
Posts: 74
Babel fish
|
OP
Babel fish
Joined: Mar 2005
Posts: 74 |
the register works fine it shows You are already registered when i try to register again I'm not sure about login since it didn't message me back
how do i see the hashtable?
i'm not really sure about adding lvl cause when i try to add lvl, it crashed everytime i add lvl. not sure what's wrong with it
Thx
Last edited by KidSol; 03/10/05 03:37 PM.
|
|
|
|
Joined: Mar 2005
Posts: 74
Babel fish
|
OP
Babel fish
Joined: Mar 2005
Posts: 74 |
|
|
|
|
Joined: Jul 2003
Posts: 655
Fjord artisan
|
Fjord artisan
Joined: Jul 2003
Posts: 655 |
To view the contents of a hash table in mirc, something like this will do. Note, red line was put in at last second, remove it to view all data in a table larger than 50. Large table could lag/freeze mirc while echo'ing
syntax: /hashtablelist <table>
alias hashtablelist {
if (!$1) return
var %i = $hget($1, 0).item, %x = 1
while (%x <= %i) {
echo -s $hget($1, %x).item $+ = $+ $hget($1, %x).data
[color:red]if (%x == 50) { var %x = %i }[/color]
inc %x
}
}
If you just want to see the data, not neccersarily in mirc, you can just use hsave then open the ini file in notepad or your prefered text editor. I think the reason it was freezing when using !addlevel is because the dec %a was outside of the while loop which causes an infinite loop. Also there was a bracket mismatch. New code...
on *:text:!addlevel*:?:{
var %a = $comchan($nick,0)
while (%a) {
if ($nick isop $comchan($nick,%a)) && ($$2 ison $comchan($nick,%a)) {
var %address = $right($address($$2,0),-2)
var %levels = $replace($3-,$chr(44),$chr(32))
var %levels = $replace(%levels,$chr(32),$chr(44))
.hadd -m Register $+(Levels.,%address) $addtok($hget(Register,$+(Levels.,%address)),%levels,44)
}
dec %a
}
}
Last edited by Om3n; 05/10/05 07:05 AM.
"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
To view hash tables, I use this addon from Mr Foot
|
|
|
|
|