-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathChannelHandler.cs
More file actions
53 lines (46 loc) · 2.04 KB
/
ChannelHandler.cs
File metadata and controls
53 lines (46 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Net;
using Grpc.Core;
using Maple2.Model.Enum;
using Maple2.Model.Game;
using Maple2.PacketLib.Tools;
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.PacketHandlers;
using Maple2.Server.Core.Packets;
using Maple2.Server.Game.Packets;
using Maple2.Server.Game.Session;
using Maple2.Server.World.Service;
using WorldClient = Maple2.Server.World.Service.World.WorldClient;
namespace Maple2.Server.Game.PacketHandlers;
public class ChannelHandler : PacketHandler<GameSession> {
public override RecvOp OpCode => RecvOp.Channel;
#region Autofac Autowired
// ReSharper disable MemberCanBePrivate.Global
public required WorldClient World { private get; init; }
// ReSharper restore All
#endregion
public override void Handle(GameSession session, IByteReader packet) {
short channel = packet.ReadShort();
session.MigrationSave();
try {
var request = new MigrateOutRequest {
AccountId = session.AccountId,
CharacterId = session.CharacterId,
MachineId = session.MachineId.ToString(),
Server = Server.World.Service.Server.Game,
Channel = channel,
};
MigrateOutResponse response = World.MigrateOut(request);
var endpoint = new IPEndPoint(IPAddress.Parse(response.IpAddress), response.Port);
session.Send(MigrationPacket.GameToGame(endpoint, response.Token, session.Field?.MapId ?? 0));
session.State = SessionState.ChangeChannel;
} catch (RpcException ex) {
Logger.Error(ex, "Failed to migrate to channel {Channel}", channel);
session.Send(NoticePacket.MessageBox(new InterfaceText("Channel is unavailable, close the channel list and try again.")));
// Update the client with the latest channel list.
ChannelsResponse response = World.Channels(new ChannelsRequest());
session.Send(ChannelPacket.Load(response.Channels));
} finally {
session.Disconnect();
}
}
}