예제 #1
0
        public static bool HTTPPostStartGame(string gameName, string session, gameSettings gameSettings)
        {
            MyPacket p = new MyPacket()
            {
                gameName = gameName, session = session, gameSettings = gameSettings
            };
            string serialized = JsonConvert.SerializeObject(p);

            Log.TraceMessage(Log.Nav.NavIn, "Serialized data: " + serialized, Log.LogType.Info);
            using (var client = new HttpClient())
            {
                try
                {
                    List <Task> allGames = new List <Task>();
                    //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IklMaWtlU29ja3NPblN1bmRheXMiLCJpZCI6Mywicm9sZSI6InVzZXIiLCJpYXQiOjE1NDE4NjY1NTcsImV4cCI6MTU0MjI5ODU1N30.XWaWB_cWhUFEC1m0GxFJ4ln8uq5h086gXGxRmOLVXA0");
                    allGames.Add(Task.Run(async() =>
                    {
                        var x = await client.PostAsync(
                            "http://127.0.0.1:3080/setup",
                            new StringContent(serialized, Encoding.UTF8, "application/json"));
                        Console.WriteLine(await x.Content.ReadAsStringAsync());
                        Log.TraceMessage(Log.Nav.NavIn, "Server Response Content: " + await x.Content.ReadAsStringAsync(), Log.LogType.Info);
                        Log.TraceMessage(Log.Nav.NavIn, "Server Response: " + x, Log.LogType.Info);
                    }));
                    Task.WaitAll(allGames.ToArray());
                    return(true);
                }
                catch (Exception ex)
                {
                    string idk = ex.Message;
                    Log.TraceMessage(Log.Nav.NavIn, "Except: " + idk, Log.LogType.Info);
                    return(false);
                }
            }
        }
예제 #2
0
파일: HTTP.cs 프로젝트: TehPers/TheArena
        public static void HTTPPost(string status, string winReason, string loseReason, string logURL, string winnerTeamName, string winnerVersion, string loserTeamName, string loserVersion)
        {
            /*winReason=winReason.Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "");
             * winReason = winReason.Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "");
             * winReason = winReason.Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "");
             * loseReason =loseReason.Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "");
             * loseReason = loseReason.Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "");
             * loseReason = loseReason.Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "");
             * status =status.Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "");
             * status = status.Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "");
             * status = status.Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "");
             * logURL =logURL.Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "").Replace("\"", "");
             * logURL = logURL.Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "").Replace("\n", "");
             * logURL = logURL.Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "").Replace("\r", "");
             * string myJson =
             *  "{" +
             *  "\"status\": \"" + status + "\"," +
             *  "\"winReason\": \"" + winReason + "\"," +
             *  "\"loseReason\": \"" + loseReason + "\"," +
             *  "\"logUrl\": \"" + logURL + "\"," +
             *  "\"winner\": {" +
             *      "\"teamName\":\"" + winnerTeamName + "\"," +
             *      "\"version\":\"" + winnerVersion + "\"" +
             *  "}," +
             *  "\"loser\": {" +
             *      "\"teamName\":\"" + loserTeamName + "\"," +
             *      "\"version\":\"" + loserVersion + "\"" +
             *  "}" +
             *  "}";*/
            MyPacket p = new MyPacket()
            {
                status = status, loseReason = loseReason, winReason = winReason, logUrl = logURL, winner = new Winner()
                {
                    teamName = winnerTeamName, version = winnerVersion
                }, loser = new Loser()
                {
                    teamName = loserTeamName, version = loserVersion
                }
            };
            string serialized = JsonConvert.SerializeObject(p);

            Console.WriteLine(serialized);
            using (var client = new HttpClient())
            {
                try
                {
                    List <Task> allGames = new List <Task>();
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IklMaWtlU29ja3NPblN1bmRheXMiLCJpZCI6Mywicm9sZSI6InVzZXIiLCJpYXQiOjE1NDE4NjY1NTcsImV4cCI6MTU0MjI5ODU1N30.XWaWB_cWhUFEC1m0GxFJ4ln8uq5h086gXGxRmOLVXA0");
                    allGames.Add(Task.Run(() => client.PostAsync(
                                              "https://mmai-server.siggame.io/games/",
                                              new StringContent(serialized, Encoding.UTF8, "application/json"))));
                    Task.WaitAll(allGames.ToArray());
                }
                catch (Exception ex)
                {
                    string idk = ex.Message;
                }
            }
        }
예제 #3
0
        public static void HTTPPostSendToWeb(string status, string winReason, string loseReason, string logURL, string winnerTeamName, string winnerVersion, string loserTeamName, string loserVersion)
        {
            int intWinnerVersion;
            int intLoserVersion;

            try{
                intWinnerVersion = Int32.Parse(winnerVersion);
            }
            catch (System.FormatException e) {
                intWinnerVersion = 1;
            }

            try{
                intLoserVersion = Int32.Parse(loserVersion);
            }
            catch (System.FormatException e) {
                intLoserVersion = 1;
            }

            MyPacket p = new MyPacket()
            {
                status = status, loseReason = loseReason, winReason = winReason, logUrl = logURL, winner = new Winner()
                {
                    teamName = winnerTeamName, version = intWinnerVersion
                }, loser = new Loser()
                {
                    teamName = loserTeamName, version = intLoserVersion
                }
            };
            string serialized = JsonConvert.SerializeObject(p);

            Console.WriteLine("KEVIN: " + serialized);
            using (var client = new HttpClient())
            {
                try
                {
                    List <Task> allGames = new List <Task>();
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IlNldGhBZG1pbiIsImlkIjo0LCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE1NTUwMjU0NDQsImV4cCI6MTU1NTQ1NzQ0NH0.m4bOU5k5hH2YTnDT0094oDA1XDHxsQqMxNkSQQFCaHE");
                    allGames.Add(Task.Run(() => client.PostAsync(
                                              "https://mmai-server.siggame.io/games/",
                                              new StringContent(serialized, Encoding.UTF8, "application/json"))));
                    Task.WaitAll(allGames.ToArray());
                }
                catch (Exception ex)
                {
                    string idk = ex.Message;
                }
            }
        }