Difference between revisions of "194 Cache Format"

From RuneWiki
Jump to navigationJump to search
Line 5: Line 5:
 
=== Name hashing ===
 
=== Name hashing ===
  
Every name in the cache was hashed using the following method which is, incidentally, the same way player names are converted to longs.
+
Every name in the cache was hashed using the following method which is, incidentally, the similar to the way player names are converted to longs.
  
 
  public static final long gethash(String string) {
 
  public static final long gethash(String string) {

Revision as of 08:48, 13 August 2009

General Information

The 194 (RuneScape 2 beta) client worked with a very simple cache format. Each file in the cache was a file on the operating system.

Name hashing

Every name in the cache was hashed using the following method which is, incidentally, the similar to the way player names are converted to longs.

public static final long gethash(String string) {
    string = string.trim();
    long l = 0L;
    for (int i = 0; i < string.length() && i < 12; i++) {
        char c = string.charAt(i);
        l *= 37L;
        if (c >= 'A' && c <= 'Z')
            l += (long) ('\001' + c - 'A');
        else if (c >= 'a' && c <= 'z')
            l += (long) ('\001' + c - 'a');
        else if (c >= '0' && c <= '9')
            l += (long) ('\033' + c - '0');
    }
    return l;
}

The resulting long was converted to a string and the file was given that name.