-
Notifications
You must be signed in to change notification settings - Fork 83
Fix LoginSession not disposing #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
88e88d3
Fix LoginSession not disposing
AngeloTadeucci 849f518
join heartbeat thread
AngeloTadeucci 5855251
rework
AngeloTadeucci 73499ff
oops
AngeloTadeucci f487c18
fix
AngeloTadeucci 7753055
oops2
AngeloTadeucci be9f0cb
suggestions
AngeloTadeucci 7981eff
rabbit
AngeloTadeucci d9a284d
format
AngeloTadeucci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package maple2.server.login.service; | ||
|
|
||
| import "google/protobuf/empty.proto"; | ||
| import "common.proto"; | ||
|
|
||
| service Login { | ||
| rpc Heartbeat(maple2.HeartbeatRequest) returns (maple2.HeartbeatResponse); | ||
| } |
This file contains hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
Maple2.Server.Game/PacketHandlers/ResponseHeartbeatHandler.cs
This file contains hidden or 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,40 @@ | ||
| using Maple2.Model.Metadata; | ||
| using Maple2.PacketLib.Tools; | ||
| using Maple2.Server.Core.Constants; | ||
| using Maple2.Server.Core.PacketHandlers; | ||
| using Maple2.Server.Game.Session; | ||
|
|
||
| namespace Maple2.Server.Game.PacketHandlers; | ||
|
|
||
| public class ResponseHeartbeatHandler : PacketHandler<GameSession> { | ||
| public override RecvOp OpCode => RecvOp.ResponseHeartbeat; | ||
|
|
||
| public override void Handle(GameSession session, IByteReader packet) { | ||
| int serverTick = packet.ReadInt(); | ||
| int clientTick = packet.ReadInt(); | ||
|
|
||
| int latency = Environment.TickCount - serverTick; | ||
| if (latency > Constant.MaxAllowedLatency) { | ||
| #if !DEBUG | ||
| session.Disconnect(); | ||
| #endif | ||
| return; | ||
| } | ||
|
|
||
| if (serverTick == 0 || clientTick == 0) { | ||
| return; | ||
| } | ||
|
|
||
| if (session is { ClientTick: 0, ServerTick: 0 }) { | ||
| session.ClientTick = clientTick; | ||
| session.ServerTick = serverTick; | ||
| return; | ||
| } | ||
|
|
||
| int serverDelta = serverTick - session.ServerTick; | ||
| int clientDelta = clientTick - session.ClientTick; | ||
|
|
||
| session.ClientTick = clientTick; | ||
| session.ServerTick = serverTick; | ||
| } | ||
| } |
This file contains hidden or 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,21 @@ | ||
| using Grpc.Core; | ||
| using Maple2.Server.Core.Packets; | ||
| using Maple2.Server.Game.Session; | ||
|
|
||
| namespace Maple2.Server.Game.Service; | ||
|
|
||
| public partial class ChannelService { | ||
| public override Task<HeartbeatResponse> Heartbeat(HeartbeatRequest request, ServerCallContext context) { | ||
| if (request.CharacterId == 0) { | ||
| throw new RpcException(new Status(StatusCode.NotFound, "Character ID is 0.")); | ||
| } | ||
| if (!server.GetSession(request.CharacterId, out GameSession? session)) { | ||
| throw new RpcException(new Status(StatusCode.NotFound, "Session not found.")); | ||
| } | ||
|
|
||
| session.Send(RequestPacket.Heartbeat()); | ||
| return Task.FromResult(new HeartbeatResponse { | ||
| Success = true, | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| using Maple2.PacketLib.Tools; | ||
| using Maple2.Server.Core.Constants; | ||
| using Maple2.Server.Core.PacketHandlers; | ||
| using Maple2.Server.Login.Session; | ||
|
|
||
| namespace Maple2.Server.Login.PacketHandlers; | ||
|
|
||
| public class QuitHandler : PacketHandler<LoginSession> { | ||
| public override RecvOp OpCode => RecvOp.RequestQuit; | ||
|
|
||
| public override void Handle(LoginSession session, IByteReader packet) { | ||
| session.Disconnect(); | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
Maple2.Server.Login/PacketHandlers/ResponseHeartbeatHandler.cs
This file contains hidden or 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,33 @@ | ||
| using System; | ||
| using Maple2.PacketLib.Tools; | ||
| using Maple2.Server.Core.Constants; | ||
| using Maple2.Server.Core.PacketHandlers; | ||
| using Maple2.Server.Login.Session; | ||
|
|
||
| namespace Maple2.Server.Login.PacketHandlers; | ||
|
|
||
| public class ResponseHeartbeatHandler : PacketHandler<LoginSession> { | ||
| public override RecvOp OpCode => RecvOp.ResponseHeartbeat; | ||
|
|
||
| public override void Handle(LoginSession session, IByteReader packet) { | ||
| int serverTick = packet.ReadInt(); | ||
| int clientTick = packet.ReadInt(); | ||
|
|
||
|
|
||
|
|
||
| if (serverTick == 0 || clientTick == 0) { | ||
| return; | ||
| } | ||
|
AngeloTadeucci marked this conversation as resolved.
|
||
|
|
||
| if (session is { ClientTick: 0, ServerTick: 0 }) { | ||
| session.ClientTick = clientTick; | ||
| session.ServerTick = serverTick; | ||
| return; | ||
| } | ||
|
|
||
| int serverDelta = serverTick - session.ServerTick; | ||
| int clientDelta = clientTick - session.ClientTick; | ||
| session.ClientTick = clientTick; | ||
| session.ServerTick = serverTick; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.