quake 3 commands | Try streaming the game over VNC, is it awful Kind of, and inputs don't work as expected. | Cell 5 | Search

This Bash script sets up a virtual Linux environment to run Quake III Arena and provides remote VNC access, initializing the X11 server and game with customized settings. The script also sets up signal handling, VNC server setup, and stores process IDs for later use, with cleanup functions to terminate all processes when complete.

Cell 4

#!/bin/bash

export DISPLAY=:4000

/usr/bin/Xvfb $DISPLAY -screen 0 1000x600x24 -dpi 70 -ac +extension RANDR & echo $! > /tmp/xvfb.pid
/usr/bin/xinit -display $DISPLAY & echo $! > /tmp/x11.pid

/usr/lib/ioquake3/ioquake3 --args +set fs_game missionpack +exec ./client.cfg & echo $! > /tmp/xterm.pid

sleep 5
/usr/bin/x11vnc -scale 1000x600 -noxdamage -forever -shared -rfbport 5900 -display $DISPLAY -noxrecord & echo $! > /tmp/vnc.pid

int_handler()
{
    kill $(cat /tmp/xterm.pid) 2> /dev/null
    kill $(cat /tmp/vnc.pid)
    kill $(cat /tmp/x11.pid)
    kill $(cat /tmp/xvfb.pid)
}

trap 'int_handler' INT

wait $(cat /tmp/xterm.pid)
int_handler

What the code could have been:

#!/bin/bash

# Set display for Xvfb
DISPLAY=:4000

# Run Xvfb headless session with required settings
Xvfb_PID=$(/usr/bin/Xvfb $DISPLAY -screen 0 1000x600x24 -dpi 70 -ac +extension RANDR & echo $!)
echo $Xvfb_PID > /tmp/xvfb.pid

# Run X11 session
X11_PID=$(/usr/bin/xinit -display $DISPLAY & echo $!)
echo $X11_PID > /tmp/x11.pid

# Run ioquake3 game with specified arguments
IOQ3_PID=$(/usr/lib/ioquake3/ioquake3 --args +set fs_game missionpack +exec./client.cfg & echo $!)
echo $IOQ3_PID > /tmp/xterm.pid

# Wait for 5 seconds to ensure X11 and IOQ3 sessions are up
sleep 5

# Run x11vnc for remote desktop access
VNC_PID=$(/usr/bin/x11vnc -scale 1000x600 -noxdamage -forever -shared -rfbport 5900 -display $DISPLAY -noxrecord & echo $!)
echo $VNC_PID > /tmp/vnc.pid

# Define function to handle INT signal (Ctrl+C)
int_handler() {
  # Kill X11vnc session
  kill $(cat /tmp/vnc.pid) 2>/dev/null
  
  # Kill IOQ3 game session
  kill $(cat /tmp/xterm.pid) 2>/dev/null
  
  # Kill X11 session
  kill $(cat /tmp/x11.pid) 2>/dev/null
  
  # Kill Xvfb headless session
  kill $(cat /tmp/xvfb.pid) 2>/dev/null
}

# Trap INT signal to call int_handler function
trap 'int_handler' INT

# Wait for IOQ3 game session to finish
wait $(cat /tmp/xterm.pid)

# Call int_handler function to clean up sessions
int_handler

Code Breakdown

Introduction

This is a Bash script that sets up a virtual Linux environment for running a Quake III Arena game and provides VNC access.

Initialization

  1. export DISPLAY=:4000: Sets the display environment variable to :4000.
  2. Xvfb: Creates a virtual framebuffer with resolution 1000x600x24, DPI 70, and allows RANDR extension.
  3. xinit: Starts the X11 server and displays it on the virtual framebuffer.
  4. ioquake3: Runs the Quake III Arena game with customized settings (fs_game set to missionpack and executes client.cfg).

VNC Setup

  1. sleep 5: Waits for 5 seconds to allow the game to initialize.
  2. x11vnc: Sets up VNC server on display :4000, allowing remote access on port 5900.

Cleanup

  1. int_handler: Functions to handle signals (e.g., interrupt) by killing all running processes.
  2. trap: Sets up the int_handler function to be executed when a signal is received.
  3. wait and int_handler: Waits for the game process to exit and then kills all remaining processes.

Process IDs

The script stores the process IDs of the game, VNC server, X11 server, and Xvfb in temporary files (/tmp/xterm.pid, /tmp/vnc.pid, /tmp/x11.pid, and /tmp/xvfb.pid) for later use.