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(); } } }
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(); } }
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()); }