public static void SubmitModInfo(string modName, ISet <string> modTags, Action <string> onSuccess, Action <Exception, string> onError, Action onCompletion = null)
        {
            string url  = "http://hamstar.pw/hamstarhelpers/mod_info_submit/";
            var    json = new PostModTagsData {
                modname = modName,
                modtags = string.Join(",", modTags)
            };

            string jsonStr = JsonConvert.SerializeObject(json, Formatting.Indented);

            byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonStr);

            Action <String> onResponse = (output) => {
                JObject respJson = JObject.Parse(output);
                JToken  msg      = respJson.SelectToken("Msg");

                if (msg == null)
                {
                    onSuccess("Failure.");
                }
                else
                {
                    onSuccess(msg.ToObject <string>());
                }
            };

            Action <Exception, string> wrappedOnError = (Exception e, string str) => {
                LogHelpers.Log("!ModHelpers.PostModInfo.SubmitModInfo - Failed for post: " + jsonStr);
                onError(e, str);
            };

            NetHelpers.MakePostRequestAsync(url, jsonBytes, onResponse, wrappedOnError, onCompletion);
        }
        public static void ReportIssue(Mod mod, string issueTitle, string issueBody, Action <string> onSuccess, Action <Exception, string> onError, Action onCompletion = null)
        {
            if (!ModFeaturesHelpers.HasGithub(mod))
            {
                throw new HamstarException("Mod is not eligable for submitting issues.");
            }

            int maxLines = ModHelpersMod.Instance.Config.ModIssueReportErrorLogMaxLines;

            IEnumerable <Mod> mods       = ModListHelpers.GetAllLoadedModsPreferredOrder();
            string            bodyInfo   = string.Join("\n \n", InfoHelpers.GetGameData(mods).ToArray());
            string            bodyErrors = string.Join("\n", InfoHelpers.GetErrorLog(maxLines).ToArray());

            string url   = "http://hamstar.pw/hamstarhelpers/issue_submit/";
            string title = "Reported from in-game: " + issueTitle;
            string body  = bodyInfo;

            body += "\n \n \n \n" + "Recent error logs:\n```\n" + bodyErrors + "\n```";
            body += "\n \n" + issueBody;

            var json = new GithubModIssueReportData {
                githubuser    = ModFeaturesHelpers.GetGithubUserName(mod),
                githubproject = ModFeaturesHelpers.GetGithubProjectName(mod),
                title         = title,
                body          = body
            };
            string jsonStr = JsonConvert.SerializeObject(json, Formatting.Indented);

            byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonStr);

            Action <String> onResponse = (output) => {
                JObject respJson = JObject.Parse(output);
                //JToken data = respJson.SelectToken( "Data.html_url" );
                JToken msg = respJson.SelectToken("Msg");

                /*if( data != null ) {
                 *      string post_at_url = data.ToObject<string>();
                 *      if( !string.IsNullOrEmpty( post_at_url ) ) {
                 *              SystemHelpers.Start( post_at_url );
                 *      }
                 * }*/

                if (msg == null)
                {
                    onSuccess("Failure.");
                }
                else
                {
                    onSuccess(msg.ToObject <string>());
                }
            };

            Action <Exception, string> wrappedOnError = (Exception e, string str) => {
                LogHelpers.Log("!ModHelpers.PostGithubModIssueReports.ReportIssue - Failed for POST to " + url + " : " + jsonStr);
                onError(e, str);
            };

            NetHelpers.MakePostRequestAsync(url, jsonBytes, onResponse, wrappedOnError, onCompletion);
        }
Beispiel #3
0
        private static void DoWorkToValidateServer(ServerBrowserEntry server_data, string hash)
        {
            string hash_base = "";
            bool   found     = false;

            for (int i = 0; i < 1000000; i++)
            {
                hash_base = i + "";

                string test_hash = SystemHelpers.ComputeSHA256Hash(hash_base);
                if (hash == test_hash)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                LogHelpers.Log("Server browser processing failed; no matching hash.");
                return;
            }

            var output_obj = new ServerBrowserWorkProof {
                ServerIP  = server_data.ServerIP,
                Port      = server_data.Port,
                WorldName = server_data.WorldName,
                HashBase  = hash_base
            };

            string json_str = JsonConvert.SerializeObject(output_obj, Formatting.None);

            byte[] json_bytes = Encoding.UTF8.GetBytes(json_str);

            Thread.Sleep(1500);

            NetHelpers.MakePostRequestAsync(ServerBrowserReporter.URL, json_bytes, delegate(string output) {
                LogHelpers.Log("Server browser processing complete.");
            }, delegate(Exception e, string output) {
                LogHelpers.Log("Server browser reply returned error: " + e.ToString());
            });

            ServerBrowserReporter.LastSendTimestamp = SystemHelpers.TimeStampInSeconds();
        }
        ////////////////

        public static void AnnounceServer()
        {
            ServerBrowserMod mymod = ServerBrowserMod.Instance;
            Version          vers  = mymod.Version;

            int port = Netplay.ListenPort;
            //if( mymod.Config.ServerBrowserCustomPort != -1 ) {
            //	port = mymod.Config.ServerBrowserCustomPort;
            //}

            int pvp = 0;

            bool[] team_checks = new bool[10];
            ServerBrowserReporter server_browser = mymod.Reporter;

            for (int i = 0; i < Main.player.Length; i++)
            {
                Player player = Main.player[i];
                if (player == null || !player.active)
                {
                    continue;
                }

                if (player.hostile)
                {
                    pvp++;
                }
                team_checks[player.team] = true;
            }

            int team_count = 0;

            for (int i = 1; i < team_checks.Length; i++)
            {
                if (team_checks[i])
                {
                    team_count++;
                }
            }

            try {
                var server_data = new ServerBrowserEntry();
                server_data.ServerIP       = NetHelpers.GetPublicIP();
                server_data.Port           = port;
                server_data.IsPassworded   = Netplay.ServerPassword != "";
                server_data.Motd           = Main.motd;
                server_data.WorldName      = Main.worldName;
                server_data.WorldProgress  = InfoHelpers.GetVanillaProgress();
                server_data.WorldEvent     = string.Join(", ", InfoHelpers.GetCurrentVanillaEvents().ToArray());
                server_data.MaxPlayerCount = Main.maxNetPlayers;
                server_data.PlayerCount    = Main.ActivePlayersCount;
                server_data.PlayerPvpCount = pvp;
                server_data.TeamsCount     = team_count;
                server_data.AveragePing    = InfoHelpers.GetAveragePingOfServer();
                server_data.Mods           = new Dictionary <string, string>();
                server_data.Version        = (vers.Major * 1000000) + (vers.Minor * 10000) + (vers.Build * 100) + vers.Revision;

                foreach (Mod mod in ModLoader.LoadedMods)
                {
                    if (mod.File == null)
                    {
                        continue;
                    }
                    server_data.Mods[mod.DisplayName] = mod.Version.ToString();
                }

                string json_str   = JsonConvert.SerializeObject(server_data, Formatting.None);
                byte[] json_bytes = Encoding.UTF8.GetBytes(json_str);

                Action <string> on_response = delegate(string output) {
                    ServerBrowserReporter.HandleServerAnnounceOutputAsync(server_data, output);
                };
                Action <Exception, string> on_error = delegate(Exception e, string output) {
                    LogHelpers.Log("Server browser returned error: " + e.ToString());
                };

                NetHelpers.MakePostRequestAsync(ServerBrowserReporter.URL, json_bytes, on_response, on_error);

                ServerBrowserReporter.LastSendTimestamp = SystemHelpers.TimeStampInSeconds();
            } catch (Exception e) {
                LogHelpers.Log("AnnounceServer - " + e.ToString());
                return;
            }
        }