mIRC Home    About    Download    Register    News    Help

Print Thread
#152822 06/07/06 07:50 PM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
I have this bot that adds admin but not savely.
I want to add a host to make it saver.
But have no idea how to start.
This is what I have:
Code:
 add.admin {
  set %nickz $?="Nick to be added?"
  var %a = 2
  while (%a <= $lines($botini)) { if ($gettok($read($botini,%a),1,61) == %nickz) { echo -a > %nickz is already admin. | halt }
    inc %a
  }
  set %pass $?="Password of user for access in bot? (without spaces)"
  writeini $botini Admin %nickz %pass
  echo -a > %nickz added.
}
 

I tryed something like: set %address $address(nick,1)
and then add %address after %pass but that doesn't work.
checking the pass etc goes like this:
Code:
 on *:chat:*:{
 if (.pass != $strip($1)) && (%dccpass == 0) { msg =$nick Invalid command. | close -c $nick | halt }
  if (.pass == $strip($1)) && (%dccpass == 1) { msg =$nick You already are identified. | halt }
  if (.pass == $strip($1)) && (%dccpass == 0) {  
    var %a = 1
    while (%a <= $lines($botini)) {
      if ($gettok($read($botini,%a),1,61) == $nick) && ($gettok($read($botini,%a),2,61) === $strip($2)) { write data\online.txt $nick $address($nick,2) | msg =$nick Accepted password :) | mostra.codes | set %dccpass 1 | halt }
      inc %a
    }
    set %dccpass 1
    msg =$nick Invalid password.
    close -c $nick
  }


My thanks upfront for your time and trouble

#152823 07/07/06 02:05 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I must admit that i havent used INI files at all before, (well besides reading some stuff outa them), I mostly uses for mirc either simple text files or hashtables depending on the need, but anyway.

Im sure your accessing the $botini file incorrectly, your ment to use $readini

Code:
add.admin {
  var %nick = $iif($gettok($1,1,32),$v1,$iif(!$isid,$?="Nick to be added?"))
  if (!%nick) { $iif($isid,return,echo -a) > No nick entered. | return }
  if ([color:blue]$readini($botini,n,Admin,%nick)[/color]) { $iif($isid,return,echo -a) > %nickz is already admin. | return }
  var %pass = $remove($iif($2,$2,$iif(!$isid,$?="Password for %nick for access in bot? (without spaces)")),$chr(32))
  if (!%pass) { $iif($isid,return,echo -a) > No pass entered. | return }
  writeini $botini Admin %nick %pass
  $iif($isid,return,echo -a) > %nick added. | return
}
;
on *:chat:*:{
  if (.pass != $strip($1)) && ($($+(%,dccpass.,$nick),2) == 0) { msg =$nick Invalid command. | close -c $nick | halt }
  if (.pass == $strip($1)) && ($($+(%,dccpass.,$nick),2) == 1) { msg =$nick You already are identified. | halt }
  if (.pass == $strip($1)) && ($($+(%,dccpass.,$nick),2) == 0) {
    if ([color:blue]$readini($botini,n,Admin,$nick)[/color] == $strip($2)) {
      write data\online.txt $nick $address($nick,2) | msg =$nick Accepted password :) | mostra.codes | set $+(%,dccpass.,$nick) 1 | halt
    }
    else {
      msg =$nick Invalid password. | close -c $nick | halt 
    }
  }
}

* untested *

in the add.admin alias
you can now pass it nick and password if u like as follows
/add.admin <nick> <password> OR $add.admin(<nick>,<password>)
if u use $add.admin the normally echoed result is passed back, this was kinda done by mistake, i didnt read what you wanted careflly enough, so i added it as if you were doing the command remotely through a on chat event, (but anyway)

ok in the ON CHAT, im using the same $readini but i also set %dccpass.$nick to 1 when the nick password is accepted, becuase otherwise, your justsetting passowrd accepted and anyone can then be valid!

PS: u still have a bit to do here, like removing valid user when the disconnect etc.

#152824 07/07/06 05:11 AM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
I can't follow your code there dave.
I'm not sure where it adds the host($address) to ident the one who is doing the on chat request.
Also it is not writing the stuff to the online.txt and i'm not getting my password accepted message.
I hope you can explain to me what you did and how the code works.

#152825 07/07/06 06:40 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
I'm not sure where it adds the host($address) to ident the one who is doing the on chat request.


I have no idea what your talking about about this, u never had any code to that effect that i saw.


* i have tested my code now and repaired it, it had a few small errors, i now think are all corrected *
[code]alias add.admin {
var %nick = $iif($gettok($1,1,32),$v1,$iif(!$isid,$?="Nick to be added?"))
if (!%nick) { $iif($isid,return,echo -a) > No nick entered. | return }
if ($readini($botini,n,Admin,%nick)) { $iif($isid,return,echo -a) > %nick is already admin. | return }
var %pass = $remove($iif($2,$2,$iif(!$isid,$?="Password for %nick for access in bot? (without spaces)")),$chr(32))
if (!%pass) { $iif($isid,return,echo -a) > No pass entered. | return }
writeini $botini Admin %nick %pass
$iif($isid,return,echo -a) > %nick added as admin. | return
}
;
on *:chat:*:{
if (.pass != $strip($1)) && (!$($+(%,dccpass.,$nick),2)) { msg =$nick Invalid command. | close -c $nick | halt }
if (.pass == $strip($1)) && ( $($+(%,dccpass.,$nick),2)) { msg =$nick You already are identified. | halt }
if (.pass == $strip($1)) && (!$($+(%,dccpass.,$nick),2)) {
if (($strip($2)) && ($readini($botini,n,Admin,$nick) == $strip($2))) {
write data\online.txt $nick $address($nick,2) | msg =$nick Accepted password smile | mostra.codes | set $+(%,dccpass.,$nick) 1 | halt
}
else {
msg =$nick Invalid password. | close -c $nick | halt
}
}
}[code]
.
.
here is a break down of things u likely migth not know...
.
var %nick = $iif($gettok($1,1,32),$v1,$iif(!$isid,$?="Nick to be added?"))
var %nick = $iif(A,B,$iif(C,D))
A is a conditional test to see if the first word in $1 exists ($1 maybe more than one word if passed using $add.admin)
B is selected if A is true and value is A pulled from the $iif conditional test (shorter and faster than writing out all of A again)
C is a conditional test to see if you are NOT using $add.admin (i used this so $add.admin was automated, you never get prompted)
D is selected if C is true, and is a request prompt for nick
.
if (!%nick) { $iif($isid,return,echo -a) > No nick entered. | return }
if (A) { $iif(B,C,D) > No nick entered. | return }
A is a conditinal test to see if %nick does NOT exist
B use the RETURN command if in $add.admin
C use the ECHO -a command if not in $add.admin
.
if ($readini($botini,n,Admin,%nick)) { $iif($isid,return,echo -a) > %nick is already admin. | return }
if ($readini(A,B,C,D)) { $iif($isid,return,echo -a) > %nick is already admin. | return }
A is the ini filename
B is a switch meaning to not evaluate lines (ex a line might be $time, with out the ,n, u would get back 12:00:00 or what ever the time is)
C is the section header [section header]
D is the valuename valuename=value
* $readini returns value of valuename=value, so if it exists then thats the passord, thus user exists & return/echo message and exit
.
var %pass = $remove($iif($2,$2,$iif(!$isid,$?="Password for %nick for access in bot? (without spaces)")),$chr(32))
var %pass = $remove($iif(A,B,$iif(C,D)),$chr(32))
A is a conditional test to see if <password> was passed
B is the password
C is a conditional test to see if you are NOT using $add.admin (i used this so $add.admin was automated, you never get prompted)
D is selected if C is true, and is a request prompt for password
* $remove used to remove spaces from any password
.
if (!%pass) { $iif($isid,return,echo -a) > No pass entered. | return }
if (A) { $iif($isid,return,echo -a) > No pass entered. | return }
A is a conditinal test to see if %pass does NOT exist
.
if (.pass != $strip($1)) && (!$($+(%,dccpass.,$nick),2)) { msg =$nick Invalid command. | close -c $nick | halt }
if (.pass != $strip($1)) && (!$($+(A,B,C),2)) { msg =$nick Invalid command. | close -c $nick | halt }
A is the % sign in %dccpass.$nick variable
B is the dccpass. in %dccpass.$nick variable
C is the $nick in %dccpass.$nick variable
$+( ) connects them all together to make %dccpass.$nick ($nick is of course the actual nickname)
$( ,2) cause mirc to know your not wanting the string litteral %dccpass.$nick but the contents of that variable name
* so %dccpass.$nick is essentially a nick specific %dccpass varaiable (dynamic variable name)
.
$+(%,dccpass.,$nick) 1
when setting a dynamic variable you dont encolse it in $( ,2) becuase u just need the name of the varaiable NOT its value


Link Copied to Clipboard