Skip to content

Commit

Permalink
feat: Add hostname access
Browse files Browse the repository at this point in the history
  • Loading branch information
lycorisor committed Jan 27, 2023
1 parent cc52dd8 commit bb8c73d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type minecraft struct {
EnableHostnameRewrite bool
RewrittenHostname string `json:",omitempty"`

EnableHostnameAccess bool
HostnameAccess string `json:",omitempty"`

OnlineCount onlineCount

IgnoreFMLSuffix bool `json:",omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions service/minecraft/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func NewConnHandler(s *config.ConfigProxyService,
if err != nil {
return nil, err
}
if s.Minecraft.EnableHostnameAccess {
if !strings.Contains(hostname, s.Minecraft.HostnameAccess) {
c.(*net.TCPConn).SetLinger(0)
return nil, errors.New("hostname not allowed")
}
}
if nextState == 1 { // status
if s.Minecraft.MotdDescription == "" && s.Minecraft.MotdFavicon == "" {
// directly proxy MOTD from server
Expand Down

0 comments on commit bb8c73d

Please sign in to comment.