aclist / dztui

DayZ GUI server browser and frontend for Linux
https://aclist.github.io/dzgui/dzgui
GNU General Public License v3.0
89 stars 10 forks source link

Feature request: connect with ip #1

Closed maplepy closed 2 years ago

maplepy commented 2 years ago

Hey!

Love the project so far but whenever I need to connect to a friend, I'll ask him for the ip since you can't really connect to him with steam directly as you won't get the mods. So what I have been doing is to modify the script every time to put the server id after looking up the ip or the name he told me.

Is there a way to fetch the server directly with a name or an ip and maybe get the mods and connect to it? That'd be very nice :)

Thank you

aclist commented 2 years ago

I'm glad it helped you.

Short answer: I made you a small helper script for now. I think this is the functionality you are looking for (query by static IP, add server into your whitelist).

Longer answer: (proper searching) is a limitation of the current API being used, which does not let you query directly by IP or name. While it is possible to fetch the entire list of servers, and "browse" them, it exceeds 60 pages, so the request would get rate limited. I would like to eventually add a more full-featured custom query API to fetch info from servers directly. It would also add to the number of files necessary to run/install this, so it couldn't be packaged as a standalone file.

For now, I have a simple hack for you. WARNING: it contains absolutely no error handling. It will make a backup of your current dztui script; in case anything goes wrong, you can revert it.

Place this script adjacent to your dztui file and run it. Then, simply enter the full IP with port as when prompted and it will do a simple curl request and append this ID to your current whitelist. The port is important because servers run different game mods/maps off of the same IP but under different query ports. Again, I didn't add any error handling, since this is just a quick fix for your use case, so make sure the IP is not malformed and that you enter/paste it exactly. Re-run dztui and it should be added to your list.

Once you test it for me a bit, I could definitely build this up into a function and put it in the main script with additional error handling if there is a need for adding servers by IP into your list on the fly, but it's more of a workaround, since we are just crawling the top page of the site with a plaintext query. Maybe it could be added into the table as a│add server by IP.

#!/bin/bash
file=dztui.bk
newfile=dztui

old_whitelist(){
    awk -F\" '/whitelist=/ {print $2}' $file
}
fetch_id(){
    encode=$(echo $input | sed 's/:/%3A/')
    url="https://www.battlemetrics.com/servers/search?q=%22$encode%22&game=dayz"
    temp=$(mktemp)
    curl -Ls "$url" > $temp
    id=$(awk -F"<a title=" '{print $2}' $temp | awk -F\" '{print $4}' | awk -F/ '{print $4}' | awk 'NF')
    name=$(awk -F"<a title=" '{print $2}' $temp | awk -F\" '{print $2}' | awk 'NF')
}
main(){
    fetch_id
    printf "[INFO] Fetching ID...\n"
    printf "[INFO] Added $id, $name\n"
    awk -v old=$(old_whitelist) -v new=$id 'NR==14 {$0= sprintf("whitelist=\"%s,%s\"", old,new)}1' $file > $newfile
    chmod +x $newfile
}

mv $newfile $file
read -p "Enter IP as <IP:port> " input
main
aclist commented 2 years ago

"Add server by ID" is now supported in the DZGUI branch: https://github.com/aclist/dztui/tree/dzgui

aclist commented 2 years ago

This is now live on the stable branch.