mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-07-04 15:32:19 +02:00
Compare commits
9 Commits
f609ec5ee8
...
dff7579360
Author | SHA1 | Date | |
---|---|---|---|
|
dff7579360 | ||
|
d9caefed71 | ||
|
070436585e | ||
|
0b90619cdb | ||
|
536568180e | ||
|
2d166d44b7 | ||
|
de2e74ce5e | ||
|
fd57ad36fb | ||
|
715fe93440 |
@ -32,7 +32,7 @@ var (
|
|||||||
DiscordCallbackURL string
|
DiscordCallbackURL string
|
||||||
|
|
||||||
DiscordSession *discordgo.Session
|
DiscordSession *discordgo.Session
|
||||||
DiscordGuildId string
|
DiscordGuildID string
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleDiscordCallback(w http.ResponseWriter, r *http.Request) (string, error) {
|
func HandleDiscordCallback(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||||
@ -111,15 +111,15 @@ func RetrieveDiscordId(code string) (string, error) {
|
|||||||
return user.Id, nil
|
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
|
// fetch all roles from discord
|
||||||
roles, err := DiscordSession.GuildRoles(discordGuildId)
|
roles, err := DiscordSession.GuildRoles(discordGuildID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch all roles from user
|
// fetch all roles from user
|
||||||
userRoles, err := DiscordSession.GuildMember(discordGuildId, discordId)
|
userRoles, err := DiscordSession.GuildMember(discordGuildID, discordId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@ func Init(mux *http.ServeMux) error {
|
|||||||
|
|
||||||
// admin
|
// admin
|
||||||
mux.HandleFunc("POST /admin/account/discord-link", handleAdminDiscordLink)
|
mux.HandleFunc("POST /admin/account/discord-link", handleAdminDiscordLink)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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)
|
response, err := account.Info(username, discordId, googleId, uuid, hasAdminRole)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -665,12 +669,6 @@ func handleProviderLogout(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleAdminDiscordLink(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)
|
uuid, err := uuidFromRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, r, err, http.StatusUnauthorized)
|
httpError(w, r, err, http.StatusUnauthorized)
|
||||||
@ -683,8 +681,7 @@ func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hasRole, err := account.IsUserDiscordAdmin(userDiscordId, account.DiscordGuildId)
|
hasRole, err := account.IsUserDiscordAdmin(userDiscordId, account.DiscordGuildID)
|
||||||
|
|
||||||
if !hasRole || err != nil {
|
if !hasRole || err != nil {
|
||||||
httpError(w, r, fmt.Errorf("user does not have the required role"), http.StatusForbidden)
|
httpError(w, r, fmt.Errorf("user does not have the required role"), http.StatusForbidden)
|
||||||
return
|
return
|
||||||
@ -695,6 +692,8 @@ func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
|||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
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)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,8 @@ func main() {
|
|||||||
|
|
||||||
gameurl := flag.String("gameurl", "https://pokerogue.net", "URL for game server")
|
gameurl := flag.String("gameurl", "https://pokerogue.net", "URL for game server")
|
||||||
|
|
||||||
discordbottoken := flag.String("discordbottoken", "dbt", "Discord Bot Token")
|
discordbottoken := flag.String("discordbottoken", "", "Discord Bot Token")
|
||||||
discordguildid := flag.String("discordguildid", "dgid", "Discord Guild ID")
|
discordguildid := flag.String("discordguildid", "", "Discord Guild ID")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ func main() {
|
|||||||
account.GoogleClientSecret = *googlesecretid
|
account.GoogleClientSecret = *googlesecretid
|
||||||
account.GoogleCallbackURL = *callbackurl + "/auth/google/callback"
|
account.GoogleCallbackURL = *callbackurl + "/auth/google/callback"
|
||||||
account.DiscordSession, _ = discordgo.New("Bot " + *discordbottoken)
|
account.DiscordSession, _ = discordgo.New("Bot " + *discordbottoken)
|
||||||
account.DiscordGuildId = *discordguildid
|
account.DiscordGuildID = *discordguildid
|
||||||
// register gob types
|
// register gob types
|
||||||
gob.Register([]interface{}{})
|
gob.Register([]interface{}{})
|
||||||
gob.Register(map[string]interface{}{})
|
gob.Register(map[string]interface{}{})
|
||||||
|
Loading…
Reference in New Issue
Block a user