Guest User

Untitled

a guest
Jul 13th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.09 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "net"
  6.     "os"
  7.     "bytes"
  8. )
  9.  
  10. type RegUser struct {
  11.     pass string
  12.     nick string
  13.     user string
  14.     host string
  15.     server string
  16.     real string
  17. }
  18.  
  19. func (r *RegUser) userString() string {
  20.     return r.user + " " + r.host+ " " + r.server+ " " + r.real
  21. }
  22.  
  23. func (r *RegUser) nickString() string {
  24.     return r.nick
  25. }
  26.  
  27. type Message struct {
  28.     servername string
  29.     nickname string
  30.     username string
  31.     hostname string
  32.     command string
  33.     target string
  34.     message string
  35. }
  36.  
  37. func register(c net.Conn, r *RegUser) {
  38.     if len(r.pass) != 0 {
  39.         c.Write(bytes.NewBufferString("PASS " + r.pass + "\r\n").Bytes())
  40.     }
  41.     c.Write(bytes.NewBufferString("NICK " + r.nickString() + "\r\n").Bytes())
  42.     c.Write(bytes.NewBufferString("USER " + r.userString() + "\r\n").Bytes())
  43. }
  44.  
  45. type ServerResponse struct {
  46.     nBytes int
  47.     err os.Error
  48.     msg []byte
  49. }
  50.  
  51.  
  52. }
  53.  
  54. type ServerResponse struct {
  55.     nBytes int
  56.     err os.Error
  57.     msg []byte
  58. }
  59.  
  60. func main() {
  61.  
  62.     reg := &RegUser{
  63.         nick: "oneechan",
  64.         user: "g",
  65.         host: "0",
  66.         server: "*",
  67.         real:"~oneechan~",
  68.     }
  69.  
  70.     con, ok := net.Dial("tcp", "irc.rizon.net:6667")
  71.  
  72.  
  73.     if ok != os.EOF {
  74.         register(con, reg)
  75.         ch := make(chan *ServerResponse)
  76.  
  77.         go func() {
  78.             for {
  79.             var b [512]byte
  80.                 nBytes, ok := con.Read(b[0:512])
  81.                 ch <- &ServerResponse{nBytes:nBytes, err: ok, msg: b[0:512]}
  82.             }
  83.         }()
  84.  
  85.         for {
  86.             resp := <- ch
  87.             _, ok, msg := resp.nBytes, resp.err, resp.msg
  88.             if ok != os.EOF {
  89.                 msgs := bytes.Split(msg[0:512], bytes.NewBufferString("\r\n").Bytes())
  90.                 for _, val := range msgs {
  91.                    // match and switch on the message
  92.                    parse(val)
  93.                 }
  94.             } else {
  95.                 fmt.Printf("Error: connection terminated by server.\n")
  96.                 break
  97.             }
  98.         }
  99.     }
  100. }
  101.  
  102.  
  103. func parse(b []byte) {
  104.  
  105. }
Add Comment
Please, Sign In to add comment