private void ProcessSubscribeResponse(PegasusPacket packet, ClientRequestType request) { if (packet.Body is SubscribeResponse) { SystemChannel system = request.System; int systemId = system.SystemId; SubscribeResponse body = (SubscribeResponse)packet.Body; if (body.Result == SubscribeResponse.ResponseResult.FAILED_UNAVAILABLE) { this.ScheduleResubscribeWithNewRoute(system); } else { system.SubscriptionStatus.CurrentState = SubscriptionStatusType.State.SUBSCRIBED; system.SubscriptionStatus.SubscribedTime = DateTime.Now; system.Route = body.Route; system.CurrentPhase = RequestPhase.STARTUP; system.SubscribeAttempt = 0; system.KeepAliveSecs = body.KeepAliveSecs; system.MaxResubscribeAttempts = body.MaxResubscribeAttempts; system.PendingResponseTimeout = body.PendingResponseTimeout; system.PendingSubscribeTimeout = body.PendingSubscribeTimeout; this.m_state.m_pendingDelivery.Enqueue(packet); system.m_subscribePacketsReceived++; } } }
private void MoveRequestsFromPendingResponseToSend(SystemChannel system, RequestPhase phase, PendingMapType pendingMap) { List <uint> list = new List <uint>(); List <uint> list2 = new List <uint>(); foreach (KeyValuePair <uint, ClientRequestType> pair in this.m_state.m_contextIdToRequestMap) { uint key = pair.Key; ClientRequestType type = pair.Value; if ((type.System.SystemId == system.SystemId) && (phase == type.Phase)) { if (type.ShouldRetryOnError) { list.Add(key); } else { list2.Add(key); } } } foreach (uint num2 in list) { string reason = (phase != RequestPhase.STARTUP) ? "moving_to_pending_running_phase" : "moving_to_pending_startup_phase"; ClientRequestType item = this.GetClientRequest(num2, reason, true); pendingMap.PendingSend.Enqueue(item); this.m_state.m_contextIdToDroppedPacketMap.Add(num2, item); } foreach (uint num3 in list2) { ClientRequestType type3 = this.GetClientRequest(num3, "moving_to_dropped", true); this.m_state.m_contextIdToDroppedPacketMap.Add(num3, type3); } }
private void ProcessClientRequests(SystemChannel system) { PendingMapType pendingMap = (system.CurrentPhase != RequestPhase.STARTUP) ? system.Phases.Running : system.Phases.StartUp; foreach (KeyValuePair <uint, ClientRequestType> pair in this.m_state.m_contextIdToRequestMap) { ClientRequestType type2 = pair.Value; if ((!type2.IsSubsribeRequest && (type2.System != null)) && ((type2.System.SystemId == system.SystemId) && (system.PendingResponseTimeout != 0))) { TimeSpan span = (TimeSpan)(DateTime.Now - type2.SendTime); if (span.TotalSeconds >= system.PendingResponseTimeout) { this.ScheduleResubscribeWithNewRoute(system); return; } } } if (pendingMap.PendingSend.Count > 0) { ClientRequestType request = pendingMap.PendingSend.Dequeue(); this.SendToUtil(system, system.Route, request, pendingMap); } else if ((system.CurrentPhase == RequestPhase.STARTUP) && this.m_state.m_runningPhaseEnabled) { system.CurrentPhase = RequestPhase.RUNNING; } }
private void SendSubscriptionRequest(SystemChannel system) { int systemId = system.SystemId; if (system.Route == 0) { this.MoveRequestsFromPendingResponseToSend(system, RequestPhase.STARTUP, system.Phases.StartUp); this.MoveRequestsFromPendingResponseToSend(system, RequestPhase.RUNNING, system.Phases.Running); } ClientRequestType request = new ClientRequestType { Type = 0x13a, SubID = 0, Body = ProtobufUtil.ToByteArray(this.m_subscribePacket), RequestId = this.GetNextRequestId(), IsSubsribeRequest = true }; system.SubscriptionStatus.CurrentState = SubscriptionStatusType.State.PENDING_RESPONSE; system.SubscriptionStatus.LastSend = DateTime.Now; PendingMapType pendingMap = (system.CurrentPhase != RequestPhase.STARTUP) ? system.Phases.Running : system.Phases.StartUp; system.SubscriptionStatus.ContexId = this.SendToUtil(system, system.Route, request, pendingMap); system.SubscribeAttempt++; this.m_state.m_subscribePacketsSent++; }
private async void ChannelListComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { SystemChannel newChannel = (ChannelListComboBox.SelectedItem as ComboBoxItem).Tag as SystemChannel; // 'Color' can technically be any CSS colour string // For now, we assume that it'll always be in "#000000" format int color = Int32.Parse(newChannel.VisualIdentity.Color.Substring(1), System.Globalization.NumberStyles.HexNumber); var newColor = Color.FromRgb( (byte)((color >> 16) & 0xFF), (byte)((color >> 8) & 0xFF), (byte)(color & 0xFF)); Dispatcher.Invoke(() => { ChannelColorEllipse.Fill = new SolidColorBrush() { Color = newColor }; }); try { await newChannel.JoinAsync(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private bool ProcessSubscribeStatePendingSend(SystemChannel system) { TimeSpan span = (TimeSpan)(DateTime.Now - system.SubscriptionStatus.LastSend); if (span.TotalSeconds > system.PendingSubscribeTimeout) { this.SendSubscriptionRequest(system); } return(system.Route != 0L); }
private bool ProcessSubscribeStatePendingResponse(SystemChannel system) { TimeSpan span = (TimeSpan)(DateTime.Now - system.SubscriptionStatus.LastSend); if (span.TotalSeconds > system.PendingSubscribeTimeout) { this.ScheduleResubscribeKeepRoute(system); } return(system.Route != 0L); }
private uint SendToUtil(SystemChannel system, ulong route, ClientRequestType request, PendingMapType pendingMap) { uint key = this.GenerateContextId(); BattleNet.SendUtilPacket(request.Type, system.SystemId, request.Body, request.Body.Length, request.SubID, (int)key, route); request.Context = key; request.System = system; request.SendTime = DateTime.Now; this.m_state.m_contextIdToRequestMap.Add(key, request); string str = !request.IsSubsribeRequest ? request.Phase.ToString() : "SUBSCRIBE"; return(key); }
private SystemChannel GetOrCreateSystem(int systemId) { SystemChannel channel = null; if (!this.m_state.m_systems.Systems.TryGetValue(systemId, out channel)) { channel = new SystemChannel { SystemId = systemId }; this.m_state.m_systems.Systems[systemId] = channel; } return(channel); }
private int CountPendingResponsesForSystemId(SystemChannel system) { int num = 0; foreach (KeyValuePair <uint, ClientRequestType> pair in this.m_state.m_contextIdToRequestMap) { if (pair.Value.System.SystemId == system.SystemId) { num++; } } return(num); }
private void TerminateImpl() { Unsubscribe protobuf = new Unsubscribe(); byte[] bytes = ProtobufUtil.ToByteArray(protobuf); foreach (KeyValuePair <int, SystemChannel> pair in this.m_state.m_systems.Systems) { SystemChannel channel = pair.Value; if ((channel.SubscriptionStatus.CurrentState == SubscriptionStatusType.State.SUBSCRIBED) && (channel.Route != 0)) { BattleNet.SendUtilPacket(0x149, channel.SystemId, bytes, bytes.Length, 0, 0, channel.Route); } } }
private bool UpdateStateSubscribeImpl(SystemChannel system) { switch (system.SubscriptionStatus.CurrentState) { case SubscriptionStatusType.State.PENDING_SEND: return(this.ProcessSubscribeStatePendingSend(system)); case SubscriptionStatusType.State.PENDING_RESPONSE: return(this.ProcessSubscribeStatePendingResponse(system)); case SubscriptionStatusType.State.SUBSCRIBED: return(this.ProcessSubscribeStateSubscribed(system)); } return(system.SubscriptionStatus.CurrentState == SubscriptionStatusType.State.SUBSCRIBED); }
private ClientRequestType GetPendingSendRequest(uint contextId, string reason, bool removeIfFound = true) { ClientRequestType type = null; foreach (KeyValuePair <int, SystemChannel> pair in this.m_state.m_systems.Systems) { SystemChannel channel = pair.Value; type = this.GetPendingSendRequestForPhase(contextId, removeIfFound, channel.Phases.Running); if (type != null) { return(type); } type = this.GetPendingSendRequestForPhase(contextId, removeIfFound, channel.Phases.StartUp); } return(type); }
private bool SendClientRequestImpl(int type, IProtoBuf body, ClientRequestConfig clientRequestConfig, RequestPhase requestPhase, int subID) { if (type == 0) { return(false); } if ((requestPhase < RequestPhase.STARTUP) || (requestPhase > RequestPhase.RUNNING)) { return(false); } ClientRequestConfig config = (clientRequestConfig != null) ? clientRequestConfig : this.m_defaultConfig; int requestedSystem = config.RequestedSystem; SystemChannel orCreateSystem = this.GetOrCreateSystem(requestedSystem); if (requestPhase < orCreateSystem.CurrentPhase) { return(false); } if (orCreateSystem.WasEverInRunningPhase && (requestPhase < RequestPhase.RUNNING)) { return(false); } if (body == null) { return(false); } ClientRequestType item = new ClientRequestType { Type = type, ShouldRetryOnError = config.ShouldRetryOnError, SubID = subID, Body = ProtobufUtil.ToByteArray(body), Phase = requestPhase, RetryCount = 0, RequestId = this.GetNextRequestId() }; if (item.Phase == RequestPhase.STARTUP) { orCreateSystem.Phases.StartUp.PendingSend.Enqueue(item); } else { orCreateSystem.Phases.Running.PendingSend.Enqueue(item); } return(true); }
private bool ProcessSubscribeStateSubscribed(SystemChannel system) { TimeSpan span = (TimeSpan)(DateTime.Now - system.SubscriptionStatus.SubscribedTime); if (((ulong)span.TotalSeconds) >= system.KeepAliveSecs) { if (this.CountPendingResponsesForSystemId(system) > 0) { return(true); } if (system.KeepAliveSecs > 0L) { system.SubscriptionStatus.CurrentState = SubscriptionStatusType.State.PENDING_SEND; } } return(true); }
internal static ChannelBase GetChannelObject(ChannelTransport channelTransport, Connection connection) { if (channelTransport == null) { if (defaultChannel == null) { defaultChannel = new DefaultChannel(connection); } return(defaultChannel); } ChannelBase channel; switch (channelTransport.ChannelType) { case ChannelType.Default: if (defaultChannel == null) { defaultChannel = new DefaultChannel(connection); } channel = defaultChannel; break; case ChannelType.System: channel = new SystemChannel(channelTransport as SystemChannelTransport, connection); break; default: channel = null; break; } return(channel); }
private void ScheduleResubscribeWithNewRoute(SystemChannel system) { system.Route = 0L; system.SubscriptionStatus.CurrentState = SubscriptionStatusType.State.PENDING_SEND; }