Jump to content

Multiplayer launcher script for Linux


Fincer

Recommended Posts

Hello folks,

As I use Linux, I found starting a multiplayer game session in Wine-based Renegade X little troublesome and frustating: Wine doesn't support the way Renegade X loads multiplayer server lists. Typing an IP address into the launch command of the game is also very unpractical method to start the game.

That's why I decided to develop something useful to simplify server selection process for a Renegade X on Linux.

The following bash script downloads servers.jsp file from the web, breaks it into pieces and, as a result, shows a quite readable updated Renegade X server listing in your bash/terminal window. I did the script with my very limited bash scripting skills so please feel completely free to improve its functionality in all matters. At the moment of writing, it's just ugly & awful, but at least it does what it is expected to be done.

When you execute the script, a terminal window will be opened (unless you execute the script in a existing terminal window) and you're asked for a valid server number. Just pick your favorite server from the showed list and you're ready to play the game online.

Recommended installation steps for this bash script:

1. Download the script below and save it into your preferred location (e.g. /home/john/launch_renegadex.sh):

#!/bin/bash

#The goal of this script is to provide a human readable, simple game server 
#list & selection tool for the linux users of the Windows game Renegade X.

#I know the scripting is quite awful, so if you have time, interest and
#skills to improve the script written below, please feel free to do so.

#Download a temporary, local copy of Renegade X server listing:
wget -N http://renegadexgs.appspot.com/servers.jsp -P /tmp/

################################################################################
#THESE VARIABLES PARSE THE FILE servers.jsp INTO PIECES. PLEASE DO NOT MODIFY
#UNLESS YOU KNOW WHAT YOU'RE DOING.

#Parse server IP's from servers.jsp file and show them line by line:
servers_ip=$(grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' /tmp/servers.jsp | sed -e 's/^/"/;s/$/"/' | awk '{printf "%d\t%s\n", NR, $0}' | sed -e 's/^/server_/' -e "s/[[:space:]]\+/ /g" | awk '$1=$1' ORS=' ')

#Parse all server names:
servers_name=$(grep -e '"Name":' /tmp/servers.jsp | sed -e 's/"Name"://g' -e 's|["',\:']||g' -e 's/^ *//')

#Parse all server IP addresses:
servers_ip=$(grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' /tmp/servers.jsp)

#Get number values for each available servers, listed in servers.jsp file. The first server gets number 1, the second server on the list gets number 2 and so on:
server_number=$(grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' /tmp/servers.jsp | awk '{printf "%d\t%s\n", NR, $0}' | sed -r 's/(\b[0-9]{1,3}\.){3}[0-9]{1,3}\b'// | sed -e "s/[[:space:]]\+/ /g" | sed -e 's/^/Server /' | sed 's/[ \t]\+$//')

#Parse current server-specific player numbers:
server_players_now=$(grep -e '"Players":' /tmp/servers.jsp | sed -e 's/Players//g' -e 's|["',\:']||g' -e 's/ //g')

#Parse maximum server-specific player numbers:
server_players_max=$(grep -e '"Player Limit":' /tmp/servers.jsp | sed -e 's/"Player Limit"://g' -e 's|["',\:']||g' -e 's/ //g')

#Parse currently played server-specific map name:
server_current_map=$(grep -e '"Current Map":' /tmp/servers.jsp | sed -e 's/"Current Map"://g' -e 's/cnc-//g' -e 's|["',\:']||g' -e 's/^ *//' -e 's/.*/\u&/' -e 's/_/ /g')

#Combine the two previous variables listed above into one:
server_players_all=$(paste <(echo "$server_players_now") <(echo "$server_players_max") --delimiters '/')

#Parse server-specific "password required" status lines, either reading true or false:
password_required=$(grep -e '"bPassworded":' /tmp/servers.jsp | sed -e 's/"bPassworded"://g' -e 's|["',\:']||g' -e 's/^ *//' -e 's/.*/\u&/' )

#Combine all variables listed above:
serverlist_all=$(paste <(echo -e "Server\n$server_number") <(echo -e "IP Address\n$servers_ip") <(echo -e "Server Name\n$servers_name") <(echo -e "Current Map\n$server_current_map") <(echo -e "Players\n$server_players_all") <(echo -e "Password\n$password_required") | column -s $'\t' -t | sed -e '2i\\')

#Get the current time stamp:
timestamp=$(date +%H:%M:%S\ %d/%m/%Y)

################################################################################
#SHOW PARSED OUTPUT TO THE USER AS A GAMESERVER LIST WITH USER INPUT

echo -e "Server list updated at $timestamp\n" #Show current time to the user
echo -e "$serverlist_all" | sed  -e '$a\' -e '' #List all servers available, with important details.

read -p "Please select the server by typing its number from the list. Then press [ENTER] to launch the game: " NUM #User input field. Ask for the number of a server which the user wants to play on

echo -e "\nServer selected. Starting Renegade X...\n" #Just a notification message
sleep 2 # Stop executing this script for 2 seconds. This is just to prevent "things going too fast on the screen", nothing more.

selected_server=$(echo "$servers_ip" | sed "$NUM!d") #Put selected server IP into new variable, to be used with the game launch command.

rm /tmp/servers.jsp #Finally, delete servers.jsp file as it shows server statuses only temporarily.

################################################################################
#PUT RENEGADE X LAUNCH COMMAND HERE. 
#KEEP VARIABLE $selected_server AT THE END OF YOUR COMMAND STRING.

/usr/share/playonlinux/playonlinux --run "Renegade X" $selected_server

2. If you have a desktop shortcut file for your Wine-based Renegade X installation, please open that desktop file in your preferred text editor.

3. Copy the execution command from the line starting with string Exec (do not copy string Exec=, just the command itself)

4. Open the downloaded bash script. Scroll down and paste the copied game execution command to the end of the script file. Replace the existing one (/usr/share/playonlinux/playonlinux --run "Renegade X), but just remember not to delete variable $selected_server as it provides the vital server IP information for your Renegade X launch command.

5. Open the Renegade X desktop file again. Go to line Exec=. Delete the existing command in that line. Paste the bash script execution command as a replacement (e.g. Exec=bash /home/john/launch_renegadex.sh)

NOTE: I've found that, for some reason, sh command may not work with the current script structure. Try bash command instead as shown in the example above.

6. In the desktop file, edit line Terminal=false to Terminal=true. If this line doesn't exist, just create it.

7. Save the Renegade X desktop file and execute it. A terminal window should pop up, asking you for a valid multiplayer server:

renegadex_server_selection.jpg

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...