BattleClient.cs and PresenceService.cs cleanup.

This commit is contained in:
Lucca Faria Ferri 2023-01-26 20:35:48 -08:00
parent 2aecf414ef
commit 7299279393
2 changed files with 130 additions and 117 deletions

View File

@ -1,44 +1,22 @@
//#define LOG_KEEP_ALIVE using bgs.protocol;
//Blizzless Project 2022
using bgs.protocol;
//Blizzless Project 2022
using DiIiS_NA.Core.Helpers.Hash; using DiIiS_NA.Core.Helpers.Hash;
//Blizzless Project 2022
using DiIiS_NA.Core.Logging; using DiIiS_NA.Core.Logging;
//Blizzless Project 2022
using DiIiS_NA.GameServer.ClientSystem; using DiIiS_NA.GameServer.ClientSystem;
//Blizzless Project 2022
using DiIiS_NA.LoginServer.AccountsSystem; using DiIiS_NA.LoginServer.AccountsSystem;
//Blizzless Project 2022
using DiIiS_NA.LoginServer.Base; using DiIiS_NA.LoginServer.Base;
//Blizzless Project 2022
using DiIiS_NA.LoginServer.ChannelSystem; using DiIiS_NA.LoginServer.ChannelSystem;
//Blizzless Project 2022
using DiIiS_NA.LoginServer.Objects; using DiIiS_NA.LoginServer.Objects;
//Blizzless Project 2022
using DiIiS_NA.LoginServer.ServicesSystem; using DiIiS_NA.LoginServer.ServicesSystem;
//Blizzless Project 2022
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
//Blizzless Project 2022
using DotNetty.Transport.Channels.Sockets; using DotNetty.Transport.Channels.Sockets;
//Blizzless Project 2022
using Google.ProtocolBuffers; using Google.ProtocolBuffers;
//Blizzless Project 2022
using Google.ProtocolBuffers.DescriptorProtos; using Google.ProtocolBuffers.DescriptorProtos;
//Blizzless Project 2022
using Google.ProtocolBuffers.Descriptors; using Google.ProtocolBuffers.Descriptors;
//Blizzless Project 2022
using System; using System;
//Blizzless Project 2022
using System.Collections.Concurrent; using System.Collections.Concurrent;
//Blizzless Project 2022
using System.Collections.Generic; using System.Collections.Generic;
//Blizzless Project 2022
using System.Linq; using System.Linq;
//Blizzless Project 2022
using System.Net.Security; using System.Net.Security;
//Blizzless Project 2022
using System.Threading.Tasks; using System.Threading.Tasks;
using DiIiS_NA.GameServer.MessageSystem.Message.Definitions.Text; using DiIiS_NA.GameServer.MessageSystem.Message.Definitions.Text;
@ -46,7 +24,7 @@ namespace DiIiS_NA.LoginServer.Battle
{ {
public class BattleClient : SimpleChannelInboundHandler<BNetPacket>, IRpcChannel public class BattleClient : SimpleChannelInboundHandler<BNetPacket>, IRpcChannel
{ {
private static readonly Logger Logger = LogManager.CreateLogger("F-Client"); private static readonly Logger Logger = LogManager.CreateLogger(nameof(BattleClient));
public Dictionary<uint, uint> Services { get; private set; } public Dictionary<uint, uint> Services { get; private set; }
public ISocketChannel SocketConnection { get; private set; } public ISocketChannel SocketConnection { get; private set; }
@ -55,17 +33,17 @@ namespace DiIiS_NA.LoginServer.Battle
public ClientLocale ClientLanguage = ClientLocale.enUS; public ClientLocale ClientLanguage = ClientLocale.enUS;
public IRpcController ListenerController; public IRpcController ListenerController;
private uint _tokenCounter = 0; private uint _tokenCounter = 0;
public static bgs.protocol.NO_RESPONSE NO_RESPONSE = bgs.protocol.NO_RESPONSE.CreateBuilder().Build(); public static NO_RESPONSE NO_RESPONSE = NO_RESPONSE.CreateBuilder().Build();
private readonly Dictionary<int, RPCCallBack> _pendingResponses = new Dictionary<int, RPCCallBack>(); private readonly Dictionary<int, RPCCallBack> _pendingResponses = new(); // TODO: Check usage and remove if not needed
public bgs.protocol.v2.Attribute AttributeOfServer { get; set; } public bgs.protocol.v2.Attribute AttributeOfServer { get; set; }
public Account Account { get; set; } public Account Account { get; set; }
public const byte ServiceReply = 0xFE; public const byte ServiceReply = 0xFE;
public SslStream ssl = null; public SslStream Ssl = null;
private static int REQUEST_SERVICE_ID = 0; private static int REQUEST_SERVICE_ID = 0;
private static int RESPONSE_SERVICE_ID = 254; private static int RESPONSE_SERVICE_ID = 254;
//public object clientLock = new object(); //public object clientLock = new object();
public object _serviceLock = new object(); public readonly object _serviceLock = new object();
public object messageLock = new object(); public object messageLock = new object();
private ulong _listenerId; // last targeted rpc object. private ulong _listenerId; // last targeted rpc object.
public bool MOTDSent { get; private set; } public bool MOTDSent { get; private set; }
@ -94,7 +72,7 @@ namespace DiIiS_NA.LoginServer.Battle
get get
{ {
if (_currentChannel == null) if (_currentChannel == null)
_currentChannel = this.Channels.Values.Where(c => !c.IsChatChannel).FirstOrDefault(); _currentChannel = Channels.Values.FirstOrDefault(c => !c.IsChatChannel);
return _currentChannel; return _currentChannel;
} }
set set
@ -102,17 +80,17 @@ namespace DiIiS_NA.LoginServer.Battle
if (value == null) if (value == null)
{ {
if (_currentChannel != null) if (_currentChannel != null)
this.Channels.Remove(this._currentChannel.DynamicId); Channels.Remove(_currentChannel.DynamicId);
//Logger.Trace("Client removed from CurrentChannel: {0}, setting new CurrentChannel to {1}", this._currentChannel, this.Channels.FirstOrDefault().Value); //Logger.Trace("Client removed from CurrentChannel: {0}, setting new CurrentChannel to {1}", this._currentChannel, this.Channels.FirstOrDefault().Value);
this._currentChannel = Channels.FirstOrDefault().Value; _currentChannel = Channels.FirstOrDefault().Value;
} }
else if (!Channels.ContainsKey(value.DynamicId)) else if (!Channels.ContainsKey(value.DynamicId))
{ {
this.Channels.Add(value.DynamicId, value); Channels.Add(value.DynamicId, value);
this._currentChannel = value; _currentChannel = value;
} }
else else
this._currentChannel = value; _currentChannel = value;
} }
} }
@ -122,14 +100,14 @@ namespace DiIiS_NA.LoginServer.Battle
if (text.Trim() == string.Empty) return; if (text.Trim() == string.Empty) return;
var notification = bgs.protocol.notification.v1.Notification.CreateBuilder() var notification = bgs.protocol.notification.v1.Notification.CreateBuilder()
.SetTargetId(this.Account.GameAccount.BnetEntityId) .SetTargetId(Account.GameAccount.BnetEntityId)
.SetType("WHISPER") .SetType("WHISPER")
.SetSenderId(this.Account.GameAccount.BnetEntityId) .SetSenderId(Account.GameAccount.BnetEntityId)
.SetSenderAccountId(this.Account.BnetEntityId) .SetSenderAccountId(Account.BnetEntityId)
.AddAttribute(bgs.protocol.Attribute.CreateBuilder().SetName("whisper") .AddAttribute(bgs.protocol.Attribute.CreateBuilder().SetName("whisper")
.SetValue(Variant.CreateBuilder().SetStringValue(text).Build()).Build()).Build(); .SetValue(Variant.CreateBuilder().SetStringValue(text).Build()).Build()).Build();
this.MakeRPC((lid) => bgs.protocol.notification.v1.NotificationListener.CreateStub(this). MakeRPC((lid) => bgs.protocol.notification.v1.NotificationListener.CreateStub(this).
OnNotificationReceived(new HandlerController() OnNotificationReceived(new HandlerController()
{ {
ListenerId = lid ListenerId = lid
@ -146,7 +124,7 @@ namespace DiIiS_NA.LoginServer.Battle
public void LeaveAllChannels() public void LeaveAllChannels()
{ {
List<Channel> _channels = this.Channels.Values.ToList(); List<Channel> _channels = Channels.Values.ToList();
foreach (var channel in _channels) foreach (var channel in _channels)
{ {
try try
@ -155,7 +133,7 @@ namespace DiIiS_NA.LoginServer.Battle
} }
catch { } catch { }
} }
this.Channels.Clear(); Channels.Clear();
} }
#endregion #endregion
@ -165,7 +143,7 @@ namespace DiIiS_NA.LoginServer.Battle
SocketConnection = socketChannel; SocketConnection = socketChannel;
Services = new Dictionary<uint, uint>(); Services = new Dictionary<uint, uint>();
MappedObjects = new ConcurrentDictionary<ulong, ulong>(); MappedObjects = new ConcurrentDictionary<ulong, ulong>();
this.MOTDSent = false; MOTDSent = false;
if (SocketConnection.Active) if (SocketConnection.Active)
Logger.Trace("Client - {0} - successfully encrypted the connection", socketChannel.RemoteAddress); Logger.Trace("Client - {0} - successfully encrypted the connection", socketChannel.RemoteAddress);
} }
@ -289,12 +267,15 @@ namespace DiIiS_NA.LoginServer.Battle
ListenerId = 0 ListenerId = 0
}; };
#if DEBUG #if DEBUG
#if !LOG_KEEP_ALIVE if (method.Name == "KeepAlive")
if (method.Name != "KeepAlive")
#endif
{ {
Logger.Warn("Call: {0}, Service hash: {1}, Method: {2}, ID: {3}", Logger.Debug(
service.GetType().Name, header.ServiceHash, method.Name, header.MethodId); $"Call: {service.GetType().Name}, Service hash: {header.ServiceHash}, Method: {method.Name}, ID: {header.MethodId}");
}
else
{
Logger.Trace(
$"Call: {service.GetType().Name}, Service hash: {header.ServiceHash}, Method: {method.Name}, ID: {header.MethodId}");
} }
#endif #endif
@ -412,9 +393,9 @@ namespace DiIiS_NA.LoginServer.Battle
//{ //{
try try
{ {
if (this.SocketConnection == null || !this.SocketConnection.Active) return; if (SocketConnection == null || !SocketConnection.Active) return;
var listenerId = this.GetRemoteObjectId(targetObject.DynamicId); var listenerId = GetRemoteObjectId(targetObject.DynamicId);
Logger.Debug("[RPC: {0}] Method: {1} Target: {2} [localId: {3}, remoteId: {4}].", this.GetType().Name, rpc.Method.Name, Logger.Debug("[RPC: {0}] Method: {1} Target: {2} [localId: {3}, remoteId: {4}].", GetType().Name, rpc.Method.Name,
targetObject.ToString(), targetObject.DynamicId, listenerId); targetObject.ToString(), targetObject.DynamicId, listenerId);
rpc(listenerId); rpc(listenerId);
@ -431,8 +412,8 @@ namespace DiIiS_NA.LoginServer.Battle
//{ //{
try try
{ {
if (this.SocketConnection == null || !this.SocketConnection.Active) return; if (SocketConnection == null || !SocketConnection.Active) return;
Logger.Debug("[RPC: {0}] Method: {1} Target: N/A", this.GetType().Name, rpc.Method.Name); Logger.Debug("[RPC: {0}] Method: {1} Target: N/A", GetType().Name, rpc.Method.Name);
rpc(0); rpc(0);
} }
catch { } catch { }
@ -450,7 +431,7 @@ namespace DiIiS_NA.LoginServer.Battle
str = method.Service.Options.UnknownFields[90000].LengthDelimitedList[0].ToStringUtf8().Remove(0, 2); str = method.Service.Options.UnknownFields[90000].LengthDelimitedList[0].ToStringUtf8().Remove(0, 2);
var serviceHash = StringHashHelper.HashIdentity(str); var serviceHash = StringHashHelper.HashIdentity(str);
if (!this.Services.ContainsKey(serviceHash)) if (!Services.ContainsKey(serviceHash))
{ {
Logger.Warn("Service not found for client {0} [0x{1}].", serviceName, serviceHash.ToString("X8")); Logger.Warn("Service not found for client {0} [0x{1}].", serviceName, serviceHash.ToString("X8"));
// in english: "Service not found for client {0} [0x{1}]." // in english: "Service not found for client {0} [0x{1}]."
@ -465,8 +446,8 @@ namespace DiIiS_NA.LoginServer.Battle
_listenerId = (controller as HandlerController).ListenerId; _listenerId = (controller as HandlerController).ListenerId;
} }
var serviceId = this.Services[serviceHash]; var serviceId = Services[serviceHash];
var token = this._tokenCounter++; var token = _tokenCounter++;
sendRequest(Connect, serviceHash, GetMethodId(method), token, request, (uint)_listenerId, status); sendRequest(Connect, serviceHash, GetMethodId(method), token, request, (uint)_listenerId, status);
} }
public static void sendRequest(IChannelHandlerContext ctx, uint serviceHash, uint methodId, uint token, IMessage request, uint listenerId, uint status) public static void sendRequest(IChannelHandlerContext ctx, uint serviceHash, uint methodId, uint token, IMessage request, uint listenerId, uint status)
@ -489,7 +470,7 @@ namespace DiIiS_NA.LoginServer.Battle
{ {
try try
{ {
this.MappedObjects[localObjectId] = remoteObjectId; MappedObjects[localObjectId] = remoteObjectId;
} }
catch (Exception e) catch (Exception e)
{ {
@ -502,7 +483,7 @@ namespace DiIiS_NA.LoginServer.Battle
{ {
try try
{ {
this.MappedObjects.TryRemove(localObjectId, out _); MappedObjects.TryRemove(localObjectId, out _);
} }
catch (Exception e) catch (Exception e)
{ {
@ -511,7 +492,7 @@ namespace DiIiS_NA.LoginServer.Battle
} }
public ulong GetRemoteObjectId(ulong localObjectId) public ulong GetRemoteObjectId(ulong localObjectId)
{ {
return localObjectId != 0 ? this.MappedObjects[localObjectId] : 0; return localObjectId != 0 ? MappedObjects[localObjectId] : 0;
} }
public static uint GetMethodId(MethodDescriptor method) public static uint GetMethodId(MethodDescriptor method)
{ {
@ -537,13 +518,13 @@ namespace DiIiS_NA.LoginServer.Battle
} }
public void SendMOTD() public void SendMOTD()
{ {
if (this.MOTDSent) if (MOTDSent)
return; return;
var motd = "Welcome to BlizzLess.Net Alpha-Build Server!"; var motd = "Welcome to BlizzLess.Net Alpha-Build Server!";
this.SendServerWhisper(motd); SendServerWhisper(motd);
this.MOTDSent = true; MOTDSent = true;
} }
public override void ChannelInactive(IChannelHandlerContext context) public override void ChannelInactive(IChannelHandlerContext context)
@ -554,7 +535,7 @@ namespace DiIiS_NA.LoginServer.Battle
private void DisconnectClient() private void DisconnectClient()
{ {
if (this.Account != null && this.Account.GameAccount != null) this.Account.GameAccount.LoggedInClient = null; if (Account != null && Account.GameAccount != null) Account.GameAccount.LoggedInClient = null;
PlayerManager.PlayerDisconnected(this); PlayerManager.PlayerDisconnected(this);
} }
} }

View File

@ -20,7 +20,7 @@ using System.Threading.Tasks;
namespace DiIiS_NA.LoginServer.ServicesSystem.Services namespace DiIiS_NA.LoginServer.ServicesSystem.Services
{ {
[Service(serviceID: 0xb, serviceName: "bnet.protocol.presence.PresenceService")]//: )] [Service(serviceID: 0xb, serviceName: "bnet.protocol.presence.PresenceService")]
public class PresenceService : bgs.protocol.presence.v1.PresenceService, IServerService public class PresenceService : bgs.protocol.presence.v1.PresenceService, IServerService
{ {
private static readonly Logger Logger = LogManager.CreateLogger(); private static readonly Logger Logger = LogManager.CreateLogger();
@ -39,22 +39,28 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
switch (req.GetHighIdType()) switch (req.GetHighIdType())
{ {
case EntityIdHelper.HighIdType.AccountId: case EntityIdHelper.HighIdType.AccountId:
{
var account = AccountManager.GetAccountByPersistentID(req.Low); var account = AccountManager.GetAccountByPersistentID(req.Low);
if (account != null) if (account != null)
{ {
Logger.Trace("Subscribe() {0} {1}", ((controller as HandlerController).Client), account); Logger.Debug("Subscribe() {0} {1}", (((HandlerController)controller).Client), account);
account.AddSubscriber(((controller as HandlerController).Client), request.ObjectId); account.AddSubscriber((((HandlerController)controller).Client), request.ObjectId);
response.AddSubscribeFailed(SubscribeResult.CreateBuilder().SetEntityId(req).SetResult(0)); response.AddSubscribeFailed(SubscribeResult.CreateBuilder().SetEntityId(req)
.SetResult(0));
}
} }
break; break;
case EntityIdHelper.HighIdType.GameAccountId: case EntityIdHelper.HighIdType.GameAccountId:
var gameaccount = GameAccountManager.GetAccountByPersistentID(req.Low);
if (gameaccount != null)
{ {
Logger.Trace("Subscribe() {0} {1}", ((controller as HandlerController).Client), gameaccount); var gameAccount = GameAccountManager.GetAccountByPersistentID(req.Low);
gameaccount.AddSubscriber(((controller as HandlerController).Client), request.ObjectId); if (gameAccount != null)
response.AddSubscribeFailed(SubscribeResult.CreateBuilder().SetEntityId(req).SetResult(0)); {
Logger.Debug("Subscribe() {0} {1}", (((HandlerController)controller).Client),
gameAccount);
gameAccount.AddSubscriber((((HandlerController)controller).Client), request.ObjectId);
response.AddSubscribeFailed(SubscribeResult.CreateBuilder().SetEntityId(req)
.SetResult(0));
}
} }
break; break;
default: default:
@ -72,7 +78,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
public override void BatchUnsubscribe(IRpcController controller, BatchUnsubscribeRequest request, Action<NoData> done) public override void BatchUnsubscribe(IRpcController controller, BatchUnsubscribeRequest request, Action<NoData> done)
{ {
throw new NotImplementedException(); Logger.Fatal("Batch Unsubscribe not implemented");
} }
public override void Query(IRpcController controller, QueryRequest request, Action<QueryResponse> done) public override void Query(IRpcController controller, QueryRequest request, Action<QueryResponse> done)
@ -82,26 +88,34 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
switch (request.EntityId.GetHighIdType()) switch (request.EntityId.GetHighIdType())
{ {
case EntityIdHelper.HighIdType.AccountId: case EntityIdHelper.HighIdType.AccountId:
var account = AccountManager.GetAccountByPersistentID(request.EntityId.Low); {
var gameAccount = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
foreach (var key in request.KeyList) foreach (var key in request.KeyList)
{ {
Logger.Trace("Query() {0} {1} - {2}, {3}, {4}", ((controller as HandlerController).Client), account, (FieldKeyHelper.Program)key.Program, (FieldKeyHelper.OriginatingClass)key.Group, key.Field); Logger.Debug("Query() {0} {1} - {2}, {3}, {4}", (((HandlerController)controller).Client),
var field = account.QueryField(key); gameAccount, (FieldKeyHelper.Program)key.Program, (FieldKeyHelper.OriginatingClass)key.Group,
key.Field);
var field = gameAccount.QueryField(key);
if (field != null) builder.AddField(field); if (field != null) builder.AddField(field);
} }
}
break; break;
case EntityIdHelper.HighIdType.GameAccountId: case EntityIdHelper.HighIdType.GameAccountId:
var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low); {
var gameAccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
foreach (var key in request.KeyList) foreach (var key in request.KeyList)
{ {
Logger.Trace("Query() {0} {1} - {2}, {3}, {4}", ((controller as HandlerController).Client), gameaccount, (FieldKeyHelper.Program)key.Program, (FieldKeyHelper.OriginatingClass)key.Group, key.Field); Logger.Debug("Query() {0} {1} - {2}, {3}, {4}", (((HandlerController)controller).Client),
var field = gameaccount.QueryField(key); gameAccount, (FieldKeyHelper.Program)key.Program,
(FieldKeyHelper.OriginatingClass)key.Group, key.Field);
var field = gameAccount.QueryField(key);
if (field != null) builder.AddField(field); if (field != null) builder.AddField(field);
} }
}
break; break;
default: default:
Logger.Warn("Recieved an unhandled Presence.Query request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16")); Logger.Warn("Received an unhandled Presence.Query request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16"));
break; break;
} }
@ -115,23 +129,27 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
switch (request.EntityId.GetHighIdType()) switch (request.EntityId.GetHighIdType())
{ {
case EntityIdHelper.HighIdType.AccountId: case EntityIdHelper.HighIdType.AccountId:
var account = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
if (account != null)
{ {
Logger.Trace("Subscribe() {0} {1}", ((controller as HandlerController).Client), account); var gameAccount = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
account.AddSubscriber(((controller as HandlerController).Client), request.ObjectId); if (gameAccount != null)
{
Logger.Trace("Subscribe() {0} {1}", (((HandlerController)controller).Client), gameAccount);
gameAccount.AddSubscriber((((HandlerController)controller).Client), request.ObjectId);
}
} }
break; break;
case EntityIdHelper.HighIdType.GameAccountId: case EntityIdHelper.HighIdType.GameAccountId:
{
var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low); var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
if (gameaccount != null) if (gameaccount != null)
{ {
Logger.Trace("Subscribe() {0} {1}", ((controller as HandlerController).Client), gameaccount); Logger.Debug("Subscribe() {0} {1}", (((HandlerController)controller).Client), gameaccount);
gameaccount.AddSubscriber(((controller as HandlerController).Client), request.ObjectId); gameaccount.AddSubscriber((((HandlerController)controller).Client), request.ObjectId);
}
} }
break; break;
default: default:
Logger.Warn("Recieved an unhandled Presence.Subscribe request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16")); Logger.Warn("Received an unhandled Presence.Subscribe request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16"));
break; break;
} }
}); });
@ -146,24 +164,29 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
switch (request.EntityId.GetHighIdType()) switch (request.EntityId.GetHighIdType())
{ {
case EntityIdHelper.HighIdType.AccountId: case EntityIdHelper.HighIdType.AccountId:
var account = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
// The client will probably make sure it doesn't unsubscribe to a null ID, but just to make sure..
if (account != null)
{ {
account.RemoveSubscriber(((controller as HandlerController).Client)); var gameAccount = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
Logger.Trace("Unsubscribe() {0} {1}", ((controller as HandlerController).Client), account); // The client will probably make sure it doesn't unsubscribe to a null ID, but just to make sure..
if (gameAccount != null)
{
gameAccount.RemoveSubscriber((((HandlerController) controller).Client));
Logger.Debug("Unsubscribe() {0} {1}", (((HandlerController) controller).Client), gameAccount);
}
} }
break; break;
case EntityIdHelper.HighIdType.GameAccountId: case EntityIdHelper.HighIdType.GameAccountId:
var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
if (gameaccount != null)
{ {
gameaccount.RemoveSubscriber(((controller as HandlerController).Client)); var gameAccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
Logger.Trace("Unsubscribe() {0} {1}", ((controller as HandlerController).Client), gameaccount); if (gameAccount != null)
{
gameAccount.RemoveSubscriber((((HandlerController) controller).Client));
Logger.Debug("Unsubscribe() {0} {1}", (((HandlerController) controller).Client), gameAccount);
}
} }
break; break;
default: default:
Logger.Warn("Recieved an unhandled Presence.Unsubscribe request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16")); Logger.Warn("Received an unhandled Presence.Unsubscribe request with type {0} (0x{1})",
request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16"));
break; break;
} }
@ -178,31 +201,40 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
switch (request.EntityId.GetHighIdType()) switch (request.EntityId.GetHighIdType())
{ {
case EntityIdHelper.HighIdType.AccountId: case EntityIdHelper.HighIdType.AccountId:
{
if (request.EntityId.Low <= 0) break; if (request.EntityId.Low <= 0) break;
var account = AccountManager.GetAccountByPersistentID(request.EntityId.Low); var gameAccount = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
if (account == null) break; if (gameAccount == null) break;
var a_trace = string.Format("Update() {0} {1} - {2} Operations", ((controller as HandlerController).Client), account, request.FieldOperationCount); var traceData = $"Update() {(((HandlerController)controller).Client)} {gameAccount} - {request.FieldOperationCount} Operations";
foreach (var fieldOp in request.FieldOperationList) foreach (var fieldOp in request.FieldOperationList)
{ {
a_trace += string.Format("\t{0}, {1}, {2}", (FieldKeyHelper.Program)fieldOp.Field.Key.Program, (FieldKeyHelper.OriginatingClass)fieldOp.Field.Key.Group, fieldOp.Field.Key.Field); traceData += $"\t{(FieldKeyHelper.Program)fieldOp.Field.Key.Program}, {(FieldKeyHelper.OriginatingClass)fieldOp.Field.Key.Group}, {fieldOp.Field.Key.Field}";
}
gameAccount.Update(request.FieldOperationList);
Logger.Debug(traceData);
} }
account.Update(request.FieldOperationList);
Logger.Trace(a_trace);
break; break;
case EntityIdHelper.HighIdType.GameAccountId: case EntityIdHelper.HighIdType.GameAccountId:
{
if (request.EntityId.Low <= 0) break; if (request.EntityId.Low <= 0) break;
var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low); var gameAccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
if (gameaccount == null) break; if (gameAccount == null) break;
var ga_trace = string.Format("Update() {0} {1} - {2} Operations", ((controller as HandlerController).Client), gameaccount, request.FieldOperationCount); var traceData =
$"Update() {(((HandlerController) controller).Client)} {gameAccount} - {request.FieldOperationCount} Operations";
foreach (var fieldOp in request.FieldOperationList) foreach (var fieldOp in request.FieldOperationList)
{ {
ga_trace += string.Format("\t{0}, {1}, {2}", (FieldKeyHelper.Program)fieldOp.Field.Key.Program, (FieldKeyHelper.OriginatingClass)fieldOp.Field.Key.Group, fieldOp.Field.Key.Field); traceData +=
$"\t{(FieldKeyHelper.Program)fieldOp.Field.Key.Program}, {(FieldKeyHelper.OriginatingClass)fieldOp.Field.Key.Group}, {fieldOp.Field.Key.Field}";
} }
gameaccount.Update(request.FieldOperationList);
Logger.Trace(ga_trace); gameAccount.Update(request.FieldOperationList);
Logger.Debug(traceData);
break; break;
}
default: default:
Logger.Warn("Recieved an unhandled Presence.Update request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16")); Logger.Warn("Received an unhandled Presence.Update request with type {0} (0x{1})",
request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16"));
break; break;
} }