/// <inheritdoc /> public void Register(int key, ZoneClientSession value) { if (!ZoneMap.TryAdd(key, value)) { throw new InvalidOperationException($"Failed to add Key: {key} Type: {nameof(ZoneClientSession)} to {nameof(DefaultSessionCollection)}"); } }
/// <inheritdoc /> public ManagedClientSession <GameServerPacketPayload, GameClientPacketPayload> Create([NotNull] ManagedClientSessionCreationContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (Logger.IsDebugEnabled) { Logger.Debug($"Creating new session. Details: {context.Details}"); } try { ZoneClientSession clientSession = new ZoneClientSession(context.Client, context.Details, HandlerService, Logger); //We should add this to the session collection, and also make sure it is unregistered on disconnection SessionRegisterable.Register(context.Details.ConnectionId, clientSession); clientSession.OnSessionDisconnection += (source, args) => { OnSessionDisconnection?.Invoke(source, args); return(Task.CompletedTask); }; return(clientSession); } catch (Exception e) { if (Logger.IsErrorEnabled) { Logger.Error($"Failed to create Client: {context.Details} Error: {e.Message} \n\n Stack: {e.StackTrace}"); } throw; } }