Exemple #1
0
        private static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.Title           = "ENVIUM DEDICATED SERVER";

            Out.MsgC(ConsoleColor.Green, "Initializing the server ...");

            _buffer        = new byte[4096];
            _boundEndPoint = new IPEndPoint(IPAddress.Any, 644);

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            try {
                _socket.Bind(_boundEndPoint);
            } catch (SocketException ex) {
                Out.Error("Network: Cannot bound at address {0}: {1}", _boundEndPoint, ex.Message);
                Console.ReadLine();
                return;
            }

            Out.Msg("Network: Socket bounded at {0}", _socket.LocalEndPoint as IPEndPoint);

            FrameSnapshotManager = new FrameSnapshotManager();
            ServerPluginHandler  = new ServerPlugin();
            Server = new GameServer(_socket)
            {
                State        = EServerState.Loading,
                TickInterval = GetTickInterval()
            };

            Networking.Initialize();

            new Thread(GameTick)
            {
                IsBackground = true
            }.Start();
            Server.State = EServerState.Active;
            Out.Msg("Done loading.");

            var clientEp = (EndPoint) new IPEndPoint(IPAddress.Any, 0);

            _socket.BeginReceiveFrom(_buffer, 0, _buffer.Length, SocketFlags.None, ref clientEp, DoReceiveFrom, clientEp);

            string read;

            while ((read = Console.ReadLine()) != "exit")
            {
                if (read == "help")
                {
                    continue;
                }

                if (read == "curtime")
                {
                    var time = Utils.SysTime();
                    Console.WriteLine("Current server time: {0}", time);
                    continue;
                }

                Console.WriteLine("Unknown command \"{0}\".", read);
            }
        }