Exemplo n.º 1
0
Arquivo: Program.cs Projeto: 602p/krpc
 public static void Main(string[] args)
 {
     KRPC.Service.Scanner.Scanner.GetServices ();
     var cmdargs = args.ToList ();
     if (cmdargs.Contains ("--debug")) {
         cmdargs.Remove ("--debug");
         Logger.Enabled = true;
         Logger.Level = Logger.Severity.Debug;
     } else if (cmdargs.Contains ("--quiet")) {
         cmdargs.Remove ("--quiet");
         Logger.Enabled = true;
         Logger.Level = Logger.Severity.Warning;
     } else {
         Logger.Enabled = true;
         Logger.Level = Logger.Severity.Info;
     }
     if (args.Contains ("--help") || args.Contains ("-h")) {
         Help ();
         return;
     }
     ushort rpcPort, streamPort;
     try {
         rpcPort = ushort.Parse (cmdargs [0]);
         streamPort = ushort.Parse (cmdargs [1]);
     } catch (Exception) {
         Help ();
         return;
     }
     const int frameTime = 50;
     var server = new KRPCServer (IPAddress.Loopback, rpcPort, streamPort);
     KRPCServer.Context.SetGameScene (GameScene.SpaceCenter);
     var timeSpan = new TimeSpan ();
     server.GetUniversalTime = () => timeSpan.TotalSeconds;
     server.OnClientRequestingConnection += (s, e) => e.Request.Allow ();
     server.Start ();
     while (server.Running) {
         Stopwatch timer = Stopwatch.StartNew ();
         server.Update ();
         var elapsed = timer.ElapsedMilliseconds;
         var sleep = frameTime - elapsed;
         if (sleep > 0)
             System.Threading.Thread.Sleep ((int)sleep);
     }
 }
Exemplo n.º 2
0
        void Init()
        {
            if (server != null)
            {
                return;
            }

            config = new KRPCConfiguration("settings.cfg");
            config.Load();
            server = new KRPCServer(
                config.Address, config.RPCPort, config.StreamPort,
                config.OneRPCPerUpdate, config.MaxTimePerUpdate, config.AdaptiveRateControl,
                config.BlockingRecv, config.RecvTimeout);

            // Auto-start the server, if required
            if (config.AutoStartServer)
            {
                StartServer();
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            KRPC.Service.Scanner.Scanner.GetServices ();
            var cmdargs = args.ToList ();
            if (cmdargs.Contains ("--debug")) {
                cmdargs.Remove ("--debug");
                Logger.Enabled = true;
                Logger.Level = Logger.Severity.Debug;
            } else if (cmdargs.Contains ("--quiet")) {
                cmdargs.Remove ("--quiet");
                Logger.Enabled = true;
                Logger.Level = Logger.Severity.Warning;
            } else {
                Logger.Enabled = true;
                Logger.Level = Logger.Severity.Info;
            }
            bool serverDebug = cmdargs.Contains ("--server-debug");
            cmdargs.Remove ("--server-debug");
            if (args.Contains ("--help") || args.Contains ("-h")) {
                Help ();
                return;
            }
            ushort rpcPort, streamPort;
            try {
                rpcPort = ushort.Parse (cmdargs [0]);
                streamPort = ushort.Parse (cmdargs [1]);
            } catch (Exception) {
                Help ();
                return;
            }

            server = new KRPCServer (IPAddress.Loopback, rpcPort, streamPort);
            KRPCServer.Context.SetGameScene (GameScene.SpaceCenter);
            var timeSpan = new TimeSpan ();
            server.GetUniversalTime = () => timeSpan.TotalSeconds;
            server.OnClientRequestingConnection += (s, e) => e.Request.Allow ();
            server.Start ();

            const long targetFPS = 60;
            long update = 0;
            long ticksPerUpdate = Stopwatch.Frequency / targetFPS;
            var timer = new Stopwatch ();
            while (server.Running) {
                timer.Reset ();
                timer.Start ();

                server.Update ();

                if (serverDebug && update % targetFPS == 0) {
                    // Output details about whether server.Update() took too little or too long to execute
                    var elapsed = timer.ElapsedTicks;
                    var diffTicks = Math.Abs (ticksPerUpdate - elapsed);
                    var diffTime = Math.Round ((double)diffTicks / (double)Stopwatch.Frequency * 1000d, 2);
                    if (elapsed > ticksPerUpdate)
                        Console.WriteLine ("Slow by " + diffTime + " ms (" + diffTicks + " ticks)");
                    else
                        Console.WriteLine ("Fast by " + diffTime + " ms (" + diffTicks + " ticks)");
                }

                // Wait, to force 60 FPS
                while (timer.ElapsedTicks < ticksPerUpdate) {
                }
                update++;
            }
        }
Exemplo n.º 4
0
 internal static void Set(KRPCServer server, IClient rpcClient)
 {
     Server    = server;
     RPCClient = rpcClient;
 }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            bool showHelp = false;
            bool showVersion = false;

            Logger.Enabled = true;
            Logger.Level = Logger.Severity.Info;
            RPCException.VerboseErrors = false;
            bool serverDebug = false;
            String writePortsPath = null;
            ushort rpcPort = 0;
            ushort streamPort = 0;

            var options = new OptionSet () { {
                    "h|help", "show this help message and exit",
                    v => showHelp = v != null
                }, {
                    "v|version", "show program's version number and exit",
                    v => showVersion = v != null
                }, {
                    "rpc-port=", "Port number to use for the RPC server. If unspecified, use an ephemeral port.",
                    (ushort v) => rpcPort = v
                }, {
                    "stream-port=", "Port number to use for the stream server. If unspecified, use an ephemeral port.",
                    (ushort v) => streamPort = v
                }, {
                    "debug", "Set log level to 'debug', defaults to 'info'",
                    v => {
                        if (v != null) {
                            Logger.Enabled = true;
                            Logger.Level = Logger.Severity.Debug;
                            RPCException.VerboseErrors = true;
                        }
                    }
                }, { "quiet", "Set log level to 'warning'",
                    v => {
                        if (v != null) {
                            Logger.Enabled = true;
                            Logger.Level = Logger.Severity.Warning;
                            RPCException.VerboseErrors = false;
                        }
                    }
                }, {
                    "server-debug", "Output debug information about the server",
                    v => serverDebug = v != null
                }, { "write-ports=", "Write the server's port numbers to the given {FILE}",
                    v => writePortsPath = v
                },
            };
            options.Parse (args);

            if (showHelp) {
                Help (options);
                return;
            }

            if (showVersion) {
                var assembly = Assembly.GetEntryAssembly ();
                var info = FileVersionInfo.GetVersionInfo (assembly.Location);
                var version = String.Format ("{0}.{1}.{2}", info.FileMajorPart, info.FileMinorPart, info.FileBuildPart);
                Console.WriteLine ("TestServer.exe version " + version);
                return;
            }

            KRPC.Service.Scanner.Scanner.GetServices ();
            server = new KRPCServer (IPAddress.Loopback, rpcPort, streamPort);
            KRPCServer.Context.SetGameScene (GameScene.SpaceCenter);
            var timeSpan = new TimeSpan ();
            server.GetUniversalTime = () => timeSpan.TotalSeconds;
            server.OnClientRequestingConnection += (s, e) => e.Request.Allow ();
            server.Start ();

            if (writePortsPath != null)
                System.IO.File.WriteAllText (writePortsPath, server.RPCPort.ToString () + "\n" + server.StreamPort.ToString () + "\n");

            const long targetFPS = 60;
            long update = 0;
            long ticksPerUpdate = Stopwatch.Frequency / targetFPS;
            var timer = new Stopwatch ();
            while (server.Running) {
                timer.Reset ();
                timer.Start ();

                server.Update ();

                if (serverDebug && update % targetFPS == 0) {
                    // Output details about whether server.Update() took too little or too long to execute
                    var elapsed = timer.ElapsedTicks;
                    var diffTicks = Math.Abs (ticksPerUpdate - elapsed);
                    var diffTime = Math.Round ((double)diffTicks / (double)Stopwatch.Frequency * 1000d, 2);
                    if (elapsed > ticksPerUpdate)
                        Console.WriteLine ("Slow by " + diffTime + " ms (" + diffTicks + " ticks)");
                    else
                        Console.WriteLine ("Fast by " + diffTime + " ms (" + diffTicks + " ticks)");
                }

                // Wait, to force 60 FPS
                while (timer.ElapsedTicks < ticksPerUpdate) {
                }
                update++;
            }
        }
Exemplo n.º 6
0
 internal static void Set(KRPCServer server, IClient rpcClient)
 {
     Server = server;
     RPCClient = rpcClient;
 }
Exemplo n.º 7
0
 internal static void Clear()
 {
     Server = null;
     RPCClient = null;
 }