This commit is contained in:
parent
761cc5f2e8
commit
50a1fb41d1
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2022, Captain ALM
|
||||
Copyright (c) 2023, Captain ALM
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
@ -1,8 +1,6 @@
|
||||
package pageHandler
|
||||
|
||||
import (
|
||||
"golang.captainalm.com/mc-webserver/conf"
|
||||
"golang.captainalm.com/mc-webserver/pageHandler/utils"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
@ -11,6 +9,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.captainalm.com/mc-webserver/conf"
|
||||
"golang.captainalm.com/mc-webserver/pageHandler/utils"
|
||||
)
|
||||
|
||||
const indexName = "index.go"
|
||||
@ -286,6 +287,9 @@ func (ph *PageHandler) GetRegisteredPages() []string {
|
||||
}
|
||||
|
||||
func (ph *PageHandler) GetCachedPages() []string {
|
||||
if ph.pageContentsCacheRWMutex == nil {
|
||||
return make([]string, 0)
|
||||
}
|
||||
ph.pageContentsCacheRWMutex.RLock()
|
||||
defer ph.pageContentsCacheRWMutex.RUnlock()
|
||||
pages := make([]string, len(ph.PageContentsCache))
|
||||
@ -298,6 +302,9 @@ func (ph *PageHandler) GetCachedPages() []string {
|
||||
}
|
||||
|
||||
func (ph *PageHandler) GetNumberOfCachedPages() int {
|
||||
if ph.pageContentsCacheRWMutex == nil {
|
||||
return 0
|
||||
}
|
||||
ph.pageContentsCacheRWMutex.RLock()
|
||||
defer ph.pageContentsCacheRWMutex.RUnlock()
|
||||
return len(ph.PageContentsCache)
|
||||
|
@ -2,12 +2,14 @@ package index
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DataYaml struct {
|
||||
PageTitle string `yaml:"pageTitle"`
|
||||
ServerDescription template.HTML `yaml:"serverDescription"`
|
||||
Footer string `yaml:"footer"`
|
||||
MCAddress string `yaml:"mcAddress"`
|
||||
MCPort uint16 `yaml:"mcPort"`
|
||||
MCType string `yaml:"mcType"`
|
||||
@ -27,3 +29,7 @@ type DataYaml struct {
|
||||
AllowDisplayModded bool `yaml:"allowDisplayModded"`
|
||||
AllowModListing bool `yaml:"allowModListing"`
|
||||
}
|
||||
|
||||
func (dy DataYaml) GetCleanMCType() string {
|
||||
return strings.Title(dy.MCType)
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"golang.captainalm.com/mc-webserver/utils/io"
|
||||
"gopkg.in/yaml.v3"
|
||||
"html/template"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -10,6 +8,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.captainalm.com/mc-webserver/utils/io"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const templateName = "index.go.html"
|
||||
|
@ -18,10 +18,19 @@ type MC struct {
|
||||
MOTD string
|
||||
ActualHost *string
|
||||
ActualPort *uint16
|
||||
Favicon *template.HTML
|
||||
Favicon *string
|
||||
Edition *string
|
||||
ModCount int64
|
||||
Mods []string
|
||||
SecureProfilesEnforced *bool
|
||||
PreviewChatEnforced *bool
|
||||
}
|
||||
|
||||
func (m MC) GetFaviconSRC() template.HTMLAttr {
|
||||
toReturn := "src=\""
|
||||
if m.Favicon != nil {
|
||||
toReturn += *m.Favicon
|
||||
}
|
||||
toReturn += "\""
|
||||
return template.HTMLAttr(toReturn)
|
||||
}
|
||||
|
@ -2,12 +2,13 @@ package index
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/mcstatus-io/mcutil"
|
||||
"github.com/mcstatus-io/mcutil/options"
|
||||
"github.com/mcstatus-io/mcutil/response"
|
||||
"html/template"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mcstatus-io/mcutil"
|
||||
"github.com/mcstatus-io/mcutil/options"
|
||||
"github.com/mcstatus-io/mcutil/response"
|
||||
)
|
||||
|
||||
type Marshal struct {
|
||||
@ -24,7 +25,7 @@ func (m Marshal) NewMC() (MC, error) {
|
||||
switch strings.ToLower(m.Data.MCType) {
|
||||
case "java":
|
||||
r, err := mcutil.Status(m.Data.MCAddress, m.Data.MCPort, options.JavaStatus{
|
||||
EnableSRV: m.ExtendedShown && m.Data.AllowDisplayActualAddress,
|
||||
EnableSRV: m.Data.AllowDisplayActualAddress,
|
||||
Timeout: m.Data.MCTimeout,
|
||||
ProtocolVersion: m.Data.MCProtocolVersion,
|
||||
})
|
||||
@ -32,6 +33,7 @@ func (m Marshal) NewMC() (MC, error) {
|
||||
return MC{}, err
|
||||
}
|
||||
r2, err := mcutil.StatusRaw(m.Data.MCAddress, m.Data.MCPort, options.JavaStatus{
|
||||
EnableSRV: m.Data.AllowDisplayActualAddress,
|
||||
Timeout: m.Data.MCTimeout,
|
||||
ProtocolVersion: m.Data.MCProtocolVersion,
|
||||
})
|
||||
@ -51,7 +53,7 @@ func (m Marshal) NewMC() (MC, error) {
|
||||
MOTD: r.MOTD.Clean,
|
||||
ActualHost: CollectSRVHost(r.SRVResult),
|
||||
ActualPort: CollectSRVPort(r.SRVResult),
|
||||
Favicon: CollectFavicon(r.Favicon),
|
||||
Favicon: r.Favicon,
|
||||
Edition: CollectModEdition(r.ModInfo),
|
||||
ModCount: CollectModCount(r.ModInfo),
|
||||
Mods: CollectMods(r.ModInfo),
|
||||
@ -60,7 +62,7 @@ func (m Marshal) NewMC() (MC, error) {
|
||||
}, nil
|
||||
case "legacy", "legacyjava", "javalegacy", "legacy java", "java legacy", "legacy_java", "java_legacy":
|
||||
r, err := mcutil.StatusLegacy(m.Data.MCAddress, m.Data.MCPort, options.JavaStatusLegacy{
|
||||
EnableSRV: m.ExtendedShown && m.Data.AllowDisplayActualAddress,
|
||||
EnableSRV: m.Data.AllowDisplayActualAddress,
|
||||
Timeout: m.Data.MCTimeout,
|
||||
ProtocolVersion: m.Data.MCProtocolVersion,
|
||||
})
|
||||
@ -89,7 +91,7 @@ func (m Marshal) NewMC() (MC, error) {
|
||||
}, nil
|
||||
case "bedrock":
|
||||
r, err := mcutil.StatusBedrock(m.Data.MCAddress, m.Data.MCPort, options.BedrockStatus{
|
||||
EnableSRV: m.ExtendedShown && m.Data.AllowDisplayActualAddress,
|
||||
EnableSRV: m.Data.AllowDisplayActualAddress,
|
||||
Timeout: m.Data.MCTimeout,
|
||||
ClientGUID: m.Data.MCClientGUID,
|
||||
})
|
||||
@ -146,14 +148,6 @@ func CollectSRVPort(srv *response.SRVRecord) *uint16 {
|
||||
return &srv.Port
|
||||
}
|
||||
|
||||
func CollectFavicon(favicon *string) *template.HTML {
|
||||
if favicon == nil {
|
||||
return nil
|
||||
}
|
||||
toReturn := template.HTML(*favicon)
|
||||
return &toReturn
|
||||
}
|
||||
|
||||
func CollectModEdition(mod *response.ModInfo) *string {
|
||||
if mod == nil {
|
||||
return nil
|
||||
@ -204,8 +198,8 @@ func (m Marshal) CollectIPv4Port(port *uint16) uint16 {
|
||||
return *port
|
||||
}
|
||||
|
||||
func (m *Marshal) ToggleQuery(option string) string {
|
||||
toReturn := ""
|
||||
func (m *Marshal) ToggleQuery(option string) template.HTML {
|
||||
toReturn := "?"
|
||||
if (!m.Dark && option == "dark") || (m.Dark && option != "dark") {
|
||||
toReturn += "dark&"
|
||||
}
|
||||
@ -218,5 +212,5 @@ func (m *Marshal) ToggleQuery(option string) string {
|
||||
if (!m.PlayersShown && option == "players") || (m.PlayersShown && option != "players") {
|
||||
toReturn += "players"
|
||||
}
|
||||
return strings.TrimRight(toReturn, "&")
|
||||
return template.HTML(strings.TrimRight(toReturn, "&"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user