forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server/session.go: Handle new server bound packets
- Loading branch information
1 parent
b98787c
commit 408171b
Showing
7 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package diagnostics | ||
|
||
// Diagnostics represents the latest diagnostics data of the client. | ||
type Diagnostics struct { | ||
// AverageFramesPerSecond is the average amount of frames per second that the client has been | ||
// running at. | ||
AverageFramesPerSecond float64 | ||
// AverageServerSimTickTime is the average time that the server spends simulating a single tick | ||
// in milliseconds. | ||
AverageServerSimTickTime float64 | ||
// AverageClientSimTickTime is the average time that the client spends simulating a single tick | ||
// in milliseconds. | ||
AverageClientSimTickTime float64 | ||
// AverageBeginFrameTime is the average time that the client spends beginning a frame in | ||
// milliseconds. | ||
AverageBeginFrameTime float64 | ||
// AverageInputTime is the average time that the client spends processing input in milliseconds. | ||
AverageInputTime float64 | ||
// AverageRenderTime is the average time that the client spends rendering in milliseconds. | ||
AverageRenderTime float64 | ||
// AverageEndFrameTime is the average time that the client spends ending a frame in milliseconds. | ||
AverageEndFrameTime float64 | ||
// AverageRemainderTimePercent is the average percentage of time that the client spends on | ||
// tasks that are not accounted for. | ||
AverageRemainderTimePercent float64 | ||
// AverageUnaccountedTimePercent is the average percentage of time that the client spends on | ||
// unaccounted tasks. | ||
AverageUnaccountedTimePercent float64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package session | ||
|
||
import ( | ||
"github.com/df-mc/atomic" | ||
"github.com/df-mc/dragonfly/server/player/diagnostics" | ||
"github.com/sandertv/gophertunnel/minecraft/protocol/packet" | ||
) | ||
|
||
// ServerBoundDiagnosticsHandler handles diagnostic updates from the client. | ||
type ServerBoundDiagnosticsHandler struct { | ||
currentID atomic.Uint32 | ||
} | ||
|
||
// Handle ... | ||
func (h *ServerBoundDiagnosticsHandler) Handle(p packet.Packet, s *Session) error { | ||
pk := p.(*packet.ServerBoundDiagnostics) | ||
s.c.UpdateDiagnostics(diagnostics.Diagnostics{ | ||
AverageFramesPerSecond: float64(pk.AverageFramesPerSecond), | ||
AverageServerSimTickTime: float64(pk.AverageServerSimTickTime), | ||
AverageClientSimTickTime: float64(pk.AverageClientSimTickTime), | ||
AverageBeginFrameTime: float64(pk.AverageBeginFrameTime), | ||
AverageInputTime: float64(pk.AverageInputTime), | ||
AverageRenderTime: float64(pk.AverageRenderTime), | ||
AverageEndFrameTime: float64(pk.AverageEndFrameTime), | ||
AverageRemainderTimePercent: float64(pk.AverageRemainderTimePercent), | ||
AverageUnaccountedTimePercent: float64(pk.AverageUnaccountedTimePercent), | ||
}) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package session | ||
|
||
import ( | ||
"fmt" | ||
"github.com/df-mc/atomic" | ||
"github.com/sandertv/gophertunnel/minecraft/protocol/packet" | ||
) | ||
|
||
// ServerBoundLoadingScreenHandler handles loading screen updates from the clients. It is used to ensure that | ||
// the server knows when the client is loading a screen, and when it is done loading it. | ||
type ServerBoundLoadingScreenHandler struct { | ||
currentID atomic.Uint32 | ||
expectedID atomic.Uint32 | ||
} | ||
|
||
// Handle ... | ||
func (h *ServerBoundLoadingScreenHandler) Handle(p packet.Packet, s *Session) error { | ||
pk := p.(*packet.ServerBoundLoadingScreen) | ||
if h.expectedID.Load() == 0 { | ||
return fmt.Errorf("unexpected loading screen packet") | ||
} | ||
v, ok := pk.LoadingScreenID.Value() | ||
if !ok { | ||
return fmt.Errorf("expected loading screen ID %d, got nothing", h.expectedID.Load()) | ||
} else if v != h.expectedID.Load() { | ||
return fmt.Errorf("expected loading screen ID %d, got %d", h.expectedID.Load(), v) | ||
} else if pk.Type == packet.LoadingScreenTypeEnd { | ||
s.changingDimension.Store(false) | ||
h.expectedID.Store(0) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters