mIRC Home    About    Download    Register    News    Help

Print Thread
#13728 02/03/03 02:46 AM
Joined: Dec 2002
Posts: 111
E
Vogon poet
OP Offline
Vogon poet
E
Joined: Dec 2002
Posts: 111
aight another problem, Ports are limited to only one connection per port, how can i randomly assign connections to a range of ports, or redirect connections to an open port that come in? Seeing as how telnet forces you to type in a port number =/

also is it possible to remotely clear a telnet screen?

#13729 02/03/03 03:45 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
A single listening socket can receive as much connections as needed.

I don't know how it exactly works, but every /sockaccept redirects the incoming connection to a specific environment so that it doesn't conflict with other connections.

For more info you can read this article.

#13730 02/03/03 04:51 AM
Joined: Dec 2002
Posts: 111
E
Vogon poet
OP Offline
Vogon poet
E
Joined: Dec 2002
Posts: 111
ok i read all that and understand it, but i've programmed myself into a hole and didnt even know it. look:

Code:
on *:load: {
  socklisten telnet 4445
}
on *:socklisten:telnet: {
  sockaccept telnetopen
  set %ipname $sock(telnetopen).ip
  set %ipname telnetopen $+ %ipname
  sockrename telnetopen %ipname
  echo Telnet Session Initiated from $sock(%ipname).ip
  set %checktelip $read(data\telnetiplist.db, w, $sock(%ipname).ip)
  if (%checktelip != $null) {
    write -ds $sock(%ipname).ip data\telnetiplist.db
  }
  write data\telnetiplist.db $sock(%ipname).ip
  set %checktelname $read(data\telnetnamelist.db, w, telnetopen $+ $sock(%ipname).ip)
  if (%checktelname != $null) {
    write -ds telnetopen $+ $sock(%ipname).ip data\telnetnamelist.db
  }
  write data\telnetnamelist.db telnetopen $+ $sock(%ipname).ip

  set %temp1 $read(data\telnetiplist.db, w, $sock(%ipname).ip)
  set %sockwritename $read(data\telnetnamelist.db, w, * $+ %temp1)

  sockwrite -tn %sockwritename MessageBot Telnet Console Version 1.0 Copyright 2002-2003 MessageBot.net
  sockwrite -tn %sockwritename ========================================================================
  set %test $read(data\registerlist.db,1)
  set %checkpass $gettok($hget(nicks,%test),1,32)
  if (%checkpass == $null) {
    sockwrite -tn %sockwritename ERROR: The databases have not been loaded into memory. Please connect $&
      MessageBot to a server first to load the databases before attempting to login via telnet.
    sockclose %sockwritename
  }
  sockwrite %sockwritename Please login below
  sockwrite %sockwritename Username:
  set %state 1
}

on *:sockclose:telnetopen: {
  set %temp1 $read(data\telnetiplist.db, w, $sock(%ipname).ip)
  set %sockwritename $read(data\telnetnamelist.db, w, * $+ %temp1)
  echo Telnet Connection Closed due to exit by client.
  sockclose %sockwritename
}

on *:sockread:telnetopen: {
  set %temp1 $read(data\telnetiplist.db, w, $sock(%ipname).ip)
  set %sockwritename $read(data\telnetnamelist.db, w, * $+ %temp1)
  if (%state == 1) {
    sockread %username
    if (%username == $null) { halt }
    echo %username
    sockwrite -tn telnetopen Sent username ' $+ %username $+ '
    sockwrite -tn telnetopen Password:
    set %state 2
  }
  if (%state == 2) {
    sockread %password
    if (%password == $null) { halt }
    echo %password
    set %checkpass $gettok($hget(nicks,%username),1,32)
    if (%checkpass != %password) {
      sockwrite -tn telnetopen Invalid login or password.
      sockclose telnetopen
      echo Telnet Connection Closed due to invalid login.
    }
    else {
      sockwrite -tn telnetopen Password accepted for user ' $+ %username $+ '
    }
  }
}


I'm trying to make it so that it can be an unlimited number of sessions going on at once, and i was thinking, "ok well i will just store the users ip address, and then make their individual socket name out of the ip address and be able to do it that way!" and then i realized in order to grab the persons IP i have to have their socket name in the first place, so everything was going fine until i realized i was using the variable %ipname to specify their socketname to grab their SECOND socket name off of the telnetnamelist.db file. Which is a completely worthless, and i dont know why i didnt realize that before i went and wrote all that.

I figure the only way to be able to do this right, is to be able to grab the persons IP during the on *:sockread part of the code before anything else is initiated, then i can use the ip to search the file telnetnamelist.db and can get their socketname from there... and i cant find anything to do this.....

Last edited by Hammer; 02/03/03 04:11 PM.
#13731 02/03/03 06:45 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Try this commented version, maybe it will point things out:
Code:

On *:start:{
  ;
  ; Please note: I changed the event from on Load to on Start.
  ;
  socklisten telnet 4445
}
 
On *:socklisten:telnet:{
  ;
  ; If there was an error, stop the script.
  ; (I always check $sockerr on Socklisten and Sockopen).
  ;
  if $sockerr { return }
  ;
  ; Assign the incoming connection a temporary name
  ; then grab its IP address, store it in a local variable
  ; and rename the socket the IP address.
  ;
  sockaccept temp
  var %sockname = $sock(temp).ip
  sockrename temp %sockname
  ;
  ; Welcome the user
  ;
  echo -se * Telnet Session Initiated from %sockname
  sockwrite -tn %sockname MessageBot Telnet Console Version 1.0 Copyright 2002-2003 MessageBot.net
  sockwrite -tn %sockname ========================================================================
  sockwrite -tn %sockname Please login below
  sockwrite -tn %sockname Username:
}
 
On *:sockread:?*.?*.?*.?*:{
  var %data
  sockread %data
  if !%data { return }
  var %mark = $sock($sockname).mark, %user = $gettok(%mark,1,32), %pass = $gettok(%mark,2,32) 
  tokenize 32 %data
  ;
  if !%pass {
    if !%user {
      ;
      ; Set username.
      ;
      sockwrite -tn $sockname Sent username ' $+ $1 $+ '
      sockwrite -tn $sockname Password:
      sockmark $sockname $1
      return
    }
    ;
    ; Verify password
    ;
    if $1 != $gettok($hget(nicks,%user),1,32) {
      sockwrite -tn $sockname Invalid password, bye.
      sockclose $sockname
      return
    }
    ;
    ; Accept user logon.
    ;
    sockwrite -tn $sockname Password accepted for %user
    sockmark $sockname %user $1
    return
  }
  ;
  ; Your stuff goes here. Info you can retrieve:
  ;
  ;   User:    %user
  ;   Pass:    %pass
  ;   IP:      $sockname
  ;   Command: $1-        
  ;
}

#13732 02/03/03 02:59 PM
Joined: Dec 2002
Posts: 111
E
Vogon poet
OP Offline
Vogon poet
E
Joined: Dec 2002
Posts: 111
haha im such a noob at this, ive been pouring over the help files and didnt even realize you could just use $sockname for the socket name and mirc would do all the hard work for you for naming the sockets. lol thanx

one thing tho is it possible to clear a telnet screen remotely? like have somethin like sockwrite -c $sockname to clear the telnet screen?


Link Copied to Clipboard