Esempio n. 1
0
        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
            }
        }