mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-03 03:27:13 +08:00
Better endpoints + bugfix on friends online count
This commit is contained in:
parent
0b53bb87c3
commit
9b4e400558
@ -42,8 +42,8 @@ func Init(mux *http.ServeMux) error {
|
||||
mux.HandleFunc("POST /account/login", handleAccountLogin)
|
||||
mux.HandleFunc("POST /account/changepw", handleAccountChangePW)
|
||||
mux.HandleFunc("GET /account/logout", handleAccountLogout)
|
||||
mux.HandleFunc("POST /account/addfriend", handleAddFriend)
|
||||
mux.HandleFunc("POST /account/removefriend", handleRemoveFriend)
|
||||
mux.HandleFunc("POST /account/friends", handleAddFriend)
|
||||
mux.HandleFunc("DELETE /account/friends", handleRemoveFriend)
|
||||
mux.HandleFunc("GET /account/friendsonline", handleFriendsOnlineStat)
|
||||
|
||||
// game
|
||||
|
@ -160,19 +160,20 @@ func handleAddFriend(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func handleRemoveFriend(w http.ResponseWriter, r *http.Request) {
|
||||
formErr := r.ParseForm()
|
||||
if formErr != nil {
|
||||
httpError(w, r, fmt.Errorf("failed to parse request form: %s", formErr), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
uuid, err := uuidFromRequest(r)
|
||||
if err != nil {
|
||||
httpError(w, r, err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
success, err := db.RemoveFriend(uuid, r.Form.Get("username"))
|
||||
var friend string
|
||||
if r.URL.Query().Has("username") {
|
||||
friend = r.URL.Query().Get("username")
|
||||
} else {
|
||||
httpError(w, r, fmt.Errorf("No friend specified."), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
success, err := db.RemoveFriend(uuid, friend)
|
||||
message := "Success"
|
||||
if !success {
|
||||
message = err.Error()
|
||||
|
@ -269,6 +269,11 @@ func FetchUUIDFromUsername(username string) ([]byte, error) {
|
||||
var uuid []byte
|
||||
err := handle.QueryRow("SELECT uuid FROM accounts WHERE username = ?", username).Scan(&uuid)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
// No rows is not an error in this context, it signifies that the user does not exists
|
||||
// we reserve err for db errors.
|
||||
return uuid, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user