RE: euLibnet and IRC

new topic     » goto parent     » topic index » view thread      » older message » newer message

On 31 May 2001, at 22:03, Grape Vine wrote:

> 
> Yea, i dont need a gui right now, A) ill make my own when i need it B) 
> im going to run this as a command line bot tell i get used to makign IRC 
> apps

You'll share your code too? smile

Ok, here it is, use at your own risk, etc..... It's not clean, it's just as i i
used it in
testing last time. It doesn't check for err_msgs, and the do_events() and
sleep(0) need
to be tied together, so an abort can be sent to tcp4u if the server is
disconnected
during a loop somehow, etc. etc.. Oh, and the numeric parse isn't working, etc..
I was
going to set up something along the lines of mirc's on_events{} following the 
NumericParse(). It does demo how to get on irc, and how to get and send some
msgs.
That poke4() fix to tcp4u *must* be done, since it's a bug anyhow, or you will
not be
able to connect to any ports higher than 255, and irc generally lives on ports
6665-
7000 and 9000! Also, you must set the ip# of the server you wish to connect to,
since i
didn't bother to do a dns on the server name. Valinor on sorcerynet is set
below. It's a
good idea to ask the server owner about testing new code on their servers, i
asked,
and i tested during a relatively idle time. The owner is mentioned in the motd.

And it needs a cleanup, i threw this together since i couldn't sleep one nite
due to
storms, i wrote and tested the whole thing tween 1am and 8am.

For reference material, check out:

RFC 1459 from 
http://www.cis.ohio-state.edu/cgi-bin/rfc/rfc1459.html
or
http://ds.internic.net/rfc/rfc1459.txt

(there are later rfcs for irc, but they don't offer anything useful)


and 

http://www.teleport.com/~jeepster/numeric.html 
Jeepster’s Numeric’s may also be found at: http://www.ircworks.com/ 

Have fun!

Kat




-- BE SURE TO SET my_nick TO SOMETHING!!
-- no errors are checked for....

with trace

include tcp4u.ew
with trace
integer ret, char, port, logfile
sequence sock_connect, sock_receive, server_ip, server_name, data, logfilename
sequence recievedline, my_nick

-- where to store the log?
logfilename = "D:\\irc_Tiggr\\Eu client\\log.txt"

-- sorcerynet prefers port 9000, check your net
port = 9000

-- i haven't done any dns on the servername, 
-- so i declared the ip address
server_ip = "216.122.249.75"
server_name = "valinor.sorcery.net"
my_nick = "" -- you must have a nick!!


function find_all(object value, sequence s)
-- Gabriel Boehme
-- return a list of all indexes where value is found in s
sequence list
   list = {}
   for i = 1 to length(s) do
      if equal(value, s[i]) then
	 list = append(list, i)
      end if
   end for
   return list
end function


function deparse(sequence list, integer c)
-- Gabriel Boehme
-- convert parsed list back into a string with c delimiters
sequence s
integer len
   len = length(list)

   if len then
      s = list[1]
      for i = 2 to len do
	 s = s & c & list[i]
      end for

      return s
   end if

   return ""
end function -- deparse


global function parse(sequence s, object c)
sequence list
integer prev, curr

if integer(c) then
-- Gabriel Boehme
-- parse string s based on delimiter c into a sequence of values
-- s = "http://coverage.cnet.com/Resources/Info/Glossary/Terms/ac3.html"
-- c = '/'
   while length(s) and ( s[1] = c ) do
      s = s[2..length(s)]
   end while
   while length(s) and ( s[length(s)] = c ) do
     s = s[1..length(s)-1]
   end while

   if length(s) then
      list = find_all(c, s & c) -- list of delimiter positions
      prev = 0
      for i = 1 to length(list) do
	 curr = list[i]
	 list[i] = s[prev+1..curr-1]
	 prev = curr
      end for

      return list -- now, a list of the delimited values
   end if
end if -- integer(c)
return""
end function -- parse


function ParseNumeric(sequence data)
 if not sequence(data) then return "" end if
 if not length(data) then return "" end if
 data = parse(data,32)
 if equal(data[1],":"&server_name)
 --and integer(data[2])
   then
   trace(1)
     if equal(data[1][1],':') then data[1][1] = 32 end if
     if equal(data[4][1],':') then data[4][1] = 32 end if
     if equal(data[4][1],'-') then data[4][1] = 32 end if
     data = data[2] & data[3] & deparse(data[4..length(data)],32)
     return data
   else
     return ""
 end if
 return ""

end function -- ParseNumeric(sequence data)


function numeric(sequence data)
sequence val
 if not sequence(data) then return 0 end if
 if not length(data) then return 0 end if
 data = parse(data,32)
 val = value(data[2])
 if equal(data[1],':'&server_name) and not equal(val[1],"GET_FAIL")
   then return 1
   else return 0
 end if
end function -- numeric()


function GetMyText()
  return""
end function -- GetMyText()


function ServerNeedsAttention(object sock)
 if tcp4u_is_data_avail(sock)
   then return(1)
   else return(0)
 end if
end function -- ServerNeedsAttention()

function ReadServer(object sock)

recievedline = ""
 while tcp4u_is_data_avail(sock) do
   sock_receive = tcp4u_receive(sock,1,1)

   if sock_connect[1] != TCP4U_SUCCESS then
     printf(1, "tcp4u_connect error '%s'\n",
       {tcp4u_error_string(sock_connect[tcp4u_ret])} )
     exit
   end if

   if equal(sock_receive[2],{10}) then
     sock_receive[2] = ""
   end if
   if equal(sock_receive[2],{13})
     then
       puts(1,recievedline&"\n")
       puts(logfile,recievedline&"\n")
       return recievedline
     else
       recievedline &= sock_receive[2]
   end if

  end while -- tcp4u_is_data_avail(sock_connect[2]) do
  return""
end function -- checkserver


procedure SendToServer(object sock, sequence data)
  if not equal(data[length(data)],"\n") then
    data &= "\n"
  end if
  ret = tcp4u_send(sock, data, length(data))
end procedure -- SendToServer(sequence data)


logfile = open(logfilename,"w")
puts (1,"Connecting to an IRC server.\n")
puts (logfile,"Connecting to an IRC server.\n")

if tcp4u_init() != TCP4U_SUCCESS then
  wait_abort("tcp4u_init error")
end if

-- the following will fail if you didn't make the poke4 correction to tcp4u!!
sock_connect = tcp4u_connect(server_ip, NULL, port)
if sock_connect[tcp4u_ret] != TCP4U_SUCCESS then
printf(1, "tcp4u_connect error
  '%s'\n",{tcp4u_error_string(sock_connect[tcp4u_ret])} )
  puts(1,"\naborting on any keypress")
  char = wait_key()
  abort(1)
end if

puts(1, "...connection
established\n------------------------------------------\n")
puts(logfile, "...connection
established\n------------------------------------------\n")

-- :valinor.sorcery.net NOTICE AUTH :*** Hello, you are connecting to 
valinor.sorcery.net, the progress of your connection follows
-- etc
-- then numerics 001 , 002, 003, 004, and 005

if ServerNeedsAttention(sock_connect[2]) then
  data = ReadServer(sock_connect[2])
end if

if 1=1 then
--trace(1)
-- send the ip# of the server as the pass! <blink>
data = "PASS "&server_ip&"\n"
ret = tcp4u_send(sock_connect[2], data, length(data))
if ret != TCP4U_SUCCESS then
  printf(1, "tcp4u_send error '%s'\n", tcp4u_error_string(ret))
  puts(1,"\naborting on any keypress")
  char = wait_key()
  abort(1)
end if


data = "NICK "&my_nick&"\n"
ret = tcp4u_send(sock_connect[2], data, length(data))

-- check for:
-- Numeric Replies:
--    ERR_NONICKNAMEGIVEN
--    ERR_ERRONEUSNICKNAME
--    ERR_NICKNAMEINUSE
--    ERR_NICKCOLLISION

-- Parameters: <username> <hostname> <servername> <realname>
data = "USER username \"\" "&server_name&" :something cute\n"
ret = tcp4u_send(sock_connect[2], data, length(data))

-- check for numerics:
--   ERR_NEEDMOREPARAMS
--   ERR_ALREADYREGISTRED

--data = "MOTD\n"
--ret = tcp4u_send(sock_connect[2], data, length(data) )

end if

SendToServer(sock_connect[2],"MODE "&my_nick&" +i \n")
SendToServer(sock_connect[2],"ISON chanserv nickserv\n")
SendToServer(sock_connect[2],"JOIN #TiggrBot\n")
SendToServer(sock_connect[2],"PRIVMSG #TiggrBot testing!\n")

while 1 do

 char = get_key()
 if (char = 'Q') then
   SendToServer(sock_connect[2],"QUIT :my quit message goes here!")
   exit
 end if
--trace(1)

  if ServerNeedsAttention(sock_connect[2]) then
    data = ReadServer(sock_connect[2])
  end if

-- process the data here, like mirc events
if numeric(data) then
 data = ParseNumeric(data)
 if equal(data[1],"303") then puts(1,"Notify: "&data[3]) end if

end if

  data = GetMyText()

-- process the on_input here, like, send it to the server

  if not equal(data,"") then
    SendToServer(sock_connect[2],data)
  end if

end while -- 1 do


ret = tcp4u_close(sock_connect[2])
if ret != TCP4U_SUCCESS then
 printf(1, "tcp4u_close error '%s'\n", {tcp4u_error_string(ret)} )
 puts(1,"\naborting on any keypress")
 char = wait_key()
 abort(1)
end if

puts(1, "\n------------------------------------------\n...connection closed\n")
puts(logfile, "\n------------------------------------------\n...connection
closed\n")

ret = tcp4u_cleanup()
if ret != TCP4U_SUCCESS then
 printf(1, "tcp4u_cleanup error '%s'\n", {tcp4u_error_string(ret)} )
 puts(1,"\naborting on any keypress")
 char = wait_key()
 abort(1)
end if

close(logfile)
puts(1, "press any key to close up and abort\n")
ret = wait_key()
abort(0)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu