mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-07-04 23:42:19 +02:00
Compare commits
No commits in common. "dff7579360330e9ea291a1b4fa434c779d2a6928" and "f609ec5ee8663fef717d69dfa3efb19cce26039d" have entirely different histories.
dff7579360
...
f609ec5ee8
@ -32,7 +32,7 @@ var (
|
||||
DiscordCallbackURL string
|
||||
|
||||
DiscordSession *discordgo.Session
|
||||
DiscordGuildID string
|
||||
DiscordGuildId string
|
||||
)
|
||||
|
||||
func HandleDiscordCallback(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||
@ -111,15 +111,15 @@ func RetrieveDiscordId(code string) (string, error) {
|
||||
return user.Id, nil
|
||||
}
|
||||
|
||||
func IsUserDiscordAdmin(discordId string, discordGuildID string) (bool, error) {
|
||||
func IsUserDiscordAdmin(discordId string, discordGuildId string) (bool, error) {
|
||||
// fetch all roles from discord
|
||||
roles, err := DiscordSession.GuildRoles(discordGuildID)
|
||||
roles, err := DiscordSession.GuildRoles(discordGuildId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// fetch all roles from user
|
||||
userRoles, err := DiscordSession.GuildMember(discordGuildID, discordId)
|
||||
userRoles, err := DiscordSession.GuildMember(discordGuildId, discordId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -69,7 +69,6 @@ func Init(mux *http.ServeMux) error {
|
||||
|
||||
// admin
|
||||
mux.HandleFunc("POST /admin/account/discord-link", handleAdminDiscordLink)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -70,10 +69,7 @@ func handleAccountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
var hasAdminRole bool
|
||||
if discordId != "" {
|
||||
hasAdminRole, _ = account.IsUserDiscordAdmin(discordId, account.DiscordGuildID)
|
||||
}
|
||||
hasAdminRole, _ := account.IsUserDiscordAdmin(discordId, account.DiscordGuildId)
|
||||
|
||||
response, err := account.Info(username, discordId, googleId, uuid, hasAdminRole)
|
||||
if err != nil {
|
||||
@ -669,6 +665,12 @@ func handleProviderLogout(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
httpError(w, r, fmt.Errorf("failed to parse request form: %s", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
uuid, err := uuidFromRequest(r)
|
||||
if err != nil {
|
||||
httpError(w, r, err, http.StatusUnauthorized)
|
||||
@ -681,7 +683,8 @@ func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
hasRole, err := account.IsUserDiscordAdmin(userDiscordId, account.DiscordGuildID)
|
||||
hasRole, err := account.IsUserDiscordAdmin(userDiscordId, account.DiscordGuildId)
|
||||
|
||||
if !hasRole || err != nil {
|
||||
httpError(w, r, fmt.Errorf("user does not have the required role"), http.StatusForbidden)
|
||||
return
|
||||
@ -692,8 +695,6 @@ func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
||||
httpError(w, r, err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("%s: %s added discord id %s to username %s", r.URL.Path, userDiscordId, r.Form.Get("discordId"), r.Form.Get("username"))
|
||||
|
||||
fmt.Printf("%s added discord id %s to username %s", userDiscordId, r.Form.Get("discordId"), r.Form.Get("username"))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ func main() {
|
||||
|
||||
gameurl := flag.String("gameurl", "https://pokerogue.net", "URL for game server")
|
||||
|
||||
discordbottoken := flag.String("discordbottoken", "", "Discord Bot Token")
|
||||
discordguildid := flag.String("discordguildid", "", "Discord Guild ID")
|
||||
discordbottoken := flag.String("discordbottoken", "dbt", "Discord Bot Token")
|
||||
discordguildid := flag.String("discordguildid", "dgid", "Discord Guild ID")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
@ -71,7 +71,7 @@ func main() {
|
||||
account.GoogleClientSecret = *googlesecretid
|
||||
account.GoogleCallbackURL = *callbackurl + "/auth/google/callback"
|
||||
account.DiscordSession, _ = discordgo.New("Bot " + *discordbottoken)
|
||||
account.DiscordGuildID = *discordguildid
|
||||
account.DiscordGuildId = *discordguildid
|
||||
// register gob types
|
||||
gob.Register([]interface{}{})
|
||||
gob.Register(map[string]interface{}{})
|
||||
|
Loading…
Reference in New Issue
Block a user