Esempio n. 1
0
        public static void ParseEndGameResults(int id)
        {
            jsonFormats.ValueGR result;
            try
            {
                string url    = "https://1xstavka.ru/LiveFeed/GetGameZip?id=" + id + "&lng=ru&partner=51";
                string strRes = Utilites.GetHTML(url);
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var obj = serializer.Deserialize <jsonFormats.GameResRootObj>(strRes);

                if (obj == null || obj.Value == null)
                {
                    return;
                }

                result = obj.Value;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return;
            }

            //if game wasn't finish
            if (!result.F)
            {
                return;
            }

            lock (Program.gamesLocker)
            {
                if (!Program.games.ContainsKey(id))
                {
                    return;
                }
                Game game = Program.games[id];
                game.isFinished = result.F || result.SC.TS == 3600;

                if (result.SC == null || result.SC.PS == null || result.SC.PS.Length == 0)
                {
                    return;
                }

                game.updTimeUNIX = Utilites.NowUNIX();
                game.gameTime    = result.SC.TS;

                game.teams[0].goals1T = result.SC.PS[0].Value.S1;
                game.teams[1].goals1T = result.SC.PS[0].Value.S2;

                game.teams[0].allGoals = result.SC.PS[0].Value.S1 + result.SC.PS[1].Value.S1;
                game.teams[1].allGoals = result.SC.PS[0].Value.S2 + result.SC.PS[1].Value.S2;

                Program.games[id] = game;
            }
        }
Esempio n. 2
0
        static void CompleteTask()
        {
            try
            {
                while (doOtherThreads)
                {
                    Task task;
                    lock (tasksLocker)
                    {
                        task = tasks[0];
                    }

                    int sleepTime = task.TimeUNIX - Utilites.NowUNIX();
                    if (sleepTime > 0)
                    {
                        Thread.Sleep(sleepTime * 1000);
                    }

                    try
                    {
                        task.Func(task.GameID);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }

                    lock (tasksLocker)
                    {
                        tasks.Remove(task);
                        if (tasks.Count == 0)
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Esempio n. 3
0
        public static void ParseLive()
        {
            if (lastLVParseTime.AddSeconds(5) > DateTime.Now)
            {
                return;
            }

            jsonFormats.ValueLV[] results;
            try
            {
                string url    = "https://1xstavka.ru/LiveFeed/Get1x2_VZip?sports=8&count=50&mode=4&country=1&partner=51&getEmpty=true";
                string strRes = Utilites.GetHTML(url);

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var obj = serializer.Deserialize <jsonFormats.LiveRootObj>(strRes);

                if (obj == null || obj.Value == null)
                {
                    return;
                }

                results = obj?.Value;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return;
            }

            for (int i = 0; i < results.Length; i++)
            {
                jsonFormats.ValueLV result = results[i];
                int  id = result.N;
                Game game;

                result.E = RebuidE_array(result.E);
                if (result.E == null)
                {
                    continue;
                }

                lock (Program.gamesLocker)
                {
                    if (!Program.games.ContainsKey(id))
                    {
                        continue;
                    }
                    game = Program.games[id];

                    game.startTimeUNIX = result.S;
                    game.updTimeUNIX   = Utilites.NowUNIX();
                    game.gameTime      = result.SC.TS;
                    if (result.E.Length < 10)
                    {
                        continue;
                    }

                    game.totalL = result.E[8].P;

                    if (result.E.Length > 13 && game.favTeam > -1)
                    {
                        if (game.favTeam == 0)
                        {
                            game.iTotalL  = result.E[10].P;
                            game.iTkfMore = result.E[10].C;
                            game.iTkfLess = result.E[11].C;
                        }
                        else
                        {
                            game.iTotalL  = result.E[12].P;
                            game.iTkfMore = result.E[12].C;
                            game.iTkfLess = result.E[13].C;
                        }
                    }

                    if (result.SC != null && result.SC.PS != null && result.SC.PS.Length > 0)
                    {
                        game.teams[0].goals1T = result.SC.PS[0].Value.S1;
                        game.teams[1].goals1T = result.SC.PS[0].Value.S2;
                    }

                    game.TkfMore = result.E[8].C;
                    game.TkfLess = result.E[9].C;

                    game.teams[0].name = result.O1;
                    game.teams[1].name = result.O2;

                    Program.games[id] = game;
                }
            }
            //
            if (results != null && results.Length > 0)
            {
                lastLVParseTime = DateTime.Now;
            }
        }
Esempio n. 4
0
        //Я понимаю, что весь код связанный с json нечитабелен, но json в
        //источнике минифицирован, поэтому я просто не знал, что делать
        public static void ParseLine(int ID = -1)
        {
            if (lastLNParseTime.AddSeconds(5) > DateTime.Now)
            {
                return;
            }

            Debug.Log("Проверяю страницу \"Линия\"");
            jsonFormats.ValueLN[] results;
            try
            {
                string url    = "https://1xstavka.ru/LineFeed/Get1x2_VZip?sports=8&count=50&mode=4&country=1&partner=51&getEmpty=true";
                string strRes = Utilites.GetHTML(url);

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var obj = serializer.Deserialize <jsonFormats.LineRootObj>(strRes);

                if (obj == null || obj.Value == null)
                {
                    return;
                }

                results = obj?.Value;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return;
            }

            for (int i = 0; i < results.Length; i++)
            {
                jsonFormats.ValueLN result = results[i];
                int  id = result.N;
                Game game;

                result.E = RebuidE_array(result.E);
                if (result.E == null)
                {
                    continue;
                }

                bool containsGame;
                lock (Program.gamesLocker)
                {
                    containsGame = Program.games.ContainsKey(id);
                    game         = containsGame ? Program.games[id] : new Game();

                    game.league        = result.L;
                    game.startTimeUNIX = result.S;
                    game.updTimeUNIX   = Utilites.NowUNIX();

                    if (result.E.Length < 10)
                    {
                        continue;
                    }

                    game.totalF  = result.E[8].P;
                    game.TkfMore = result.E[8].C;
                    game.TkfLess = result.E[9].C;

                    game.teams[0].name = result.O1;
                    game.teams[1].name = result.O2;

                    game.teams[0].kf = result.E[0].C;
                    game.teams[1].kf = result.E[2].C;

                    Program.games[id] = game;
                }
                if (game.startTimeUNIX < Utilites.NowUNIX() + 301)
                {
                    if (game.teams[0].kf > 0 && game.teams[0].kf <= 1.6)
                    {
                        game.favTeam = 0;
                    }
                    else if (game.teams[1].kf > 0 && game.teams[1].kf <= 1.6)
                    {
                        game.favTeam = 1;
                    }

                    if (result.E.Length > 13 && game.favTeam > -1)
                    {
                        game.iTotalF = result.E[12 + game.favTeam].P;
                    }

                    //Алгоритм, который проверяет и удаляет игру в конце
                    if (!game.deleteFuncIsActivated)
                    {
                        Task task = new Task
                        {
                            GameID   = id,
                            TimeUNIX = game.startTimeUNIX + 3660, //61 min
                            Func     = Algorithms.CheckOnTheEnd
                        };
                        TasksMgr.AddTask(task);
                        game.deleteFuncIsActivated = true;
                    }/*
                      * if (!game.algoritms[0].actived)
                      * {
                      * Task task = new Task
                      * {
                      *     GameID = id,
                      *     TimeUNIX = game.startTimeUNIX + 600, //10 min
                      *     Func = Algorithms.FirstAlg
                      * };
                      * TasksMgr.AddTask(task);
                      * game.algoritms[0].actived = true;
                      * }*/
                    if (!game.algoritms[1].actived)
                    {
                        Task task = new Task
                        {
                            GameID   = id,
                            TimeUNIX = game.startTimeUNIX + 300, //5 min
                            Func     = Algorithms.SecondAlg
                        };
                        TasksMgr.AddTask(task);
                        game.algoritms[1].actived = true;
                    }/*
                      * if (!game.algoritms[2].actived && game.favTeam >= 0)
                      * {
                      * Task task = new Task
                      * {
                      *     GameID = id,
                      *     TimeUNIX = game.startTimeUNIX + 1800, //30 min
                      *     Func = Algorithms.ThirdAlg
                      * };
                      * TasksMgr.AddTask(task);
                      * game.algoritms[2].actived = true;
                      * }*/
                }
                else if (!containsGame)
                {
                    int  rand = (int)(new Random().NextDouble() * 150);
                    Task task = new Task
                    {
                        GameID   = id,
                        TimeUNIX = game.startTimeUNIX - 300 + rand,
                        Func     = ParseLine
                    };
                    TasksMgr.AddTask(task);
                }
            }
            //
            if (results != null && results.Length > 0)
            {
                lastLNParseTime = DateTime.Now;
            }
        }
Esempio n. 5
0
        public static void SecondAlg(int id)
        {
            Parser.ParseLive();
            lock (Program.gamesLocker)
            {
                Game game = Program.games[id];

                if (game.gameTime > 1200) //20 min
                {
                    return;
                }

                bool ret = false;
                if (game.updTimeUNIX + 30 > Utilites.NowUNIX() && game.totalF * game.totalL > 0)
                {
                    string team1 = game.teams[0].name;
                    string team2 = game.teams[1].name;

                    Debug.Log("Проверка игры \"" + team1 + " - " + team2 + "\" на \"Тотал в 1 тайме\"");

                    if (game.teams[0].kf * game.teams[1].kf > 0)
                    {
                        team1 += " (" + game.teams[0].kf + ")";
                        team2 += " (" + game.teams[1].kf + ")";
                    }

                    double totalF     = Math.Round(game.totalF / 2);
                    double totalL     = Math.Round(game.totalL / 2);
                    double deltaTotal = totalL - totalF;
                    string recomend   = "";
                    if (deltaTotal >= 5)
                    {
                        recomend = "ТБ " + totalL + " - " + game.TkfLess;
                        Program.games[id].algoritms[1].sendedTotal = totalL;
                        Program.games[id].algoritms[1].tMore       = false;
                    }
                    else if (deltaTotal <= -4)
                    {
                        recomend = "ТМ " + totalL + " - " + game.TkfMore;
                        Program.games[id].algoritms[1].sendedTotal = totalL;
                        Program.games[id].algoritms[1].tMore       = true;
                    }

                    //Calculating rate
                    //
                    double rate = game.teams[0].goals1T + game.teams[1].goals1T;
                    //оставить 2 знака после запятой ииии 1800=30*60 из уравнения клиента
                    rate -= Math.Round(game.totalF * game.gameTime / 1800, 2);

                    string text = "#Signal_" + Params.LastSignalNumer
                                  + "\nАлгоритм - \"Тотал в 1 тайме\""
                                  + "\nЛига - \"" + game.league + "\""
                                  + "\nКоманда - \"" + team1 + " - " + team2 + "\""
                                  + "\nВремя - \"" + TimeSpan.FromSeconds(game.gameTime).ToString("mm\\:ss") + "\""
                                  + "\nСчёт - \"" + game.teams[0].goals1T + ":" + game.teams[1].goals1T + "\""
                                  + "\n"
                                  + "\nНачальный тотал -  \"" + totalF + "\""
                                  + "\n"
                                  + "\nТемп -  \"" + rate + "\""
                                  + "\nСейчас тотал -  \"" + totalL + "\""
                                  + "\nРазница тотала - \"" + deltaTotal + "\""
                                  + "\nРекомендую - \"" + recomend + "\"";

                    if (recomend.Length > 0)
                    {
                        ret = Telegram.SendMessagesFromAlgorithms(text, 2, id);
                    }
                }
                if (!ret)
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 25,
                        Func     = SecondAlg,
                        GameID   = id
                    });
                }
                else //if signal was succesful sended to anybody
                {
                    Params.LastSignalNumer++;
                }
            }
        }
Esempio n. 6
0
        public static void CheckOnTheEnd(int id)
        {
            Parser.ParseEndGameResults(id);

            lock (Program.gamesLocker)
            {
                Game game = Program.games[id];

                //if game wasn't finished
                if (!game.isFinished)
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 30,
                        Func     = CheckOnTheEnd,
                        GameID   = id
                    });
                    return;
                }
                //смайлы в Telegram
                string yes = Encoding.UTF8.GetString(new byte[] { 0xE2, 0x9C, 0x85 });
                string not = Encoding.UTF8.GetString(new byte[] { 0xE2, 0x9D, 0x8E });

                string   text;
                double   goals;
                Algoritm algoritm;
                //First algoritm
                algoritm = game.algoritms[0];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[0].allGoals + game.teams[1].allGoals;

                    if ((algoritm.tMore && goals > algoritm.sendedTotal) ||
                        (!algoritm.tMore && goals < algoritm.sendedTotal))
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    Debug.Log("Редактирую сообщения");

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }

                //Second algoritm
                algoritm = game.algoritms[1];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[0].goals1T + game.teams[1].goals1T;

                    if ((algoritm.tMore && goals > algoritm.sendedTotal) ||
                        (!algoritm.tMore && goals < algoritm.sendedTotal))
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }

                //Third algoritm
                algoritm = game.algoritms[2];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[game.favTeam - 1].goals1T;

                    if (goals > algoritm.sendedTotal)
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }


                Program.games.Remove(id);
            }
        }
Esempio n. 7
0
        public static void ThirdAlg(int id)
        {
            Parser.ParseLive();
            lock (Program.gamesLocker)
            {
                Game game = Program.games[id];
                if (game.gameTime < 1800)
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 1800 - game.gameTime,
                        Func     = ThirdAlg,
                        GameID   = id
                    });
                    return;
                }
                if (game.updTimeUNIX + 10 < Utilites.NowUNIX())
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 5,
                        Func     = ThirdAlg,
                        GameID   = id
                    });
                    return;
                }

                if (game.gameTime > 1810 && game.favTeam > -1 && game.iTotalF * game.iTotalL > 0)
                {
                    string team1 = game.teams[0].name;
                    string team2 = game.teams[1].name;

                    Debug.Log("Проверка игры \"" + team1 + " - " + team2 + "\" на \"Индивидуальный тотал Фаворита\"");

                    if (game.teams[0].kf * game.teams[1].kf > 0)
                    {
                        team1 += " (" + game.teams[0].kf + ")";
                        team2 += " (" + game.teams[1].kf + ")";
                    }

                    double totalMF = Math.Round(game.iTotalF / 2);
                    double totalML = Math.Round(game.iTotalL / 2);

                    double favGoalsAim = totalMF - 4;
                    double realGoals   = game.teams[game.favTeam].goals1T;

                    double totalL = game.iTotalL;

                    string favTeam  = game.teams[game.favTeam].name;
                    string recomend = "ТБ " + game.iTotalL + " - " + game.iTkfLess;

                    Program.games[id].algoritms[2].sendedTotal = game.iTotalL;
                    Program.games[id].algoritms[2].tMore       = true;

                    string text = "#Signal_" + Params.LastSignalNumer
                                  + "\nАлгоритм - \"Индивидуальный тотал Фаворита\""
                                  + "\nЛига - \"" + game.league + "\""
                                  + "\nКоманда - \"" + team1 + " - " + team2 + "\""
                                  + "\nВремя - \"" + TimeSpan.FromSeconds(game.gameTime).ToString("mm\\:ss") + "\""
                                  + "\nСчёт - \"" + game.teams[0].goals1T + ":" + game.teams[1].goals1T + "\""
                                  + "\n"
                                  + "\nНачальный тотал -  \"" + totalMF + "\""
                                  + "\n"
                                  + "\nСейчас тотал -  \"" + totalML + "\""
                                  + "\nФаворит - \"" + favTeam + "\""
                                  + "\nРекомендую - \"" + recomend + "\"";
                    if (realGoals <= favGoalsAim && totalL < totalMF + realGoals)
                    {
                        if (Telegram.SendMessagesFromAlgorithms(text, 3, id))
                        {
                            Params.LastSignalNumer++;
                        }
                    }
                }
            }
        }