Ejemplo n.º 1
0
        private static void StartLiteNetLibServer()
        {
            var logger = System.Console.Out;
            var server = new LiteNetLibServer(logger);

            var timer = new Timer(state => server.PollEvents(), null, 1000, 10);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int roomSize      = 2;
            int waitInSeconds = 5;

            var sw = new Stopwatch();

            sw.Start();
            Console.Write($"Enter room size (defaults to {roomSize} after {waitInSeconds} seconds): ");
            while (!Console.KeyAvailable && sw.Elapsed.Seconds < waitInSeconds)
            {
                Thread.Sleep(1);
            }
            sw.Stop();

            if (Console.KeyAvailable)
            {
                roomSize = Console.ReadKey().KeyChar - 48;
            }
            Console.Write(Environment.NewLine);

            var server = new LiteNetLibServer();

            var room = new Room(server, roomSize);

            room.Open(9050);

            while (!Console.KeyAvailable)
            {
                server.PollEvents();
                Thread.Sleep(1);
            }
        }
Ejemplo n.º 3
0
    public LnlServerHost()
    {
        _testEnvironment = new TestEnvironmoent();

        _loader = new Mod.Loader.Loader(true);
        _loader.LoadForCurrentProcess();

        _host   = LiteNetLibServer.Create(_loader.Logger, _loader.Manager.LoaderApi, new Utils.Server.Configuration.Config());
        _client = new LiteNetLibClient(IPAddress.Loopback, "", _host.Host.Manager.LocalPort);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Asynchronously starts the host.
    /// </summary>
    public static LiteNetLibServer Create(ILogger logger, IModLoader modLoader, Config config)
    {
        var mod = new LiteNetLibServer(logger, modLoader);

        mod.Host = new LiteNetLibHost <MessageDispatcher <LiteNetLibState> >(true, new MessageDispatcher <LiteNetLibState>());
        mod.Host.ConnectionRequestEvent += mod.HandleConnectionRequest;

        new SetModState().AddToDispatcher(mod, ref mod.Host.Dispatcher);
        new GetLoadedMods().AddToDispatcher(mod, ref mod.Host.Dispatcher);

        mod.RestartWithConfig(config);
        return(mod);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Entry point for your mod.
    /// </summary>
    public async void StartEx(IModLoaderV1 loaderApi, IModConfigV1 modConfig)
    {
        // For more information about this template, please see
        // https://reloaded-project.github.io/Reloaded-II/ModTemplate/
        _modLoader = (IModLoader)loaderApi;
        _modConfig = (IModConfig)modConfig;
        _logger    = (ILogger)_modLoader.GetLogger();

        // Your config file is in Config.json.
        // Need a different name, format or more configurations? Modify the `Configurator`.
        // If you do not want a config, remove Configuration folder and Config class.
        var configurator = new Configurator(_modLoader.GetModConfigDirectory(_modConfig.ModId));

        _configuration = configurator.GetConfiguration <Config>(0);
        _configuration.ConfigurationUpdated += OnConfigurationUpdated;

        // Start the server on another thread so we don't delay startup with JIT overhead.
        _lnlServer = await Task.Run(() => LiteNetLibServer.Create(_logger, _modLoader, _configuration));
    }
Ejemplo n.º 6
0
        public Form1()
        {
            InitializeComponent();
            Width          = 800;
            Height         = 600;
            DoubleBuffered = true;

            random = new Random();
            server = new LiteNetLibServer();

            this.MouseClick += Click;

            field = new Field(Width - 50, Height - 50);

            updateTimer          = new Timer();
            updateTimer.Interval = 1000 / SimulationUpdatesPerSec; // 20 times per sec
            updateTimer.Tick    += Update_Tick;

            updateTimer.Start();

            drawTimer          = new Timer();
            drawTimer.Interval = 1000 / DrawUpdatesPerSec; // 60 fps
            drawTimer.Tick    += Draw_Tick;

            drawTimer.Start();

            networkTimer          = new Timer();
            networkTimer.Interval = 1000 / NetworkUpdatesPerSec;
            networkTimer.Tick    += Network_Tick;

            networkTimer.Start();

            label2.Text = "0"; // circles
            label4.Text = "0"; // clients
            label6.Text = "0"; // msg size
            label8.Text = "0";
        }