//We are trying to split name and country static Pair tryGetNameAndCountry(string partname, DemoNames names) { var country = ""; if (names != null && (partname == names.dfName || partname == names.uName || partname == names.oName)) { //name can contains dots so if username from parameters equals part in brackets, no country here return(new Pair(partname, country)); } int i = partname.LastIndexOf('.'); if (i < 0) { i = partname.LastIndexOf(','); } if (i > 0 && i + 1 < partname.Length) { country = partname.Substring(i + 1, partname.Length - i - 1).Trim(); country = RawInfo.removeColors(country); if (country.Where(c => char.IsNumber(c)).Count() == 0) { return(new Pair(partname.Substring(0, i), country)); } } return(new Pair(partname, "")); }
public static string getNameOnline(string demoTimeCmd) { //print \"Rom^7 reached the finish line in ^23:38:208^7\n\" demoTimeCmd = Regex.Replace(demoTimeCmd, "(\\^[0-9]|\\\"|\\n|\")", ""); //print Rom reached the finish line in 3:38:208 string name = demoTimeCmd.Substring(6, demoTimeCmd.LastIndexOf(" reached") - 6); //Rom return(DemoNames.normalizeName(name)); }
public static string getNameOfflineOld1(string demoTimeCmd) { //NewTime -971299442 7:200 \"defrag 1.80\" \"Viper\" route ya->->rg demoTimeCmd = Regex.Replace(demoTimeCmd, "(\\^[0-9]|\\\"|\\n|\")", ""); //NewTime -971299442 7:200 defrag 1.80 Viper route ya->->rg var parts = demoTimeCmd.Split(' '); var name = parts[5]; return(DemoNames.normalizeName(name)); }
public static string getNameOffline(string demoTimeCmd) { //print "Time performed by ^2uN-DeaD!Enter^7 : ^331:432^7 (v1.91.23 beta)\n" //print \"Time performed by Chell ^s: 00:54:184\n\" demoTimeCmd = Regex.Replace(demoTimeCmd, "(\\^.|\\\"|\\n|\")", ""); //print Time performed by uN-DeaD!Enter : 31:432 (v1.91.23 beta) demoTimeCmd = demoTimeCmd.Substring(24); //uN-DeaD!Enter : 31:432 (v1.91.23 beta) demoTimeCmd = demoTimeCmd.Substring(0, demoTimeCmd.LastIndexOf(" : ")); //uN-DeaD!Enter return(DemoNames.normalizeName(demoTimeCmd)); }
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); }
static TimeStringInfo getFastestTimeStringInfo(List <TimeStringInfo> timestrings, DemoNames names) { TimeStringInfo fastestTimeString = null; if (timestrings.Count == 1) { fastestTimeString = timestrings.First(); } else if (timestrings.Count >= 1) { var cuStrings = timestrings.Where(x => (!string.IsNullOrEmpty(x.oName) && (x.oName == names.dfName || x.oName == names.uName))); if (cuStrings.Count() == 0) { var groups = timestrings.GroupBy(x => x.oName); if (groups.Count() == 1) { cuStrings = timestrings; } } if (cuStrings.Count() > 0) { fastestTimeString = Ext.MinOf(cuStrings, x => (long)x.time.TotalMilliseconds); } } return(fastestTimeString); }
//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); }