Running multiple admin clients

From PC2wiki
Jump to: navigation, search

This article provides one way to run the Administrator module connected to different server modules within the same directory under Version 8

Version 9

With version 9 there is no longer a need for multiple admins, the entire contest configuration can be controlled using a single administrator module.

Description

While running a multi-site contest with centralized server control, there was a need for some contest administrators to run multiple administrative clients out of a single PC^2 directory without creating multiple versions of pc2v8.ini and swapping between them before connecting to each site. A bash script (below) was created to prompt for the target site then to edit the pc2v8.ini file, inserting the site specific details. After using that for a short while, A bit more code was added to provide the capability to start any of the client modes of PC² from the script.

This code has not been extensively tested.

The environment variables JAVAHOME and PC2HOME should be edited to reflect your environment, as well as the site names and their corresponding IP addresses. A version of GNU sed that supports in-place editing as well as extended regular expressions is required. The regular expressions used here are greedy so as to be more "universal" and could be made simpler by inserting known characteristics of the data that will be used by your site.

The script mainly consists of two select/case structures, where the first prompts the user for the target server then uses sed to alter pc2v8.ini appropriately. The second select/case structure prompts the user to select the client function that they wish to invoke, then runs the relevant command.

Example Shell Script

Note: This sample script is not supported by the PC² Team, also it is clear that a user would be required to modify this script to make it it work, as opposed to relying upon a properties/config/ini file for the server contact data (IP and port).

#!/bin/bash
echo -e "Setting environment variables\n"
export JAVAHOME=/opt/sun-jdk-1.5.0_08
export PC2HOME=/opt/pc2/pc2
export CLASSPATH=$JAVAHOME/lib:$PC2HOME
if ! $(echo $PATH | grep -q $JAVAHOME)
then
   export PATH=$JAVAHOME/bin:$PATH
fi

PS3="Select PC^2 Server: "
select SERVER in "SITE1" "SITE2" "SITE3"
do
   case $SERVER in
      "SITE1")
        echo "Setting server to $SERVER"
        sed -i -r 's/^server=.+$/server=111.111.111.111:50002/' $PC2HOME/pc2v8.ini
        sed -i -r 's/^site=.+$/site=SITE1/' $PC2HOME/pc2v8.ini
        break
         ;;
      "SITE2")
        echo "Setting server to $SERVER"
        sed -i -r 's/^server=.+$/server=222.222.222.222:50002/' $PC2HOME/pc2v8.ini
        sed -i -r 's/^site=.+$/site=SITE2/' $PC2HOME/pc2v8.ini
        break
         ;;
      "SITE3")
        echo "Setting server to $SERVER"
        sed -i -r 's/^server=.+$/server=333.333.333.333:50002/' $PC2HOME/pc2v8.ini
        sed -i -r 's/^site=.+$/site=SITE3/' $PC2HOME/pc2v8.ini          
        break
         ;;
   esac
done

PS3="Select PC2 client: "
select CLIENT in "Team" "Admin" "Server" "Judge"
do
   case $CLIENT in
      "Client")
         echo "Starting PC^2 Team"
         $PC2HOME/pc2team
         break
         ;;
      "Admin")
         echo "Starting PC^2 Admin"
         $PC2HOME/pc2admin
         break
         ;;
      "Judge")
         echo "Starting PC^2 Judge"
         $PC2HOME/pc2judge
         break
         ;;
      "Board")
         echo "Starting PC^2 Board"
         $PC2HOME/pc2board
         break
         ;;
   esac
done

See Also