Ejemplo n.º 1
0
        TimeStringInfo GetGoodTimeStringInfo()
        {
            long time = 0;

            if (fin.HasValue)
            {
                time = fin.Value.Value.time;
            }
            var tmpNames = new DemoNames();

            tmpNames.setNamesByPlayerInfo(kPlayer);

            if (time > 0)
            {
                for (int i = 0; i < timeStrings.Count; i++)
                {
                    if (!string.IsNullOrEmpty(timeStrings[i].oName))
                    {
                        var sameName = (timeStrings[i].oName == tmpNames.uName || timeStrings[i].oName == tmpNames.dfName);
                        if (timeStrings[i].time.TotalMilliseconds == time && sameName)
                        {
                            return(timeStrings[i]);
                        }
                    }
                    else
                    {
                        if (timeStrings[i].time.TotalMilliseconds == time)
                        {
                            return(timeStrings[i]);
                        }
                    }
                }
            }
            else
            {
                var userStrings = timeStrings.Where(x => !string.IsNullOrEmpty(x.oName) &&
                                                    (x.oName == tmpNames.uName || x.oName == tmpNames.dfName)).ToList();
                if (userStrings.Count > 0)
                {
                    return(Ext.MinOf(userStrings, x => (long)x.time.TotalMilliseconds));
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        //We get the filled demo from the full raw information pulled from the demo
        public static Demo GetDemoFromRawInfo(RawInfo raw)
        {
            var file = new FileInfo(raw.demoPath);

            var frConfig = raw.getFriendlyInfo();

            Demo demo = new Demo();

            demo.rawInfo = raw;

            //file
            demo.file = file;
            if (frConfig.Count == 0 || !frConfig.ContainsKey(RawInfo.keyClient))
            {
                demo.hasError = true;
                demo.isBroken = true;
                return(demo);
            }

            //config names
            var names = new DemoNames();

            names.setNamesByPlayerInfo(Ext.GetOrNull(frConfig, RawInfo.keyPlayer));

            //time from triggers
            if (raw.fin.HasValue)
            {
                demo.time        = TimeSpan.FromMilliseconds(raw.fin.Value.Value.time);
                demo.hasTr       = raw.fin.Value.Key > 1;
                demo.triggerTime = true;
            }

            var timestrings = raw.timeStrings;

            var fastestTimeString = getFastestTimeStringInfo(timestrings, names);

            if (demo.time.TotalMilliseconds > 0)
            {
                var date = timestrings.LastOrDefault(x => x.recordDate != null);
                demo.recordTime = date?.recordDate;
            }
            else
            {
                //time from commands
                if (fastestTimeString != null)
                {
                    demo.time       = fastestTimeString.time;
                    demo.recordTime = fastestTimeString.recordDate;

                    var user = raw.getPlayerInfoByPlayerName(fastestTimeString.oName);
                    if (user != null)
                    {
                        names.setNamesByPlayerInfo(user);
                    }
                }
            }
            if (fastestTimeString != null)
            {
                names.setOnlineName(fastestTimeString.oName);
            }

            var filename       = demo.normalizedFileName;
            var countryAndName = getNameAndCountry(filename);

            if (Ext.ContainsAny(countryAndName, tasTriggers))
            {
                demo.isTas = true;
                foreach (string tasFlag in tasTriggers)
                {
                    countryAndName = removeSubstr(countryAndName, tasFlag);
                }
            }
            var countryNameParsed = tryGetNameAndCountry(countryAndName, names);

            //fle name
            names.setBracketsName(countryNameParsed.Key);   //name from the filename

            demo.playerName = names.chooseNormalName();

            //demo has not info about country, so take it from filename
            demo.country = countryNameParsed.Value;

            //at least some time (from name of demo)
            if (demo.time.TotalMilliseconds > 0)
            {
                demo.rawTime = true;
            }
            else
            {
                var demoNameTime = tryGetTimeFromFileName(filename);
                if (demoNameTime != null)
                {
                    demo.time = demoNameTime.Value;
                }
            }

            //Map
            var mapInfo = raw.rawConfig.ContainsKey(Q3Const.Q3_DEMO_CFG_FIELD_MAP) ? raw.rawConfig[Q3Const.Q3_DEMO_CFG_FIELD_MAP] : "";
            var mapName = Ext.GetOrNull(frConfig[RawInfo.keyClient], "mapname");

            //If in mapInfo the name of the same map is written, then we take the name from there
            if (mapName.ToLowerInvariant().Equals(mapInfo.ToLowerInvariant()))
            {
                demo.mapName = mapInfo;
            }
            else
            {
                demo.mapName = mapName.ToLowerInvariant();
            }

            //tas
            var modPhysic = getModPhysic(filename);

            if (modPhysic != null && Ext.ContainsAny(modPhysic, tasTriggers))
            {
                demo.isTas = true;
            }

            //Gametype
            var gInfo = raw.gameInfo;

            if (gInfo.isDefrag)
            {
                if (!string.IsNullOrEmpty(gInfo.modType))
                {
                    demo.modphysic = string.Format("{0}.{1}.{2}", gInfo.gameTypeShort, gInfo.gameplayTypeShort, gInfo.modType);
                }
                else
                {
                    demo.modphysic = string.Format("{0}.{1}", gInfo.gameTypeShort, gInfo.gameplayTypeShort);
                }
            }
            else
            {
                demo.modphysic = string.Format("{0}.{1}", gInfo.gameNameShort, gInfo.gameTypeShort);
            }

            if (demo.hasTr)
            {
                demo.modphysic = string.Format("{0}.{1}", demo.modphysic, "tr");
            }
            if (demo.isTas)
            {
                demo.modphysic = string.Format("{0}.{1}", demo.modphysic, "tas");
            }

            //If demo has cheats, write it
            demo.validDict = checkValidity(demo.time.TotalMilliseconds > 0, demo.rawTime, gInfo);

            if (demo.triggerTime)
            {
                demo.userId = tryGetUserIdFromFileName(file);
            }
            return(demo);
        }