mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-21 10:04:18 +00:00
ca8fcc823c
SHA256 was chosen because it is reasonably standard, the file names don't explode in length (this rules out SHA512) and it is supported by basically all versions of OpenSSL (this rules out SHA512/256 and SHA3). The protocol is changed in a backward compatible way: The supporting server sends the SHA256 corresponding to the map in the `MAP_DETAILS` message prior to sending the `MAP_CHANGE` message. The client saves the SHA256 obtained from the `MAP_DETAILS` message until the next `MAP_CHANGE` message. For servers not supporting this protocol, the client falls back to simply opening maps like in the previous scheme. Remove the `map_version` tool, it is not being used and would have been a little bit effort to update. Use the OpenSSL implementation of SHA256 if it is supported, otherwise fall back to a public domain one. Fix #1127.
97 lines
2 KiB
C++
97 lines
2 KiB
C++
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
|
#ifndef ENGINE_SHARED_DATAFILE_H
|
|
#define ENGINE_SHARED_DATAFILE_H
|
|
|
|
#include <base/hash.h>
|
|
|
|
// raw datafile access
|
|
class CDataFileReader
|
|
{
|
|
struct CDatafile *m_pDataFile;
|
|
void *GetDataImpl(int Index, int Swap);
|
|
int GetFileDataSize(int Index);
|
|
public:
|
|
CDataFileReader() : m_pDataFile(0) {}
|
|
~CDataFileReader() { Close(); }
|
|
|
|
bool IsOpen() const { return m_pDataFile != 0; }
|
|
|
|
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType);
|
|
bool Close();
|
|
|
|
void *GetData(int Index);
|
|
void *GetDataSwapped(int Index); // makes sure that the data is 32bit LE ints when saved
|
|
int GetDataSize(int Index);
|
|
void UnloadData(int Index);
|
|
void *GetItem(int Index, int *pType, int *pID);
|
|
int GetItemSize(int Index);
|
|
void GetType(int Type, int *pStart, int *pNum);
|
|
void *FindItem(int Type, int ID);
|
|
int NumItems();
|
|
int NumData();
|
|
void Unload();
|
|
|
|
SHA256_DIGEST Sha256();
|
|
unsigned Crc();
|
|
int MapSize();
|
|
IOHANDLE File();
|
|
};
|
|
|
|
// write access
|
|
class CDataFileWriter
|
|
{
|
|
struct CDataInfo
|
|
{
|
|
int m_UncompressedSize;
|
|
int m_CompressedSize;
|
|
void *m_pCompressedData;
|
|
};
|
|
|
|
struct CItemInfo
|
|
{
|
|
int m_Type;
|
|
int m_ID;
|
|
int m_Size;
|
|
int m_Next;
|
|
int m_Prev;
|
|
void *m_pData;
|
|
};
|
|
|
|
struct CItemTypeInfo
|
|
{
|
|
int m_Num;
|
|
int m_First;
|
|
int m_Last;
|
|
};
|
|
|
|
enum
|
|
{
|
|
MAX_ITEM_TYPES=0xffff,
|
|
MAX_ITEMS=1024,
|
|
MAX_DATAS=1024,
|
|
};
|
|
|
|
IOHANDLE m_File;
|
|
int m_NumItems;
|
|
int m_NumDatas;
|
|
int m_NumItemTypes;
|
|
CItemTypeInfo *m_pItemTypes;
|
|
CItemInfo *m_pItems;
|
|
CDataInfo *m_pDatas;
|
|
|
|
public:
|
|
CDataFileWriter();
|
|
~CDataFileWriter();
|
|
void Init();
|
|
bool OpenFile(class IStorage *pStorage, const char *pFilename);
|
|
bool Open(class IStorage *pStorage, const char *Filename);
|
|
int AddData(int Size, void *pData);
|
|
int AddDataSwapped(int Size, void *pData);
|
|
int AddItem(int Type, int ID, int Size, void *pData);
|
|
int Finish();
|
|
};
|
|
|
|
|
|
#endif
|