Exemple #1
0
        private static IEnumerable <string> LookupAndDownloadLevel(string levelIdHash)
        {
            var li = levelIdHash.IndexOf(".MP");

            MenuManager.AddMpStatus("SEARCHING " + levelIdHash.Substring(0, li), 1f, 9);
            string lastData = null;

            foreach (var x in NetworkMatch.Get("mpget", new Dictionary <string, string> {
                { "level", levelIdHash }
            }, "https://www.overloadmaps.com/api/"))
            {
                lastData = x;
                yield return(null);
            }
            JObject ret = null;

            try
            {
                ret = JObject.Parse(lastData);
            }
            catch (Exception ex)
            {
                Debug.Log(ex);
            }
            if (ret == null || !ret.TryGetValue("url", out JToken urlVal))
            {
                string msg = ret == null ? "OVERLOADMAPS.COM LOOKUP FAILED" : "LEVEL NOT FOUND ON OVERLOADMAPS.COM";
                Debug.Log(msg);
                MenuManager.AddMpStatus(msg, 2f, 9);
                yield return(msg);

                yield break;
            }

            string url = urlVal.GetString();
            var    i   = url.LastIndexOf('/');

            MenuManager.AddMpStatus("DOWNLOADING " + url.Substring(i + 1), 1f, 9);
            string lastMsg = null;

            foreach (var msg in MaybeDownloadLevel(url, levelIdHash))
            {
                if (msg != lastMsg)
                {
                    MenuManager.AddMpStatus(msg, 1f, 9);
                    lastMsg = msg;
                }
                yield return(msg);
            }
            Debug.Log("DoGetLevel last download status: " + lastMsg);
        }