Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _datafiles/**/plugin-data/*
**/config-overrides.yaml
**/.roundcount
vendor/
modules/all-modules.go
server.crt
server.key
__debug*
63 changes: 39 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,45 @@ console:
docker-%:
@$(MAKE) console DOCKER_CMD="make $(patsubst docker-%,%,$@)"

#
#
# For a complete list of GOOS/GOARCH combinations:
# Run: go tool dist list
#
#

.PHONY: build_rpi_zero2w
build_rpi_zero2w: generate ### Build a binary for a raspberry pi zero 2w
env GOOS=linux GOARCH=arm64 go build -o $(BIN)-rpi
make ungenerate

.PHONY: build_win64
build_win64: generate ### Build a binary for 64bit windows
env GOOS=windows GOARCH=amd64 go build -o $(BIN)-win64.exe
make ungenerate

.PHONY: build_linux64
build_linux64: generate ### Build a binary for linux
env GOOS=linux GOARCH=amd64 go build -o $(BIN)-linux64
make ungenerate

.PHONY: build
build: validate build_local ### Validate the code and build the binary.

.PHONY: build_local
build_local: generate
CGO_ENABLED=0 go build -trimpath -a -o $(BIN)
make ungenerate

.PHONY: ungenerate
ungenerate: ### Reverts to a clean version of modules/all-modules.go
@cp cmd/generate/_all-modules.go modules/all-modules.go

.PHONY: generate
generate: ### Generates include directives for modules
@go generate


# Clean both development and production containers
.PHONY: clean
clean:
Expand Down Expand Up @@ -96,30 +135,6 @@ server.crt server.key:
-days 365 -subj "/CN=localhost"


#
#
# For a complete list of GOOS/GOARCH combinations:
# Run: go tool dist list
#
#
.PHONY: build_rpi
build_rpi: ### Build a binary for a raspberry pi
env GOOS=linux GOARCH=arm GOARM=5 go build -o $(BIN)-rpi

.PHONY: build_win64
build_win64: ### Build a binary for 64bit windows
env GOOS=windows GOARCH=amd64 go build -o $(BIN)-win64.exe

.PHONY: build_linux64
build_linux64: ### Build a binary for linux
env GOOS=linux GOARCH=amd64 go build -o $(BIN)-linux64

.PHONY: build
build: validate build_local ### Validate the code and build the binary.

.PHONY: build_local
build_local:
CGO_ENABLED=0 go build -trimpath -a -o $(BIN)

# Go targets

Expand Down
16 changes: 16 additions & 0 deletions cmd/generate/_all-modules.go

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

62 changes: 62 additions & 0 deletions cmd/generate/module-imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// ///////////////////////////////////////////////////////////////
// NOTE: Do not run this file directly.
//
// This is intended to be run by a "go generate" command
// off of the project root.
// It automatically builds a list of includes that get written
// to modules/all-modules.go
//
// ///////////////////////////////////////////////////////////////
package main

import (
"bytes"
"fmt"
"log"
"os"
"path/filepath"
"strings"
)

func main() {
root := "modules"
pkgs := []string{}

entries, err := os.ReadDir(root)
if err != nil {
log.Fatal(err)
}

for _, d := range entries {
if !d.IsDir() {
continue
}

dir := filepath.Join(root, d.Name())

// scan that one sub‐dir for a .go file
files, _ := os.ReadDir(dir)
for _, f := range files {
if !f.IsDir() && strings.HasSuffix(f.Name(), ".go") {
pkgPath := filepath.ToSlash(dir) // e.g. "modules/foo"
pkgs = append(pkgs, pkgPath)
break
}
}
}
var buf bytes.Buffer
buf.WriteString("// Code generated by go:generate; DO NOT EDIT.\n\n")
buf.WriteString("// Generated with command: go generate\n")
buf.WriteString("// (from the project root)\n\n")

buf.WriteString("package modules\n\nimport (\n")
for _, p := range pkgs {
buf.WriteString(fmt.Sprintf("\t_ \"github.com/GoMudEngine/GoMud/%s\"\n", p))
}
buf.WriteString(")\n")

if err := os.WriteFile("modules/all-modules.go", buf.Bytes(), 0644); err != nil {
fmt.Fprintf(os.Stderr, "error writing all-modules.go: %v\n", err)
os.Exit(1)
}
}
6 changes: 5 additions & 1 deletion internal/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,11 @@ func Load(dataFilesPath string) {
}
}

mudlog.Info("plugins", "loadedCount", pluginCt)
if pluginCt == 0 {
mudlog.Warn("plugins", "loadedCount", pluginCt, "error", "Did you forget to run \"go generate\" before compiling the server? This error can be ignored.")
} else {
mudlog.Info("plugins", "loadedCount", pluginCt)
}
}

func Save() {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate go run cmd/generate/module-imports.go
package main

import (
Expand Down
10 changes: 6 additions & 4 deletions modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Extract any modules into this folder.

* Modules should be named uniquely, in a manner that identifies their purpose.
* Modules should be inside of a subfolder of `modules`, named after their package.
* Example: `modules/birds/` would contain the `birds` module/package.

* Module folders should container a `datafiles` folder that contains any datafiles needed.
* Files within `datafiles` will be treated as though located within the actual `_datafiles`
Expand All @@ -24,10 +26,10 @@ Extract any modules into this folder.

## Basic user command function

* time.go
* time/*
* time/time.go
* time/files/*

## User command with maintained state and save/loading of data

* leaderbaord.go
* leaderboard/*
* leaderboards/leaderboards.go
* leaderboards/files/*
16 changes: 16 additions & 0 deletions modules/all-modules.go

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

8 changes: 4 additions & 4 deletions modules/auctions.go → modules/auctions/auctions.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package auctions

import (
"embed"
Expand All @@ -24,8 +24,8 @@ var (
// It embeds the relative path into the var below it.
//////////////////////////////////////////////////////////////////////

//go:embed auctions/*
auctions_Files embed.FS // All vars must be a unique name since the module package/namespace is shared between modules.
//go:embed files/*
files embed.FS
)

// ////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -53,7 +53,7 @@ func init() {
//
// Add the embedded filesystem
//
if err := a.plug.AttachFileSystem(auctions_Files); err != nil {
if err := a.plug.AttachFileSystem(files); err != nil {
panic(err)
}
//
Expand Down
2 changes: 1 addition & 1 deletion modules/gmcp.Char.go → modules/gmcp/gmcp.Char.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package gmcp

import (
"math"
Expand Down
2 changes: 1 addition & 1 deletion modules/gmcp.Comm.go → modules/gmcp/gmcp.Comm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package gmcp

import (
"github.com/GoMudEngine/GoMud/internal/events"
Expand Down
2 changes: 1 addition & 1 deletion modules/gmcp.Game.go → modules/gmcp/gmcp.Game.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package gmcp

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion modules/gmcp.Party.go → modules/gmcp/gmcp.Party.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package gmcp

import (
"math"
Expand Down
2 changes: 1 addition & 1 deletion modules/gmcp.Room.go → modules/gmcp/gmcp.Room.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package gmcp

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion modules/gmcp.go → modules/gmcp/gmcp.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package gmcp

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package leaderboards

import (
"embed"
Expand All @@ -24,8 +24,8 @@ var (
// It embeds the relative path into the var below it.
//////////////////////////////////////////////////////////////////////

//go:embed leaderboards/*
leaderboard_Files embed.FS // All vars must be a unique name since the module package/namespace is shared between modules.
//go:embed files/*
files embed.FS
)

// ////////////////////////////////////////////////////////////////////
Expand All @@ -36,7 +36,6 @@ var (
// program starts running.
// ////////////////////////////////////////////////////////////////////
func init() {

//
// We can use all functions only, but this demonstrates
// how to use a struct
Expand All @@ -48,7 +47,7 @@ func init() {
//
// Add the embedded filesystem
//
if err := t.plug.AttachFileSystem(leaderboard_Files); err != nil {
if err := t.plug.AttachFileSystem(files); err != nil {
panic(err)
}
//
Expand Down
8 changes: 4 additions & 4 deletions modules/time.go → modules/time/time.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modules
package time

import (
"embed"
Expand All @@ -18,8 +18,8 @@ var (
// It embeds the relative path into the var below it.
//////////////////////////////////////////////////////////////////////

//go:embed time/*
time_Files embed.FS // All vars must be a unique name since the module package/namespace is shared between modules.
//go:embed files/*
files embed.FS
)

// ////////////////////////////////////////////////////////////////////
Expand All @@ -39,7 +39,7 @@ func init() {
//
// Add the embedded filesystem
//
if err := plug.AttachFileSystem(time_Files); err != nil {
if err := plug.AttachFileSystem(files); err != nil {
panic(err)
}
//
Expand Down
2 changes: 1 addition & 1 deletion provisioning/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ RUN mkdir -p /app/log
RUN touch /app/log/logfile.log

COPY . .
RUN go generate
RUN go build -o ${BIN}


FROM alpine:latest AS runner
ARG BIN=go-mud-server
ENV BIN=${BIN}
Expand Down
2 changes: 1 addition & 1 deletion provisioning/copy-rpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RPI_BIN="go-mud-server-rpi"

# Build the raspberry pi binary... building on the rpi is problematic.
echo "Building bin for Raspberry Pi Zero"
make build_rpi
make build_rpi_zero2w

# Kill the process before overwriting the binary
echo "Killing process on RaspPi: ${RPI_HOST}"
Expand Down
Loading