Treat empty loc groups as valid

I've decided to reverse my decision in
e3e0094b43.

If you treat empty loc groups as valid, some OSRS caches do have 100%
valid keys. Being able to pick these out in the list of caches will be
useful.

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 40d6ccbb61
commit ee567cc76f
  1. 17
      archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt
  2. 2
      archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql
  3. 14
      archive/src/main/resources/org/openrs2/archive/templates/caches/index.html
  4. 2
      archive/src/main/resources/org/openrs2/archive/templates/caches/show.html
  5. 6
      archive/src/main/resources/org/openrs2/archive/templates/keys/index.html

@ -15,30 +15,40 @@ public class KeyExporter @Inject constructor(
val allKeys: Long, val allKeys: Long,
val validKeys: Long, val validKeys: Long,
val encryptedGroups: Long, val encryptedGroups: Long,
val validGroups: Long val validGroups: Long,
val emptyGroups: Long
) { ) {
val validKeysFraction: Double = if (allKeys == 0L) { val validKeysFraction: Double = if (allKeys == 0L) {
1.0 1.0
} else { } else {
validKeys.toDouble() / allKeys validKeys.toDouble() / allKeys
} }
val validGroupsFraction: Double = if (encryptedGroups == 0L) { val validGroupsFraction: Double = if (encryptedGroups == 0L) {
1.0 1.0
} else { } else {
validGroups.toDouble() / encryptedGroups validGroups.toDouble() / encryptedGroups
} }
val emptyGroupsFraction: Double = if (encryptedGroups == 0L) {
1.0
} else {
emptyGroups.toDouble() / encryptedGroups
}
} }
public suspend fun count(): Stats { public suspend fun count(): Stats {
return database.execute { connection -> return database.execute { connection ->
val encryptedGroups: Long val encryptedGroups: Long
val validGroups: Long val validGroups: Long
val emptyGroups: Long
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT SELECT
COUNT(*), COUNT(*),
COUNT(*) FILTER (WHERE c.key_id IS NOT NULL) COUNT(*) FILTER (WHERE c.key_id IS NOT NULL),
COUNT(*) FILTER (WHERE c.key_id IS NULL AND c.empty_loc)
FROM containers c FROM containers c
WHERE c.encrypted WHERE c.encrypted
""".trimIndent() """.trimIndent()
@ -48,6 +58,7 @@ public class KeyExporter @Inject constructor(
encryptedGroups = rows.getLong(1) encryptedGroups = rows.getLong(1)
validGroups = rows.getLong(2) validGroups = rows.getLong(2)
emptyGroups = rows.getLong(3)
} }
} }
@ -65,7 +76,7 @@ public class KeyExporter @Inject constructor(
val allKeys = rows.getLong(1) val allKeys = rows.getLong(1)
val validKeys = rows.getLong(2) val validKeys = rows.getLong(2)
Stats(allKeys, validKeys, encryptedGroups, validGroups) Stats(allKeys, validKeys, encryptedGroups, validGroups, emptyGroups)
} }
} }
} }

@ -238,7 +238,7 @@ LEFT JOIN (
i.master_index_id, i.master_index_id,
COUNT(*) FILTER (WHERE c.id IS NOT NULL) AS valid_groups, COUNT(*) FILTER (WHERE c.id IS NOT NULL) AS valid_groups,
COUNT(*) AS groups, COUNT(*) AS groups,
COUNT(*) FILTER (WHERE c.key_id IS NOT NULL) AS valid_keys, COUNT(*) FILTER (WHERE c.encrypted AND (c.key_id IS NOT NULL OR c.empty_loc)) AS valid_keys,
COUNT(*) FILTER (WHERE c.encrypted) AS keys, COUNT(*) FILTER (WHERE c.encrypted) AS keys,
SUM(length(c.data)) FILTER (WHERE c.id IS NOT NULL) AS size SUM(length(c.data)) FILTER (WHERE c.id IS NOT NULL) AS size
FROM resolved_indexes i FROM resolved_indexes i

@ -21,7 +21,7 @@
<th>Source(s)</th> <th>Source(s)</th>
<th>Indexes</th> <th>Indexes</th>
<th>Groups</th> <th>Groups</th>
<th>Keys</th> <th>Keys<sup><a href="#empty-locs">1</a></sup></th>
<th>Links</th> <th>Links</th>
</tr> </tr>
</thead> </thead>
@ -95,6 +95,18 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<p>
<sup id="empty-locs">1</sup> Map squares in the middle of the
sea are unreachable by normal players, making it impossible to
obtain the keys for their loc groups. However, the loc groups
for these map squares are empty. As XTEA does not hide the
length of the compressed data, this service infers which
encrypted loc groups are empty and includes them in the number
of valid keys, regardless of whether the key is known or not.
After downloading a cache from this service, a cache editor may
be used to replace the empty encrypted loc groups with
unencrypted replacements.
</p>
</main> </main>
</body> </body>
</html> </html>

@ -59,7 +59,7 @@
</td> </td>
</tr> </tr>
<tr class="thead-dark"> <tr class="thead-dark">
<th>Keys</th> <th>Keys<sup><a href="/caches#empty-locs">1</a></sup></th>
<td th:class="${cache.stats}? (${cache.stats.allKeysValid}? 'table-success' : 'table-warning')" <td th:class="${cache.stats}? (${cache.stats.allKeysValid}? 'table-success' : 'table-warning')"
th:text="${cache.stats}? ${#numbers.formatInteger(cache.stats.validKeys, 1, 'COMMA')} + ' / ' + ${#numbers.formatInteger(cache.stats.keys, 1, 'COMMA')} + ' (' + ${#numbers.formatPercent(cache.stats.validKeysFraction, 1, 2)} + ')' : 'Calculating...'"> th:text="${cache.stats}? ${#numbers.formatInteger(cache.stats.validKeys, 1, 'COMMA')} + ' / ' + ${#numbers.formatInteger(cache.stats.keys, 1, 'COMMA')} + ' (' + ${#numbers.formatPercent(cache.stats.validKeysFraction, 1, 2)} + ')' : 'Calculating...'">
Calculating... Calculating...

@ -27,7 +27,11 @@
<strong <strong
th:text="${#numbers.formatInteger(stats.validGroups, 1, 'COMMA')} + ' (' + ${#numbers.formatPercent(stats.validGroupsFraction, 1, 2)} + ')'">0</strong> th:text="${#numbers.formatInteger(stats.validGroups, 1, 'COMMA')} + ' (' + ${#numbers.formatPercent(stats.validGroupsFraction, 1, 2)} + ')'">0</strong>
have a validated key. This is equal to the total number of have a validated key. This is equal to the total number of
validated keys if and only if keys are not re-used. validated keys if and only if keys are not re-used. A further
<strong
th:text="${#numbers.formatInteger(stats.emptyGroups, 1, 'COMMA')} + ' (' + ${#numbers.formatPercent(stats.emptyGroupsFraction, 1, 2)} + ')'">0</strong>
groups do not have a validated key, but are empty and can be
replaced with an unencrypted equivalent with a cache editor.
</p> </p>
<h2>Download</h2> <h2>Download</h2>

Loading…
Cancel
Save