SysOp IRC Services — File Browser

SysOpIRCServicesv0.1 / SysOpIRCServicesv0.1 / system / connect.mrc

connect.mrc — 7.37 KB — Download this file

; Copying or editing of any of the scripts included in this module is strictly prohibited, you may distribute the package
; in its entireity un edited in any form. Support can only be given to those who do not edit these files please do not ask
; if you plan to edit them yourself. Credits and links back to us must remain in the script we do not advertise using your
; network unless the .VERSION command is triggered. You must also agree when connecting the service to any IRC net
; that you have the correct permission to connect the service, you MUST NOT connect the service to Digi-Net and you
; connect the service at your own risk. For support see http://www.digi-net.org


alias start {
  if ($sock(Serv)) {
    echo > Closing current service link
    sockclose Serv
  }
  echo > SysOP Services Loading
  echo > Loading current services configuration
  echo >> Connecting Services to $netconf(server,ip) using Port $netconf(server,port)
  var %errors = 0
  echo -a :-
  echo -a : $+ %color $+  Self Diagnosis
  if $isdir($mircdir $+ data) {
    echo -a : $+ %color The Data Folder exists and is correct
  }
  else {
    echo -a : $+ %color 4Error: The Data Folder was not Found
    inc %errors
  }
  if (%errors = 0) {
    echo -a : $+ %color - Checking required data files...
    if (!$exists(data\blacklist.db)) {
      echo -a : $+ %color 4Error: The data\blacklist.db does not exist!!
      inc %errors
    }
    if (!$exists(data\channels.db)) {
      echo -a : $+ %color 4Error: The data\channels.db does not exist!!
      inc %errors
    }
    if (!$exists(data\clients.db)) {
      echo -a : $+ %color 4Error: The data\clients.db does not exist!!
      inc %errors
    }
    if (!$exists(data\news.db)) {
      echo -a : $+ %color 4Error: The data\news.db does not exist!!
      inc %errors
    }
    if (!$exists(data\nicknames.db)) {
      echo -a : $+ %color 4Error: The data\nicknames.db does not exist!!
      inc %errors
    }
    if (!$exists(data\notes.db)) {
      echo -a : $+ %color 4Error: The data\notes.db does not exist!!
      inc %errors
    }
    if (!$exists(data\pending.db)) {
      echo -a : $+ %color 4Error: The data\pending.db does not exist!!
      inc %errors
    }
    if (!$exists(data\seen.db)) {
      echo -a : $+ %color 4Error: The data\seen.db does not exist!!
      inc %errors
    }
    if (!$exists(data\set_topics.txt)) {
      echo -a : $+ %color 4Error: The data\set_topics.txt does not exist!!
      inc %errors
    }
  }
  if (%errors = 0) {
    echo -a : $+ %color 3OK: No problems found :)
  }
  if $isdir($mircdir $+ lang) {
    echo -a : $+ %color The Lang Folder exists and is correct
  }
  else {
    echo -a : $+ %color 4Error: The Lang Folder was not Found
    inc %errors
  }
  echo -a : $+ %color - Checking for any language files...
  if ($findfile($mircdir $+ \lang,lang_*.db,0) < 1) {
    echo -a : $+ %color 4Error: No language files found!!
    inc %errors
  }
  else {
    echo -a : $+ %color There are  $+ $findfile($mircdir $+ \lang,lang_*.db,0) $+  language files available
  }
  if (%errors = 0) {
    echo -a : $+ %color 3OK: No problems found :)
  }
  echo -a : $+ %color - Checking Configuration file...
  if (!$exists(services.conf)) {
    echo -a : $+ %color 4Error: Configuration file not found services.conf
    inc %errors
  }
  if (%errors = 0) {
    echo -a : $+ %color 3OK: No problems found :)
  }
  var %x = $ctime
  echo -a : $+ %color Test complete at $asctime(%x) and found  $+ %errors $+  problems.
  echo -a :-
  if (%errors < 1) {
    sockopen serv $netconf(server,ip) $netconf(server,port)
    set %connect_time $ctime
    timerclearall 0 900 /clearall
  }
}
alias stop {
  echo > Killing service link
  echo > Clearing Temporary Records
  .remove data/activechans.db
  .remove data/admin.db
  .remove data/id.db
  set %whosonline 0
  sockclose serv
}

on 1:sockopen:serv: {
  if ($sockerr > 0) { echo -s >>> There was an error creating service link (Error Code: $sockerr $+ ) | Return }
  unset %RT*
  echo >>> Sending password to server
  sockwrite -tn serv PASS $+(:,$netconf(server,pass))
  echo >>> Creating Server
  sockwrite -tn serv SERVER $netconf(server,server) 1 $+(:,$netconf(server,info))
  set %used no
  echo >>> Service Link Established, Preparing to load Services
}
on 1:sockread:serv: {
  if ($sockerr > 0) { echo >>> There was an error connecting services (Error Code: $sockerr $+ ) | return }
  if (%used == NO) {
    echo >>>> Beginning Service Connection
    services_connect
    unset %used 
  }
  :read_more
  sockread %data
  if ($sockbr == 0) { unset %data | return }
  if (%data == $null) { set %data - }
  data_in %data
  goto read_more
}
on 1:sockclose:serv: {
  echo Lost connection with $+($sock($sockname).ip,:,$sock($sockname).port)
}
alias services_connect {
  if ($2 == -s) { echo >>>>> Stopping System Service | .sockwrite -tn serv : $+ SYSOP QUIT :Recieved Termination signal from Console }
  elseif ($2 == -r) { echo >>>>> Reloading System Service | .sockwrite -tn serv : $+ SYSOP QUIT :Recieved Restart signal from Console }
  .sockwrite -tn serv NICK $netconf(system,nickname) 1 $ctime services $netconf(server,domain) $netconf(server,server) * $+(,:,$netconf(system,name))
  .sockwrite -tn serv NICK $netconf(system,service2) 1 $ctime services $netconf(server,domain) $netconf(server,server) * $+(,:,$netconf(system,name))
  .sockwrite -tn serv $+(:,$netconf(system,nickname)) MODE $netconf(system,nickname) +iHpSqz
  .sockwrite -tn serv $+(:,$netconf(system,nickname)) SWHOIS $netconf(system,nickname) :For help with $netconf(system,nickname) Service type /msg $netconf(system,nickname) HELP
  .sockwrite -tn serv $+(:,$netconf(system,service2)) MODE $netconf(system,service2) +iSqz
  join_chans
}

alias join_chans {
  echo >>>>> Joining Registered Channels
  var %x = 1
  while ($ini(data/channels.db,%x)) {
    if (!$readchan($ini(data/channels.db,%x),suspended)) {
      .sockwrite -tn serv $+(:,$netconf(system,nickname)) MODE $ini(data/channels.db,%x) $iif($readchan($ini(data/channels.db,%x),modes),$ifmatch,+nt)
      .sockwrite -tn serv $+(:,$netconf(system,nickname)) TOPIC $ini(data/channels.db,%x) $netconf(system,nickname) $ctime : $+ $remove($read(data/set_topics.txt, s, $ini(data/channels.db,%x) $+ :),$ini(data/channels.db,%x) $+ :)
    }
    if ($readchan($ini(data/channels.db,%x),topicfreq) == on) {
      timer $+ $ini(data/channels.db,%x) $+ topic 0 14400 sockwrite -tn serv $+(:,$netconf(system,nickname)) TOPIC $ini(data/channels.db,%x) $netconf(system,nickname) $ctime : $+ $remove($read(data/set_topics.txt, s, $ini(data/channels.db,%x) $+ :),$ini(data/channels.db,%x) $+ :)
    }
    if ($readchan($ini(data/channels.db,%x),inchan) == on) && (!$readchan($ini(data/channels.db,%x),suspended)) { 
      .sockwrite -tn serv $+(:,$netconf(system,nickname)) JOIN $ini(data/channels.db,%x)
      .sockwrite -tn serv $+(:,$netconf(server,server)) MODE $ini(data/channels.db,%x) +o $netconf(system,nickname)
    }
    inc %x
  }
}
alias leave_chans {
  echo >>>>> Leaving Registered Channels
  var %x = 1
  while ($ini(data/channels.db,%x)) {
    if ($readchan($ini(data/channels.db,%x),inchan) == on) { 
      .sockwrite -tn serv $+(:,$netconf(system,nickname)) PART $ini(data/channels.db,%x) PartAll By Console
    }
    inc %x
  }
}