You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.4 KiB
Go
106 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
"os"
|
|
|
|
"github.com/EngoEngine/ecs"
|
|
"github.com/ThreeDotsLabs/watermill/message"
|
|
"github.com/ThreeDotsLabs/watermill/message/router/middleware"
|
|
"github.com/ThreeDotsLabs/watermill/message/router/plugin"
|
|
"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
|
|
|
|
"code.ndumas.com/ndumas/gomud"
|
|
"code.ndumas.com/ndumas/gomud/engine"
|
|
"code.ndumas.com/ndumas/gomud/logger"
|
|
"code.ndumas.com/ndumas/gomud/telnet"
|
|
)
|
|
|
|
var (
|
|
port int
|
|
verbose int
|
|
versionFlag bool
|
|
)
|
|
|
|
func main() {
|
|
|
|
flag.IntVar(&verbose, "verbose", 0, "-5:Trace, -4:Debug, 0:Info, 4:Warn, 8:Error")
|
|
flag.IntVar(&port, "port", 5555, "MUD server port")
|
|
flag.BoolVar(&versionFlag, "version", false, "print build version")
|
|
flag.Parse()
|
|
|
|
if versionFlag {
|
|
fmt.Printf("%s@%s\n", gomud.VERSION, gomud.BUILD)
|
|
return
|
|
}
|
|
|
|
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
|
if err != nil {
|
|
log.Fatalf("error binding to port %d\n: %s", port, err)
|
|
}
|
|
defer l.Close()
|
|
|
|
traceFile, err := os.OpenFile("trace.log", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
|
if err != nil {
|
|
log.Fatalf("couldn't open trace log: %s\n", err)
|
|
}
|
|
|
|
traceLogConfig := logger.LogConfig{
|
|
Writer: traceFile,
|
|
Format: "json",
|
|
Level: -5,
|
|
}
|
|
|
|
stdoutLogConfig := logger.LogConfig{
|
|
Writer: os.Stdout,
|
|
Format: "text",
|
|
Level: verbose,
|
|
}
|
|
|
|
wrappedSlogger := logger.NewWrappedSlogger(
|
|
traceLogConfig,
|
|
stdoutLogConfig,
|
|
)
|
|
|
|
router, err := message.NewRouter(message.RouterConfig{}, wrappedSlogger)
|
|
|
|
router.AddPlugin(plugin.SignalsHandler)
|
|
|
|
router.AddMiddleware(
|
|
middleware.CorrelationID,
|
|
middleware.Recoverer,
|
|
)
|
|
|
|
pubSub := gochannel.NewGoChannel(gochannel.Config{}, wrappedSlogger)
|
|
|
|
ctx := context.Background()
|
|
ts := telnet.NewTELNETServer(ctx, l, pubSub, wrappedSlogger)
|
|
tp := telnet.NewTELNETParser(ctx, pubSub, wrappedSlogger)
|
|
|
|
wrappedSlogger.Info("booting up, welcome back formers", nil)
|
|
go tp.Handle()
|
|
|
|
// create the world
|
|
world := ecs.World{}
|
|
// create systems
|
|
world.AddSystem(&engine.TELNETRenderSystem{})
|
|
// load saved state
|
|
|
|
for {
|
|
conn, err := ts.Accept()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
// now that i have a connection, i need to pass it to
|
|
// the telnet server for parsing incoming telnet and mud
|
|
// inputs. I also need to pass it to the RenderSystem so
|
|
// game output can be emitted to the appropriate user
|
|
|
|
go ts.Handle(wrappedSlogger)(conn)
|
|
}
|
|
}
|