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 (
"github.com/gdamore/tcell/v2"
"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/blammo"
)

@ -1,4 +1,4 @@
package server
package sim
import (
"context"
@ -12,7 +12,6 @@ import (
"github.com/gorilla/websocket"
"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/blammo"
)
@ -20,7 +19,7 @@ import (
type Server struct {
*blammo.Log
http *http.Server
world *sim.World
world *World
sync.Mutex
lastSessionID int
@ -42,7 +41,7 @@ func (s *Server) Start(host string, port int) error {
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)
addr := fmt.Sprintf("%s:%d", host, port)

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

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

Loading…
Cancel
Save