예제 #1
0
        static void Main()
        {
            // Avoid running 2 servers at once.
            // Clients prevent it anyway using mutex but that doesn't cover
            // scenario where server is manually started multiple times.
            if (Server.isServerAlreadyRunning())
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ServerForm server_form = new ServerForm();

            Application.Run(server_form);
        }
예제 #2
0
        public Server(ServerForm form_ = null)
        {
            loaded   = false;
            form     = form_;
            has_form = form_ != null;

            market            = new Market(this);
            Connection.market = market;

            Action on_load = () => {
                if (market.was_market_interrupted)
                {
                    Log("The server was closed or killed while having connected clients, data will be restored.", "WARNING");
                    Log($"If the stock holder ({market.StockHolderId}) does not return within 5 seconds, the stock will be released.", "WARNING");
                    scheduleStockReleaseIfOwnerAbandoned(5000);
                    scheduleDidntReconnectMessages(5000);
                }

                Thread t = new Thread(RunServer);
                // if has form then thread cannot exist without it
                // if does not have form, then thread can exist on it's own
                t.IsBackground = has_form;
                t.Name         = $"RunServer thread";
                t.Start();
                loaded = true;
            };

            if (has_form)
            {
                form.Load += new EventHandler((object o, EventArgs e) => on_load());
            }
            else
            {
                on_load();
            }
        }