Merge CTS Records - Printable Version +- Xonotic Forums (https://forums.xonotic.org) +-- Forum: Support (https://forums.xonotic.org/forumdisplay.php?fid=3) +--- Forum: Xonotic - Server Administration (https://forums.xonotic.org/forumdisplay.php?fid=16) +--- Thread: Merge CTS Records (/showthread.php?tid=6983) |
Merge CTS Records - Antares* - 12-25-2016 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. RE: Merge CTS Records - -z- - 03-09-2017 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 Code: grep "cts100record/speed/crypto_idfp" /home/z/.xonotic/data/data/server.db |awk -F "\\" '{ print $3 }' |sort |uniq |_url_decode 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= 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 Hope this helps! |