Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Latest commit

 

History

History
43 lines (35 loc) · 1.02 KB

README.md

File metadata and controls

43 lines (35 loc) · 1.02 KB

GoMiNET

Basic Minecraft server library written on Golang and based on Taylor Blau's project over at ttaylorr/minecraft.

Installation:

go get -t github.com/justblender/gominet

Creating your own basic server:

package main

import (
	"fmt"
	"errors"
	"reflect"
	"github.com/justblender/gominet"
	"github.com/justblender/gominet/protocol"
	"github.com/justblender/gominet/protocol/packet"
)

func main() {
	server := gominet.NewServer("127.0.0.1", 25565, handlePackets)
	server.ListenAndServe()
}

func handlePackets(conn *protocol.Connection, holder packet.Holder) error {
	switch conn.State {
	case protocol.Handshake:
		handshake, ok := holder.(packet.Handshake)
		if !ok {
			return errors.New(fmt.Sprintf("Expected handshake, received: %s", reflect.TypeOf(holder)))
		}

		conn.Protocol = uint16(handshake.ProtocolVersion)
		conn.State = protocol.State(uint8(handshake.NextState))

	default:
		// Do your own thing here now
		return errors.New("Not implemented yet")
	}

	return nil
}