Ejemplo n.º 1
0
        /// <summary>
        /// Parses a Byte Array at a specific location, and builds a Packet.
        /// </summary>
        /// <param name="buffer">The Array of Bytes</param>
        /// <param name="indx">The Start Index</param>
        /// <param name="count">The number of Bytes to process</param>
        /// <returns></returns>
        static public HTTPMessage ParseByteArray(byte[] buffer, int indx, int count)
        {
            HTTPMessage  TheMessage = new HTTPMessage();
            UTF8Encoding UTF8       = new UTF8Encoding();
            String       TempData   = UTF8.GetString(buffer, indx, count);
            DText        parser     = new DText();
            String       TempString;

            int idx = TempData.IndexOf("\r\n\r\n");

            if (idx < 0)
            {
                return(null);
            }
            TempData = TempData.Substring(0, idx);

            parser.ATTRMARK = "\r\n";
            parser.MULTMARK = ":";
            parser[0]       = TempData;
            string CurrentLine = parser[1];

            DText HdrParser = new DText();

            HdrParser.ATTRMARK = " ";
            HdrParser.MULTMARK = "/";
            HdrParser[0]       = CurrentLine;

            if (CurrentLine.ToUpper().StartsWith("HTTP/") == true)
            {
                TheMessage.ResponseCode = int.Parse(HdrParser[2]);
                int s1 = CurrentLine.IndexOf(" ");
                s1 = CurrentLine.IndexOf(" ", s1 + 1);
                TheMessage.ResponseData = HTTPMessage.UnEscapeString(CurrentLine.Substring(s1));
                try
                {
                    TheMessage.Version = HdrParser[1, 2];
                }
                catch (Exception ex)
                {
                    OpenSource.Utilities.EventLogger.Log(ex);
                    TheMessage.Version = "0.9";
                }
            }
            else
            {
                TheMessage.Directive = HdrParser[1];
                TempString           = CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1);
                if (TempString.ToUpper().StartsWith("HTTP/") == false)
                {
                    TheMessage.Version      = "0.9";
                    TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(TempString);
                }
                else
                {
                    TheMessage.Version = TempString.Substring(TempString.IndexOf("/") + 1);
                    int fs = CurrentLine.IndexOf(" ") + 1;
                    TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(CurrentLine.Substring(
                                                                             fs,
                                                                             CurrentLine.Length - fs - TempString.Length - 1));
                }
            }
            String Tag     = "";
            String TagData = "";

            for (int line = 2; line <= parser.DCOUNT(); ++line)
            {
                if (Tag != "" && parser[line, 1].StartsWith(" "))
                {
                    TagData = parser[line, 1].Substring(1);
                }
                else
                {
                    Tag     = parser[line, 1];
                    TagData = "";
                    for (int i = 2; i <= parser.DCOUNT(line); ++i)
                    {
                        if (TagData == "")
                        {
                            TagData = parser[line, i];
                        }
                        else
                        {
                            TagData = TagData + parser.MULTMARK + parser[line, i];
                        }
                    }
                }
                TheMessage.AppendTag(Tag, TagData);
            }
            int cl = 0;

            if (TheMessage.HasTag("Content-Length"))
            {
                try
                {
                    cl = int.Parse(TheMessage.GetTag("Content-Length"));
                }
                catch (Exception ex)
                {
                    OpenSource.Utilities.EventLogger.Log(ex);
                    cl = -1;
                }
            }
            else
            {
                cl = -1;
            }

            byte[] tbuffer;
            if (cl > 0)
            {
                tbuffer = new byte[cl];
                if ((idx + 4 + cl) > count)
                {
                    // NOP
                }
                else
                {
                    Array.Copy(buffer, idx + 4, tbuffer, 0, cl);
                    TheMessage.DataBuffer = tbuffer;
                }
            }
            if (cl == -1)
            {
                tbuffer = new Byte[count - (idx + 4)];
                Array.Copy(buffer, idx + 4, tbuffer, 0, tbuffer.Length);
                TheMessage.DataBuffer = tbuffer;
            }
            if (cl == 0)
            {
                TheMessage.DataBuffer = new byte[0];
            }
            return(TheMessage);
        }
Ejemplo n.º 2
0
    public void ReadNode(string Key)
    {
        HideChoiceButtons();

        GameManager.GetComponent <StatManager> ().ClearDebugUI();

        Node myNode;

        if (Suivant)
        {
            Suivant = false;
            Key     = Suivant_Node;
        }

        LastNode.GetNext().TryGetValue(Key, out myNode);

        UI_Text_Main.GetComponent <TypewritingScript> ().TypeWrite(myNode.content);
        int local = 0;

        LastNode = myNode;


        string Local_StatName;
        string TempStringDeux;
        int    Local_StatChangeValue;

        string[] TempArray;

        foreach (string LocalTag in myNode.Tags)
        {
            if (LocalTag.Length > 0)
            {
                TempArray      = LocalTag.Split(":" [0]);
                Local_StatName = TempArray [0];

                if (TempArray [1].Contains("="))
                {
                    TempStringDeux = TempArray [1].Replace("=", "");
                }
                else
                {
                    TempStringDeux = TempArray [1];
                }
                //Debug.Log (TempStringDeux);
                Local_StatChangeValue = int.Parse(TempStringDeux);
                StatManager.ins.ModifyStatValue(Local_StatName, Local_StatChangeValue);
            }
            else
            {
                GameManager.GetComponent <StatManager> ().ChangePersoName(0);
                //Debug.Log ("Empty Tags");
            }
        }
        foreach (Node n in myNode.GetNext().Values)
        {
            autoCondition = true;
            string CleanText;
            CleanText = n.choiceText;
            int tempBool = 0;
            if (n.choiceText.Contains("{"))
            {
                autoCondition = false;

                string output;
                output = n.choiceText.Split(new char[] { '{', '}' }) [1];

                string[]    conditions;
                string[]    TempArrayConditions_1;
                string[]    tempCleanText;
                List <bool> ListOfBool = new List <bool> ();
                conditions    = output.Split(";" [0]);
                tempCleanText = n.choiceText.Split("{" [0]);
                CleanText     = tempCleanText [0];

                foreach (string condition in conditions)
                {
                    string varName;
                    string TempString;
                    string signe;
                    string valueString;
                    int    value;
                    TempArrayConditions_1 = condition.Split(":" [0]);
                    varName     = TempArrayConditions_1 [0];
                    TempString  = TempArrayConditions_1 [1];
                    signe       = TempString.Substring(0, 1);
                    valueString = TempString.Substring(1, TempString.Length - 1);
                    value       = int.Parse(valueString);

                    ListOfBool.Add(GameManager.GetComponent <StatManager> ().CompareValue(varName, signe, value));
                    //Debug.Log ("Nom var: " + varName + " Signe: " + signe + " Valeur: " + value);
                }

                foreach (bool l in ListOfBool)
                {
                    if (l == false)
                    {
                        tempBool++;
                        //Debug.Log ("Something is false");
                    }
                }
            }
            if (tempBool != 0)
            {
                autoCondition = false;
            }
            else
            {
                autoCondition = true;
            }

            if (CleanText.Contains("("))
            {
                string[] TempArrayCleaner;
                TempArrayCleaner = CleanText.Split("(" [0]);
                CleanText        = TempArrayCleaner [0];
            }

            if (local == 4 && autoCondition)
            {
                UI_Text_Button5.transform.parent.gameObject.SetActive(true);
                UI_Text_Button5.GetComponent <TextRead> ().ShowText_External(CleanText);
                UI_Button5.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);
                //Debug.Log ("Max Choices Reached");
            }
            if (local == 3 && autoCondition)
            {
                UI_Text_Button4.transform.parent.gameObject.SetActive(true);
                UI_Text_Button4.GetComponent <TextRead> ().ShowText_External(CleanText);
                UI_Button4.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);
                local = 4;
            }
            if (local == 2 && autoCondition)
            {
                UI_Text_Button3.transform.parent.gameObject.SetActive(true);
                UI_Text_Button3.GetComponent <TextRead> ().ShowText_External(CleanText);
                UI_Button3.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);
                local = 3;
            }
            if (local == 1 && autoCondition)
            {
                UI_Text_Button2.transform.parent.gameObject.SetActive(true);
                UI_Text_Button2.GetComponent <TextRead> ().ShowText_External(CleanText);
                UI_Button2.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);
                local = 2;
            }

            if (local == 0 && autoCondition)
            {
                if (n.choiceText.Contains("Suivant") || n.choiceText.Contains("suivant"))
                {
                    Suivant      = true;
                    Suivant_Node = n.choiceText;
                    UI_Text_Button1.GetComponent <TextRead> ().ShowText_External("Suivant");
                }
                else
                {
                    UI_Text_Button1.GetComponent <TextRead> ().ShowText_External(CleanText);
                }
                UI_Text_Button1.transform.parent.gameObject.SetActive(true);
                UI_Button1.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);

                local = 1;
            }
        }
    }
        public static List <int> ReadInFromFile()
        {
            string TempString;
            string VirtAddWidthString    = "Null";
            string TLBEntriesString      = "Null";
            string TLBOrganizationString = "Null";
            string PageSizeString        = "Null";
            string PhysAddWidthString    = "Null";
            string L1BlocksString        = "Null";
            string L1BlockSizeString     = "Null";
            string L1OrgString           = "Null";

            int VirtAddWidth    = -1;
            int TLBEntries      = -1;
            int TLBOrganization = -1;
            int PageSize        = -1;
            int PhysAddWidth    = -1;
            int L1Blocks        = -1;
            int L1BlockSize     = -1;
            int L1Org           = -1;

            List <int> ValuesFromFileList = new List <int>();

            try
            {
                StreamReader sr = new StreamReader("info.txt");
                TempString         = sr.ReadLine();
                VirtAddWidthString = TempString.Substring(22);
                VirtAddWidth       = int.Parse(VirtAddWidthString);

                TempString       = sr.ReadLine();
                TLBEntriesString = TempString.Substring(12);
                TLBEntries       = int.Parse(TLBEntriesString);

                TempString            = sr.ReadLine();
                TLBOrganizationString = TempString.Substring(17);
                if (TLBOrganizationString.Contains("8"))
                {
                    TLBOrganization = 8;
                }
                else if (TLBOrganizationString.Contains("2"))
                {
                    TLBOrganization = 2;
                }
                else if (TLBOrganizationString.Contains("4"))
                {
                    TLBOrganization = 4;
                }
                else if (TLBOrganizationString.Contains("16"))
                {
                    TLBOrganization = 16;
                }

                TempString     = sr.ReadLine();
                PageSizeString = TempString.Substring(10);
                PageSize       = int.Parse(PageSizeString);

                TempString         = sr.ReadLine();
                PhysAddWidthString = TempString.Substring(23);
                PhysAddWidth       = int.Parse(PhysAddWidthString);

                TempString     = sr.ReadLine();
                L1BlocksString = TempString.Substring(10);
                L1Blocks       = int.Parse(L1BlocksString);

                TempString        = sr.ReadLine();
                L1BlockSizeString = TempString.Substring(14);
                L1BlockSize       = int.Parse(L1BlockSizeString);

                TempString  = sr.ReadLine();
                L1OrgString = TempString.Substring(16);
                if (L1OrgString.Contains("2"))
                {
                    L1Org = 2;
                }
                else if (L1OrgString.Contains("4"))
                {
                    L1Org = 4;
                }
                else if (L1OrgString.Contains("8"))
                {
                    L1Org = 8;
                }
                else if (L1OrgString.Contains("16"))
                {
                    L1Org = 16;
                }

                ValuesFromFileList.Add(VirtAddWidth);
                ValuesFromFileList.Add(TLBEntries);
                ValuesFromFileList.Add(TLBOrganization);
                ValuesFromFileList.Add(PageSize);
                ValuesFromFileList.Add(PhysAddWidth);
                ValuesFromFileList.Add(L1Blocks);
                ValuesFromFileList.Add(L1BlockSize);
                ValuesFromFileList.Add(L1Org);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(ValuesFromFileList);
        }
Ejemplo n.º 4
0
        static string GameResult(List <Socket> UsersSockets, ref List <Player> PlayerList)
        {
            Combinations Rang       = 0;
            List <int>   HeightList = new List <int>();
            Player       Win        = new Player();
            string       Viner      = String.Empty;

            //string Viners = String.Empty;

            for (int l = 0; l < PlayerList.Count; l = l + 1)
            {
                if (!PlayerList[l].fold)
                {
                    string bufStr, TempString;
                    bufStr = PlayerList[l].table + PlayerList[l].card1 + PlayerList[l].card2;
                    for (int t = 0; t < bufStr.Length; t = t + 2)
                    {
                        for (int o = t + 2; o + 2 + t < bufStr.Length; o = o + 2)
                        {
                            TempString = bufStr.Substring(0, t) + bufStr.Substring(t + 2, t + o - t - 2) + bufStr.Substring(t + 2 + o, bufStr.Length - t - o - 2);



                            Char[] charArray = TempString.ToCharArray();
                            for (int j = 0; j < charArray.Length; j++)
                            {
                                if (charArray[j].Equals('T'))
                                {
                                    charArray[j] = (char)59;
                                }
                                if (charArray[j].Equals('J'))
                                {
                                    charArray[j] = (char)60;
                                }
                                if (charArray[j].Equals('Q'))
                                {
                                    charArray[j] = (char)61;
                                }
                                if (charArray[j].Equals('K'))
                                {
                                    charArray[j] = (char)62;
                                }
                                if (charArray[j].Equals('A'))
                                {
                                    charArray[j] = (char)63;
                                }
                            }
                            for (int j = 0; j < charArray.Length; j = j + 2)
                            {
                                for (int k = 0; k < charArray.Length - 3; k = k + 2)
                                {
                                    if (charArray[k] > charArray[k + 2])
                                    {
                                        Char buf = charArray[k + 2];
                                        charArray[k + 2] = charArray[k];
                                        charArray[k]     = buf;
                                        buf = charArray[k + 1];
                                        charArray[k + 1] = charArray[k + 3];
                                        charArray[k + 3] = buf;
                                    }
                                }
                            }


                            bool flash     = false;
                            bool streight  = false;
                            bool kare      = false;
                            bool fullhouse = false;
                            bool tree      = false;
                            bool twopairs  = false;
                            bool highcard  = true;
                            bool pair      = false;

                            int[] len = new int[2] {
                                1, 0
                            };                               //Для отслеживания двух пар и фулхауса
                            int num = 0;

                            for (int i = 2; i < charArray.Length; i = i + 2)
                            {
                                if (charArray[i] == charArray[i - 2])
                                {
                                    len[num]++;
                                }
                                else
                                if ((len[num] > 1) && (num != 1))
                                {
                                    num++;
                                    len[num]++;
                                }
                                else if (len[num] <= 1)
                                {
                                    len[num] = 1;
                                }
                            }


                            //Работаем с полной комбинацией

                            //Проверка на флеш
                            flash = true;
                            for (int i = 3; i < charArray.Length; i = i + 2)
                            {
                                if (charArray[i] != (charArray[1]))
                                {
                                    flash = false;
                                    break;
                                }
                            }

                            //Проверка на стрит
                            streight = true;
                            for (int i = 2; i < charArray.Length; i++)
                            {
                                if ((charArray[i - 2] - charArray[i] != 1) && (charArray[i - 2] - charArray[i] != 9))
                                {
                                    streight = false;
                                    break;
                                }
                            }

                            if ((len[0] == 2) || (len[1] == 2))
                            {
                                pair = true;
                            }
                            if ((len[0] == 3) || (len[1] == 3))
                            {
                                tree = true;
                            }
                            if ((len[0] == 2) && (len[1] == 2))
                            {
                                twopairs = true;
                            }
                            if (((len[0] == 2) && (len[1] == 3)) || ((len[0] == 3) && (len[1] == 2)))
                            {
                                fullhouse = true;
                            }
                            if (len[0] == 4)
                            {
                                kare = true;
                            }



                            if (streight && flash)
                            {
                                if (Rang < (Combinations)9)
                                {
                                    Rang  = (Combinations)9;
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Win   = PlayerList[l];
                                }
                            }
                            if (streight)
                            {
                                if (Rang < (Combinations)5)
                                {
                                    Rang  = (Combinations)5;
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Win   = PlayerList[l];
                                }
                            }
                            if (flash)
                            {
                                if (Rang < (Combinations)6)
                                {
                                    Rang  = (Combinations)6;
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Win   = PlayerList[l];
                                }
                            }
                            if (kare)
                            {
                                if (Rang < (Combinations)8)
                                {
                                    Rang  = (Combinations)8;
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Win   = PlayerList[l];
                                }
                            }
                            if (fullhouse)
                            {
                                if (Rang < (Combinations)7)
                                {
                                    Rang  = (Combinations)7;
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Win   = PlayerList[l];
                                }
                            }
                            if (twopairs)
                            {
                                if (Rang < (Combinations)3)
                                {
                                    Rang  = (Combinations)3;
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Win   = PlayerList[l];
                                }
                            }
                            if (tree)
                            {
                                if (Rang < (Combinations)4)
                                {
                                    Rang  = (Combinations)4;
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Win   = PlayerList[l];
                                }
                            }
                            if (pair)
                            {
                                if (Rang < (Combinations)2)
                                {
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Rang  = (Combinations)2;
                                    Win   = PlayerList[l];
                                }
                            }
                            if (highcard)
                            {
                                if (Rang < (Combinations)1)
                                {
                                    Rang  = (Combinations)1;
                                    Viner = TempString + "_" + PlayerList[l].login;
                                    Win   = PlayerList[l];
                                }
                            }
                        }
                    }
                }
            }
            Win.money += AllMoney;
            Win.fold   = false;
            return(Viner + "-" + Rang.ToString());
        }