Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/src/main/main
golang-mud
/dist
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM alpine:latest

# docker build expects binaries to have already been built
ENV DIST_NAME golang-mud
ENV APP_HOME /opt/mud
WORKDIR $APP_HOME

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

COPY ./dist $APP_HOME/
COPY ./docker/* $APP_HOME/
COPY ./resources $APP_HOME/resources
RUN chmod +x $APP_HOME/$DIST_NAME && chmod +x $APP_HOME/*.sh

ENTRYPOINT ["/opt/mud/entrypoint.sh"]
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
VERSION_FILE=VERSION

SRC_PKGS=$(shell go list ./... | grep -v vendor)

ifeq ($(strip $(NO_REV)),)
REV=$(shell git rev-parse --short HEAD)
endif

ifeq ($(BUILD_VERSION),)
VERSION=$(shell cat $(VERSION_FILE))
BUILD_VERSION_NO_REV=$(VERSION)
ifeq ($(strip $(REV)),)
BUILD_VERSION=$(VERSION)
else
BUILD_VERSION=$(VERSION)-$(REV)
endif
endif

IMAGE_REPO=golang-mud
ifeq ($(IMAGE_NAME),)
IMAGE_NAME=$(IMAGE_REPO):$(BUILD_VERSION_NO_REV)
endif

.PHONY: clean image test

all: compile

clean:
go clean ./src/...
rm -rf dist

compile:
CGO_ENABLED=0 go build -ldflags "-X main.appVersion=$(BUILD_VERSION)" .

dist:
CGO_ENABLED=0 go build -ldflags "-X main.appVersion=$(BUILD_VERSION)" -o dist/golang-mud

image:
docker build -t $(IMAGE_NAME) -t $(IMAGE_REPO):latest .

test:
set -e;
for pkg in $(SRC_PKGS); \
do \
go test -v $$pkg; \
done
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
Just tinkering with Go, using a MUD as an exercise to learn the language. If you are a Go-pro and see something I can
improve, please let me know!

## Installation

```sh
go get github.com/Saeven/golang-mud
```

## Usage

```sh
golang-mud run
```

### Commands

Expand All @@ -12,4 +23,4 @@ command and its executable closure!

### Rooms

Rooms are currently only implemented as basic structs. A web-based SPA room editor sure would be cool.
Rooms are currently only implemented as basic structs. A web-based SPA room editor sure would be cool.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
5 changes: 5 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

ls .
ls -l $APP_HOME
$APP_HOME/$DIST_NAME "$@"
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/Saeven/golang-mud

go 1.12

require github.com/spf13/cobra v0.0.5
33 changes: 33 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
95 changes: 95 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"context"
"fmt"
"math/rand"
"net"
"os"
"time"

mudcore "github.com/Saeven/golang-mud/src/saevenx"
"github.com/spf13/cobra"
)

var (
rootContext context.Context
appVersion string
appName string
)

const (
defaultVersion = "0.0.0-dev"
defaultAppName = "golang-mud"
)

func main() {
if appVersion == "" {
appVersion = defaultVersion
}

rand.Seed(time.Now().Unix())

rootContext = context.Background()
rootCmd.Execute()
}

func init() {
rootCmd.AddCommand(runCmd)
rootCmd.AddCommand(versionCmd)
}

var rootCmd = &cobra.Command{
Use: appName,
Short: "",
Long: "",
}

var runCmd = &cobra.Command{
Use: "run",
Short: "run the mud server",
Long: "run the mud server",
Run: func(cmd *cobra.Command, args []string) {
service := ":7777"

tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
checkError(err)

listener, err := net.ListenTCP("tcp", tcpAddr)
checkError(err)
defer listener.Close()

mudcore.GetServer().Start()
listenForConnections(listener)
},
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "show version information",
Long: "show version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s v%s\n", appName, appVersion)
},
}

func listenForConnections(listener *net.TCPListener) {
for {
conn, err := listener.Accept()
if err != nil {
continue
}
newDescriptor(conn)
}
}

func checkError(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
os.Exit(1)
}
}

func newDescriptor(connection net.Conn) {
mudcore.ServerInstance.AddConnection(connection)
}
43 changes: 0 additions & 43 deletions src/main/main.go

This file was deleted.

13 changes: 13 additions & 0 deletions vendor/github.com/inconshreveable/mousetrap/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions vendor/github.com/inconshreveable/mousetrap/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/github.com/inconshreveable/mousetrap/trap_others.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading