mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-07-04 15:32:19 +02:00
Compare commits
10 Commits
339019fd09
...
f89e20dd10
Author | SHA1 | Date | |
---|---|---|---|
|
f89e20dd10 | ||
|
dff7579360 | ||
|
d9caefed71 | ||
|
070436585e | ||
|
0b90619cdb | ||
|
536568180e | ||
|
2d166d44b7 | ||
|
de2e74ce5e | ||
|
fd57ad36fb | ||
|
715fe93440 |
@ -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,6 +69,7 @@ func Init(mux *http.ServeMux) error {
|
||||
|
||||
// admin
|
||||
mux.HandleFunc("POST /admin/account/discord-link", handleAdminDiscordLink)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -69,7 +70,10 @@ func handleAccountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
hasAdminRole, _ := account.IsUserDiscordAdmin(discordId, account.DiscordGuildId)
|
||||
var hasAdminRole bool
|
||||
if discordId != "" {
|
||||
hasAdminRole, _ = account.IsUserDiscordAdmin(discordId, account.DiscordGuildID)
|
||||
}
|
||||
|
||||
response, err := account.Info(username, discordId, googleId, uuid, hasAdminRole)
|
||||
if err != nil {
|
||||
@ -665,12 +669,6 @@ 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)
|
||||
@ -683,8 +681,7 @@ 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
|
||||
@ -695,6 +692,8 @@ func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
||||
httpError(w, r, err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s added discord id %s to username %s", userDiscordId, r.Form.Get("discordId"), r.Form.Get("username"))
|
||||
|
||||
log.Printf("%s: %s added discord id %s to username %s", r.URL.Path, 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", "dbt", "Discord Bot Token")
|
||||
discordguildid := flag.String("discordguildid", "dgid", "Discord Guild ID")
|
||||
discordbottoken := flag.String("discordbottoken", "", "Discord Bot Token")
|
||||
discordguildid := flag.String("discordguildid", "", "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