2021-10-15 21:07:41 +00:00
|
|
|
package game
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-10-16 17:36:39 +00:00
|
|
|
"os"
|
2021-10-16 19:35:31 +00:00
|
|
|
"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 {
|
2021-10-16 19:35:31 +00:00
|
|
|
if qu, err := gm.getQuoteById(quoteId); err != nil {
|
2021-10-16 17:36:39 +00:00
|
|
|
return err
|
|
|
|
} else {
|
2021-10-16 19:35:31 +00:00
|
|
|
if qu.GetSourceId() != usrId {
|
2021-10-16 17:36:39 +00:00
|
|
|
return fmt.Errorf("usrId does not match quote source id")
|
|
|
|
}
|
2021-10-16 19:35:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2021-10-16 19:35:31 +00:00
|
|
|
|
|
|
|
func (gm *Game) removeQuoteFromList(qu *quote.Quote) {
|
|
|
|
gm.mu.Lock()
|
|
|
|
defer gm.mu.Unlock()
|
|
|
|
|
|
|
|
delete(gm.quotes, qu.GetId())
|
|
|
|
}
|