Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 1.29 KB

README.md

File metadata and controls

65 lines (46 loc) · 1.29 KB

Diablo II TCP client

Go Report Card GoDoc

D2Client is a TCP client that logs into the Diablo II server and can then write messages to the server, both in the chat and whisper specific accounts.

Message example

Install

$ go get github.com/nokka/d2client

Usage

package main

import (
	"fmt"
	"log"

	"github.com/nokka/d2client"
)

func main() {
	client := d2client.New()
	client.Open("private.server:3001")
	defer client.Close()

	// Setup channel to read on.
	ch := make(chan []byte)

	// Setup output error channel.
	errors := make(chan error)

	client.Read(ch, errors)

	err := client.Login("user", "password")
	if err != nil {
		log.Fatal(err)
	}

	client.Whisper("nokka", "Hello!")


	// Read the output from the chat onto a channel.
	for {
		select {
		// This case means we recieved data on the connection.
		case data := <-ch:
			fmt.Println(string(data))

		case err := <-errors:
			fmt.Println(err)
			break
		}
	}
}

Contributing

Please see CONTRIBUTING.md.