示例#1
0
        private void HandleGetWorld(NetworkMessage msg)
        {
            MsgGetWorld wldChunk = msg as MsgGetWorld;

            if (Unpacker == null)
            {
                Unpacker = new WorldUnpacker();
            }

            Unpacker.AddData(wldChunk.Data);

            if (wldChunk.Offset > 0)
            {
                if (WorldDownloadProgress != null)
                {
                    WorldDownloadProgress.Invoke(this, new WorldDownloadProgressEventArgs((float)Unpacker.Size() / (float)(((UInt32)wldChunk.Offset + Unpacker.Size()))));
                }
                NetClient.SendMessage(new MsgGetWorld((UInt32)Unpacker.Size()));
            }
            else
            {
                if (WorldDownloadProgress != null)
                {
                    WorldDownloadProgress.Invoke(this, new WorldDownloadProgressEventArgs(1));
                }

                SetMap(Unpacker.Unpack());
                if (WorldCache != null)
                {
                    WorldCache.SaveMapToCache(WorldHash, Unpacker.GetBuffer());
                }
                SendEnter();
            }
        }
示例#2
0
        public WorldMap ReadMapFromCache(string hash)
        {
            if (Folder == null)
            {
                return(null);
            }

            FileInfo file = new FileInfo(Path.Combine(Folder.FullName, hash + ".bzwc"));

            if (!file.Exists)
            {
                return(null);
            }

            WorldUnpacker unpacker = new WorldUnpacker();
            FileStream    fs       = file.OpenRead();

            byte[] bits = new byte[file.Length];
            if (fs.Read(bits, 0, bits.Length) != bits.Length)
            {
                fs.Close();
                return(null);
            }
            fs.Close();
            unpacker.AddData(bits);
            return(unpacker.Unpack());
        }