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