コード例 #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
        private void worldWWW_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (WorldDownloadProgress != null)
            {
                WorldDownloadProgress.Invoke(this, new WorldDownloadProgressEventArgs(1.0f));
            }

            if (e.Cancelled || e.Error != null)
            {
                SendGetWorld();
            }
            else
            {
                WorldUnpacker unpacker = new WorldUnpacker(e.Result);
                SetMap(unpacker.Unpack());
                if (Map == null)
                {
                    SendGetWorld();
                }
                else
                {
                    WorldCache.SaveMapToCache(WorldHash, unpacker.GetBuffer());
                    SendEnter();
                }
            }
        }
コード例 #3
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());
        }
コード例 #4
0
 protected void SendGetWorld()
 {
     if (WorldDownloadProgress != null)
     {
         WorldDownloadProgress.Invoke(this, new WorldDownloadProgressEventArgs(0));
     }
     Unpacker = new WorldUnpacker();
     NetClient.SendMessage(new MsgGetWorld(0));
 }
コード例 #5
0
        public void SaveMapToCache(string hash, byte[] data)
        {
            if (Folder == null)
            {
                return;
            }

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

            if (!file.Exists)
            {
                return;
            }

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

            fs.Write(data, 0, data.Length);

            fs.Close();
        }