merge server and sim packages as sim package

master
Jordan Orelli 4 years ago
parent 9c90e4bece
commit df3597a330

@ -3,7 +3,7 @@ package app
import ( import (
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/jordanorelli/astro-domu/internal/math" "github.com/jordanorelli/astro-domu/internal/math"
"github.com/jordanorelli/astro-domu/internal/server/sim" "github.com/jordanorelli/astro-domu/internal/sim"
"github.com/jordanorelli/astro-domu/internal/wire" "github.com/jordanorelli/astro-domu/internal/wire"
"github.com/jordanorelli/blammo" "github.com/jordanorelli/blammo"
) )

@ -1,4 +1,4 @@
package server package sim
import ( import (
"context" "context"
@ -12,7 +12,6 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/jordanorelli/astro-domu/internal/errors" "github.com/jordanorelli/astro-domu/internal/errors"
"github.com/jordanorelli/astro-domu/internal/server/sim"
"github.com/jordanorelli/astro-domu/internal/wire" "github.com/jordanorelli/astro-domu/internal/wire"
"github.com/jordanorelli/blammo" "github.com/jordanorelli/blammo"
) )
@ -20,7 +19,7 @@ import (
type Server struct { type Server struct {
*blammo.Log *blammo.Log
http *http.Server http *http.Server
world *sim.World world *World
sync.Mutex sync.Mutex
lastSessionID int lastSessionID int
@ -42,7 +41,7 @@ func (s *Server) Start(host string, port int) error {
s.Log = blammo.NewLog("astro", options...).Child("server") s.Log = blammo.NewLog("astro", options...).Child("server")
} }
s.world = sim.NewWorld(s.Log.Child("world")) s.world = NewWorld(s.Log.Child("world"))
go s.world.Run(3) go s.world.Run(3)
addr := fmt.Sprintf("%s:%d", host, port) addr := fmt.Sprintf("%s:%d", host, port)

@ -1,4 +1,4 @@
package server package sim
import ( import (
"encoding/json" "encoding/json"
@ -6,7 +6,6 @@ import (
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/jordanorelli/astro-domu/internal/server/sim"
"github.com/jordanorelli/astro-domu/internal/wire" "github.com/jordanorelli/astro-domu/internal/wire"
"github.com/jordanorelli/blammo" "github.com/jordanorelli/blammo"
) )
@ -47,7 +46,7 @@ func (sn *session) run() {
} }
// read reads for messages on the underlying websocket. // read reads for messages on the underlying websocket.
func (sn *session) read(c chan sim.Request) { func (sn *session) read(c chan Request) {
for { for {
t, b, err := sn.conn.ReadMessage() t, b, err := sn.conn.ReadMessage()
if err != nil { if err != nil {
@ -93,16 +92,16 @@ func (sn *session) read(c chan sim.Request) {
switch v := req.Body.(type) { switch v := req.Body.(type) {
case *wire.Login: case *wire.Login:
sn.Name = v.Name sn.Name = v.Name
c <- sim.Request{ c <- Request{
From: sn.Name, From: sn.Name,
Seq: req.Seq, Seq: req.Seq,
Wants: &sim.SpawnPlayer{ Wants: &SpawnPlayer{
Name: sn.Name, Name: sn.Name,
Outbox: sn.outbox, Outbox: sn.outbox,
}, },
} }
case sim.Effect: case Effect:
c <- sim.Request{ c <- Request{
From: sn.Name, From: sn.Name,
Seq: req.Seq, Seq: req.Seq,
Wants: v, Wants: v,

@ -7,7 +7,7 @@ import (
"github.com/jordanorelli/astro-domu/internal/app" "github.com/jordanorelli/astro-domu/internal/app"
"github.com/jordanorelli/astro-domu/internal/exit" "github.com/jordanorelli/astro-domu/internal/exit"
"github.com/jordanorelli/astro-domu/internal/server" "github.com/jordanorelli/astro-domu/internal/sim"
"github.com/jordanorelli/blammo" "github.com/jordanorelli/blammo"
) )
@ -37,7 +37,7 @@ func main() {
case "client": case "client":
runClient(os.Args[2]) runClient(os.Args[2])
case "server": case "server":
s := server.Server{} s := sim.Server{}
if err := s.Start("127.0.0.1", 12805); err != nil { if err := s.Start("127.0.0.1", 12805); err != nil {
exit.WithMessage(1, "unable to start server: %v", err) exit.WithMessage(1, "unable to start server: %v", err)
} }

Loading…
Cancel
Save