예제 #1
0
        public Server()
        {
            Log("Starting Server");
            s = this;
            consolePlayer = new ConsolePlayer(s);
            consolePlayer.SetUsername(ConsoleName);
            //Group.DefaultGroup = new DefaultGroup(); //debugging
            mainlevel = new World(0, 127, 0, "main", new Random().Next());
            World.worlds.Add(mainlevel);
            ml = new MainLoop("server");
            #region updatetimer
            ml.Queue(delegate
            {
                updateTimer.Elapsed += delegate
                {
                Player.GlobalUpdate();
                }; updateTimer.Start();
            });
            #endregion
            //TODO AI Update Timer

            //Setup();

            Log("Server Started");

            //new Creeper(new Point3(0, 0, 0), mainlevel);
        }
예제 #2
0
        public Server()
        {
            Log("Starting Server");
            s = this;
            mainlevel = new World(0, 127, 0, "main");
            World.worlds.Add(mainlevel);
            ml = new MainLoop("server");
            #region updatetimer
            ml.Queue(delegate
            {
                updateTimer.Elapsed += delegate
                {
                    Player.GlobalUpdate();
                }; updateTimer.Start();
            });
            #endregion

            Setup();

            Log("Server Started");
        }
예제 #3
0
        static System.Timers.Timer messageTimer = new System.Timers.Timer(60000 * 5); //Every 5 mins

        #endregion Fields

        #region Constructors

        public Server()
        {
            ml = new MainLoop("server");
            Server.s = this;
        }
예제 #4
0
        public Server()
        {
            Log("Starting Server");
            s = this;
            if (Directory.Exists("main"))
            {
                mainlevel = World.LoadLVL("main");
            }
            else
            {
                mainlevel = new World(0, 127, 0, "main", 0) { ChunkLimit = 4 };
                World.worlds.Add(mainlevel);
            } //changed to seed 0 for now
            ml = new MainLoop("server");
            #region updatetimer
            ml.Queue(delegate
            {
                updateTimer.Elapsed += delegate
                {
                Player.GlobalUpdate();
                }; updateTimer.Start();
            });
            ml.Queue(delegate
            {
                playerlisttimer.Elapsed += delegate
                {
                    Player.PlayerlistUpdate();
                }; playerlisttimer.Start();
            });
            #endregion
            //TODO AI Update Timer

            //Setup();

            //new Creeper(new Point3(0, 72, 0), mainlevel);
        }
예제 #5
0
 public void FixtureSetup()
 {
     loop = new MainLoop("Test Loop");
 }
 public MainLoopTests()
 {
     loop = new MainLoop("Test Loop");
     count = 0;
 }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="manager">The torrent which the peer is associated with.</param>
        /// <param name="id">The peer whose message queue you want to start processing</param>
        internal async void TryProcessQueue(TorrentManager manager, PeerId id)
        {
            if (!id.MessageQueue.BeginProcessing())
            {
                return;
            }

            await MainLoop.SwitchToThreadpool();

            ByteBufferPool.Releaser messageBuffer = default;
            ByteBufferPool.Releaser pieceBuffer   = default;
            PeerMessage             msg;

            try {
                while ((msg = id.MessageQueue.TryDequeue()) != null)
                {
                    var msgLength = msg.ByteLength;

                    if (msg is PieceMessage pm)
                    {
                        if (pieceBuffer.Buffer == null)
                        {
                            pieceBuffer = DiskManager.BufferPool.Rent(msgLength, out ByteBuffer _);
                        }
                        pm.DataReleaser = pieceBuffer;
                        try {
                            await DiskManager.ReadAsync(manager, pm.StartOffset + ((long)pm.PieceIndex * manager.Torrent.PieceLength), pm.Data, pm.RequestLength).ConfigureAwait(false);
                        } catch (Exception ex) {
                            await ClientEngine.MainLoop;
                            manager.TrySetError(Reason.ReadFailure, ex);
                            return;
                        }
                        System.Threading.Interlocked.Increment(ref id.piecesSent);
                    }
                    else
                    {
                        pieceBuffer.Dispose();
                    }

                    if (messageBuffer.Buffer == null || messageBuffer.Buffer.Data.Length < msg.ByteLength)
                    {
                        messageBuffer.Dispose();
                        messageBuffer = NetworkIO.BufferPool.Rent(msgLength, out ByteBuffer _);
                    }
                    await PeerIO.SendMessageAsync(id.Connection, id.Encryptor, msg, manager.UploadLimiters, id.Monitor, manager.Monitor, messageBuffer.Buffer).ConfigureAwait(false);

                    if (msg is PieceMessage)
                    {
                        System.Threading.Interlocked.Decrement(ref id.isRequestingPiecesCount);
                    }

                    id.LastMessageSent.Restart();
                }
            } catch {
                await ClientEngine.MainLoop;
                CleanupSocket(manager, id);
            } finally {
                messageBuffer.Dispose();
                pieceBuffer.Dispose();
            }
        }