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