session no longer has a reference to the world sim

master
Jordan Orelli 4 years ago
parent 3f657da4cd
commit 6192d01bb8

@ -88,7 +88,6 @@ func (s *Server) createSession(conn *websocket.Conn) *session {
conn: conn, conn: conn,
outbox: make(chan wire.Response), outbox: make(chan wire.Response),
done: make(chan bool, 1), done: make(chan bool, 1),
world: s.world,
} }
if s.sessions == nil { if s.sessions == nil {
s.sessions = make(map[int]*session) s.sessions = make(map[int]*session)
@ -124,7 +123,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sn := s.createSession(conn) sn := s.createSession(conn)
go sn.run() go sn.run()
sn.read() sn.read(s.world.Inbox)
s.dropSession(sn) s.dropSession(sn)
sn.Info("closing connection") sn.Info("closing connection")

@ -15,7 +15,6 @@ type session struct {
*blammo.Log *blammo.Log
Name string Name string
id int id int
world *sim.World
entityID int entityID int
start time.Time start time.Time
conn *websocket.Conn conn *websocket.Conn
@ -48,7 +47,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() { func (sn *session) read(c chan sim.Request) {
for { for {
t, b, err := sn.conn.ReadMessage() t, b, err := sn.conn.ReadMessage()
if err != nil { if err != nil {
@ -94,7 +93,7 @@ func (sn *session) read() {
switch v := req.Body.(type) { switch v := req.Body.(type) {
case *wire.Login: case *wire.Login:
sn.Name = v.Name sn.Name = v.Name
sn.world.Inbox <- sim.Request{ c <- sim.Request{
From: sn.Name, From: sn.Name,
Seq: req.Seq, Seq: req.Seq,
Wants: &sim.SpawnPlayer{ Wants: &sim.SpawnPlayer{
@ -103,7 +102,7 @@ func (sn *session) read() {
}, },
} }
case sim.Effect: case sim.Effect:
sn.world.Inbox <- sim.Request{ c <- sim.Request{
From: sn.Name, From: sn.Name,
Seq: req.Seq, Seq: req.Seq,
Wants: v, Wants: v,

Loading…
Cancel
Save