Chore: solved some todos
This commit is contained in:
@ -183,17 +183,6 @@ func cacheSetSession(key string, session *models.Session) error {
|
||||
return err
|
||||
}
|
||||
memcache.Set(key, sesb)
|
||||
// TODO: to config
|
||||
memcache.Expire(key, 60*60)
|
||||
memcache.Expire(key, cfg.SessionLifetime)
|
||||
return nil
|
||||
}
|
||||
|
||||
// unused
|
||||
// func updateRoomInSession(ctx context.Context, roomID string) (context.Context, error) {
|
||||
// s, ok := ctx.Value(models.CtxSessionKey).(*models.Session)
|
||||
// if !ok {
|
||||
// return context.TODO(), errors.New("failed to extract session from ctx")
|
||||
// }
|
||||
// s.CurrentRoom = roomID
|
||||
// return context.WithValue(ctx, "session", s), nil
|
||||
// }
|
||||
|
@ -167,8 +167,6 @@ func HandleAddBot(w http.ResponseWriter, r *http.Request) {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
// TODO: what if bot exists already?
|
||||
// control number and names of bots
|
||||
botname := fmt.Sprintf("bot_%d", len(llmapi.SignalChanMap)+1) // what if many rooms?
|
||||
bot, err := llmapi.NewBot(role, team, botname, fi.Room.ID, cfg)
|
||||
if err != nil {
|
||||
|
@ -135,11 +135,14 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
// TODO: check if enough players; also button should be hidden if already running
|
||||
// check if enough players
|
||||
if err := fi.Room.CanStart(); err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
fi.Room.IsRunning = true
|
||||
fi.Room.IsOver = false
|
||||
fi.Room.TeamTurn = "blue"
|
||||
// fi.Room.LoadTestCards()
|
||||
loadCards(fi.Room)
|
||||
fi.Room.UpdateCounter()
|
||||
fi.Room.TeamWon = ""
|
||||
|
@ -26,7 +26,6 @@ func init() {
|
||||
memcache = cache.MemCache
|
||||
cfg = config.LoadConfigOrDefault("")
|
||||
Notifier = broker.Notifier
|
||||
// go Notifier.Listen()
|
||||
}
|
||||
|
||||
func HandlePing(w http.ResponseWriter, r *http.Request) {
|
||||
@ -84,6 +83,7 @@ func HandleExit(w http.ResponseWriter, r *http.Request) {
|
||||
if len(exitedRoom.PlayerList) == 0 || creatorLeft {
|
||||
removeRoom(exitedRoom.ID)
|
||||
// TODO: notify users if creator left
|
||||
// and throw them away
|
||||
notify(models.NotifyRoomListUpdate, "")
|
||||
}
|
||||
if err := saveState(fi.State.Username, fi.State); err != nil {
|
||||
|
@ -26,9 +26,7 @@ func LogRequests(next http.Handler) http.Handler {
|
||||
|
||||
func GetSession(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: move
|
||||
cookieName := "session_token"
|
||||
sessionCookie, err := r.Cookie(cookieName)
|
||||
sessionCookie, err := r.Cookie(models.AuthCookie)
|
||||
if err != nil {
|
||||
msg := "auth failed; failed to get session token from cookies"
|
||||
log.Debug(msg, "error", err)
|
||||
@ -54,7 +52,7 @@ func GetSession(next http.Handler) http.Handler {
|
||||
sessionToken := cookieValue[sha256.Size:]
|
||||
//verify signature
|
||||
mac := hmac.New(sha256.New, []byte(cfg.CookieSecret))
|
||||
mac.Write([]byte(cookieName))
|
||||
mac.Write([]byte(models.AuthCookie))
|
||||
mac.Write([]byte(sessionToken))
|
||||
expectedSignature := mac.Sum(nil)
|
||||
if !hmac.Equal([]byte(signature), expectedSignature) {
|
||||
|
Reference in New Issue
Block a user