func handle(processor pages.Processor, w http.ResponseWriter, r *http.Request) { cj := sutil.NewCookieJar(w, r, config) context := pages.NewContext(dbc, cj, mailer, w, r) context.Authenticate() processor.Process(context, w, r) }
func mainSocketHandler(w http.ResponseWriter, r *http.Request) { var account db.Account authenticated := false if dbc != nil { cj := util.NewCookieJar(w, r, config) account, _, authenticated = cj.Authenticate(dbc) cj.SaveSession() fmt.Println("Authentication: ", authenticated, "(ID: ", account.Id, ") User: "******"Couldn't upgrade websocket:", err) } conn := NewConn(wsConn) var baseName string if authenticated { baseName = account.Username } else { baseName = "guest" } name := baseName nameNumber := 1 var client *Client for { var isNew bool client, isNew = globalGame.clientWithId(name) if isNew { break } name = fmt.Sprintf("%s-%d", baseName, nameNumber) nameNumber++ } // FIXME: We could give the client their entity's // actual initial state as part of the handshake, // but it's currently impossible since the entity // isn't yet created at the handshake stage. info := makePlayerEntityCreatedMessage(game.EntityId(name), &game.BioticState{}) conn.Send(&proto.MsgHandshakeReply{ ServerTime: float64(time.Now().UnixNano()) / 1e6, ClientId: name, PlayerEntityInfo: *info, }) client.Run(conn) }