コード例 #1
0
        private void Replace(CatchPos cpos, Player p)
        {
            List <Pos> buffer = new List <Pos>();
            ushort     x, z, y;
            ushort     xmin = Math.Min((ushort)cpos.pos.x, (ushort)cpos.pos2.x),
                       xmax = Math.Max((ushort)cpos.pos.x, (ushort)cpos.pos2.x),
                       zmin = Math.Min((ushort)cpos.pos.z, (ushort)cpos.pos2.z),
                       zmax = Math.Max((ushort)cpos.pos.z, (ushort)cpos.pos2.z),
                       ymin = Math.Min((ushort)cpos.pos.y, (ushort)cpos.pos2.y),
                       ymax = Math.Max((ushort)cpos.pos.y, (ushort)cpos.pos2.y);

            for (x = xmin; x <= xmax; ++x)
            {
                for (z = zmin; z <= zmax; ++z)
                {
                    for (y = ymin; y <= ymax; ++y)
                    {
                        if (cpos.oldType.Contains(p.Level.GetBlock(x, z, y)))
                        {
                            BufferAdd(buffer, new Vector3S(x, z, y));
                        }
                    }
                }
            }

            p.SendMessage(buffer.Count.ToString() + " blocks.");
            buffer.ForEach(delegate(Pos pos)
            {
                BlockQueue.Addblock(p, (ushort)pos.pos.x, (ushort)pos.pos.y, (ushort)pos.pos.z, cpos.newType);
            });
        }
コード例 #2
0
 public override void Use(Player p, string message)
 {
     if (p != null)
     {
         p.ClearBlockchange();
         p.painting       = false;
         p.BlockAction    = 0;
         p.megaBoid       = false;
         p.cmdTimer       = false;
         p.staticCommands = false;
         p.deleteMode     = false;
         p.ZoneCheck      = false;
         p.modeType       = 0;
         p.aiming         = false;
         p.onTrain        = false;
         p.isFlying       = false;
         try
         {
             p.level.blockqueue.RemoveAll((BlockQueue.block b) => { if (b.p == p)
                                                                    {
                                                                        return(true);
                                                                    }
                                                                    return(false); });
         }
         finally { BlockQueue.resume(); }
         Player.SendMessage(p, "Every toggle or action was aborted.");
         return;
     }
     Player.SendMessage(p, "This command can only be used in-game!");
 }
コード例 #3
0
ファイル: Archiver.cs プロジェクト: masleshov/gziptest
 /// <summary>
 /// Создает новый экземпляр архиватора, неким образом обрабатывающего очередь блоков
 /// </summary>
 /// <param name="inputQueue">Входная очередь байтовых блоков, подлежащая обработке алгоритмом архивации/разархивации</param>
 protected Archiver(BlockQueue inputQueue)
 {
     _inputQueue      = inputQueue;
     _resultQueue     = new BlockQueue(1);
     _threads         = new Thread[Environment.ProcessorCount];
     _queueDispatcher = new BlockQueueDispatcher(_resultQueue, _threads.Length);
 }
コード例 #4
0
 public void StartWrite(FileInfo outFile, BlockQueue outputQueue)
 {
     _outFile     = outFile;
     _innerThread = new Thread(new ParameterizedThreadStart(StartWriteInner));
     _innerThread.IsBackground = true;
     _innerThread.Start(Tuple.Create <FileInfo, BlockQueue>(outFile, outputQueue));
 }
コード例 #5
0
 public override void Use(Player p, string message)
 {
     if (p == null)
     {
         MessageInGameOnly(p); return;
     }
     p.ClearBlockchange();
     p.painting         = false;
     p.cmdTimer         = false;
     p.staticCommands   = false;
     p.deleteMode       = false;
     p.ZoneCheck        = false;
     p.modeType         = 0;
     p.aiming           = false;
     p.onTrain          = false;
     p.isFlying         = false;
     p.BrushName        = "normal";
     p.DefaultBrushArgs = "";
     try
     {
         p.level.blockqueue.RemoveAll(b => b.p == p);
     }
     finally { BlockQueue.Resume(); }
     Player.SendMessage(p, "Every toggle or action was aborted.");
 }
コード例 #6
0
        public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            byte b = p.level.GetTile(x, y, z);

            p.SendBlockchange(x, y, z, b);
            CatchPos cpos = (CatchPos)p.blockchangeObject;

            unchecked { if (cpos.type != (byte)-1)
                        {
                            type = cpos.type;
                        }
            }
            List <Pos> buffer = new List <Pos>();

            for (ushort xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
            {
                for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                {
                    for (ushort zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                    {
                        if (p.level.GetTile(xx, yy, zz) == type)
                        {
                            BufferAdd(buffer, xx, yy, zz);
                        }
                    }
                }
            }

            if (buffer.Count > p.group.maxBlocks)
            {
                Player.SendMessage(p, "You tried to replace " + buffer.Count + " blocks.");
                Player.SendMessage(p, "You cannot replace more than " + p.group.maxBlocks + ".");
                wait = 1;
                return;
            }

            Player.SendMessage(p, buffer.Count.ToString() + " blocks.");

            if (p.level.bufferblocks && !p.level.Instant)
            {
                buffer.ForEach(delegate(Pos pos)
                {
                    BlockQueue.Addblock(p, pos.x, pos.y, pos.z, cpos.type2);                  //update block for everyone
                });
            }
            else
            {
                buffer.ForEach(delegate(Pos pos)
                {
                    p.level.Blockchange(p, pos.x, pos.y, pos.z, cpos.type2);                  //update block for everyone
                });
            }

            wait = 2;
            if (p.staticCommands)
            {
                p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
            }
        }
コード例 #7
0
        void OnPlayerBlockChange_Normal(Player sender, API.Events.BlockChangeEventArgs args)
        {
            sender.OnPlayerBlockChange.Normal -= OnPlayerBlockChange_Normal;
            int rx    = (int)sender.ExtraData["BallRadius"];
            int count = 0;
            IEnumerable <Vector3S> blocks;

            if (sender.ExtraData["BallType"] != null && ((string)sender.ExtraData["BallType"] == "h" || (string)sender.ExtraData["BallType"] == "hollow"))
            {
                blocks = (new Vector3S(args.X, args.Z, args.Y)).GetNearBlocksHollow(rx, rx, rx);
            }
            else
            {
                blocks = (new Vector3S(args.X, args.Z, args.Y)).GetNearBlocks(rx, rx, rx);
            }
            foreach (Vector3S v in blocks)
            {
                if (v.x > 0 && v.z > 0 && v.y > 0 && v.x < sender.Level.CWMap.Size.x && v.z < sender.Level.CWMap.Size.z && v.y < sender.Level.CWMap.Size.y)
                {
                    BlockQueue.Addblock(sender, (ushort)v.x, (ushort)v.y, (ushort)v.z, args.Holding);
                    count++;
                }
            }
            sender.SendMessage(count + " Blocks");
        }
コード例 #8
0
ファイル: BlockQueueTest.cs プロジェクト: ciwik/gzipper
        public void EnqueueDequeueManyBlocks()
        {
            //Arrange
            int   queueLength = 3;
            var   queue       = new BlockQueue(queueLength);
            Block inputBlock1 = new Block(1, new byte[] { 1, 1, 2, 3, 5, 8 });
            Block inputBlock2 = new Block(2, new byte[] { 13, 21 });
            Block inputBlock3 = new Block(3, new byte[] { 34, 55, 89 });

            //Act
            queue.Enqueue(inputBlock1);
            queue.Enqueue(inputBlock2);
            queue.Enqueue(inputBlock3);

            bool result1 = queue.TryDequeue(out var outputBlock1);
            bool result2 = queue.TryDequeue(out var outputBlock2);
            bool result3 = queue.TryDequeue(out var outputBlock3);

            //Assert
            Assert.True(result1);
            Assert.True(result2);
            Assert.True(result3);

            Assert.AreEqual(inputBlock1, outputBlock1);
            Assert.AreEqual(inputBlock2, outputBlock2);
            Assert.AreEqual(inputBlock3, outputBlock3);
        }
コード例 #9
0
ファイル: Reader.cs プロジェクト: masleshov/gziptest
 /// <summary>
 /// Создает экземпляр читателя файла с указанным режимом чтения
 /// </summary>
 /// <param name="filePath">Путь до читаемого файла</param>
 /// <param name="mode">Режим чтения - чтение распакованного файла (для последующего сжатия)
 /// или чтение сжатого файла (для дальнейшей распаковки)</param>
 public Reader(string filePath, HandleMode mode)
 {
     _queue           = new BlockQueue(Environment.ProcessorCount);
     _queueDispatcher = new BlockQueueDispatcher(_queue, 1);
     _filePath        = filePath;
     _mode            = mode;
 }
コード例 #10
0
        void CatchBlockTwo(Player sender, BlockChangeEventArgs e)
        {
            e.Cancel();
            sender.OnPlayerBlockChange.Normal -= CatchBlockTwo;

            try {
                BlockInfo raw   = (BlockInfo)sender.ExtraData.GetIfExist <object, object>("Command.Line");
                Vector3S  from  = raw.Pos;
                Vector3S  to    = new Vector3S(e.X, e.Z, e.Y);
                byte      block = raw.Block;

                IEnumerable <Vector3S> path = from.PathTo(to);
                if (sender.Group.MaxBlockChange < path.Count())
                {
                    sender.SendMessage("You are not allowed to change that many blocks");
                    return;
                }
                foreach (var pos in path)
                {
                    if (!sender.Level.IsInBounds(pos))
                    {
                        continue;
                    }
                    BlockQueue.Addblock(sender, (ushort)pos.x, (ushort)pos.y, (ushort)pos.z, block);
                }


                sender.SendMessage(string.Format("Changed {0} blocks in a line", path.Count()));
            }
            catch (Exception er) {
                sender.SendMessage("An Error occurred while trying to make a pretty line");
                Logger.LogError(er);
            }
        }
コード例 #11
0
        protected void PlaceBlock(Player p, Level lvl, ushort x, ushort y, ushort z, byte type, byte extType)
        {
            Level.BlockPos bP = default(Level.BlockPos);
            switch (method)
            {
            case M_PBlockQueue:
                if (!lvl.DoBlockchange(p, x, y, z, type, extType))
                {
                    return;
                }
                bP.name  = p.name;
                bP.index = lvl.PosToInt(x, y, z);
                bP.SetData(type, extType, type == 0);

                lvl.blockCache.Add(bP);
                BlockQueue.Addblock(p, bP.index, type, extType);
                TotalModified++;
                break;

            case M_PBlockChange:
                if (!lvl.DoBlockchange(p, x, y, z, type, extType))
                {
                    return;
                }
                bP.name  = p.name;
                bP.index = lvl.PosToInt(x, y, z);

                bP.SetData(type, extType, type == 0);
                lvl.blockCache.Add(bP);
                Player.GlobalBlockchange(lvl, x, y, z, type, extType);
                TotalModified++;
                break;

            case M_PSetTile:
                byte old = lvl.GetTile(x, y, z);
                if (old == Block.Zero || !lvl.CheckAffectPermissions(p, x, y, z, old, type))
                {
                    return;
                }
                lvl.SetTile(x, y, z, type, p, extType);
                p.loginBlocks++;
                p.overallBlocks++;
                TotalModified++;
                break;

            case M_BlockChange:
                lvl.Blockchange(x, y, z, type, extType);
                TotalModified++;
                break;

            case M_SetTile:
                lvl.SetTile(x, y, z, type);
                if (type == Block.custom_block)
                {
                    lvl.SetExtTile(x, y, z, extType);
                }
                TotalModified++;
                break;
            }
        }
コード例 #12
0
        public void StartRead(FileInfo inFile, BlockQueue inputQueue)
        {
            Thread innerThread = new Thread(new ParameterizedThreadStart(StartReadInner));

            innerThread.IsBackground = true;
            innerThread.Start(Tuple.Create <FileInfo, BlockQueue>(inFile, inputQueue));
        }
コード例 #13
0
ファイル: BaseProcessor.cs プロジェクト: ciwik/gzipper
        protected BaseProcessor(Stream inputStream, Stream outputStream, int queueSize)
        {
            InputStream  = inputStream;
            OutputStream = outputStream;

            _readBlockQueue  = new BlockQueue(queueSize);
            _writeBlockQueue = new BlockQueue(queueSize);
        }
コード例 #14
0
ファイル: BlockSpawner.cs プロジェクト: hahn2014/Tetris99
 void Start()
 {
     if (queue == null)
     {
         queue = GameObject.Find("BlockQueue").GetComponent <BlockQueue>();
     }
     queue.generateQueue();
 }
コード例 #15
0
ファイル: FetchThread.cs プロジェクト: ackratos/USTCMap
        private BlockQueue<string> quadkeyQueue; //a reference

        #endregion Fields

        #region Constructors

        public FetchThread(BlockQueue<string> queue, DataManager dm, BlockQueue<QuadtreeEntry> entryQueue)
        {
            this.quadkeyQueue = queue;
            this.dm = dm;
            this.entryQueue = entryQueue;
            _thread = new Thread(run);
            _thread.Start();
        }
コード例 #16
0
 public AuthClientSession(Socket pmSocket)
 {
     this.clientSocket = pmSocket;
     authReceiveBuffer = new ReceiveBuffer(1048576);
     outAPQueue        = new BlockQueue <AuthPacket>(1000);
     receiveThread     = null;
     sendThread        = null;
     handleThread      = null;
     this.working      = false;
 }
コード例 #17
0
ファイル: DrawOp.Performer.cs プロジェクト: Benedani/MCGalaxy
        static void OutputBlock(DrawOpBlock b, DrawOp op)
        {
            if (b.Block == Block.Invalid)
            {
                return;
            }
            Level  lvl = op.Level;
            Player p = op.Player;
            byte   old = lvl.GetTile(b.X, b.Y, b.Z), oldExt = 0;

            if (old == Block.custom_block)
            {
                oldExt = lvl.GetExtTile(b.X, b.Y, b.Z);
            }

            if (op.TotalModified > Server.DrawReloadLimit)
            {
                if (old == Block.Invalid)
                {
                    return;
                }
                bool same = old == b.Block;
                if (same && b.Block == Block.custom_block)
                {
                    same = lvl.GetExtTile(b.X, b.Y, b.Z) == b.ExtBlock;
                }
                if (same || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block, b.ExtBlock))
                {
                    return;
                }

                lvl.SetTile(b.X, b.Y, b.Z, b.Block, p, b.ExtBlock, op.Flags);
                p.IncrementBlockStats(b.Block, true);
            }
            else if (op.TotalModified == Server.DrawReloadLimit)
            {
                Player.Message(p, "Affected over {0} blocks, prepared to reload map..", Server.DrawReloadLimit);
                lock (lvl.queueLock)
                    lvl.blockqueue.Clear();
            }
            else
            {
                if (!lvl.DoBlockchange(p, b.X, b.Y, b.Z, b.Block, b.ExtBlock, true))
                {
                    return;
                }

                lvl.BlockDB.Add(p, b.X, b.Y, b.Z, op.Flags,
                                old, oldExt, b.Block, b.ExtBlock);
                int index = lvl.PosToInt(b.X, b.Y, b.Z);
                BlockQueue.Addblock(p, index, b.Block, b.ExtBlock);
            }
            op.TotalModified++;
        }
コード例 #18
0
        protected override void WriteToFileStream(FileStream outFileStream, BlockQueue outputQueue)
        {
            while (!_cancelled)
            {
                Block rawBlock = outputQueue.DequeueBlock();
                outFileStream.Write(rawBlock.Content, 0, rawBlock.Content.Length);

                _blocksWritten++;
                _blockWrittenEvent.Set();
            }
        }
コード例 #19
0
ファイル: CmdAbort.cs プロジェクト: voidpublic/MCZombie
        public override void Use(Player p, string message)
        {
            if (p != null)
            {
                p.ClearBlockchange();
                p.painting       = false;
                p.BlockAction    = 0;
                p.megaBoid       = false;
                p.cmdTimer       = false;
                p.staticCommands = false;
                p.deleteMode     = false;
                p.ZoneCheck      = false;
                p.modeType       = 0;
                p.aiming         = false;
                p.onTrain        = false;
                p.isFlying       = false;
                p.modemode       = false;
                ushort x = (ushort)((p.pos[0]));
                ushort y = (ushort)((p.pos[1]));
                ushort z = (ushort)((p.pos[2]));
                p.SendUserMOTD();
                Player.GlobalDie(p, false);
                if (!p.referee)
                {
                    Player.GlobalSpawn(p, x, y, z, p.level.rotx, p.level.roty, true);
                }
                try
                {
                    p.level.blockqueue.RemoveAll((BlockQueue.block b) => { if (b.p == p)
                                                                           {
                                                                               return(true);
                                                                           }
                                                                           return(false); });
                }
                finally { BlockQueue.resume(); }
                Player.SendMessage(p, "Every toggle or action was aborted.");

                /*string number1 = "75";
                 * string number2 = "0";
                 * string number3 = "25";
                 * string lastLevelVote1 = "poison_run";
                 * string lastLevelVote2 = "hazeltastic";
                 * string lastLevelVote3 = "whites_mountain";
                 * Player.GlobalMessage(c.aqua + "---------------------------------------------");
                 * Player.GlobalMessage(c.aqua + "Vote results are in:");
                 * Player.GlobalMessage(c.lime + lastLevelVote1 + "(" + number1 + "%" + ")" + Server.DefaultColor + " / "
                 + c.red + lastLevelVote2 + "(" + number2 + "%" + ")" + Server.DefaultColor + " / "
                 + c.blue + lastLevelVote3 + "(" + number3 + "% )");
                 + Player.GlobalMessage(c.aqua + "---------------------------------------------");*/
                return;
            }
            Player.SendMessage(p, "This command can only be used in-game!");
        }
コード例 #20
0
        protected override void WriteToFileStream(FileStream outFileStream, BlockQueue outputQueue)
        {
            while (!_cancelled)
            {
                Block compressedBlock = outputQueue.DequeueBlock();
                outFileStream.WriteBlockHeader(compressedBlock.RawSize, compressedBlock.CompressedSize);
                outFileStream.Write(compressedBlock.Content, 0, compressedBlock.Content.Length);

                _blocksWritten++;
                _blockWrittenEvent.Set();
            }
        }
コード例 #21
0
ファイル: CmdPaste.cs プロジェクト: Amounx/SinCraft
        public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            byte b = p.level.GetTile(x, y, z);

            p.SendBlockchange(x, y, z, b);

            Player.UndoPos Pos1;
            //p.UndoBuffer.Clear();
            if (p.level.bufferblocks && !p.level.Instant)
            {
                p.CopyBuffer.ForEach(delegate(Player.CopyPos pos)
                {
                    Pos1.x = (ushort)(Math.Abs(pos.x) + x);
                    Pos1.y = (ushort)(Math.Abs(pos.y) + y);
                    Pos1.z = (ushort)(Math.Abs(pos.z) + z);

                    if (pos.type != Block.air || p.copyAir)
                    {
                        unchecked { if (p.level.GetTile(Pos1.x, Pos1.y, Pos1.z) != Block.Zero)
                                    {
                                        BlockQueue.Addblock(p, (ushort)(Pos1.x + p.copyoffset[0]), (ushort)(Pos1.y + p.copyoffset[1]), (ushort)(Pos1.z + p.copyoffset[2]), pos.type);
                                    }
                        }
                    }
                });
            }
            else
            {
                p.CopyBuffer.ForEach(delegate(Player.CopyPos pos)
                {
                    Pos1.x = (ushort)(Math.Abs(pos.x) + x);
                    Pos1.y = (ushort)(Math.Abs(pos.y) + y);
                    Pos1.z = (ushort)(Math.Abs(pos.z) + z);

                    if (pos.type != Block.air || p.copyAir)
                    {
                        unchecked { if (p.level.GetTile(Pos1.x, Pos1.y, Pos1.z) != Block.Zero)
                                    {
                                        p.level.Blockchange(p, (ushort)(Pos1.x + p.copyoffset[0]), (ushort)(Pos1.y + p.copyoffset[1]), (ushort)(Pos1.z + p.copyoffset[2]), pos.type);
                                    }
                        }
                    }
                });
            }

            Player.SendMessage(p, "Pasted " + p.CopyBuffer.Count + " blocks.");

            if (p.staticCommands)
            {
                p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
            }
        }
コード例 #22
0
        void BlockChange2(Player sender, BlockChangeEventArgs args)
        {
            //string direction = null;
            sender.OnPlayerBlockChange.Normal -= BlockChange2;
            CatchPos cpos = (CatchPos)sender.GetDatapass(this.Name);

            foreach (Vector3S v in BlockString(cpos.message, cpos.pos, new Vector3S(args.X, args.Z, args.Y), sender.Level.CWMap.Size))
            {
                BlockQueue.Addblock(sender, (ushort)v.x, (ushort)v.y, (ushort)v.z, args.Holding);
            }
            args.Cancel();
            return;
        }
コード例 #23
0
ファイル: CacheManager.cs プロジェクト: ackratos/USTCMap
        public CacheManager(int capacity, MainPage mp)
        {
            mainPage = mp;

            cache = new Cache<string, Tile[]>(capacity);

            //            mSet = new HastSet<K>();

            mQueue = new BlockQueue<string>();

            //            wSet = new HastSet<K>();

            //            avail = new Dictionary<K, V>();
        }
コード例 #24
0
ファイル: BlockQueueTest.cs プロジェクト: ciwik/gzipper
        public void EnqueueDequeueOneBlock()
        {
            //Arrange
            int   queueLength = 3;
            var   queue       = new BlockQueue(queueLength);
            Block inputBlock  = new Block(1, new byte[] { 1, 1, 2, 3, 5, 8 });
            Block outputBlock;

            //Act
            queue.Enqueue(inputBlock);
            bool result = queue.TryDequeue(out outputBlock);

            //Assert
            Assert.True(result);
            Assert.AreEqual(inputBlock, outputBlock);
        }
コード例 #25
0
        private void StartWriteInner(object param)
        {
            try
            {
                var        tuple       = param as Tuple <FileInfo, BlockQueue>;
                FileInfo   outFile     = tuple.Item1;
                BlockQueue outputQueue = tuple.Item2;

                using (FileStream outFileStream = outFile.Create())
                    WriteToFileStream(outFileStream, outputQueue);
            }
            catch (Exception ex)
            {
                string msg = string.Format("'{0}' exception: '{1}'", this.GetType().Name, ex.ToString());
                Logger.TraceError(msg);
            }
        }
コード例 #26
0
 public void Use(Player p, string[] args)
 {
     if (p.ExtraData.ContainsKey("Mode"))
     {
         p.ExtraData["Mode"] = false;
     }
     if (p.ExtraData.ContainsKey("OpChat"))
     {
         p.ExtraData["OpChat"] = false;
     }
     if (p.ExtraData.ContainsKey("AdminChat"))
     {
         p.ExtraData["Admin"] = false;
     }
     if (p.ExtraData.ContainsKey("IsWhispering"))
     {
         p.ExtraData["IsWhispering"] = false;
     }
     if (p.ExtraData.ContainsKey("WhisperingTo"))
     {
         p.ExtraData["WhisperingTo"] = null;
     }
     if (p.ExtraData.ContainsKey("ModeBlock"))
     {
         p.ExtraData["ModeBlock"] = null;
     }
     if (p.ExtraData.ContainsKey("HasMarked"))
     {
         p.ExtraData["HasMarked"] = false;
     }
     if (p.ExtraData.ContainsKey("IsFlying"))
     {
         p.ExtraData["IsFlying"] = null;
     }
     try
     {
         p.Level.blockqueue.RemoveAll((BlockQueue.block b) => { if (b.p == p)
                                                                {
                                                                    return(true);
                                                                }
                                                                return(false); });
     }
     finally { BlockQueue.resume(); }
     p.SendMessage("Every toggled action has been diabled.");
 }
コード例 #27
0
        private void StartReadInner(object param)
        {
            try
            {
                var        tuple      = param as Tuple <FileInfo, BlockQueue>;
                FileInfo   inFile     = tuple.Item1;
                BlockQueue inputQueue = tuple.Item2;

                using (FileStream inFileStream = inFile.OpenRead())
                {
                    ReadFileStream(inFileStream, inputQueue);
                    _done = true;
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("'{0}' exception: '{1}'", this.GetType().Name, ex.ToString());
                Logger.TraceError(msg);
            }
        }
コード例 #28
0
        protected override void ReadFileStream(FileStream inFileStream, BlockQueue inputQueue)
        {
            if (inFileStream == null)
            {
                throw new ArgumentNullException("inFileStream");
            }
            if (inputQueue == null)
            {
                throw new ArgumentNullException("inputQueue");
            }

            while (inFileStream.Position < inFileStream.Length)
            {
                int    bytesToRead = (int)Math.Min(Constants.BlockSizeBytes, inFileStream.Length - inFileStream.Position);
                byte[] rawBuffer   = new byte[bytesToRead];
                inFileStream.Read(rawBuffer, 0, rawBuffer.Length);

                inputQueue.EnqueueBlock(new Block(_nextBlockId, rawBuffer, rawBuffer.Length, 0));
                _nextBlockId++;

                ProgressIndicator.ShowPercentProgress("Compressing... ", Math.Min(inFileStream.Position, inFileStream.Length - 1), inFileStream.Length);
            }
        }
コード例 #29
0
        public void BlockQueueTest1()
        {
            byte[] buffer = new byte[1024];
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = (byte)(i % Byte.MaxValue);
            }

            BlockQueue <byte[]> queue = new BlockQueue <byte[]>();

            queue.Enqueue(buffer);

            byte[] tmpBuf = queue.Dequeue();

            Assert.AreNotEqual(tmpBuf, null);

            Assert.AreEqual(tmpBuf.Length, buffer.Length);

            for (int i = 0; i < buffer.Length; i++)
            {
                Assert.AreEqual(tmpBuf[i], buffer[i]);
            }
        }
コード例 #30
0
        protected override void ReadFileStream(FileStream inFileStream, BlockQueue inputQueue)
        {
            if (inFileStream == null)
            {
                throw new ArgumentNullException("inFileStream");
            }
            if (inputQueue == null)
            {
                throw new ArgumentNullException("inputQueue");
            }

            while (inFileStream.Position < inFileStream.Length)
            {
                int rawSize, compressedSize;
                inFileStream.ReadBlockHeader(out rawSize, out compressedSize);
                byte[] compressedBuffer = new byte[compressedSize];
                inFileStream.Read(compressedBuffer, 0, compressedBuffer.Length);

                inputQueue.EnqueueBlock(new Block(_nextBlockId, compressedBuffer, rawSize, compressedBuffer.Length));
                _nextBlockId++;

                ProgressIndicator.ShowPercentProgress("Decompressing... ", Math.Min(inFileStream.Position, inFileStream.Length - 1), inFileStream.Length);
            }
        }
コード例 #31
0
        public void DoWork(object param)
        {
            int blockId = -1;

            try
            {
                var        tuple    = param as Tuple <BlockQueue, BlockQueue>;
                BlockQueue inQueue  = tuple.Item1;
                BlockQueue outQueue = tuple.Item2;

                while (true)
                {
                    Block inputBlock = inQueue.DequeueBlock();
                    blockId = inputBlock.Id;
                    Block outputBlock = ApplyAlgorythm(inputBlock);
                    outQueue.EnqueueBlock(outputBlock);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("'{0}' blockId: '{1}' exception: '{2}'", this.GetType().Name, blockId, ex.ToString());
                Logger.TraceError(msg);
            }
        }
コード例 #32
0
        /// <summary>
        /// Inits this instance.
        /// </summary>
        public static void Init()
        {
            Running = true;

            Logger.WriteLog("--------- Server Started at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " ---------");
            Logger.Log("Debug mode started", LogType.Debug);
            //TODO Add debug messages
            //TODO load the level if it exists
            Block.InIt();
            Logger.Log("Starting update timer", LogType.Debug);
            UpdateTimer = new System.Threading.Timer((e) => Update(), null, 0, 100);
            Logger.Log("Log timer started", LogType.Debug);
            Logger.Log("Loading DLL's", LogType.Debug);
            LoadAllDlls.Init();
            Logger.Log("Finished loading DLL's", LogType.Debug);
            Logger.Log("Sending Heartbeat..", LogType.Debug);
            Logger.Log("Auto-Updater Starting..", LogType.Debug);
            Updater.InIt();
            HeartThread = new Thread(new ThreadStart(Heartbeat.ActivateHeartBeat));
            HeartThread.Start();
            Logger.Log("Starting Physics Tick..", LogType.Debug);
            PhysicsBlock.InIt();
            CmdReloadCmds reload = new CmdReloadCmds();

            reload.Initialize();

            Groups.PlayerGroup.Load();
            VerifyGroup = Groups.PlayerGroup.Find(ServerSettings.GetSetting("VerifyGroup"));
            Mainlevel   = Level.LoadLevel(ServerSettings.GetSetting("Main-Level"));
            if (Mainlevel == null)
            {
                Mainlevel = Level.CreateLevel(new Vector3S(256, 128, 64), Level.LevelTypes.Flat);
                ServerSettings.SetSetting("Main-Level", null, "main");
            }
            Level.Levels.Add(Mainlevel);
            if (ServerSettings.GetSettingBoolean("LoadAllLevels"))
            {
                Level.LoadAllLevels();
            }
            BlockQueue.Start();
            Backup.StartBackup();

            Database.Init();

            CreateCoreFiles();

            InternetUtils = new InetUtils();
            InetUtils.InternetAvailable = InetUtils.CanConnectToInternet();

            Logger.Log("Loading Bans", LogType.Debug);
            Logger.Log("IPBANS", LogType.Debug);
            IPBans = new List <string>(File.ReadAllLines("bans/IPBans.txt"));
            Logger.Log("IPBANS", LogType.Debug);
            UsernameBans = new List <string>(File.ReadAllLines("bans/NameBans.txt"));
            StartListening();
            Started = true;

            if (OnServerFinishSetup != null)
            {
                OnServerFinishSetup();
            }
            blockThread = new Thread(new ThreadStart(delegate
            {
                while (true)
                {
                    Thread.Sleep(60000);
                    Level.Levels.ForEach(delegate(Level l)
                    {
                        try
                        {
                            l.SaveToBinary();
                        }
                        catch (Exception e)
                        {
                            Logger.LogError(e);
                        }
                    });
                }
            }));
            blockThread.Start();
            Logger.Log("[Important]: Server Started.", Color.Black, Color.White);
            if (!ServerSettings.GetSettingBoolean("VerifyNames"))
            {
                Logger.Log("[Important]: The server is running with verify names off! This could lead to bad things! Please turn on verify names if you dont know the risk and dont want these bad things to happen!", LogType.Critical);
            }

            if (ServerSettings.GetSettingBoolean("IRC-Enabled"))
            {
                try
                {
                    IRC = new ServerChat();
                    IRC.Connect();
                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                }
            }

            if (ServerSettings.GetSettingBoolean("GC-Enabled"))
            {
                GC = new GlobalChat();
                try
                {
                    GC.Connect();
                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                }
            }

            try
            {
                RC = new ConsoleListener();
                RC.Start();
            }
            catch { }

            PlayerConnectionTimeoutChecker = new Thread(() => {
                int sleep = ServerSettings.GetSettingInt("AutoTimeout");
                if (sleep < 0)
                {
                    sleep = 30;
                }
                if (sleep != 0)
                {
                    while (Running)
                    {
                        for (int i = 0; i < sleep && Running; i++)
                        {
                            Thread.Sleep(1000);
                        }
                        if (!Running)
                        {
                            break;
                        }
                        foreach (Player p in Players)
                        {
                            if (p.lastReceived.AddSeconds(sleep) < DateTime.Now)
                            {
#if !DEBUG
                                p.Kick("The connection timed out");
#endif
                            }
                        }
                    }
                }
            });
            PlayerConnectionTimeoutChecker.Start();
        }