Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Merge CTS Records

#1
One of my server's usual visitors has changed their client id file, now has 2 different records for the same maps, and requested me to merge those and discard the worse time.

It seems the records are stored in server.db.
Can I get instructions on how to properly do this?

Append:

For the record, it's not just a plain text replace. The client id fields for the rows uid2name have characters such as + / =. Meanwhile the client id fields for the rows cts100record/crypto_idfp#/ will not and instead have stuff like %2F %2B.
Reply

#2
server.db is a hash table written to file so white space is very important. The "stuff like %2F and %2B" is url encoding (here's a website that can do it).
For demonstration purposes, I will outline the steps one could take to merge ids with bash, using a little help from php (for convenience). This is untested and only theoretical until someone tells me it won't deserialize properly. Make backups first.
In a GNU+Linux environment we could define two helper functions to make it easy to translate encoded keys:
Code:
#!/bin/bash

function _url_decode() { php -r "echo urldecode(file_get_contents('php://stdin'));"; };
function _url_encode() { php -r "echo urlencode(file_get_contents('php://stdin'));"; };
We can verify that these functions work by greping for records in server.db that contain keys. awk is used to split by delimiter "\", and grab the key chunk, then we pipe it to our _url_decode helper function.
Code:
grep "cts100record/speed/crypto_idfp" /home/z/.xonotic/data/data/server.db |awk -F "\\" '{ print $3 }' |sort |uniq |_url_decode

xQMEUcegy8s47JRH01kgPn/xA5q2XWvWqtOXyeJ4SEo=
...
This gets us the decoded keys.

Knowing this, lets revisit our challenge, we want to "merge ids", or as you noted, it's actually a find/replace. Under the assumption that you'll be finding and replacing many keys, lets go ahead, and create a replace.txt file, where the first column is the old key and the second column is the new key (obviously fake for effect).

Code:
xQMEUcegy8jG7JRH0OkgPn/xA5q2XWvWqtOXyeJ4SEo= MYnewKEY=
xQMEUcegy853453JRH0OkgPn/xA5asdfas2XyeJ4SEo= MYnewKEY=
...

We can read through this list of keys to find/replace and apply it to our server.db as such:

Code:
while read old new; do o=$(echo -n $old|_url_encode); n=$(echo -n $new|_url_encode); echo $o; sed -i "s/$o/$n/g" /home/z/.xonotic/data/data/server.db; done < replace.txt

and if we check out server.db now, those keys should be replaced.

Code:
\sxb1/cts100record/speed/crypto_idfp\MYnewKEY%3D
\sxb1/cts100record/speed/crypto_idfp\MYnewKEY%3D

Hope this helps!
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Server CTS Leaderboards: Now on the Web Antares* 9 7,263 03-21-2017, 06:31 PM
Last Post: Antares*
  [XR] Xonotic Records server -- flag cap records auto-posted to YouTube -z- 5 6,076 03-19-2016, 09:14 AM
Last Post: -z-
Question [SOLVED] XonStats on XDF (CTS) server? -maniac|Su- 6 7,167 01-18-2013, 05:04 PM
Last Post: -maniac|Su-
  Anyone experience cap records being reset randomly? Dokujisan 4 5,178 10-30-2012, 02:53 PM
Last Post: Mr. Bougo
  Possible UID tracking bug in CTS server liberty 5 7,196 03-12-2012, 10:37 AM
Last Post: liberty

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB original theme © iAndrew 2016, remixed by -z-