Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "net"
- "os"
- "bytes"
- )
- type RegUser struct {
- pass string
- nick string
- user string
- host string
- server string
- real string
- }
- func (r *RegUser) userString() string {
- return r.user + " " + r.host+ " " + r.server+ " " + r.real
- }
- func (r *RegUser) nickString() string {
- return r.nick
- }
- type Message struct {
- servername string
- nickname string
- username string
- hostname string
- command string
- target string
- message string
- }
- func register(c net.Conn, r *RegUser) {
- if len(r.pass) != 0 {
- c.Write(bytes.NewBufferString("PASS " + r.pass + "\r\n").Bytes())
- }
- c.Write(bytes.NewBufferString("NICK " + r.nickString() + "\r\n").Bytes())
- c.Write(bytes.NewBufferString("USER " + r.userString() + "\r\n").Bytes())
- }
- type ServerResponse struct {
- nBytes int
- err os.Error
- msg []byte
- }
- }
- type ServerResponse struct {
- nBytes int
- err os.Error
- msg []byte
- }
- func main() {
- reg := &RegUser{
- nick: "oneechan",
- user: "g",
- host: "0",
- server: "*",
- real:"~oneechan~",
- }
- con, ok := net.Dial("tcp", "irc.rizon.net:6667")
- if ok != os.EOF {
- register(con, reg)
- ch := make(chan *ServerResponse)
- go func() {
- for {
- var b [512]byte
- nBytes, ok := con.Read(b[0:512])
- ch <- &ServerResponse{nBytes:nBytes, err: ok, msg: b[0:512]}
- }
- }()
- for {
- resp := <- ch
- _, ok, msg := resp.nBytes, resp.err, resp.msg
- if ok != os.EOF {
- msgs := bytes.Split(msg[0:512], bytes.NewBufferString("\r\n").Bytes())
- for _, val := range msgs {
- // match and switch on the message
- parse(val)
- }
- } else {
- fmt.Printf("Error: connection terminated by server.\n")
- break
- }
- }
- }
- }
- func parse(b []byte) {
- }
Add Comment
Please, Sign In to add comment