;--------------------------------------------------------------------------------------------------------------------------------
;msnauth.mrc
;rom and Andy Carvell 2004-2005
;Version 1.01
;--------------------------------------------------------------------------------------------------------------------------------

alias openssl {
  var %hh,%hhp
  if ($gettok(%msn.user, 2, 64) == hotmail.com) { %web = loginnet.passport.com }
  if ($gettok(%msn.user, 2, 64) == hotmail.co.uk) { %web = loginnet.passport.com } 
  elseif ($gettok(%msn.user, 2, 64) == msn.com) { %web = msnialogin.passport.com }
  else { %web = login.passport.com }


  %hh = $gettok(%web, 1, 46) | %hhp = 80
  inc %nums
  sockopen ssl? $+ %hh $+ %nums %hh $+ .passport.com %hhp
  sockmark ssl? $+ %hh $+ %nums passport
}
on *:sockopen:ssl?*:{
  if ($sockerr > 0) { echo -s closed $sockname | return }
  else {
    echo -s $sockname
    set %auth Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in= $+ $replace(%msn.user,@,% $+ 40) $+ ,pwd= $+ %msn.pass $+ , $+ %vknc
    sockwrite -n $sockname GET /login2.srf HTTP/1.1
    sockwrite -n $sockname Authorization: %auth
    sockwrite -n $sockname Host: %web
    sockwrite -n $sockname User-Agent: MSMSGS
    sockwrite -n $sockname Connection: Keep-Alive
    sockwrite -n $sockname Cache-Control: no-cache
    sockwrite -n $sockname $str($crlf, 2)
  }
  if ( %msn.rememberpass != 1 ) { unset %msn.pass }
  ;unset %auth
}

on *:sockread:ssl?*:{
  var %a
  sockread %a
  tokenize 32 %a
  while ($sockbr) {
    if ( %msn.debug = 1 ) { echo -s $sockname : $+ %a }
    if ($gettok(%a, 1, 32) == Authentication-Info:) {
      sendmsn USR %msn.main TWN S $gettok(%a, 2, 39)
      return
    }
    sockread %a
  }
}
