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

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

Loading…
Cancel
Save