aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/bearbin
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2018-10-04 19:44:06 -0700
committerChristine Dodrill <me@christine.website>2018-10-04 19:44:06 -0700
commit1c1d089725dd9f98b7ac73276d07dbadb388b748 (patch)
treeb0e783f5e2d485050e0072faf3b303bdc66e3539 /vendor/github.com/bearbin
parente36f755db2198a96e2b87781f5f5432fcee092dd (diff)
downloadx-1c1d089725dd9f98b7ac73276d07dbadb388b748.tar.xz
x-1c1d089725dd9f98b7ac73276d07dbadb388b748.zip
add Dockerfile
Diffstat (limited to 'vendor/github.com/bearbin')
-rw-r--r--vendor/github.com/bearbin/mcgorcon/.gitignore23
-rw-r--r--vendor/github.com/bearbin/mcgorcon/.travis.yml6
-rw-r--r--vendor/github.com/bearbin/mcgorcon/LICENSE21
-rw-r--r--vendor/github.com/bearbin/mcgorcon/README.md4
-rw-r--r--vendor/github.com/bearbin/mcgorcon/mcgorcon.go141
5 files changed, 195 insertions, 0 deletions
diff --git a/vendor/github.com/bearbin/mcgorcon/.gitignore b/vendor/github.com/bearbin/mcgorcon/.gitignore
new file mode 100644
index 0000000..8365624
--- /dev/null
+++ b/vendor/github.com/bearbin/mcgorcon/.gitignore
@@ -0,0 +1,23 @@
+# Compiled Object files, Static and Dynamic libs (Shared Objects)
+*.o
+*.a
+*.so
+
+# Folders
+_obj
+_test
+
+# Architecture specific extensions/prefixes
+*.[568vq]
+[568vq].out
+
+*.cgo1.go
+*.cgo2.c
+_cgo_defun.c
+_cgo_gotypes.go
+_cgo_export.*
+
+_testmain.go
+
+*.exe
+*.test
diff --git a/vendor/github.com/bearbin/mcgorcon/.travis.yml b/vendor/github.com/bearbin/mcgorcon/.travis.yml
new file mode 100644
index 0000000..3b4e5c0
--- /dev/null
+++ b/vendor/github.com/bearbin/mcgorcon/.travis.yml
@@ -0,0 +1,6 @@
+language: go
+go:
+ - 1.1
+ - 1.2
+ - release
+ - tip \ No newline at end of file
diff --git a/vendor/github.com/bearbin/mcgorcon/LICENSE b/vendor/github.com/bearbin/mcgorcon/LICENSE
new file mode 100644
index 0000000..aa7af03
--- /dev/null
+++ b/vendor/github.com/bearbin/mcgorcon/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Alexander Harkness
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE. \ No newline at end of file
diff --git a/vendor/github.com/bearbin/mcgorcon/README.md b/vendor/github.com/bearbin/mcgorcon/README.md
new file mode 100644
index 0000000..16ad172
--- /dev/null
+++ b/vendor/github.com/bearbin/mcgorcon/README.md
@@ -0,0 +1,4 @@
+mcgorcon [![Build Status](https://travis-ci.org/bearbin/mcgorcon.svg?branch=master)](https://travis-ci.org/bearbin/mcgorcon) [![GoDoc](https://godoc.org/github.com/bearbin/mcgorcon?status.png)](https://godoc.org/github.com/bearbin/mcgorcon)
+=========
+
+A Minecraft RCON Client in Go
diff --git a/vendor/github.com/bearbin/mcgorcon/mcgorcon.go b/vendor/github.com/bearbin/mcgorcon/mcgorcon.go
new file mode 100644
index 0000000..ead96cb
--- /dev/null
+++ b/vendor/github.com/bearbin/mcgorcon/mcgorcon.go
@@ -0,0 +1,141 @@
+// Package mcgorcon is a Minecraft RCON Client written in Go.
+// It is designed to be easy to use and integrate into your own applications.
+package mcgorcon
+
+import (
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "errors"
+ "io"
+ "net"
+ "time"
+)
+
+type packetType int32
+
+// Client is a representation of an RCON client.
+type Client struct {
+ password string
+ connection net.Conn
+}
+
+// header is the header of a Minecraft RCON packet.
+type header struct {
+ Size int32
+ RequestID int32
+ PacketType packetType
+}
+
+const packetTypeCommand packetType = 2
+const packetTypeAuth packetType = 3
+const requestIDBadLogin int32 = -1
+
+// Dial up the server and establish a RCON conneciton.
+func Dial(host string, port int, pass string) (Client, error) {
+ // Combine the host and port to form the address.
+ address := host + ":" + fmt.Sprint(port)
+ // Actually establish the conneciton.
+ conn, err := net.DialTimeout("tcp", address, 10*time.Second)
+ if err != nil {
+ return Client{}, err
+ }
+ // Create the client object, since the connection has been established.
+ c := Client{password: pass, connection: conn}
+ // TODO - server validation to make sure we're talking to a real RCON server.
+ // For now, just return the client and assume it's a real server.
+ return c, nil
+}
+
+// SendCommand sends a command to the server and returns the result (often nothing).
+func (c *Client) SendCommand(command string) (string, error) {
+ // Because I'm lazy, just authenticate with every command.
+ err := c.authenticate()
+ if err != nil {
+ return "", err
+ }
+
+ // Send the packet.
+ head, payload, err := c.sendPacket(packetTypeCommand, []byte(command))
+ if err != nil {
+ return "", err
+ }
+
+ // Auth was bad, throw error.
+ if head.RequestID == requestIDBadLogin {
+ return "", errors.New("Bad auth, could not send command.")
+ }
+ return string(payload), nil
+}
+
+// authenticate authenticates the user with the server.
+func (c *Client) authenticate() error {
+ // Send the packet.
+ head, _, err := c.sendPacket(packetTypeAuth, []byte(c.password))
+ if err != nil {
+ return err
+ }
+
+ // If the credentials were bad, throw error.
+ if head.RequestID == requestIDBadLogin {
+ return errors.New("Bad auth, could not authenticate.")
+ }
+
+ return nil
+}
+
+// sendPacket sends the binary packet representation to the server and returns the response.
+func (c *Client) sendPacket(t packetType, p []byte) (header, []byte, error) {
+ // Generate the binary packet.
+ packet, err := packetise(t, p)
+ if err != nil {
+ return header{}, nil, err
+ }
+
+ // Send the packet over the wire.
+ _, err = c.connection.Write(packet)
+ if err != nil {
+ return header{}, nil, err
+ }
+ // Receive and decode the response.
+ head, payload, err := depacketise(c.connection)
+ if err != nil {
+ return header{}, nil, err
+ }
+
+ return head, payload, nil
+}
+
+// packetise encodes the packet type and payload into a binary representation to send over the wire.
+func packetise(t packetType, p []byte) ([]byte, error) {
+ // Generate a random request ID.
+ pad := [2]byte{}
+ length := int32(len(p) + 10)
+ var buf bytes.Buffer
+ binary.Write(&buf, binary.LittleEndian, length)
+ binary.Write(&buf, binary.LittleEndian, int32(0))
+ binary.Write(&buf, binary.LittleEndian, t)
+ binary.Write(&buf, binary.LittleEndian, p)
+ binary.Write(&buf, binary.LittleEndian, pad)
+ // Notchian server doesn't like big packets :(
+ if buf.Len() >= 1460 {
+ return nil, errors.New("Packet too big when packetising.")
+ }
+ // Return the bytes.
+ return buf.Bytes(), nil
+}
+
+// depacketise decodes the binary packet into a native Go struct.
+func depacketise(r io.Reader) (header, []byte, error) {
+ head := header{}
+ err := binary.Read(r, binary.LittleEndian, &head)
+ if err != nil {
+ return header{}, nil, err
+ }
+ payload := make([]byte, head.Size-8)
+ _, err = io.ReadFull(r, payload)
+ if err != nil {
+ return header{}, nil, err
+ }
+ return head, payload[:len(payload)-2], nil
+}