Ejemplo n.º 1
0
        /// <summary>
        /// Bind query and heartbeat listeners to the specified port
        /// </summary>
        /// <param name="listenPort">Port (TCP and UDP) to bind the listeners to</param>
        private void Bind(int listenPort)
        {
            if (queryListeners.ContainsKey(listenPort))
            {
                MasterServer.Log("[NET] Port {0} already bound", listenPort);
                return;
            }

            try
            {
                IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, listenPort);

                QueryListener queryListener = new QueryListener(endpoint, serverList, geoIP, md5Manager, banManager, cdKeyValidator, gameStats);
                queryListeners.Add(listenPort, queryListener);

                HeartbeatListener heartbeatListener = new HeartbeatListener(endpoint);
                heartbeatListener.ReceivedHeartbeat += new ReceivedHeartbeatHandler(serverList.ReceivedHeartbeat);
                heartbeatListeners.Add(listenPort, heartbeatListener);

                MasterServer.Log("[NET] Port {0} bound successfully", listenPort);
            }
            catch (Exception ex)
            {
                MasterServer.Log("[NET] Error binding port(s) {0}, {1}", listenPort, ex.Message);

                queryListeners.Remove(listenPort);
                heartbeatListeners.Remove(listenPort);
            }

            UpdateListenPortList();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts/runs the server.
        /// </summary>
        /// <param name="databaseManager">The database manager used to interact with the master game database.</param>
        public void Run(/*DatabaseManager databaseManager*/)
        {
            this.ServerGui = ServerGui.CreateGui(this);

            this.ServerGui.AddStatusText(Resources.DatabaseManagerConnectingToDatabase);

            try
            {
                this.DbManager = new MainDatabaseDataContext();
                this.ServerGui.AddStatusText(Resources.DatabaseManagerConnectedToDatabase);

                ChatFilter.Initialize();
                PacketSender.Initialize(this);

                //// TODO: Add all the IProcessables
                //// this.processers.Add(...

                this.clientListener = new PlayerListener();
                this.clientListener.Start();

                this.queryListener = new QueryListener();
                this.queryListener.Start();

                // Server is now running!
                this.Running = true;

                // Run the processing loop...
                while (this.Running)
                {
                    this.CleanDisconnectedPlayers();

                    for (int i = 0; i < this.processers.Count; i++)
                    {
                        this.processers[i].Process();
                    }

                    // TODO: Do all processing here
                    Thread.Sleep(1);
                }

                // Shut down the connection listeners
                this.clientListener.Stop();
                this.queryListener.Stop();
                this.ServerGui.AddStatusText(Resources.NetworkListenersShutDown);

                // Disconnect all clients
                while (this.Clients.Count > 0)
                {
                    this.Clients[0].Dispose();
                    this.Clients.RemoveAt(0);
                    this.ServerGui.UpdatePlayerCount(this.Clients.Count);
                }

                // Close database connection
                // TODO: We didn't actually close anything...
                this.ServerGui.AddStatusText(Resources.DatabaseManagerConnectionCloseSuccess);

                // Successfully shut down everything
                this.ServerGui.AddStatusText(Resources.ServerSuccessfulShutdown);
            }
            catch (InvalidOperationException)
            {
                this.ServerGui.AddStatusText(Resources.DatabaseManagerConnectionFailed);
            }

            // Wait 3 seconds, destroy the GUI then fully exit the environment
            Thread.Sleep(3000);
            this.ServerGui.Dispose();
            Environment.Exit(Environment.ExitCode);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            //Bug workaround
            System.Web.Util.HttpEncoder.Current = System.Web.Util.HttpEncoder.Default;

            Directory.SetCurrentDirectory(MineSharp.Settings.BaseWorldsPath);
            Console.WriteLine();
            Console.WriteLine("Starting Mineproxy: " + DateTime.Now);
            Log.Init();

            //Init commands
            Commands.MainCommands.Init();

            System.Threading.Thread.CurrentThread.Name = "Player Listener";

            Console.CancelKeyPress += HandleConsoleCancelKeyPress;

            int controllerPort = 25465;

#if DEBUG
            //Only for debugging the live server
            //MinecraftServer.Port = 25665;

            //Debug.WriteLine(MinecraftProtocol.Minecraft.Protocol);
#endif


            //Load settings
            Banned.LoadBanned();
            MineProxy.Regions.WarpPortalVisuals.Init();

            //VoteListener.Start();
            ServerCommander.Startup();
            ControlListener.Start(controllerPort);
            BackupProxy.Start();

            try
            {
                PlayerList.StartUpdater();
                //SpawnRegion.Start ();
                Settings.Start();
                QueryListener.Start();
            } catch (Exception e)
            {
                Log.WriteServer(e);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }

            while (true)
            {
                Console.WriteLine(DateTime.Now + " Starting Main true loop");
                listener = new TcpListener(IPAddress.Any, MinecraftServer.MainPort);
                try
                {
                    listener.Start();

                    Console.WriteLine("Listening for players on " + MinecraftServer.MainPort);

                    while (Active)
                    {
                        TcpClient client = listener.AcceptTcpClient();
                        if (Active == false)
                        {
                            break;
                        }

                        //Console.WriteLine ("Got incoming");
                        try
                        {
                            //check banned ip
                            if (Banned.IsBanned(((IPEndPoint)client.Client.RemoteEndPoint).Address))
                            {
                                try
                                {
                                    client.Close();
                                } catch (Exception e)
                                {
                                    Log.WriteServer("Error closing banned ip", e);
                                }
                                continue;
                            }

                            Client proxy = new VanillaClient(client.Client);
                            proxy.Start();
                        } catch (SocketException)
                        {
                            try
                            {
                                client.Close();
                            } catch
                            {
                            }
                        }
                    }

                    //Program is exiting here
                    Console.WriteLine("Kicking all players: " + ShutdownMessage);
                    foreach (Client p in PlayerList.List)
                    {
                        p.Kick(ShutdownMessage);
                    }

                    Log.Flush();
                    ServerCommander.Shutdown();
                    ControlListener.Stop();
                    return;

#if !DEBUG
                } catch (Exception e)
                {
                    Console.WriteLine(DateTime.Now + " Main loop error: " + e.GetType().Name + " " + e.Message);
                    Log.WriteServer("MainClass.Main general", e);
                    System.Threading.Thread.Sleep(500);
#endif
                } finally
                {
                    Console.WriteLine(DateTime.Now + " Main loop finally Start");
                    try
                    {
                        //Save region stats
                        RegionLoader.Save(World.Main.Regions);
                        Regions.WarpPortalVisuals.Stop();
                    } catch (Exception e)
                    {
                        Log.WriteServer("Main closing region stats saving", e);
                    }
                    Console.WriteLine(DateTime.Now + " Main loop finally End");
                    Environment.Exit(0);
                }
            }
        }
Ejemplo n.º 4
0
    public static void Main(string[] args) 
    {
        Storage storage = StorageFactory.Instance.CreateStorage();
        storage.Open("testlinq.dbs");
        QueryListener listener = new QueryListener();
        storage.Listener = listener;
        Database db = new Database(storage);
        int n;

        Customer customer1 = new Customer();
        customer1.name = "Age Soft";
        customer1.address = "MT, Freen Valley, 5";
        customer1.phone = "111-1111";
        customer1.contactPerson = "John Smith";
        customer1.vip = true;
        db.AddRecord(customer1);

        Customer customer2 = new Customer();
        customer2.name = "WebAlta";
        customer2.address = "Moscow, Russia, Kolomenskay nab.,2";
        customer2.phone = "222-22222";
        customer2.contactPerson = "Piter Volokov";
        db.AddRecord(customer2);

        
        BugReport bug1 = new BugReport();
        bug1.issuedBy = customer1;
        bug1.priority = BugReport.Priority.Low;
        bug1.description = "It doesn't work";
        bug1.version = 1.03M;
        db.AddRecord(bug1);

        BugReport bug2 = new BugReport();
        bug2.issuedBy = customer2;
        bug2.priority = BugReport.Priority.High;
        bug2.description = "Something is definitely wrong";
        bug2.version = 2.01M;
        db.AddRecord(bug2);
       
        Console.WriteLine("Search customer by name");
        n = 0;
        foreach (Customer c in db.Select<Customer>(c => c.name == "WebAlta")) 
        { 
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        Console.WriteLine("Locate customers issued high priority bugs for version 2.0");
        n = 0;
        var query1 = from bug in db.GetTable<BugReport>()
            where bug.priority >= BugReport.Priority.High && bug.version >= 2.0M
            orderby bug.priority
            select bug.issuedBy;
        foreach (var c in query1)
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        Console.WriteLine("Select customer by name and contact person");
        n = 0;
        string name = "Age Soft";
        string person = "John Smith";
        var query2 = from c in db.GetTable<Customer>()
            where name == c.name && c.contactPerson == person
            select c;
        foreach (var c in query2)
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        name = "WebAlta";
        person = "Piter Volokov";
        n = 0;
        foreach (var c in query2)
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);
        Debug.Assert(listener.nSeqSearches == 0);

        Console.WriteLine("Select with index join");
        n = 0;
        foreach (BugReport bug in db.Select<BugReport>(bug => bug.issuedBy.name == "WebAlta" || bug.issuedBy.name == "Age Soft")) 
        { 
            Console.WriteLine(bug);
            n += 1;
        }
        Debug.Assert(n == 2);
        
        Console.WriteLine("Select with index prefix search");
        n = 0;
        foreach (Customer customer in db.Select<Customer>(customer => customer.phone == "222-22222" && customer.name.StartsWith("Web"))) 
        { 
            Console.WriteLine(customer);
            n += 1;
        }
        Debug.Assert(n == 1);

        Debug.Assert(listener.nSeqSearches == 0);
        

        Console.WriteLine("Select without search condition");
        n = 0;
        var query3 = from bug in db.GetTable<BugReport>()
                     orderby bug.priority
                     select bug;
        foreach (var b in query3)
        {
            Console.WriteLine(b);
            n += 1;
        }
        Debug.Assert(n == 2);

        Console.WriteLine("Select using sequential search");
        n = 0;
        var query4 = from bug in db.GetTable<BugReport>()
                     where bug.version >= 2.0M
                     select bug;
        foreach (var b in query4)
        {
            Console.WriteLine(b);
            n += 1;
        }
        Debug.Assert(n == 1);
        
        n = 0;
        var query5 = from bug in db.GetTable<BugReport>() 
                     where bug.issuedBy == customer1
                     select bug;
        foreach (var b in query5)
        {
            Console.WriteLine(b);
            n += 1;
        }
        Debug.Assert(n == 1);

        n = 0;
        List<Customer> customers = new List<Customer>();
        customers.Add(customer1);
        customers.Add(customer2);
        var query6 = from bug in db.GetTable<BugReport>() 
                     where customers.Contains(bug.issuedBy)
                     select bug;
        foreach (var b in query6)
        {
            Console.WriteLine(b);
            n += 1;
        }
        Debug.Assert(n == 2);

        n = 0;
        foreach (Customer c in db.Select<Customer>(c => c.name.CompareTo("A") >= 0)) 
        { 
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 2);

        n = 0;
        foreach (Customer c in db.Select<Customer>(c => String.Compare(c.name, "webalta", StringComparison.CurrentCultureIgnoreCase) == 0)) 
        { 
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        n = 0;
        foreach (Customer c in db.Select<Customer>(c => c.vip)) 
        { 
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        n = 0;
        foreach (Customer c in db.Select<Customer>(c => !c.vip)) 
        { 
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);


        Debug.Assert(listener.nSeqSearches == 1);

        storage.Close();
    }
Ejemplo n.º 5
0
    public static void Main(string[] args)
    {
        Storage storage = StorageFactory.Instance.CreateStorage();

        storage.Open("testlinq.dbs");
        QueryListener listener = new QueryListener();

        storage.Listener = listener;
        Database db = new Database(storage);
        int      n;

        Customer customer1 = new Customer();

        customer1.name          = "Age Soft";
        customer1.address       = "MT, Freen Valley, 5";
        customer1.phone         = "111-1111";
        customer1.contactPerson = "John Smith";
        customer1.vip           = true;
        db.AddRecord(customer1);

        Customer customer2 = new Customer();

        customer2.name          = "WebAlta";
        customer2.address       = "Moscow, Russia, Kolomenskay nab.,2";
        customer2.phone         = "222-22222";
        customer2.contactPerson = "Piter Volokov";
        db.AddRecord(customer2);


        BugReport bug1 = new BugReport();

        bug1.issuedBy    = customer1;
        bug1.priority    = BugReport.Priority.Low;
        bug1.description = "It doesn't work";
        bug1.version     = 1.03M;
        db.AddRecord(bug1);

        BugReport bug2 = new BugReport();

        bug2.issuedBy    = customer2;
        bug2.priority    = BugReport.Priority.High;
        bug2.description = "Something is definitely wrong";
        bug2.version     = 2.01M;
        db.AddRecord(bug2);

        Console.WriteLine("Search customer by name");
        n = 0;
        foreach (Customer c in db.Select <Customer>(c => c.name == "WebAlta"))
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        Console.WriteLine("Locate customers issued high priority bugs for version 2.0");
        n = 0;
        var query1 = from bug in db.GetTable <BugReport>()
                     where bug.priority >= BugReport.Priority.High && bug.version >= 2.0M
                     orderby bug.priority
                     select bug.issuedBy;

        foreach (var c in query1)
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        Console.WriteLine("Select customer by name and contact person");
        n = 0;
        string name   = "Age Soft";
        string person = "John Smith";
        var    query2 = from c in db.GetTable <Customer>()
                        where name == c.name && c.contactPerson == person
                        select c;

        foreach (var c in query2)
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        name   = "WebAlta";
        person = "Piter Volokov";
        n      = 0;
        foreach (var c in query2)
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);
        Debug.Assert(listener.nSeqSearches == 0);

        Console.WriteLine("Select with index join");
        n = 0;
        foreach (BugReport bug in db.Select <BugReport>(bug => bug.issuedBy.name == "WebAlta" || bug.issuedBy.name == "Age Soft"))
        {
            Console.WriteLine(bug);
            n += 1;
        }
        Debug.Assert(n == 2);

        Console.WriteLine("Select with index prefix search");
        n = 0;
        foreach (Customer customer in db.Select <Customer>(customer => customer.phone == "222-22222" && customer.name.StartsWith("Web")))
        {
            Console.WriteLine(customer);
            n += 1;
        }
        Debug.Assert(n == 1);

        Debug.Assert(listener.nSeqSearches == 0);


        Console.WriteLine("Select without search condition");
        n = 0;
        var query3 = from bug in db.GetTable <BugReport>()
                     orderby bug.priority
                     select bug;

        foreach (var b in query3)
        {
            Console.WriteLine(b);
            n += 1;
        }
        Debug.Assert(n == 2);

        Console.WriteLine("Select using sequential search");
        n = 0;
        var query4 = from bug in db.GetTable <BugReport>()
                     where bug.version >= 2.0M
                     select bug;

        foreach (var b in query4)
        {
            Console.WriteLine(b);
            n += 1;
        }
        Debug.Assert(n == 1);

        n = 0;
        var query5 = from bug in db.GetTable <BugReport>()
                     where bug.issuedBy == customer1
                     select bug;

        foreach (var b in query5)
        {
            Console.WriteLine(b);
            n += 1;
        }
        Debug.Assert(n == 1);

        n = 0;
        List <Customer> customers = new List <Customer>();

        customers.Add(customer1);
        customers.Add(customer2);
        var query6 = from bug in db.GetTable <BugReport>()
                     where customers.Contains(bug.issuedBy)
                     select bug;

        foreach (var b in query6)
        {
            Console.WriteLine(b);
            n += 1;
        }
        Debug.Assert(n == 2);

        n = 0;
        foreach (Customer c in db.Select <Customer>(c => c.name.CompareTo("A") >= 0))
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 2);

        n = 0;
        foreach (Customer c in db.Select <Customer>(c => String.Compare(c.name, "webalta", StringComparison.CurrentCultureIgnoreCase) == 0))
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        n = 0;
        foreach (Customer c in db.Select <Customer>(c => c.vip))
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);

        n = 0;
        foreach (Customer c in db.Select <Customer>(c => !c.vip))
        {
            Console.WriteLine(c);
            n += 1;
        }
        Debug.Assert(n == 1);


        Debug.Assert(listener.nSeqSearches == 1);

        storage.Close();
    }