knowyt/server/src/game/removeQuote.go

34 lines
546 B
Go
Raw Normal View History

2021-10-15 21:07:41 +00:00
package game
import (
"fmt"
2021-10-16 17:36:39 +00:00
"os"
"sirlab.de/go/knyt/quote"
2021-10-15 21:07:41 +00:00
)
2021-10-16 17:36:39 +00:00
func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {
if qu, err := gm.getQuoteById(quoteId); err != nil {
2021-10-16 17:36:39 +00:00
return err
} else {
if qu.GetSourceId() != usrId {
2021-10-16 17:36:39 +00:00
return fmt.Errorf("usrId does not match quote source id")
}
gm.removeQuoteFromList(qu)
2021-10-15 21:07:41 +00:00
}
2021-10-16 17:36:39 +00:00
err := os.Remove(fileName)
if err != nil {
return err
2021-10-15 21:07:41 +00:00
}
2021-10-16 17:36:39 +00:00
return nil
2021-10-15 21:07:41 +00:00
}
func (gm *Game) removeQuoteFromList(qu *quote.Quote) {
gm.mu.Lock()
defer gm.mu.Unlock()
delete(gm.quotes, qu.GetId())
}