|
|
@ -68,16 +68,30 @@ func (w *world) run(hz int) {
|
|
|
|
w.register(c)
|
|
|
|
w.register(c)
|
|
|
|
|
|
|
|
|
|
|
|
case req := <-w.inbox:
|
|
|
|
case req := <-w.inbox:
|
|
|
|
|
|
|
|
w.handleRequest(req)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case <-ticker.C:
|
|
|
|
|
|
|
|
w.tick(time.Since(lastTick))
|
|
|
|
|
|
|
|
lastTick = time.Now()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case <-w.done:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (w *world) handleRequest(req Request) {
|
|
|
|
w.Info("read from inbox: %v", req)
|
|
|
|
w.Info("read from inbox: %v", req)
|
|
|
|
|
|
|
|
|
|
|
|
if req.From == "" {
|
|
|
|
if req.From == "" {
|
|
|
|
w.Error("request has no from: %v", req)
|
|
|
|
w.Error("request has no from: %v", req)
|
|
|
|
break
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
p, ok := w.players[req.From]
|
|
|
|
p, ok := w.players[req.From]
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
w.Error("received non login request of type %T from unknown player %q", req.Wants, req.From)
|
|
|
|
w.Error("received non login request of type %T from unknown player %q", req.Wants, req.From)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if p.pending == nil {
|
|
|
|
if p.pending == nil {
|
|
|
@ -85,15 +99,6 @@ func (w *world) run(hz int) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
p.outbox <- wire.ErrorResponse(req.Seq, "you already have a request for this frame")
|
|
|
|
p.outbox <- wire.ErrorResponse(req.Seq, "you already have a request for this frame")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case <-ticker.C:
|
|
|
|
|
|
|
|
w.tick(time.Since(lastTick))
|
|
|
|
|
|
|
|
lastTick = time.Now()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case <-w.done:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (w *world) register(c connect) {
|
|
|
|
func (w *world) register(c connect) {
|
|
|
|