Skip to content

Commit

Permalink
fix: status response provider
Browse files Browse the repository at this point in the history
  • Loading branch information
haveachin committed Dec 27, 2022
1 parent 6edf3ae commit db34132
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
6 changes: 3 additions & 3 deletions configs/proxies/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ defaults:
# Infrared caches the server ping response so that status pings don't spam the minecraft server.
# This is the Time To Live of the cache.
#
statusCacheTTL: 10s
#statusCacheTTL: 10s

java:
# Channel Capacity (ChanCap) is the capacity of a single channel
Expand Down Expand Up @@ -145,11 +145,11 @@ java:
rateLimiter:
# The request limit it the amount of requests a single IP can make in a specific window of time.
#
requestLimit: 1
requestLimit: 10

# This is the window of time in that a single IP can make a specific amount of requests.
#
windowLength: 50ms
windowLength: 500ms

# See Java above
#
Expand Down
14 changes: 2 additions & 12 deletions internal/pkg/java/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (

"github.com/haveachin/infrared/internal/app/infrared"
"github.com/haveachin/infrared/internal/pkg/config"
"github.com/haveachin/infrared/internal/pkg/java/protocol"
"github.com/haveachin/infrared/internal/pkg/java/protocol/handshaking"
"github.com/haveachin/infrared/internal/pkg/java/protocol/status"
)

type ServerConfig struct {
Expand Down Expand Up @@ -328,15 +325,8 @@ func newServer(id string, cfg ServerConfig) (infrared.Server, error) {
}

srv.statusResponseJSONProvider = &statusResponseJSONProvider{
server: srv,
handshakePk: handshaking.ServerBoundHandshake{
ProtocolVersion: 0,
ServerAddress: protocol.String(host),
ServerPort: protocol.UnsignedShort(port),
NextState: handshaking.StateStatusServerBoundHandshake,
}.Marshal(),
statusRequestPk: status.ServerBoundRequest{}.Marshal(),
cacheTTL: cfg.StatusCacheTTL,
server: srv,
cacheTTL: cfg.StatusCacheTTL,
}

return &InfraredServer{
Expand Down
6 changes: 2 additions & 4 deletions internal/pkg/java/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import (
)

type statusResponseJSONProvider struct {
server Server
handshakePk protocol.Packet
statusRequestPk protocol.Packet
server Server

mu sync.Mutex
cacheTTL time.Duration
Expand All @@ -43,7 +41,7 @@ func (s *statusResponseJSONProvider) requestNewStatusResponseJSON(pc *ProcessedC
return status.ResponseJSON{}, err
}

if err := rc.WritePackets(s.handshakePk, s.statusRequestPk); err != nil {
if err := rc.WritePackets(pc.readPks...); err != nil {
return status.ResponseJSON{}, err
}

Expand Down

0 comments on commit db34132

Please sign in to comment.