コード例 #1
0
ファイル: LeagueOfLegends.cs プロジェクト: Hi-Ray/PoroQueue
        private static async void OnWebsocketMessage(object sender, MessageEventArgs e)
        {
            var Messages = JArray.Parse(e.Data);

            int MessageType = 0;

            if (!int.TryParse(Messages[0].ToString(), out MessageType) || MessageType != 8)
            {
                return;
            }

            var EventName = Messages[1].ToString();

#if DEBUG_EVENTS
            Debug.WriteLine("Received an event: " + EventName);
#endif

            switch (EventName)
            {
            case LoggedInEvent:
                while (!IsLoggedIn)
                {
                    try
                    {
                        CurrentSummoner = await Summoner.GetCurrent();

                        var Lobby = await LobbyRequest.Get();

                        SetGameModeFromString(Lobby != null ? Lobby.gameConfig.gameMode : "UNKNOWN");

                        LoggedIn?.Invoke(null, EventArgs.Empty);
                        IconChanged?.Invoke(null, EventArgs.Empty);
                        break;
                    }

                    // We aren't logged in!
                    catch (System.Net.Http.HttpRequestException)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(5));
                    }
                }
                break;

            case SummonerIconChangedEvent:
                CurrentSummoner = await Summoner.GetCurrent();

                if (CurrentSummoner.profileIconId != ForcedPoroIcon)
                {
                    IconChanged?.Invoke(null, EventArgs.Empty);
                }
                else if (ForcedPoroIcon != -1 && CurrentSummoner.profileIconId != ForcedPoroIcon)
                {
                    Icon.Set(ForcedPoroIcon);
                }
                break;

            case QueueUpEvent:
                var QueueEvent = Messages[2];
                var QueueURI   = QueueEvent["uri"].ToString();

                if (QueueURI == "/lol-lobby-team-builder/v1/lobby/countdown" && QueueEvent["data"]["phaseName"].ToString() == "MATCHMAKING")
                {
                    Debug.WriteLine("Noticed start of matchmaking, setting poro icon.");
                    Icon.SetToPoro(CurrentGameMode, out ForcedPoroIcon);
                    break;
                }

                if (QueueURI != "/lol-lobby-team-builder/v1/lobby")
                {
                    break;
                }

                var QueueEventType = QueueEvent["eventType"].ToString();
                Debug.WriteLine($"QueueUpEvent: {QueueEventType}");
                if (QueueEventType == "Delete")
                {
                    Icon.ResetToDefault();
                    ForcedPoroIcon = -1;
                }
                else if (ForcedPoroIcon == -1)
                {
                    Icon.SetToPoro(CurrentGameMode, out ForcedPoroIcon);
                }
                break;

            case GameModeChangedEvent:
                var EventContainer = Messages[2];
                if (EventContainer["uri"].ToString() != "/lol-lobby/v2/lobby")
                {
                    break;
                }
                var EventType = EventContainer["eventType"].ToString();
                Debug.WriteLine("GameModeChangedEvent: " + EventType);
                switch (EventType)
                {
                case "Create":
                    var LobbyCreatedEvent = JsonConvert.DeserializeObject <LobbyCreateEvent>(Messages[2].ToString());
                    SetGameModeFromString(LobbyCreatedEvent.data.gameConfig.gameMode);
                    break;

                case "Delete":
                    CurrentGameMode = LeagueOfLegends.GameMode.Unknown;
                    break;

                case "Update":
                    var LobbyUpdatedEvent = JsonConvert.DeserializeObject <LobbyCreateEvent>(Messages[2].ToString());
                    SetGameModeFromString(LobbyUpdatedEvent.data.gameConfig.gameMode);
                    break;
                }
                GameModeUpdated?.Invoke(null, EventArgs.Empty);
                break;

            case GameEvent:
                var GameEventData = Messages[2];
                var GameURI       = GameEventData["uri"].ToString();
                if (GameURI != "/lol-gameflow/v1/session")
                {
                    break;
                }

                if (GameEventData["data"] == null)
                {
                    break;
                }

                var Phase = GameEventData["data"]["phase"].ToString();
                Debug.WriteLine("Current GameFlow phase: " + Phase);
                if (Phase == "InProgress")
                {
                    Icon.ResetToDefault();
                }
                break;
            }
        }
コード例 #2
0
ファイル: LeagueOfLegends.cs プロジェクト: Hi-Ray/PoroQueue
        private static async void Init()
        {
            IsActive = true;

            var Parts = LockFile.Split(':');

            ushort Port     = ushort.Parse(Parts[2]);
            var    Password = Parts[3];
            var    Protocol = Parts[4];

            APIDomain = String.Format("{0}://127.0.0.1:{1}", Protocol, Port);
            Request.SetUserData("riot", Password);

#if DEBUG_EVENTS
            try
            {
                var AllEventsText = await Request.Get(APIDomain + "/help");

                File.WriteAllText("events.json", AllEventsText);
            }
            catch (System.Net.Http.HttpRequestException)
            {
            }
#endif

            var Versions = await JSONRequest.Get <string[]>("http://ddragon.leagueoflegends.com/api/versions.json");

            LatestVersion = Versions[0];

            Started?.Invoke(null, EventArgs.Empty);

            Connection = new WebSocket("wss://127.0.0.1:" + Port + "/", "wamp");
            Connection.SetCredentials("riot", Password, true);
            Connection.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
            Connection.OnMessage += OnWebsocketMessage;
            Connection.Connect();

#if !DEBUG_EVENTS
            Connection.Send("[5,\"" + SummonerIconChangedEvent + "\"]");
            Connection.Send("[5,\"" + QueueUpEvent + "\"]");
            Connection.Send("[5,\"" + GameModeChangedEvent + "\"]");
            Connection.Send("[5,\"" + GameEvent + "\"]");
#else
            var HelpDocument = JsonConvert.DeserializeObject <DebugEventHelper>(File.ReadAllText("events.json"));
            foreach (var EventName in HelpDocument.events)
            {
                var Event = EventName.Key;
                if (Event == "OnJsonApiEvent")
                {
                    continue;
                }
                Connection.Send("[5,\"" + Event + "\"]");
            }
#endif

            try
            {
                CurrentSummoner = await Summoner.GetCurrent();

                var Lobby = await LobbyRequest.Get();

                SetGameModeFromString(Lobby != null ? Lobby.gameConfig.gameMode : "UNKNOWN");

                LoggedIn?.Invoke(null, EventArgs.Empty);
                IconChanged?.Invoke(null, EventArgs.Empty);
            }

            // We aren't logged in!
            catch (System.Net.Http.HttpRequestException e)
            {
#if !DEBUG_EVENTS
                Connection.Send("[5,\"" + LoggedInEvent + "\"]");
#endif
            }
        }