Beispiel #1
0
 /// <summary>
 ///     Setup DOTA 2 game coordinator callbacks
 /// </summary>
 /// <param name="cb">Manager</param>
 private void SetupDotaGcCallbacks(CallbackManager cb)
 {
     cb.Add <DotaGCHandler.GCWelcomeCallback>(a =>
     {
         log.Debug("GC session welcomed");
         _state.Fire(Trigger.DotaConnected);
     });
     cb.Add <DotaGCHandler.ConnectionStatus>(a =>
     {
         log.DebugFormat("GC connection status: {0}", a.result.status.ToString("G"));
         _state.Fire(a.result.status == GCConnectionStatus.GCConnectionStatus_HAVE_SESSION
             ? Trigger.DotaConnected
             : Trigger.DotaDisconnected);
     });
     cb.Add <DotaGCHandler.Popup>(a => log.DebugFormat("GC popup message: {0}", a.result.id.ToString("G")));
     cb.Add <DotaGCHandler.PracticeLobbySnapshot>(a => HandleLobbyUpdate(a.lobby));
     cb.Add <DotaGCHandler.PracticeLobbyLeave>(a => HandleLobbyUpdate(null));
     cb.Add <DotaGCHandler.JoinChatChannelResponse>(a =>
     {
         if (DotaGcHandler.Lobby != null && a.result.channel_id != 0 &&
             a.result.channel_name == "Lobby_" + DotaGcHandler.Lobby.lobby_id)
         {
             _lobbyChannelId = a.result.channel_id;
             JoinedLobbyChat?.Invoke(this, EventArgs.Empty);
         }
     });
     cb.Add <DotaGCHandler.ChatMessage>(
         a =>
     {
         log.DebugFormat("[Chat][" +
                         (a.result.channel_id == _lobbyChannelId ? "Lobby" : a.result.channel_id + "") + "] " +
                         a.result.persona_name + ": " + a.result.text);
         if (a.result.channel_id != _lobbyChannelId)
         {
             return;
         }
     });
     cb.Add <DotaGCHandler.MatchResultResponse>(c =>
     {
         Action <CMsgDOTAMatch> cbx;
         ulong id;
         id = c.result.match?.match_id ?? _matchId;
         if (!_callbacks.TryGetValue(id, out cbx))
         {
             return;
         }
         _callbacks.Remove(id);
         log.Warn("Match result response for " + id + ": " + ((EResult)c.result.result).ToString("G"));
         cbx(c.result.match);
     });
     cb.Add <DotaGCHandler.LobbyInviteSnapshot>(c =>
     {
         LobbyInviteReceived?.Invoke(this, c.invite);
     });
     cb.Add <DotaGCHandler.PartyInviteSnapshot>(c =>
     {
         PartyInviteReceived?.Invoke(this, c.invite);
     });
 }
Beispiel #2
0
        private void MessageReceived(object sender, IMessageBase message)
        {
            try
            {
                switch (message.MessageType)
                {
                case MessageType.ChatMessage:
                    ChatReceived?.Invoke(this, message as ChatMessage);
                    break;

                case MessageType.DataStateChanged:
                    DataStateChanged?.Invoke(this, EventArgs.Empty);
                    break;

                case MessageType.LocalEvent:
                    LocalEventReceived?.Invoke(this, message as LocalEventMessage);
                    break;

                case MessageType.LocationChanged:
                    LocationChanged?.Invoke(this, EventArgs.Empty);
                    break;

                case MessageType.PartyInviteReceived:
                    var invite = message as PartyInvite;
                    _toastService.ShowToast($"Party invite from {invite.From.Name}.");
                    PartyInviteReceived?.Invoke(this, invite);
                    break;

                case MessageType.ToastMessage:
                    if (message is ToastMessage toastMessage)
                    {
                        _toastService.ShowToast(toastMessage.Message, toastMessage.ExpirationMs, toastMessage.ClassString, toastMessage.StyleOverride);
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error while processing message.");
            }
        }