1
0

net.l 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. (def net (open "/net"))
  2. (def net-y 32)
  3. (def irc-msg (fn msg (do
  4. (let ircbuf (concat "PRIVMSG #nodrama.de :" msg))
  5. (send net ircbuf)
  6. (send net [0a])
  7. )))
  8. (def cmdbuf (alloc-str 512))
  9. (def cmd-read (list))
  10. (def remote-cmd (fn msg (do
  11. (let parts (split msg "$"))
  12. (if (gt (list-size parts) 1) (do
  13. (let cmd (concat (concat "(" (item parts 1)) ")"))
  14. (print (list "remote cmd" cmd))
  15. (def cmdbuf (alloc-str 512))
  16. (def cmd-read (read cmd))
  17. (write (eval cmd-read) cmdbuf)
  18. (print (list "result" cmdbuf))
  19. (irc-msg cmdbuf)
  20. ) 0)
  21. 0
  22. )))
  23. (def freenode "/net/tcp/62.231.75.133/6667")
  24. (def sternfreunde "/net/tcp/46.101.207.85/80")
  25. (def interim-os "/net/tcp/91.250.115.15/80")
  26. (def connect (fn net-path (do
  27. (def net (open net-path))
  28. )))
  29. (def net-task (fn (do
  30. (add-task (fn (do
  31. (let packet (recv net))
  32. (if (size packet) (do
  33. (def temp-minx minx)
  34. (def temp-maxx maxx)
  35. (def minx 1000)
  36. (def maxx 1700)
  37. (let msg (bytes->str packet))
  38. (boxfill 1000 net-y 716 64 0xffff)
  39. (let ofsy (+ (blit-str msg minx net-y) rune-h))
  40. (def minx temp-minx)
  41. (def maxx temp-maxx)
  42. (def net-y (+ 0 ofsy))
  43. (if (gt net-y maxy) (def net-y miny) 0)
  44. ; only enable this when you know what you're doing
  45. ; (remote-cmd msg)
  46. ) 0)
  47. )))
  48. 1
  49. )))
  50. (def http-get (fn host path (do
  51. (boxfill 1000 0 800 1000 0xffff)
  52. (let header (concat (concat "Host: " host) (bytes->str [0d0a0d0a])))
  53. (send net (concat (concat (concat (concat "GET " path) " HTTP/1.1") (bytes->str [0d0a])) header))
  54. )))
  55. (def irc-join (fn nick channel (do
  56. (send net "PASS *")
  57. (send net [0a])
  58. (send net (concat "NICK " nick))
  59. (send net [0a])
  60. (send net (concat "USER " (concat nick " 8 * :Interim OS")))
  61. (send net [0a])
  62. (send net (concat "JOIN " channel))
  63. (send net [0a])
  64. )))