예제 #1
0
파일: Program.cs 프로젝트: uvbs/CSGO.Report
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, ev) =>
            {
                try
                {
                    Logger.Fatal(ev.ExceptionObject);
                }
                catch { }
            };
            if (Environment.OSVersion.Platform == PlatformID.Unix && File.Exists("System.Net.Http.dll"))
            {
                File.Delete("System.Net.Http.dll");
            }
            Logger.Init("medusa");
            Logger.Info("Medusa Report Server " + Assembly.GetExecutingAssembly().GetName().Version + "(" + Server.ServerVersionName + ")");
            // Logger.Info("Build date: " + Logger.GetBuildTime());
            Logger.EnableDebug = config.GetBool("LogDebug", false);
            Logger.EnableColor = config.GetBool("LogColor", true);
            if (config.GetBool("SteamKitDebug", false))
            {
                DebugLog.Enabled = true;
                DebugLog.AddListener(new DebugListener());
            }
            if (config.GetBool("MailClientEnabled", false))
            {
                mailClient = new MailClient();
            }
            if (config["AccessKey", ""] == "")
            {
                Logger.Warning("Access key is empty,this means nobody can access the webapi.");
            }
            else
            {
                AccessKey = config["AccessKey"];
                Logger.Info("Access key read successfully(Length:" + AccessKey.Length + ").");
            }
            if (config.GetInt("ServerPort", 23336) > 0)
            {
                Logger.Info("Starting Medusa Web Server...");
                web_server = new MedusaWebServer((short)config.GetInt("ServerPort"), config["ServerAddress", "localhost"]);
                web_server.Start();
            }
            if (!File.Exists(config["AccountsFile", "accounts.json"]))
            {
                File.WriteAllText(config["AccountsFile"], "[]");
            }
            if (!config.GetBool("GameAlwaysOnline", false))
            {
                try
                {
                    var parse = config["GameOnlineStart", "9:00:00"].Split(':');
                    OnlineStart = new TimeSpan(int.Parse(parse[0]), parse.Length >= 2 ? int.Parse(parse[1]) : 0, parse.Length >= 3 ? int.Parse(parse[2]) : 0);
                    parse       = config["GameOnlineEnd", "22:00:00"].Split(':');
                    OnlineEnd   = new TimeSpan(int.Parse(parse[0]), parse.Length >= 2 ? int.Parse(parse[1]) : 0, parse.Length >= 3 ? int.Parse(parse[2]) : 0);
                }
                catch
                {
                    Logger.Error("Can't parse game online time range.");
                    OnlineStart = new TimeSpan(9, 0, 0);
                    OnlineEnd   = new TimeSpan(22, 0, 0);
                }
            }
            accountManager = new AccountManager(File.ReadAllText(config["AccountsFile"]));
            Properties.Resources.Whitelist.Split('\n').ToList().ForEach((id) =>
            {
                if (!id.StartsWith("#"))
                {
                    try
                    {
                        AccountManager.Whitelist.Add(SteamIdUtil.Parse(id.Split(',')[0]).ConvertToUInt64());
                    }
                    catch { }
                }
            });
            Logger.Info("Starting login progress...");
            accountManager.DelayedConnectAll();
            File.WriteAllText("server.pid", Process.GetCurrentProcess().Id.ToString());
            Logger.Info("Enter Main Loop...");
            long currentTick = 0;

            while (true)
            {
                Thread.Sleep(50);
                accountManager.Tick(currentTick++);
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: uvbs/CSGO.Report
        public static void ProcessSubmitReport(HttpListenerContext context, IDictionary <string, string> data)
        {
            IDictionary <string, object> result = new Dictionary <string, object>()
            {
                { "success", false }
            };

            if (!data.ContainsKey("id") || !data.ContainsKey("match") || !data.ContainsKey("account") || !data.ContainsKey("flags") || !int.TryParse(data["flags"], out int flags))
            {
                result["message"] = "参数错误";
            }
            else if (!data["account"].Split(',').All(accountManager.Accounts.ContainsKey))
            {
                result["message"] = "账户不存在";
            }
            else
            {
                SteamID steamID = SteamIdUtil.Parse(data["id"]);
                ulong   matchID = 0;
                if (data["match"].StartsWith("steam://"))
                {
                    matchID = ShareCode.Decode(data["match"].Substring(61)).MatchId;
                }
                else if (data["match"].StartsWith("CSGO-"))
                {
                    matchID = ShareCode.Decode(data["match"]).MatchId;
                }
                else
                {
                    ulong.TryParse(data["match"], out matchID);
                }
                if (steamID != null)
                {
                    if (matchID == 0)
                    {
                        result["message"] = "请提供有效的Match ID.";
                    }
                    else if (AccountManager.IsWhitelisted(steamID))
                    {
                        result["message"] = "举报目标在我们的白名单中,这通常说明举报目标不会作弊或是我们的机器人账号之一.";
                    }
                    else
                    {
                        var info = new ReportInfo()
                        {
                            SteamID      = steamID,
                            MatchID      = matchID,
                            AbusiveText  = (flags & FLAG_ABUSIVE_TEXT) == FLAG_ABUSIVE_TEXT,
                            AbusiveVoice = (flags & FLAG_ABUSIVE_VOICE) == FLAG_ABUSIVE_VOICE,
                            Griefing     = (flags & FLAG_GRIEFING) == FLAG_GRIEFING,
                            AimHacking   = (flags & FLAG_AIM_HACKING) == FLAG_AIM_HACKING,
                            WallHacking  = (flags & FLAG_WALL_HACKING) == FLAG_WALL_HACKING,
                            OtherHacking = (flags & FLAG_OTHER_HACKING) == FLAG_OTHER_HACKING
                        };
                        var submitted = data["account"].Split(',');
                        var accounts  = accountManager.Accounts.Where((kv) => submitted.Contains(kv.Key));
                        foreach (var kv in accounts)
                        {
                            kv.Value.QueueAction(info);
                        }
                        result["matchid"] = matchID;
                        result["success"] = true;
                        result["message"] = "Abusive Text:" + info.AbusiveText + "<br />" +
                                            "Abusive Voice:" + info.AbusiveVoice + "<br />" +
                                            "Griefing:" + info.Griefing + "<br />" +
                                            "Aim Hacking:" + info.AimHacking + "<br />" +
                                            "Wall Hacking:" + info.WallHacking + "<br />" +
                                            "Other Hacking:" + info.OtherHacking;
                    }
                }
                else
                {
                    result["message"] = "无法解析Steam ID,请提供有效的SteamID,SteamID3或SteamID64.";
                }
            }
            Server.SendResult(context, Body: JsonConvert.SerializeObject(result));
        }