LastMUD/cmd/lastmudserver/main.go

62 lines
938 B
Go
Raw Permalink Normal View History

2025-06-19 16:22:55 +03:00
package main
import (
2025-06-20 16:26:39 +03:00
"context"
"flag"
2025-06-19 16:22:55 +03:00
"log"
"os"
2025-06-20 16:26:39 +03:00
"os/signal"
"sync"
"syscall"
2025-06-24 16:37:26 +03:00
"time"
2025-06-19 16:22:55 +03:00
2025-06-28 01:04:18 +03:00
"net/http"
_ "net/http/pprof"
2025-06-20 16:26:39 +03:00
2025-06-28 01:04:18 +03:00
"code.haedhutner.dev/mvv/LastMUD/internal/server"
2025-06-19 16:22:55 +03:00
)
var enableDiagnostics bool = false
2025-06-19 16:22:55 +03:00
func main() {
flag.BoolVar(&enableDiagnostics, "d", false, "Enable pprof server ( port :6060 ). Disabled by default.")
flag.Parse()
2025-06-20 16:26:39 +03:00
ctx, cancel := context.WithCancel(context.Background())
wg := sync.WaitGroup{}
defer wg.Wait()
defer cancel()
2025-06-19 16:22:55 +03:00
2025-06-20 16:26:39 +03:00
_, err := server.CreateServer(ctx, &wg, ":8000")
2025-06-19 16:22:55 +03:00
if err != nil {
log.Fatal(err)
}
if enableDiagnostics {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
}
2025-06-28 01:04:18 +03:00
2025-06-20 16:26:39 +03:00
processInput()
}
func processInput() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
2025-06-19 16:22:55 +03:00
for {
2025-06-20 16:26:39 +03:00
// If interrupt received, stop
select {
case <-sigChan:
return
default:
}
2025-06-24 16:37:26 +03:00
time.Sleep(50 * time.Millisecond)
2025-06-19 16:22:55 +03:00
}
}