Esempio n. 1
0
        static void WriteToLog(string filename, string cmdrname, string lineout, bool checkjson, int part = 1)
        {
            if (checkjson)
            {
                JToken jk = JToken.Parse(lineout, out string error, JToken.ParseOptions.CheckEOL);
                if (jk == null)
                {
                    Console.WriteLine("Error in JSON " + error);
                    return;
                }
            }

            if (!File.Exists(filename))
            {
                using (Stream fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                {
                    using (StreamWriter sr = new StreamWriter(fs))
                    {
                        QuickJSONFormatter l1 = new QuickJSONFormatter();
                        l1.Object().UTC("timestamp").V("event", "Fileheader").V("part", 1).V("language", "English\\\\UK").V("gameversion", "2.2 (Beta 2)").V("build", "r121783/r0");
                        QuickJSONFormatter l2 = new QuickJSONFormatter();
                        l2.Object().UTC("timestamp").V("event", "LoadGame").V("FID", "F1962222").V("Commander", cmdrname)
                        .V("Horizons", true).V("Ship", "Anaconda").V("Ship_Localised", "Anaconda")
                        .V("ShipID", 5).V("ShipName", "CAT MINER").V("ShipIdent", "BUD-2")
                        .V("FuelLevel", 32.000000).V("FuelCapacity", 32.000000)
                        .V("GameMode", "Group").V("Group", "FleetComm").V("Credits", 3815287).V("Loan", 0);

                        Console.WriteLine(l1.Get());
                        Console.WriteLine(l2.Get());
                        sr.WriteLine(l1.Get());
                        sr.WriteLine(l2.Get());
                    }
                }
            }

            if (lineout != null)
            {
                using (Stream fs = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
                {
                    using (StreamWriter sr = new StreamWriter(fs))
                    {
                        sr.WriteLine(lineout);
                        Console.WriteLine(lineout);
                    }
                }
            }
        }
Esempio n. 2
0
 public static void FMission(QuickJSONFormatter q, int id, string name, bool pas, int time)
 {
     q.V("MissionID", id).V("Name", name).V("PassengerMission", pas).V("Expires", time);
 }
Esempio n. 3
0
        public static void JournalEntry(string filename, string cmdrname, CommandArgs argsentry, int repeatdelay)
        {
            if (argsentry.Left == 0)
            {
                Console.WriteLine("** Minimum 3 parameters of filename, cmdrname, journalentrytype");
                return;
            }

            int repeatcount = 0;

            while (true)
            {
                CommandArgs args = new CommandArgs(argsentry);

                string eventtype = args.Next.ToLower();

                Random rnd = new Random();

                string lineout = null;      //quick writer

                if (eventtype.Equals("fsd"))
                {
                    lineout = FSDJump(args, repeatcount);
                }
                else if (eventtype.Equals("fsdtravel"))
                {
                    lineout = FSDTravel(args);
                }
                else if (eventtype.Equals("loc"))
                {
                    lineout = Loc(args);
                }
                else if (eventtype.Equals("interdiction"))
                {
                    lineout = Interdiction(args);
                }
                else if (eventtype.Equals("docked"))
                {
                    lineout = "{ " + TimeStamp() + "\"event\":\"Docked\", " +
                              "\"StationName\":\"Jameson Memorial\", " +
                              "\"StationType\":\"Orbis\", \"StarSystem\":\"Shinrarta Dezhra\", \"Faction\":\"The Pilots Federation\", \"Allegiance\":\"Independent\", \"Economy\":\"$economy_HighTech;\", \"Economy_Localised\":\"High tech\", \"Government\":\"$government_Democracy;\", \"Government_Localised\":\"Democracy\", \"Security\":\"$SYSTEM_SECURITY_high;\", \"Security_Localised\":\"High Security\" }";
                }
                else if (eventtype.Equals("undocked"))
                {
                    lineout = "{ " + TimeStamp() + "\"event\":\"Undocked\", " + "\"StationName\":\"Jameson Memorial\",\"StationType\":\"Orbis\" }";
                }
                else if (eventtype.Equals("liftoff"))
                {
                    lineout = "{ " + TimeStamp() + "\"event\":\"Liftoff\", " + "\"Latitude\":7.141173, \"Longitude\":95.256424 }";
                }
                else if (eventtype.Equals("touchdown"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "Touchdown") + F("Latitude", 7.141173) + F("Longitude", 95.256424) + FF("PlayerControlled", true) + " }";
                }
                else if (eventtype.Equals("commitcrime"))
                {
                    string f  = args.Next;
                    int    id = args.Int;
                    lineout = "{ " + TimeStamp() + F("event", "CommitCrime") + F("CrimeType", "collidedAtSpeedInNoFireZone") + F("Faction", f) + FF("Fine", id) + " }";
                }
                else if (eventtype.Equals("missionaccepted") && args.Left == 3)
                {
                    string f  = args.Next;
                    string vf = args.Next;
                    int    id = args.Int;

                    lineout = "{ " + TimeStamp() + F("event", "MissionAccepted") + F("Faction", f) +
                              F("Name", "Mission_Assassinate_Legal_Corporate") + F("TargetType", "$MissionUtil_FactionTag_PirateLord;") + F("TargetType_Localised", "Pirate lord") + F("TargetFaction", vf)
                              + F("DestinationSystem", "Quapa") + F("DestinationStation", "Grabe Dock") + F("Target", "mamsey") + F("Expiry", DateTime.UtcNow.AddDays(1)) +
                              F("Influence", "Med") + F("Reputation", "Med") + FF("MissionID", id) + "}";
                }
                else if (eventtype.Equals("missioncompleted") && args.Left == 3)
                {
                    string f  = args.Next;
                    string vf = args.Next;
                    int    id = args.Int;

                    lineout = "{ " + TimeStamp() + F("event", "MissionCompleted") + F("Faction", f) +
                              F("Name", "Mission_Assassinate_Legal_Corporate") + F("TargetType", "$MissionUtil_FactionTag_PirateLord;") + F("TargetType_Localised", "Pirate lord") + F("TargetFaction", vf) +
                              F("MissionID", id) + F("Reward", "82272") + " \"CommodityReward\":[ { \"Name\": \"CoolingHoses\", \"Count\": 4 } ] }";
                }
                else if (eventtype.Equals("missionredirected") && args.Left == 3)
                {
                    string sysn     = args.Next;
                    string stationn = args.Next;
                    int    id       = args.Int;
                    lineout = "{ " + TimeStamp() + F("event", "MissionRedirected") + F("MissionID", id) + F("MissionName", "Mission_Assassinate_Legal_Corporate") +
                              F("NewDestinationStation", stationn) + F("OldDestinationStation", "Cuffey Orbital") +
                              F("NewDestinationSystem", sysn) + FF("OldDestinationSystem", "Vequess") + " }";
                }
                else if (eventtype.Equals("missions") && args.Left == 1)
                {
                    int id = args.Int;
                    BaseUtils.QuickJSONFormatter qj = new QuickJSONFormatter();

                    qj.Object().UTC("timestamp").V("event", "Missions");

                    qj.Array("Active").Object();
                    FMission(qj, id, "Mission_Assassinate_Legal_Corporate", false, 20000);
                    qj.Close(2);

                    qj.Array("Failed").Object();
                    FMission(qj, id + 1000, "Mission_Assassinate_Legal_Corporate", false, 20000);
                    qj.Close(2);

                    qj.Array("Completed").Object();
                    FMission(qj, id + 2000, "Mission_Assassinate_Legal_Corporate", false, 20000);
                    qj.Close(2);

                    lineout = qj.Get();
                }
                else if (eventtype.Equals("marketbuy") && args.Left == 3)
                {
                    string name  = args.Next;
                    int    count = args.Int;
                    int    price = args.Int;

                    BaseUtils.QuickJSONFormatter qj = new QuickJSONFormatter();

                    lineout = qj.Object().UTC("timestamp").V("event", "MarketBuy").V("MarketID", 29029292)
                              .V("Type", name).V("Type_Localised", name + "loc").V("Count", count).V("BuyPrice", price).V("TotalCost", price * count).Get();
                }
                else if (eventtype.Equals("bounty"))
                {
                    string f  = args.Next;
                    int    rw = args.Int;

                    lineout = "{ " + TimeStamp() + F("event", "Bounty") + F("VictimFaction", f) + F("VictimFaction_Localised", f + "_Loc") +
                              F("TotalReward", rw, true) + "}";
                }
                else if (eventtype.Equals("factionkillbond"))
                {
                    string f  = args.Next;
                    string vf = args.Next;
                    int    rw = args.Int;

                    lineout = "{ " + TimeStamp() + F("event", "FactionKillBond") + F("VictimFaction", vf) + F("VictimFaction_Localised", vf + "_Loc") +
                              F("AwardingFaction", f) + F("AwardingFaction_Localised", f + "_Loc") +
                              F("Reward", rw, true) + "}";
                }
                else if (eventtype.Equals("capshipbond"))
                {
                    string f  = args.Next;
                    string vf = args.Next;
                    int    rw = args.Int;

                    lineout = "{ " + TimeStamp() + F("event", "CapShipBond") + F("VictimFaction", vf) + F("VictimFaction_Localised", vf + "_Loc") +
                              F("AwardingFaction", f) + F("AwardingFaction_Localised", f + "_Loc") +
                              F("Reward", rw, true) + "}";
                }
                else if (eventtype.Equals("resurrect"))
                {
                    int ct = args.Int;

                    lineout = "{ " + TimeStamp() + F("event", "Resurrect") + F("Option", "Help me") + F("Cost", ct) + FF("Bankrupt", false) + "}";
                }
                else if (eventtype.Equals("died"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "Died") + F("KillerName", "Evil Jim McDuff") + F("KillerName_Localised", "Evil Jim McDuff The great") + F("KillerShip", "X-Wing") + FF("KillerRank", "Invincible") + "}";
                }
                else if (eventtype.Equals("miningrefined"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "MiningRefined") + FF("Type", "Gold") + " }";
                }
                else if (eventtype.Equals("engineercraft"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "EngineerCraft") + F("Engineer", "Robert") + F("Blueprint", "FSD_LongRange")
                              + F("Level", "5") + "\"Ingredients\":{ \"magneticemittercoil\":1, \"arsenic\":1, \"chemicalmanipulators\":1, \"dataminedwake\":1 } }";
                }
                else if (eventtype.Equals("navbeaconscan"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "NavBeaconScan") + FF("NumBodies", "3") + " }";
                }
                else if (eventtype.Equals("scanplanet") && args.Left >= 1)
                {
                    lineout = "{ " + TimeStamp() + F("event", "Scan") + "\"BodyName\":\"" + args.Next + "x" + repeatcount + "\", \"DistanceFromArrivalLS\":639.245483, \"TidalLock\":true, \"TerraformState\":\"\", \"PlanetClass\":\"Metal rich body\", \"Atmosphere\":\"\", \"AtmosphereType\":\"None\", \"Volcanism\":\"rocky magma volcanism\", \"MassEM\":0.010663, \"Radius\":1163226.500000, \"SurfaceGravity\":3.140944, \"SurfaceTemperature\":1068.794067, \"SurfacePressure\":0.000000, \"Landable\":true, \"Materials\":[ { \"Name\":\"iron\", \"Percent\":36.824127 }, { \"Name\":\"nickel\", \"Percent\":27.852226 }, { \"Name\":\"chromium\", \"Percent\":16.561033 }, { \"Name\":\"zinc\", \"Percent\":10.007420 }, { \"Name\":\"selenium\", \"Percent\":2.584032 }, { \"Name\":\"tin\", \"Percent\":2.449526 }, { \"Name\":\"molybdenum\", \"Percent\":2.404594 }, { \"Name\":\"technetium\", \"Percent\":1.317050 } ], \"SemiMajorAxis\":1532780800.000000, \"Eccentricity\":0.000842, \"OrbitalInclination\":-1.609496, \"Periapsis\":179.381393, \"OrbitalPeriod\":162753.062500, \"RotationPeriod\":162754.531250, \"AxialTilt\":0.033219 }";
                }
                else if (eventtype.Equals("scanstar"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "Scan") + "\"BodyName\":\"Merope A" + repeatcount + "\", \"DistanceFromArrivalLS\":0.000000, \"StarType\":\"B\", \"StellarMass\":8.597656, \"Radius\":2854249728.000000, \"AbsoluteMagnitude\":1.023468, \"Age_MY\":182, \"SurfaceTemperature\":23810.000000, \"Luminosity\":\"IV\", \"SemiMajorAxis\":12404761034752.000000, \"Eccentricity\":0.160601, \"OrbitalInclination\":18.126791, \"Periapsis\":49.512009, \"OrbitalPeriod\":54231617536.000000, \"RotationPeriod\":110414.359375, \"AxialTilt\":0.000000 }";
                }
                else if (eventtype.Equals("scanearth"))
                {
                    int rn = rnd.Next(10);
                    lineout = "{ " + TimeStamp() + F("event", "Scan") + "\"BodyName\":\"Merope " + rn + "\", \"DistanceFromArrivalLS\":901.789856, \"TidalLock\":false, \"TerraformState\":\"Terraformed\", \"PlanetClass\":\"Earthlike body\", \"Atmosphere\":\"\", \"AtmosphereType\":\"EarthLike\", \"AtmosphereComposition\":[ { \"Name\":\"Nitrogen\", \"Percent\":92.386833 }, { \"Name\":\"Oxygen\", \"Percent\":7.265749 }, { \"Name\":\"Water\", \"Percent\":0.312345 } ], \"Volcanism\":\"\", \"MassEM\":0.840000, \"Radius\":5821451.000000, \"SurfaceGravity\":9.879300, \"SurfaceTemperature\":316.457062, \"SurfacePressure\":209183.453125, \"Landable\":false, \"SemiMajorAxis\":264788426752.000000, \"Eccentricity\":0.021031, \"OrbitalInclination\":13.604733, \"Periapsis\":73.138206, \"OrbitalPeriod\":62498732.000000, \"RotationPeriod\":58967.023438, \"AxialTilt\":-0.175809 }";
                }
                else if (eventtype.Equals("afmurepairs"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "AfmuRepairs") + "\"Module\":\"$modularcargobaydoor_name;\", \"Module_Localised\":\"Cargo Hatch\", \"FullyRepaired\":true, \"Health\":1.000000 }";
                }

                else if (eventtype.Equals("sellshiponrebuy"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "SellShipOnRebuy") + "\"ShipType\":\"Dolphin\", \"System\":\"Shinrarta Dezhra\", \"SellShipId\":4, \"ShipPrice\":4110183 }";
                }

                else if (eventtype.Equals("searchandrescue") && args.Left == 2)
                {
                    string name  = args.Next;
                    int    count = args.Int;
                    BaseUtils.QuickJSONFormatter qj = new QuickJSONFormatter();
                    lineout = qj.Object().UTC("timestamp").V("event", "SearchAndRescue").V("MarketID", 29029292)
                              .V("Name", name).V("Name_Localised", name + "loc").V("Count", count).V("Reward", 10234).Get();
                }
                else if (eventtype.Equals("repairdrone"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "RepairDrone") + "\"HullRepaired\": 0.23, \"CockpitRepaired\": 0.1,  \"CorrosionRepaired\": 0.5 }";
                }

                else if (eventtype.Equals("communitygoal"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "CommunityGoal") + "\"CurrentGoals\":[ { \"CGID\":726, \"Title\":\"Alliance Research Initiative - Trade\", \"SystemName\":\"Kaushpoos\", \"MarketName\":\"Neville Horizons\", \"Expiry\":\"2017-08-17T14:58:14Z\", \"IsComplete\":false, \"CurrentTotal\":10062, \"PlayerContribution\":562, \"NumContributors\":101, \"TopRankSize\":10, \"PlayerInTopRank\":false, \"TierReached\":\"Tier 1\", \"PlayerPercentileBand\":50, \"Bonus\":200000 } ] }";
                }

                else if (eventtype.Equals("musicnormal"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "Music") + FF("MusicTrack", "NoTrack") + " }";
                }
                else if (eventtype.Equals("musicsysmap"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "Music") + FF("MusicTrack", "SystemMap") + " }";
                }
                else if (eventtype.Equals("musicgalmap"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "Music") + FF("MusicTrack", "GalaxyMap") + " }";
                }
                else if (eventtype.Equals("friends") && args.Left >= 1)
                {
                    lineout = "{ " + TimeStamp() + F("event", "Friends") + F("Status", "Online") + FF("Name", args.Next) + " }";
                }
                else if (eventtype.Equals("fuelscoop") && args.Left >= 2)
                {
                    string scoop = args.Next;
                    string total = args.Next;
                    lineout = "{ " + TimeStamp() + F("event", "FuelScoop") + F("Scooped", scoop) + FF("Total", total) + " }";
                }
                else if (eventtype.Equals("jetconeboost"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "JetConeBoost") + FF("BoostValue", "1.5") + " }";
                }
                else if (eventtype.Equals("fighterdestroyed"))
                {
                    lineout = "{ " + TimeStamp() + FF("event", "FighterDestroyed") + " }";
                }
                else if (eventtype.Equals("fighterrebuilt"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "FighterRebuilt") + FF("Loadout", "Fred") + " }";
                }
                else if (eventtype.Equals("npccrewpaidwage"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "NpcCrewPaidWage") + F("NpcCrewId", 1921) + FF("Amount", 10292) + " }";
                }
                else if (eventtype.Equals("npccrewrank"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "NpcCrewRank") + F("NpcCrewId", 1921) + FF("RankCombat", 4) + " }";
                }
                else if (eventtype.Equals("launchdrone"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "LaunchDrone") + FF("Type", "FuelTransfer") + " }";
                }
                else if (eventtype.Equals("market"))
                {
                    lineout = Market(Path.GetDirectoryName(filename), args.Next);
                }
                else if (eventtype.Equals("moduleinfo"))
                {
                    lineout = ModuleInfo(Path.GetDirectoryName(filename), args.Next);
                }
                else if (eventtype.Equals("outfitting"))
                {
                    lineout = Outfitting(Path.GetDirectoryName(filename), args.Next);
                }
                else if (eventtype.Equals("shipyard"))
                {
                    lineout = Shipyard(Path.GetDirectoryName(filename), args.Next);
                }
                else if (eventtype.Equals("powerplay"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "PowerPlay") + F("Power", "Fred") + F("Rank", 10) + F("Merits", 10) + F("Votes", 2) + FF("TimePledged", 433024) + " }";
                }
                else if (eventtype.Equals("underattack"))
                {
                    lineout = "{ " + TimeStamp() + F("event", "UnderAttack") + FF("Target", "Fighter") + " }";
                }
                else if (eventtype.Equals("promotion") && args.Left == 2)
                {
                    lineout = "{ " + TimeStamp() + F("event", "Promotion") + FF(args.Next, args.Int) + " }";
                }
                else if (eventtype.Equals("cargodepot"))
                {
                    lineout = CargoDepot(args);
                }
                else
                {
                    Console.WriteLine("** Unrecognised journal event type or not enough parameters for entry");
                    break;
                }

                if (lineout != null)
                {
                    if (!File.Exists(filename))
                    {
                        using (Stream fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                        {
                            using (StreamWriter sr = new StreamWriter(fs))
                            {
                                string line = "{ " + TimeStamp() + "\"event\":\"Fileheader\", \"part\":1, \"language\":\"English\\\\UK\", \"gameversion\":\"2.2 (Beta 2)\", \"build\":\"r121783/r0 \" }";
                                sr.WriteLine(line);
                                Console.WriteLine(line);

                                string line2 = "{ " + TimeStamp() + "\"event\":\"LoadGame\", \"Commander\":\"" + cmdrname + "\", \"Ship\":\"Anaconda\", \"ShipID\":14, \"GameMode\":\"Open\", \"Credits\":18670609, \"Loan\":0 }";
                                sr.WriteLine(line2);
                                Console.WriteLine(line2);
                            }
                        }
                    }

                    Write(filename, lineout);
                }
                else
                {
                    break;
                }

                if (repeatdelay == -1)
                {
                    ConsoleKeyInfo k = Console.ReadKey();

                    if (k.Key == ConsoleKey.Escape)
                    {
                        break;
                    }
                }
                else if (repeatdelay > 0)
                {
                    System.Threading.Thread.Sleep(repeatdelay);

                    if (Console.KeyAvailable && Console.ReadKey().Key == ConsoleKey.Escape)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }

                repeatcount++;
            }
        }
Esempio n. 4
0
        static void Main(string[] stringargs)
        {
            CommandArgs args = new CommandArgs(stringargs);

            string arg1 = args.Next();

            if (arg1 != null)
            {
                arg1 = arg1.ToLower();
            }

            if (arg1 == null)
            {
                Console.WriteLine("Journal - write journal, run for help\n" +
                                  "Phoneme <filename> <fileout> for EDDI phoneme tx\n" +
                                  "Voicerecon <filename> -  Consol read a elite bindings file and output action script lines\n" +
                                  "DeviceMappings <filename> - read elite device pid/vid file for usb info\n" +
                                  "StatusMove lat long latstep longstep heading headstep steptime\n" +
                                  "Status - run for help\n" +
                                  "StatusRead\n" +
                                  "CoriolisModules rootfolder - process coriolis-data\\modules\\<folder>\n" +
                                  "CoriolisModule name - process coriolis-data\\modules\\<folder>\n" +
                                  "CoriolisShips rootfolder - process coriolis-data\\ships\n" +
                                  "CoriolisShip name - process coriolis-data\\ships\n" +
                                  "CoriolisEng rootfolder - process coriolis-data\\modifications\n" +
                                  "FrontierData rootfolder - process cvs file exports of frontier data\n" +
                                  "scantranslate - process source files and look for .Tx definitions, run to see options\n" +
                                  "normalisetranslate- process language files and normalise, run to see options\n" +
                                  "journalindented file - read lines from file in journal format and output indented\n" +
                                  "jsonlines/jsonlinescompressed file - read a json on a single line from the file and output\n" +
                                  "json - read a json from file and output indented\n" +
                                  "escapestring - read a json from file and output text with quotes escaped for c# source files\n" +
                                  "@string - read a json from file and output text for @ strings\n" +
                                  "cutdownfile file lines -reduce a file size down to this number of lines\n" +
                                  "xmldump file - decode xml and output attributes/elements showing structure\n" +
                                  "dwwp file - for processing captured html on expeditions and outputing json of stars\n" +
                                  "svg file - read svg file of Elite regions and output EDSM JSON galmap file\n" +
                                  "readlog file - read a continuous log or journal file out to stdout\n" +
                                  "githubrelease - read the releases list and stat it\n" +
                                  "logs wildcard - read files for json lines and process\n" +
                                  "readjournals path - read all .log journal files and check\n" +
                                  "csvtocs path - read csv and turn into a cs class\n" +
                                  "comments path\n" +
                                  "mddoc path wildcard [REMOVE]\n" +
                                  "finddoclinks path wildcard typename existingdocexternfile searchstr\n" +
                                  "insertext path wildcard find insert\n"

                                  );

                return;
            }

            //*************************************************************************************************************
            // these provide their own help or do not require any more args
            //*************************************************************************************************************

            if (arg1.Equals("scantranslate"))
            {
                // sample scantranslate c:\code\eddiscovery\elitedangerous\journalevents *.cs c:\code\eddiscovery\eddiscovery\translations\ 2 italiano-it combine > c:\code\output.txt

                string path          = args.Next();
                string wildcard      = args.Next();
                string txpath        = args.Next();
                int    txsearchdepth = args.Int();
                string lang          = args.Next();

                if (path != null && wildcard != null)
                {
                    FileInfo[] allFiles       = Directory.EnumerateFiles(path, wildcard, SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();
                    bool       showrepeat     = false;
                    bool       showerrorsonly = false;

                    while (args.More)
                    {
                        string a = args.Next().ToLowerInvariant();
                        if (a == "showrepeats")
                        {
                            showrepeat = true;
                        }
                        if (a == "showerrorsonly")
                        {
                            showerrorsonly = true;
                        }
                    }

                    string ret = ScanTranslate.Process(allFiles, lang, txpath, txsearchdepth, showrepeat, showerrorsonly);
                    Console.WriteLine(ret);
                }
                else
                {
                    Console.WriteLine("Usage:\n" +
                                      "scantranslate path filewildcard languagefilepath searchdepth language[opt]..- \n\n" +
                                      "path filewildcard is where the source files to search for .Tx is in \n" +
                                      "languagefilepath is where the .tlf files are located\n" +
                                      "searchupdepth is the depth of search upwards (to root) to look thru folders for include files - 2 is normal\n" +
                                      "language is the language to compare against - example-ex\n" +
                                      "Opt: ShowRepeats means show repeated entries in output\n" +
                                      "Opt: ShowErrorsOnly means show only errors\n" +
                                      "\n" +
                                      "Example:n" +
                                      "eddtest scantranslate . *.cs  c:\\code\\eddiscovery\\EDDiscovery\\Translations 2 example-ex showerrorsonly\n" +
                                      "\nJudgement is still required to see if a found definition has to be in the example-ex file.  Its not perfect\n" +
                                      "\nYou first run this with example-ex and fix up example-ex until the translator log (in appdata) shows no errors\n" +
                                      "Then you use translatereader to normalise the example-ex and all the other files\n"
                                      );
                }

                return;
            }
            else if (arg1.Equals("finddoclinks"))
            {
                // used to search the md files from default documentation for links to external objects
                // paras: . *.md OpenTK.Graphics.OpenGL c:\code\ofc\ofc\docexternlinks.txt opengl

                string path         = args.Next();
                string wildcard     = args.Next();
                string typename     = args.Next();
                string existingfile = args.Next();
                string searchstr    = args.Next();

                if (path != null && wildcard != null && typename != null)
                {
                    FileInfo[] allFiles = Directory.EnumerateFiles(path, wildcard, SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();

                    MDDoc.Process(allFiles, typename, existingfile, searchstr);
                }
                else
                {
                    Console.WriteLine("Usage:\n" + ""
                                      );
                }

                return;
            }
            else if (arg1.Equals("mddoc"))
            {
                string path                = args.Next();
                string wildcard            = args.Next();
                bool   removerootnamespace = args.NextEmpty().Contains("REMOVE", StringComparison.InvariantCultureIgnoreCase);

                if (path != null && wildcard != null)
                {
                    FileInfo[] allFiles = Directory.EnumerateFiles(path, wildcard, SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();

                    MDDoc.PostProcessMD(allFiles, removerootnamespace);
                }
                else
                {
                    Console.WriteLine("Usage:\n" + ""
                                      );
                }

                return;
            }

            else if (arg1.Equals("inserttext"))
            {
                // find lext in string, if found, insert line
                string path     = args.Next();
                string wildcard = args.Next();
                string find     = args.Next();
                string insert   = args.Next();

                if (path != null && wildcard != null && find != null && insert != null)
                {
                    FileInfo[] allFiles = Directory.EnumerateFiles(path, wildcard, SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();

                    MDDoc.ProcessInsert(allFiles, find, insert);
                }
                else
                {
                    Console.WriteLine("Usage:\n" + ""
                                      );
                }

                return;
            }

            else if (arg1.Equals("normalisetranslate"))
            {
                string primarypath        = args.Next();
                int    primarysearchdepth = args.Int();
                string primarylanguage    = args.Next();
                string language2          = args.Next();
                string options            = args.Next();

                if (primarypath == null || primarylanguage == null)
                {
                    Console.WriteLine("Usage:\n" +
                                      "normalisetranslate path-language-files searchdepth language-to-use [secondary-language-to-compare] [options]\n" +
                                      "Read the language-to-use and write out it into the same files cleanly\n" +
                                      "If secondary is present, read it, and use its definitions instead of the language-to-use\n" +
                                      "Options: Use NS for don't report secondary\n" +
                                      "Write back out the tlf and tlp files to the current directory\n" +
                                      "Write out copy instructions to move those files back to their correct places\n" +
                                      "Example:\n" +
                                      "eddtest normalisetranslate c:\\code\\eddiscovery\\EDDiscovery\\Translations 2 example-ex deutsch-de \n"
                                      );
                }
                else
                {
                    string ret = NormaliseTranslationFiles.Process(primarylanguage, primarypath, primarysearchdepth, language2, options);
                    Console.WriteLine(ret);
                    System.Diagnostics.Debug.WriteLine(ret);
                }

                return;
            }
            else if (arg1.Equals("journal"))
            {
                Journal.JournalEntry(args);
                return;
            }
            else if (arg1.Equals("statusread"))
            {
                string file = "status.json";
                if (args.Left >= 1)
                {
                    file = args.Next();
                }
                Status.StatusRead(file);
                return;
            }
            else if (arg1.Equals("statusmove"))
            {
                Status.StatusMove(args);
                return;
            }
            else if (arg1.Equals("status"))
            {
                Status.StatusSet(args);
                return;
            }

            //*************************************************************************************************************
            // these require 1 arg min
            //*************************************************************************************************************

            if (args.Left < 1)
            {
                Console.WriteLine("Not enough arguments, please run without options for help");
            }
            else if (arg1.Equals("githubreleases"))
            {
                string file = args.Next();
                GitHub.Stats(file);
            }
            else if (arg1.Equals("dwwp"))
            {
                string       text = File.ReadAllText(args.Next());
                StringParser sp   = new StringParser(text);
                while (true)
                {
                    string notes = sp.NextWord("-");
                    if (notes == null)
                    {
                        break;
                    }

                    notes = notes.Trim();

                    if (sp.IsCharMoveOn('-'))
                    {
                        string reftext = sp.NextWord(":").Trim();

                        if (sp.IsCharMoveOn(':'))
                        {
                            string name = sp.NextWord("\r").Trim();

                            //                            Console.WriteLine("N: '" + name + "' Ref '" + reftext + "' loc '" + loc + "'");

                            QuickJSONFormatter json = new QuickJSONFormatter();
                            json.Object().V("Name", name).V("Notes", "DW3305->WPX " + notes).Close();

                            Console.WriteLine(json.Get() + ",");
                        }
                    }
                }
                return;
            }
            else if (arg1.Equals("voicerecon"))
            {
                BindingsFile.Bindings(args.Next());
            }
            else if (arg1.Equals("devicemappings"))
            {
                BindingsFile.DeviceMappings(args.Next());
            }
            else if (arg1.Equals("phoneme"))
            {
                Speech.Phoneme(args.Next(), args.Next());
            }
            else if (arg1.Equals("wikiconvert"))
            {
                WikiConvert.Convert(args.Next(), args.Next());
            }
            else if (arg1.Equals("coriolisships"))
            {
                FileInfo[] allFiles = Directory.EnumerateFiles(args.Next(), "*.json", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();
                string     ret      = CoriolisShips.ProcessShips(allFiles);
                Console.WriteLine(ret);
            }
            else if (arg1.Equals("coriolisship"))
            {
                FileInfo[] allFiles = Directory.EnumerateFiles(".", args.Next(), SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();
                string     ret      = CoriolisShips.ProcessShips(allFiles);
                Console.WriteLine(ret);
            }
            else if (arg1.Equals("coriolismodules"))
            {
                FileInfo[] allFiles = Directory.EnumerateFiles(args.Next(), "*.json", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();
                string     ret      = CoriolisModules.ProcessModules(allFiles);
                Console.WriteLine(ret);
            }
            else if (arg1.Equals("coriolismodule"))
            {
                FileInfo[] allFiles = Directory.EnumerateFiles(".", args.Next(), SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();

                string ret = CoriolisModules.ProcessModules(allFiles);
                Console.WriteLine(ret);
            }
            else if (arg1.Equals("corioliseng"))
            {
                FileInfo[] allFiles = Directory.EnumerateFiles(args.Next(), "*.json", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();
                string     ret      = CoriolisEng.ProcessEng(allFiles);
                Console.WriteLine(ret);
            }
            else if (arg1.Equals("frontierdata"))
            {
                EliteDangerousCore.MaterialCommodityMicroResourceType.FillTable();
                FrontierData.Process(args.Next());
            }
            else if (arg1.Equals("readjournals"))
            {
                JournalReader.ReadJournals(args.Next());
            }
            else if (arg1.Equals("journalindented"))
            {
                string path = args.Next();

                using (Stream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string s;
                        while ((s = sr.ReadLine()) != null)
                        {
                            JObject jo = new JObject();
                            try
                            {
                                jo = JObject.Parse(s);

                                Console.WriteLine(jo.ToString(true));
                            }
                            catch
                            {
                                Console.WriteLine("Unable to parse " + s);
                            }
                        }
                    }
                }
            }
            else if (arg1.Equals("jsonlines") || arg1.Equals("jsonlinescompressed"))
            {
                bool indent = arg1.Equals("jsonindented");

                string path = args.Next();
                try
                {
                    string text = File.ReadAllText(path);

                    using (StringReader sr = new StringReader(text))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null && (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape))
                        {
                            JToken tk = JToken.Parse(line, out string err, JToken.ParseOptions.CheckEOL);
                            if (tk != null)
                            {
                                Console.WriteLine(tk.ToString(indent));
                            }
                            else
                            {
                                Console.WriteLine($"Error in JSON {err}");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed " + ex.Message);
                }
            }
            else if (arg1.Equals("json"))
            {
                string path = args.Next();
                try
                {
                    string text = File.ReadAllText(path);

                    JToken tk = JToken.Parse(text, out string err, JToken.ParseOptions.CheckEOL);
                    if (tk != null)
                    {
                        Console.WriteLine(tk.ToString(true));
                    }
                    else
                    {
                        Console.WriteLine($"{err}\r\nERROR in JSON");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed " + ex.Message);
                }
            }
            else if (arg1.Equals("cutdownfile"))
            {
                string filename    = args.Next();
                int    numberlines = args.Int();

                using (StreamReader sr = new StreamReader(filename))              // read directly from file..
                {
                    using (StreamWriter wr = new StreamWriter(filename + ".out")) // read directly from file..
                    {
                        for (int i = 0; i < numberlines; i++)
                        {
                            string line = sr.ReadLine();
                            if (line != null)
                            {
                                wr.WriteLine(line);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else if (arg1.Equals("readlog"))
            {
                string filename = args.Next();
                long   pos      = 0;
                long   lineno   = 0;


                if (Path.GetFileName(filename).Contains("*"))
                {
                    string dir = Path.GetDirectoryName(filename);
                    if (dir == "")
                    {
                        dir = ".";
                    }
                    FileInfo[] allFiles = Directory.EnumerateFiles(dir, Path.GetFileName(filename), SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)).OrderByDescending(p => p.LastWriteTime).ToArray();
                    if (allFiles.Length > 1)
                    {
                        filename = allFiles[0].FullName;
                    }
                }

                Console.WriteLine("Reading " + filename);

                while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
                {
                    try
                    {
                        if (new FileInfo(filename).Length < pos)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("########################################################################################");
                            Console.WriteLine("");
                            pos    = 0;
                            lineno = 0;
                        }

                        var stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                        stream.Seek(pos, SeekOrigin.Begin);

                        using (var sr = new StreamReader(stream))
                        {
                            string line = null;
                            while ((line = sr.ReadLine()) != null)
                            {
                                Console.Write(string.Format("{0}:", ++lineno));
                                Console.WriteLine(line);
                            }

                            pos = stream.Position;
                        }
                    }
                    catch
                    {
                    }

                    System.Threading.Thread.Sleep(50);
                }
            }
            else if (arg1.Equals("xmldump"))
            {
                string filename = args.Next();

                XElement bindings = XElement.Load(filename);
                Dump(bindings, 0);
            }
            else if (arg1.Equals("escapestring"))
            {
                string filename = args.Next();

                string text = File.ReadAllText(filename);
                text = text.QuoteString();
                Console.WriteLine(text);
            }
            else if (arg1.Equals("@string"))
            {
                string filename = args.Next();

                string text = File.ReadAllText(filename);
                text = text.Replace("\"", "\"\"");
                Console.WriteLine(text);
            }
            else if (arg1.Equals("svg"))
            {
                string filename = args.Next();
                int    id       = 0;

                string[] names = new string[] {
                    "Galactic Centre",
                    "Empyrean Straits",
                    "Ryker's Hope",
                    "Odin's Hold",
                    "Norma Arm",
                    "Arcadian Stream",
                    "Izanami",
                    "Inner Orion-Perseus Conflux",
                    "Inner Scutum-Centaurus Arm",
                    "Norma Expanse",
                    "Trojan Belt",
                    "The Veils",
                    "Newton's Vault",
                    "The Conduit",
                    "Outer Orion-Perseus Conflux",
                    "Orion-Cygnus Arm",
                    "Temple",
                    "Inner Orion Spur",
                    "Hawking's Gap",
                    "Dryman's Point",
                    "Sagittarius-Carina Arm",
                    "Mare Somnia",
                    "Acheron",
                    "Formorian Frontier",
                    "Hieronymus Delta",
                    "Outer Scutum-Centaurus Arm",
                    "Outer Arm",
                    "Aquila's Halo",
                    "Errant Marches",
                    "Perseus Arm",
                    "Formidine Rift",
                    "Vulcan Gate",
                    "Elysian Shore",
                    "Sanguineous Rim",
                    "Outer Orion Spur",
                    "Achilles's Altar",
                    "Xibalba",
                    "Lyra's Song",
                    "Tenebrae",
                    "The Abyss",
                    "Kepler's Crest",
                    "The Void",
                };


                QuickJSONFormatter qjs = new QuickJSONFormatter();
                qjs.Array(null).LF();

                XElement bindings = XElement.Load(filename);
                foreach (XElement x in bindings.Descendants())
                {
                    if (x.HasAttributes)
                    {
                        foreach (XAttribute y in x.Attributes())
                        {
                            if (x.Name.LocalName == "path" && y.Name.LocalName == "d")
                            {
                                //Console.WriteLine(x.Name.LocalName + " attr " + y.Name + " = " + y.Value);
                                var points = BaseUtils.SVG.ReadSVGPath(y.Value);

                                qjs.Object().V("id", id).V("type", "region").V("name", names[id]);
                                qjs.Array("coordinates");
                                foreach (var p in points)
                                {
                                    qjs.Array(null).V(null, p.X * 100000.0 / 2048.0 - 49985).V(null, 0).V(null, p.Y * 100000.0 / 2048.0 - 24105).Close();
                                }
                                qjs.Close().Close().LF();
                                id++;
                            }
                        }
                    }
                }

                qjs.Close();

                Console.WriteLine(qjs.ToString());
            }
            else if (arg1.Equals("logs"))
            {
                string filename = args.Next();

                FileInfo[] allFiles = Directory.EnumerateFiles(".", filename, SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.FullName).ToArray();

                Dictionary <string, string> signals = new Dictionary <string, string>();

                foreach (var f in allFiles)
                {
                    string text = FileHelpers.TryReadAllTextFromFile(f.FullName);
                    if (text != null)
                    {
                        StringReader sr = new StringReader(text);
                        string       line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            JToken tk = JToken.Parse(line);
                            if (tk != null)
                            {
                                var sn = tk["SignalName"];
                                //  Console.WriteLine("Read " + tk.ToString());
                                if (sn != null)
                                {
                                    string str  = tk["SignalName"].Str();
                                    string strl = tk["SignalName_Localised"].Str();
                                    if (tk["IsStation"].Bool(false) == true)
                                    {
                                        if (strl.HasChars())
                                        {
                                            Console.WriteLine("***** Station has localisation");
                                        }

                                        strl = "STATION";
                                    }
                                    if (signals.ContainsKey(str))
                                    {
                                        if (signals[str] != strl)
                                        {
                                            Console.WriteLine("***** Clash, {0} {1} vs {2}", str, strl, signals[str]);
                                        }
                                    }
                                    else
                                    {
                                        signals[str] = strl;
                                    }
                                }
                            }
                        }
                    }
                }

                Console.WriteLine("***************************** ID list");
                foreach (string v in signals.Keys)
                {
                    if (signals[v] != "STATION" && signals[v].HasChars())
                    {
                        Console.WriteLine("{0} {1}", v, signals[v]);
                    }
                }
            }
            else if (arg1.Equals("csvtocs"))
            {
                string  filename = args.Next();
                string  precode  = args.Next();
                CSVFile reader   = new CSVFile();

                if (reader.Read(filename, FileShare.Read, true))
                {
                    foreach (var row in reader.Rows)
                    {
                        string line = "";
                        foreach (var cell in row.Cells)
                        {
                            if (cell.InvariantParseDoubleNull() != null || cell.InvariantParseLongNull() != null)
                            {
                                line = line.AppendPrePad(cell, ",");
                            }
                            else
                            {
                                string celln = cell.Replace("_Name;", "");

                                line = line.AppendPrePad(celln.AlwaysQuoteString(), ",");
                            }
                        }

                        Console.WriteLine($"    {precode}({line}),");
                    }
                }
            }
            else
            {
                Console.WriteLine("Unknown command, run with empty line for help");
            }
        }
Esempio n. 5
0
        public static void StatusSet(CommandArgs args)
        {
            long   flags = 0, flags2 = 0;
            int    cargo             = 0;
            double fuel              = 0;
            int    gui               = 0;
            int    fg                = 1;
            double oxygen            = 1.0;
            double health            = 1.0;
            double temperature       = 293.0;
            string SelectedWeapon    = "";
            string SelectedWeaponLoc = "";
            double gravity           = 0.166399;
            double lat               = 3.2;
            double lon               = 6.2;
            double heading           = 92.3;
            double altitude          = -999;
            double planetradius      = -999;
            string bodyname          = "";

            int[] pips = new int[] { 2, 8, 2 };

            string legalstate = "Clean";

            if (args.Left == 0)
            {
                Console.WriteLine("Status [C:cargo] [F:fuel] [FG:Firegroup] [G:Gui] [L:Legalstate] [0x:flag dec int]\n" +
                                  "       [GV:gravity] [H:health] [O:oxygen] [T:Temp] [S:selectedweapon] [B:bodyname] [P:W,E,S]\n" +
                                  "       [normalspace | supercruise | dockedstarport | dockedinstallation | fight | fighter |\n" +
                                  "        landed | SRV | TaxiNormalSpace | TaxiSupercruise | Off\n" +
                                  "        onfootininstallation | onfootplanet |\n" +
                                  "        onfootinplanetaryporthangar | onfootinplanetaryportsocialspace |\n" +
                                  "        onfootinstarporthangar | onfootinstarportsocialspace |\n"
                                  );
                Console.WriteLine("       " + string.Join(",", Enum.GetNames(typeof(StatusFlagsShip))));
                Console.WriteLine("       " + string.Join(",", Enum.GetNames(typeof(StatusFlagsSRV))));
                Console.WriteLine("       " + string.Join(",", Enum.GetNames(typeof(StatusFlagsAll))));
                Console.WriteLine("       " + string.Join(",", Enum.GetNames(typeof(StatusFlagsShipType))));
                Console.WriteLine("       " + string.Join(",", Enum.GetNames(typeof(StatusFlagsOnFoot))));
                return;
            }


            string v;

            while ((v = args.Next()) != null)
            {
                if (v.Equals("Off", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags = 0;
                }
                else if (v.Equals("Supercruise", StringComparison.InvariantCultureIgnoreCase))               // checked alpha 4
                {
                    flags = (1L << (int)StatusFlagsShipType.InMainShip) |
                            (1L << (int)StatusFlagsShip.Supercruise) |
                            (1L << (int)StatusFlagsAll.ShieldsUp);
                }
                else if (v.Equals("NormalSpace", StringComparison.InvariantCultureIgnoreCase))          // checked alpha 4
                {
                    flags = (1L << (int)StatusFlagsShipType.InMainShip) |
                            (1L << (int)StatusFlagsAll.ShieldsUp);
                }
                else if (v.Equals("TaxiSupercruise", StringComparison.InvariantCultureIgnoreCase))               // checked alpha 4
                {
                    flags = (1L << (int)StatusFlagsShipType.InMainShip) |
                            (1L << (int)StatusFlagsShip.Supercruise) |
                            (1L << (int)StatusFlagsAll.ShieldsUp);
                    flags2 = (1L << (int)StatusFlagsOnFoot.InTaxi);
                }
                else if (v.Equals("TaxiNormalSpace", StringComparison.InvariantCultureIgnoreCase))          // checked alpha 4
                {
                    flags = (1L << (int)StatusFlagsShipType.InMainShip) |
                            (1L << (int)StatusFlagsAll.ShieldsUp);
                    flags2 = (1L << (int)StatusFlagsOnFoot.InTaxi);
                }
                else if (v.Equals("Fight", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags = (1L << (int)StatusFlagsShipType.InMainShip) |
                            (1L << (int)StatusFlagsAll.ShieldsUp) |
                            (1L << (int)StatusFlagsShip.HardpointsDeployed);
                }
                else if (v.Equals("Fighter", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags = (1L << (int)StatusFlagsShipType.InFighter) |
                            (1L << (int)StatusFlagsAll.ShieldsUp);
                }
                else if (v.Equals("DockedStarPort", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags = (1L << (int)StatusFlagsShip.Docked) |
                            (1L << (int)StatusFlagsShip.LandingGear) |
                            (1L << (int)StatusFlagsShip.FsdMassLocked) |
                            (1L << (int)StatusFlagsAll.ShieldsUp) |
                            (1L << (int)StatusFlagsShipType.InMainShip);
                }
                else if (v.Equals("DockedInstallation", StringComparison.InvariantCultureIgnoreCase))   // TBD
                {
                    flags = (1L << (int)StatusFlagsShip.Docked) |
                            (1L << (int)StatusFlagsShip.LandingGear) |
                            (1L << (int)StatusFlagsShip.FsdMassLocked) |
                            (1L << (int)StatusFlagsAll.ShieldsUp) |
                            (1L << (int)StatusFlagsAll.HasLatLong) |
                            (1L << (int)StatusFlagsShipType.InMainShip);

                    bodyname     = "Nervi 2g";
                    altitude     = 0;
                    planetradius = 2796748.25;
                }
                else if (v.Equals("OnFootInPlanetaryPortHangar", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags  = (1L << (int)StatusFlagsAll.HasLatLong);
                    flags2 = (1L << (int)StatusFlagsOnFoot.OnFoot) |
                             (1L << (int)StatusFlagsOnFoot.OnFootOnPlanet) |
                             (1L << (int)StatusFlagsOnFoot.OnFootInHangar) |
                             (1L << (int)StatusFlagsOnFoot.OnFootInSocialSpace) |
                             (1L << (int)StatusFlagsOnFoot.BreathableAtmosphere);
                    bodyname = "Nervi 2g??";
                }
                else if (v.Equals("OnFootInPlanetaryPortSocialSpace", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags  = (1L << (int)StatusFlagsAll.HasLatLong);
                    flags2 = (1L << (int)StatusFlagsOnFoot.OnFoot) |
                             (1L << (int)StatusFlagsOnFoot.OnFootOnPlanet) |
                             (1L << (int)StatusFlagsOnFoot.OnFootInSocialSpace) |
                             (1L << (int)StatusFlagsOnFoot.BreathableAtmosphere);
                    bodyname = "Nervi 2g";
                }
                else if (v.Equals("OnFootInStarportHangar", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags  = (1L << (int)StatusFlagsAll.HasLatLong);
                    flags2 = (1L << (int)StatusFlagsOnFoot.OnFoot) |
                             (1L << (int)StatusFlagsOnFoot.OnFootInStation) |
                             (1L << (int)StatusFlagsOnFoot.OnFootInHangar) |
                             (1L << (int)StatusFlagsOnFoot.OnFootInSocialSpace) |
                             (1L << (int)StatusFlagsOnFoot.BreathableAtmosphere);
                    bodyname = "Drexler Colony";
                }
                else if (v.Equals("OnFootInStarportSocialSpace", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags  = (1L << (int)StatusFlagsAll.HasLatLong);
                    flags2 = (1L << (int)StatusFlagsOnFoot.OnFoot) |
                             (1L << (int)StatusFlagsOnFoot.OnFootInStation) |
                             (1L << (int)StatusFlagsOnFoot.OnFootInSocialSpace) |
                             (1L << (int)StatusFlagsOnFoot.BreathableAtmosphere);
                    bodyname = "Starport";
                }
                else if (v.Equals("OnFootInInstallation", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags  = (1L << (int)StatusFlagsAll.HasLatLong);
                    flags2 = (1L << (int)StatusFlagsOnFoot.OnFoot) |
                             (1L << (int)StatusFlagsOnFoot.OnFootOnPlanet) |
                             (1L << (int)StatusFlagsOnFoot.Cold) |
                             (1L << (int)StatusFlagsOnFoot.OnFootExterior);     // tbd if this is correct
                    temperature       = 82;
                    SelectedWeapon    = "$humanoid_fists_name;";
                    SelectedWeaponLoc = "Unarmed";
                    bodyname          = "Nervi 2g";
                }
                else if (v.Equals("OnFootPlanet", StringComparison.InvariantCultureIgnoreCase))
                {
                    flags             = (1L << (int)StatusFlagsAll.HasLatLong);
                    flags2            = (1L << (int)StatusFlagsOnFoot.OnFoot) | (1L << (int)StatusFlagsOnFoot.OnFootOnPlanet);
                    temperature       = 78;
                    bodyname          = "Nervi 2g";
                    SelectedWeapon    = "$humanoid_fists_name;";
                    SelectedWeaponLoc = "Unarmed";
                }
                else if (v.Equals("Landed", StringComparison.InvariantCultureIgnoreCase))           // checked alpha 4
                {
                    flags = (1L << (int)StatusFlagsShipType.InMainShip) |
                            (1L << (int)StatusFlagsShip.Landed) |
                            (1L << (int)StatusFlagsShip.LandingGear) |
                            (1L << (int)StatusFlagsShip.FsdMassLocked) |
                            (1L << (int)StatusFlagsAll.ShieldsUp) |
                            (1L << (int)StatusFlagsAll.HasLatLong) |
                            (1L << (int)StatusFlagsAll.Lights);
                    bodyname     = "Nervi 2g";
                    planetradius = 292892882.2;
                    altitude     = 0;
                }
                else if (v.Equals("SRV", StringComparison.InvariantCultureIgnoreCase))              // checked alpha 4
                {
                    flags = (1L << (int)StatusFlagsAll.ShieldsUp) |
                            (1L << (int)StatusFlagsAll.Lights) |
                            (1L << (int)StatusFlagsAll.HasLatLong) |
                            (1L << (int)StatusFlagsShipType.InSRV);
                    bodyname     = "Nervi 2g";
                    planetradius = 292892882.2;
                    altitude     = 0;
                }
                else if (v.StartsWith("C:"))
                {
                    cargo = v.Mid(2).InvariantParseInt(0);
                }
                else if (v.StartsWith("F:"))
                {
                    fuel = v.Mid(2).InvariantParseDouble(0);
                }
                else if (v.StartsWith("FG:"))
                {
                    fg = v.Mid(3).InvariantParseInt(0);
                }
                else if (v.StartsWith("G:"))
                {
                    gui = v.Mid(2).InvariantParseInt(0);
                }
                else if (v.StartsWith("0x:"))
                {
                    flags = long.Parse(v.Mid(3), System.Globalization.NumberStyles.HexNumber);
                }
                else if (v.StartsWith("L:"))
                {
                    legalstate = v.Mid(2);
                }
                else if (v.StartsWith("H:"))
                {
                    health = v.Mid(2).InvariantParseDouble(0);
                }
                else if (v.StartsWith("T:"))
                {
                    temperature = v.Mid(2).InvariantParseDouble(0);
                }
                else if (v.StartsWith("O:"))
                {
                    oxygen = v.Mid(2).InvariantParseDouble(0);
                }
                else if (v.StartsWith("GV:"))
                {
                    gravity = v.Mid(3).InvariantParseDouble(0);
                }
                else if (v.StartsWith("P:"))
                {
                    pips = v.Mid(2).RestoreArrayFromString(0, 3);
                }
                else if (v.StartsWith("B:"))
                {
                    bodyname = v.Mid(2);
                }
                else if (v.StartsWith("S:"))
                {
                    SelectedWeapon    = v.Mid(2);
                    SelectedWeaponLoc = SelectedWeapon + "_loc";
                }
                else if (Enum.TryParse <StatusFlagsShip>(v, true, out StatusFlagsShip s))
                {
                    flags |= 1L << (int)s;
                }
                else if (Enum.TryParse <StatusFlagsSRV>(v, true, out StatusFlagsSRV sv))
                {
                    flags |= 1L << (int)sv;
                }
                else if (Enum.TryParse <StatusFlagsAll>(v, true, out StatusFlagsAll a))
                {
                    flags |= 1L << (int)a;
                }
                else if (Enum.TryParse <StatusFlagsShipType>(v, true, out StatusFlagsShipType st))
                {
                    flags |= 1L << (int)st;
                }
                else if (Enum.TryParse <StatusFlagsOnFoot>(v, true, out StatusFlagsOnFoot of))
                {
                    flags2 |= 1L << (int)of;
                }
                else
                {
                    Console.WriteLine("Bad flag " + v);
                    Console.WriteLine("Flags " + String.Join(",", Enum.GetNames(typeof(StatusFlagsShip))));
                    Console.WriteLine("Flags " + String.Join(",", Enum.GetNames(typeof(StatusFlagsSRV))));
                    Console.WriteLine("Flags " + String.Join(",", Enum.GetNames(typeof(StatusFlagsAll))));
                    Console.WriteLine("Flags " + String.Join(",", Enum.GetNames(typeof(StatusFlagsShipType))));
                    Console.WriteLine("Flags2 " + String.Join(",", Enum.GetNames(typeof(StatusFlagsOnFoot))));
                    return;
                }
            }

            BaseUtils.QuickJSONFormatter qj = new QuickJSONFormatter();

            qj.Object().UTC("timestamp").V("event", "Status");
            qj.V("Flags", flags);

            if (flags != 0 || flags2 != 0)
            {
                qj.V("Flags2", flags2);

                if ((flags2 & (1 << (int)StatusFlagsOnFoot.OnFoot)) != 0)
                {
                    qj.V("Oxygen", oxygen);
                    qj.V("Health", health);
                    if (temperature < 0)
                    {
                        qj.Literal("\"Temperature\":nan");
                    }
                    else
                    {
                        qj.V("Temperature", temperature);
                    }
                    qj.V("SelectedWeapon", SelectedWeapon);
                    if (SelectedWeaponLoc.HasChars())
                    {
                        qj.V("SelectedWeapon_Localised", SelectedWeaponLoc);
                    }
                    qj.V("Gravity", gravity);
                }
                else
                {
                    qj.V("Pips", pips);
                    qj.V("FireGroup", fg);
                    qj.V("GuiFocus", gui);
                }

                if ((flags & (1 << (int)StatusFlagsShipType.InMainShip)) != 0 || (flags & (1 << (int)StatusFlagsShipType.InSRV)) != 0)
                {
                    qj.Object("Fuel").V("FuelMain", fuel).V("FuelReservoir", 0.32).Close();
                    qj.V("Cargo", cargo);
                }

                qj.V("LegalState", legalstate);

                if ((flags & (1 << (int)StatusFlagsAll.HasLatLong)) != 0)
                {
                    qj.V("Latitude", lat);
                    qj.V("Longitude", lon);
                    qj.V("Heading", heading);

                    if (altitude >= 0)
                    {
                        qj.V("Altitude", altitude);
                    }
                }

                if (bodyname.HasChars())
                {
                    qj.V("BodyName", bodyname);
                }

                if (planetradius >= 0)
                {
                    qj.V("PlanetRadius", planetradius);
                }
            }

            qj.Close();

            string j = qj.Get();

            File.WriteAllText("Status.json", j);
            JToken jk = JToken.Parse(j);

            if (jk != null)
            {
                DecodeJson("Status Write", jk);
            }
            else
            {
                Console.WriteLine("Bad JSON written");
            }
        }
Esempio n. 6
0
        public static void StatusMove(CommandArgs args)
        {
            long flags = (1L << (int)StatusFlagsShipType.InSRV) |
                         (1L << (int)StatusFlagsShip.Landed) |
                         (1L << (int)StatusFlagsAll.ShieldsUp) |
                         (1L << (int)StatusFlagsAll.Lights);

            double latitude   = 0;
            double longitude  = 0;
            double latstep    = 0;
            double longstep   = 0;
            double heading    = 0;
            double headstep   = 1;
            int    steptime   = 100;
            int    fg         = 1;
            int    gui        = 0;
            string legalstate = "Clean";
            double fuel       = 31.2;
            double fuelres    = 0.23;
            int    cargo      = 23;

            if (!double.TryParse(args.Next(), out latitude) || !double.TryParse(args.Next(), out longitude) ||
                !double.TryParse(args.Next(), out latstep) || !double.TryParse(args.Next(), out longstep) ||
                !double.TryParse(args.Next(), out heading) || !double.TryParse(args.Next(), out headstep) ||
                !int.TryParse(args.Next(), out steptime))
            {
                Console.WriteLine("** More/Wrong parameters: statusjson lat long latstep lonstep heading headstep steptimems");
                return;
            }

            while (true)
            {
                //{ "timestamp":"2018-03-01T21:51:36Z", "event":"Status", "Flags":18874376,
                //"Pips":[4,8,0], "FireGroup":1, "GuiFocus":0, "Latitude":-18.978821, "Longitude":-123.642052, "Heading":308, "Altitude":20016 }

                Console.WriteLine("{0:0.00} {1:0.00} H {2:0.00} F {3:0.00}:{4:0.00}", latitude, longitude, heading, fuel, fuelres);
                BaseUtils.QuickJSONFormatter qj = new QuickJSONFormatter();

                double altitude = 404;

                qj.Object().UTC("timestamp").V("event", "Status");
                qj.V("Flags", flags);
                qj.V("Pips", new int[] { 2, 8, 2 });
                qj.V("FireGroup", fg);
                qj.V("GuiFocus", gui);
                qj.V("LegalState", legalstate);
                qj.V("Latitude", latitude);
                qj.V("Longitude", longitude);
                qj.V("Heading", heading);
                qj.V("Altitude", altitude);

                qj.Object("Fuel").V("FuelMain", fuel).V("FuelReservoir", fuelres).Close();
                qj.V("Cargo", cargo);
                qj.Close();

                File.WriteAllText("Status.json", qj.Get());
                System.Threading.Thread.Sleep(steptime);

                if (Console.KeyAvailable && Console.ReadKey().Key == ConsoleKey.Escape)
                {
                    break;
                }

                latitude += latstep;
                longitude = longitude + longstep;
                heading   = (heading + headstep) % 360;

                fuelres -= 0.02;
                if (fuelres < 0)
                {
                    fuel--;
                    fuelres = 0.99;
                }
            }
        }