Rakkarsoft LLC

Autopatcher

The autopatcher system

The autopatcher is a class that manages the copying of missing or changed files between two or more systems. It handles transferring files, compressing transferred files, security, and file operations. It does not handle basic connectivity or provide a user interface - that is up to you. Autopatchers are used in all online only games and many top commercial games.

Each system needs one instance of the autopatcher class. The class consists of 4 files: Autopatcher.cpp, Autopatcher.h, DownloadableFileDescriptor.cpp, and DownloadableFileDescriptor.h. These files are located at Source/Autopatcher and will need to be included in your project. This was done because many games use different versions of fread, etc. so this allows easy source modification.

The first step is to pass the class your local instance of RakNet via SetNetworkingSystem(system). It is overloaded to take RakPeerInterface, RakClientInterface, or RakServerInterface. These calls are treated as mutually exclusive.

The next step is to tell the autopatcher what files are downloadable. This is done with the SetFileDownloadable function. This function will load the file into memory, compress it if it is large, and add it to the internal list of downloadable files. The first parameter of SetFileDownloadable is the path to the file. The second parameter is whether or not you want to check for a file of the same name with the added extension .sha. This is a file signature, the purpose of which is to make sure the file was not modified since the last time you created the signature. While not foolproof, it is an important safety measure to make sure hackers and/or viruses did not change the file since your last build. To create the signature file, call the static function Autopatcher::CreateFileSignature on the desired file(s) after uploading a new build. You will probably want to make a small program to do this automatically. If the file signature check fails, SetFileDownloadable will return SET_FILE_DOWNLOADABLE_FILE_NO_SIGNATURE_FILE or SET_FILE_DOWNLOADABLE_FILE_SIGNATURE_CHECK_FAILED.

Once these systems are connected, which is up to you, you can then have the downloading system call RequestDownloadableFileList (pull method) or you can have the uploading system call SendDownloadableFileList (push method) to initiate the process. Assuming you are connected, this will start a series of network sends between the two systems.

When you get any of these packet identifiers as the first byte of Packet::data

ID_AUTOPATCHER_FILE_LIST
ID_AUTOPATCHER_REQUEST_FILES
ID_AUTOPATCHER_SET_DOWNLOAD_LIST
ID_AUTOPATCHER_WRITE_FILE

Send the whole packet to the corresponding function

void OnAutopatcherFileList(Packet *packet, bool onlyAcceptFilesIfRequested);
void OnAutopatcherRequestFiles(Packet *packet);
void OnAutopatcherSetDownloadList(Packet *packet);
bool OnAutopatcherWriteFile(Packet *packet);

Directories structures are kept intact. So if the sending system has the directory structure
Readme.txt
Music/Song1.wav
Music/Song2.wav
The downloading system will mirror this directory structure.

The exception is that you can specify a default directory to read from and download into using SetDownloadedFileDirectoryPrefix. If you called this function with "Downloads" then the above 3 files would be looked at in, and if they are different or don't exist, then copied into:
Downloads/Readme.txt
Downloads/Music/Song1.wav
Downloads/Music/Song2.wav

See Autopatcher.h for the full set of functions and for additional documentation.
Refer to the sample implementation AutopatcherTest.cpp for usage.

See Also
Index