Exemple #1
0
        public LFSClient(string scriptfilename, bool debugmode)
        {

            this.debugmode = debugmode;

            ConsoleCtrl cc = new ConsoleCtrl();
            cc.ControlEvent += new ConsoleCtrl.ControlEventHandler(inputHandler);


            #region Car Names Tables
            shortCarNames.Add("UF1"); longCarNames.Add("UF 1000");
            shortCarNames.Add("XFG"); longCarNames.Add("XF GTI");
            shortCarNames.Add("XRG"); longCarNames.Add("XR GT");
            shortCarNames.Add("XRT"); longCarNames.Add("XR GT TURBO");
            shortCarNames.Add("RB4"); longCarNames.Add("RB4 GT");
            shortCarNames.Add("FXO"); longCarNames.Add("FXO TURBO");
            shortCarNames.Add("LX4"); longCarNames.Add("LX4");
            shortCarNames.Add("LX6"); longCarNames.Add("LX6");
            shortCarNames.Add("RAC"); longCarNames.Add("RA");
            shortCarNames.Add("FZ5"); longCarNames.Add("FZ50");
            shortCarNames.Add("MRT"); longCarNames.Add("MRT5");
            shortCarNames.Add("XFR"); longCarNames.Add("XF GTR");
            shortCarNames.Add("UFR"); longCarNames.Add("UF GTR");
            shortCarNames.Add("FOX"); longCarNames.Add("FORMULA XR");
            shortCarNames.Add("FO8"); longCarNames.Add("FORMULA V8");
            shortCarNames.Add("FXR"); longCarNames.Add("FXO GTR");
            shortCarNames.Add("XRR"); longCarNames.Add("XR GTR");
            shortCarNames.Add("FZR"); longCarNames.Add("FZ50 GTR");
            shortCarNames.Add("BF1"); longCarNames.Add("BMW SAUBER");
            shortCarNames.Add("FBM"); longCarNames.Add("BMW FB02");
            #endregion

            #region Configuring LFSStat

			// Load Config
            LFS.Configurator cfg = new LFS.Configurator();
            cfg.Load(scriptfilename);
			// Load World Record
            string PubStatIdk = cfg.Get("PubStatIdk");
            string PubStatUser = cfg.Get("PubStatUser");
            string PubStatPass = cfg.Get("PubStatPass");
            Console.Write("Loading WR...");
            if (wr.load(PubStatUser, PubStatPass, PubStatIdk))
            {
                wrLoaded = true;
                Console.WriteLine("Ok");
            }
            else
            {
                wrLoaded = false;
                Console.WriteLine("Not Loaded");
            }
			
            string adminPassword = cfg.Get("Password");

            string host = cfg.Get("Host");
			if (host == "")
				host = "127.0.0.1";

			int port = 29999;
			try { port = int.Parse(cfg.Get("Port")); }
			catch (Exception) { }

            language = cfg.Get("lang");
            if (language == "")
                language = "english";
            exportstats.getLang(language);

            raceDir = cfg.Get("raceDir");
            if (raceDir == "")
                raceDir = ".";
            qualDir = cfg.Get("qualDir");
            if (qualDir == "")
                qualDir = ".";

            try { maxTimeQualIgnore = int.Parse(cfg.Get("maxTimeQualIgnore")); }
            catch (Exception) { }

            try { TCPmode = bool.Parse(cfg.Get("TCPmode")); }
            catch (Exception) { }

			try { askForFileNameOnRST = bool.Parse(cfg.Get("askForFileNameOnRST")); }
			catch (Exception) { }

			try { askForFileNameOnSTA = bool.Parse(cfg.Get("askForFileNameOnSTA")); }
			catch (Exception) { }

			try { generateGraphs = bool.Parse(cfg.Get("generateGraphs")); }
			catch (Exception) { }

			// Export Statistics when STAte changed?
			exportOnSTAte = cfg.Get("exportOnSTAte");
			switch (exportOnSTAte)
			{
				case "yes":
				case "no":
				case "ask":
					break;

				default:
					exportOnSTAte = "yes";
					break;
			}
			// Export Statistics when Race STart?
			exportOnRaceSTart = cfg.Get("exportOnRaceSTart");
			switch (exportOnRaceSTart)
			{
				case "yes":
				case "no":
				case "ask":
					break;

				default:
					exportOnRaceSTart = "yes";
					break;
			}

            #endregion

            insimConnection.insimConnect(host, port, adminPassword , "U", "LFSStat",false,TCPmode );
            string info = "Product:" + insimConnection.Product + " Version:" + insimConnection.Version + " InSim Version:" + insimConnection.InSimVersion;
            Console.WriteLine(info);
/*
            uc = new System.Net.Sockets.UdpClient(host, port);

#if MONO
            int localport = 0;  //for mono
#else
            int localport = ((System.Net.IPEndPoint)uc.Client.LocalEndPoint).Port;//for .NET
#endif

            // init
            byte[] inSimInit = InSim.Encoder.ISI(adminPassword,localport,0);
            uc.Send(inSimInit, inSimInit.Length);

            //request version
            byte[] verreq = InSim.Encoder.VER();
            uc.Send(verreq, verreq.Length);

            //retr version info
            System.Net.IPEndPoint remoteEP = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
            byte[] recvPacket = uc.Receive(ref remoteEP);
            InSim.Decoder.VER ver = new InSim.Decoder.VER(recvPacket);
            string info = "Product:" + ver.Product + " Version:" + ver.Version + " InSim Version:" + ver.InSimVersion;
            Console.WriteLine(info);

            // send ver info to console
            SendMsg("/msg " + info);
*/
            byte[] intervalReq = InSim.Encoder.NLI(100);    //receive status every 100 ms
            insimConnection.Send(intervalReq,intervalReq.Length);

            Console.WriteLine("LFSStat is running...");
            byte[] sstreq = InSim.Encoder.SST();
            insimConnection.Send(sstreq, sstreq.Length);

            Loop(insimConnection);
//            Loop(uc);

            // terminate
            byte[] terreq = InSim.Encoder.ISC();
            insimConnection.Send(terreq, terreq.Length);

            insimConnection.Close();
//            uc.Close();
        }
Exemple #2
0
 // To intercept Ctrl-C, ..., and other break and Close Lapper in safe mode
 public void inputHandler(ConsoleCtrl.ConsoleEvent consoleEvent)
 {
     if (consoleEvent == ConsoleCtrl.ConsoleEvent.CtrlC
         || consoleEvent == ConsoleCtrl.ConsoleEvent.CtrlClose
         || consoleEvent == ConsoleCtrl.ConsoleEvent.CtrlBreak
         || consoleEvent == ConsoleCtrl.ConsoleEvent.CtrlLogoff
         || consoleEvent == ConsoleCtrl.ConsoleEvent.CtrlShutdown)
     {
         byte[] cl = InSim.Encoder.IS_TINY((byte)InSim.TypePack.ISP_TINY, 0, (byte)InSim.TypeTiny.TINY_CLOSE);
         insimConnection.Send(cl, cl.Length);
         System.Environment.Exit(-1);
     }
 }