Coder Social home page Coder Social logo

gopenttd's Introduction

Test

gopenttd is a simple Golang library for querying OpenTTD game servers.

Command Line Usage

There's a command line utility called openttd_scrape which produces nice JSON objects for you to parse externally. See the documentation there for more information.

You can run it with something like the following:

go get github.com/ropenttd/gopenttd
go run github.com/ropenttd/gopenttd/cmd/openttd_scrape

API

This library is under heavy development, and is not in the slightest bit stable. Things will change and will drastically break your code, I guarantee it.

There are three packages:

  • util, which has numerous helper functions and constants for things like colours
  • query, which utilizes OpenTTD's UDP-based polling game query protocol to glean basic information about a server without a password
  • admin, which uses OpenTTD's TCP based protocol with significantly more capability, but requires that you have the admin password for the server you are connecting to (You probably want this one if you're building a bot)

These are likely to be merged into one package in the medium term.

Please see the godoc for further information on all of these packages.

Client Protocol

Here's a brief example:

package main

import (
	"github.com/ropenttd/gopenttd/pkg/query"
	"encoding/json"
	"fmt"
)


func main() {
	result, err := query.ScanServer("s1.ttdredd.it", 3979)
	if err != nil {
        panic(err)
    }
	var b []byte
    b, err = json.MarshalIndent(result, "", "    ")
    if err != nil {
        panic(err)
    }
    fmt.Println(string(b))
}

Please see the godoc for further information.

Admin Protocol

The Admin Protocol is a connection based protocol that you communicate to using a combination of a Write command and a channel reader for responses.

The API here is pretty much a clone of discordgo, so if you've ever used that, you'll feel right at home here.

package main

import "github.com/ropenttd/gopenttd/pkg/admin"

func main() {
	sess, err := admin.New("s1.ttdredd.it", 3977, "password")
    if err != nil {
    	panic(err)
    }
    err = sess.Open()
    if err != nil {
    	panic(err)
    }
}

Please see the godoc for help using the rest of the Admin API.

Credit / Licensing

gopenttd is licensed under the MIT license.

gopenttd is heavily based on discordgo, which is licensed under the BSD license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.