tazcraft rev 5

Quiet a few improvment to tazcraft and cgi interface
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 19 22:29:36 2017 +0100 (2017-03-19)
parents d588912d23cd
children 4cfc84382409
files Makefile README images/minecraft-256x256.png images/minecraft.png tazcraft web/tazcraft.cgi
line diff
     1.1 --- a/Makefile	Sun Mar 19 17:44:13 2017 +0100
     1.2 +++ b/Makefile	Sun Mar 19 22:29:36 2017 +0100
     1.3 @@ -13,13 +13,17 @@
     1.4  	install -m 0755 -d $(DESTDIR)$(PREFIX)/bin
     1.5  	install -m 0755 -d $(DESTDIR)$(PREFIX)/share/applications
     1.6  	install -m 0755 -d $(DESTDIR)$(PREFIX)/share/pixmaps
     1.7 +	install -m 0755 -d $(DESTDIR)$(PREFIX)/share/doc/slitaz
     1.8  	install -m 0755 $(PACKAGE) $(DESTDIR)$(PREFIX)/bin
     1.9  	install data/minecraft.desktop $(DESTDIR)$(PREFIX)/share/applications
    1.10 -	install images/minecraft.png $(DESTDIR)$(PREFIX)/share/pixmaps
    1.11 +	install web/minecraft.png $(DESTDIR)$(PREFIX)/share/pixmaps
    1.12 +	install README $(DESTDIR)$(PREFIX)/share/doc/slitaz/tazcraft.txt
    1.13  
    1.14  install-server:
    1.15  	install -m 0755 -d $(DESTDIR)$(PREFIX)/bin
    1.16 +	install -m 0755 -d $(DESTDIR)$(PREFIX)/share/doc/slitaz
    1.17  	install -m 0755 $(PACKAGE) $(DESTDIR)$(PREFIX)/bin
    1.18 +	install README $(DESTDIR)$(PREFIX)/share/doc/slitaz/tazcraft.txt
    1.19  	
    1.20  # Uninstallation
    1.21  
     2.1 --- a/README	Sun Mar 19 17:44:13 2017 +0100
     2.2 +++ b/README	Sun Mar 19 22:29:36 2017 +0100
     2.3 @@ -6,24 +6,44 @@
     2.4  also optionally install the Java Runtime Environment (JRE).
     2.5  
     2.6  
     2.7 -Server operator
     2.8 ----------------
     2.9 -From the server console: /op username
    2.10 +== Play to Minecraft on SliTaz ==
    2.11 +---------------------------------
    2.12 +Tazcraft is not yet packaged, you have to grab the source from Hg and run
    2.13  
    2.14 +	$ sudo make install
    2.15  
    2.16 -Server configuration
    2.17 ---------------------
    2.18 -Config file: server.properties
    2.19 +Tazcraft will automaticaly download Minecraft client and start it. Minecraft
    2.20 +is powered by Java, it may work with icetea but Tazcraft let you install the
    2.21 +Sun Java Runtime environment, please see the Java section. When Java and 
    2.22 +Tazcraft are installed you will find a menu entry in the Games category. To
    2.23 +start playing from command line:
    2.24  
    2.25 -gamemode=
    2.26 -	0 - Survival
    2.27 -	1 - Creative
    2.28 -	2 - Adventure
    2.29 -	3 - Spectator
    2.30 +	$ tazcraft -p
    2.31  
    2.32  
    2.33 -MOTD text colours and formatting
    2.34 --------------------------------
    2.35 +== Minecraft server console commands ==
    2.36 +----------------------------------------
    2.37 +Just a few useful console commands Use the built-in help the get all commands:
    2.38 +
    2.39 +	/help [1-9]
    2.40 +	/op [username]
    2.41 +	/whitelist [on|off|list|add|remove|reload]
    2.42 +	/stop
    2.43 +
    2.44 +
    2.45 +== Server configuration: server.properties ==
    2.46 +---------------------------------------------
    2.47 +
    2.48 +	gamemode=
    2.49 +		0 - Survival
    2.50 +		1 - Creative
    2.51 +		2 - Adventure
    2.52 +		3 - Spectator
    2.53 +
    2.54 +
    2.55 +== MOTD text colours and formatting ==
    2.56 +--------------------------------------
    2.57 +
    2.58  	\u00A70 - BLACK
    2.59  	\u00A71 - DARK BLUE
    2.60  	\u00A72 - DARK GREEN
    2.61 @@ -47,7 +67,9 @@
    2.62  	\u00A7o - Italic
    2.63  	\u00A7r - Reset
    2.64  
    2.65 -Online resources
    2.66 -----------------
    2.67  
    2.68 -MOTD creator: https://mctools.org/motd-creator
    2.69 +== Online resources ==
    2.70 +----------------------
    2.71 +
    2.72 +	MOTD creator: http://mctools.org/motd-creator
    2.73 +
     3.1 Binary file images/minecraft-256x256.png has changed
     4.1 Binary file images/minecraft.png has changed
     5.1 --- a/tazcraft	Sun Mar 19 17:44:13 2017 +0100
     5.2 +++ b/tazcraft	Sun Mar 19 22:29:36 2017 +0100
     5.3 @@ -5,7 +5,7 @@
     5.4  # Authors: Kayam Lincoln-Vazquez, Christophe Lincoln
     5.5  # Copyright (C) 2017 SliTaz GNU/Linux - BSD License
     5.6  #
     5.7 -# TODO: add spigot support, rcon handler, properties settings
     5.8 +# TODO: add spigot support, rcon handler ?, properties settings
     5.9  #
    5.10  . /lib/libtaz.sh
    5.11  
    5.12 @@ -13,6 +13,8 @@
    5.13  home="/home/minecraft"
    5.14  server="$home/server"
    5.15  config="$server/server.properties"
    5.16 +ops="$server/ops.json"
    5.17 +whitelist="${server}/whitelist.json"
    5.18  
    5.19  server_jar="minecraft_server.${version}.jar"
    5.20  client_jar="Minecraft.jar"
    5.21 @@ -20,6 +22,7 @@
    5.22  
    5.23  spigot_jar="spigot-${version}.jar"
    5.24  
    5.25 +# Java settings
    5.26  java_version="8u121"
    5.27  java_id="218821"
    5.28  java_md5="e9e7ea248e2c4826b92b3f075a80e441"
    5.29 @@ -37,19 +40,24 @@
    5.30  help() {
    5.31  	cat << EOT
    5.32  
    5.33 -$(colorize 032 Usage:) $(basename $0) command
    5.34 +$(colorize 032 Usage:) $(basename $0) [command|key] [value]
    5.35  
    5.36  $(colorize 032 Commands:)
    5.37 +
    5.38    -d  downlaod      Download the Minecraft server
    5.39    -s  start         Start your Minecraft server
    5.40    -p  play          Launch the Minecraft client
    5.41    -j  java          Install Sun Java Runtime Environment
    5.42 +  -k  key           Get or set a key value in server.properties
    5.43    -i  info          Display server and java information
    5.44 -      motd          Raw display of the Message Of The Day
    5.45 -      ops           Show server operators name
    5.46 +  -m  motd          Raw display of the Message Of The Day
    5.47 +  -o  ops           Show server operators name
    5.48 +  -w  with-list     Show allowed user from white list
    5.49  
    5.50  $(colorize 032 Options:)
    5.51 +
    5.52    --gui             Run the server with a graphical user interface
    5.53 +  --mem             Set the max memory usage for Minecraft server
    5.54  
    5.55  EOT
    5.56  }
    5.57 @@ -76,10 +84,10 @@
    5.58  	fi
    5.59  }
    5.60  
    5.61 -# Get a value in
    5.62 -get_value() {
    5.63 +# Get a key value from server config file
    5.64 +get_key() {
    5.65  	val=$(grep ^${1}= ${config} | cut -d "=" -f 2)
    5.66 -	echo -n "$1"; indent 15 ": $val"
    5.67 +	echo -n "$1"; indent 15 "= $(colorize 033 $val)"
    5.68  }
    5.69  
    5.70  #
    5.71 @@ -90,21 +98,26 @@
    5.72  	-d|downlaod)
    5.73  		if [ ! -f "$server/$jar" ]; then
    5.74  			echo "Downloading Minecraft..."
    5.75 +			
    5.76  			mkdir -p ${server}
    5.77  			wget --no-check-certificate \
    5.78  				https://s3.amazonaws.com/Minecraft.Download/versions/${version}/minecraft_server.${version}.jar \
    5.79  				-O ${server}/minecraft_server.${version}.jar
    5.80 +			
    5.81  		else
    5.82  			colorize 032 "Minecraft is already downloaded :-)"
    5.83  		fi ;;
    5.84  	
    5.85  	-s|start)
    5.86  		check_java || exit 1
    5.87 -		defaut_motd
    5.88 +		[ "$mem" ] || mem="1024"
    5.89 +		
    5.90  		colorize 032 "Starting Minecraft server..."
    5.91  		[ ! "$gui" ] && opts="nogui"
    5.92  		cd ${server}
    5.93 -		${java} -Xmx1024M -Xms1024M -jar ${server_jar} ${opts} ;;
    5.94 +		${java} -Xmx${mem}M -Xms${mem}M -jar ${server_jar} ${opts} 
    5.95 +		
    5.96 +		newline ;;
    5.97  	
    5.98  	-p|play)
    5.99  		if [ ! -f "$client_path" ]; then
   5.100 @@ -135,8 +148,17 @@
   5.101  			colorize 032 "Java Runtime Environment is installed"
   5.102  			${java} -version
   5.103  		fi ;;
   5.104 +		
   5.105 +	-k|key)
   5.106 +		key="$2"
   5.107 +		val="$3"
   5.108 +		if [ "$val" ]; then
   5.109 +			echo "Setting $key to: $val"
   5.110 +			sed -i s"/${key}=.*/${key}=${val}/" ${config}
   5.111 +		fi
   5.112 +		get_key ${key} ;;
   5.113  	
   5.114 -	motd)
   5.115 +	-m|motd)
   5.116  		defaut_motd 
   5.117  		motd=$(grep ^motd= ${config} | sed s'/motd=//')
   5.118  		title "Message Of The Day (motd)"
   5.119 @@ -145,39 +167,21 @@
   5.120  	
   5.121  	-o|ops)
   5.122  		title "Server operators"
   5.123 -		ops_json="$server/ops.json"
   5.124 -		#echo "Config file: $server/ops.json"
   5.125 -		fgrep name ${ops_json} | cut -d '"' -f 4
   5.126 +		fgrep name ${ops} | cut -d '"' -f 4
   5.127 +		newline
   5.128 +		colorize 033 "Config file: $ops"
   5.129  		newline ;;
   5.130  	
   5.131  	-w|white-list)
   5.132 -		# Usage: tazcraft -w [username|--true|--false]
   5.133 -		white_list="${server}/white-list.txt"
   5.134  		title "Minecraft server white list"
   5.135  		
   5.136 -		case "$2" in
   5.137 -		
   5.138 -			--true) 
   5.139 -				echo "Activaction white list support..."
   5.140 -				sed -i s'/white-list=*./white-list=true/' ${config}
   5.141 -				touch ${white_list} ;;
   5.142 -				
   5.143 -			--false) ;;
   5.144 -			*) ;;
   5.145 -		esac
   5.146 -		# Add/remove users
   5.147 -		
   5.148 -		
   5.149 -		# --true
   5.150 -		if [ "$true" ]; then
   5.151 -			
   5.152 -		fi
   5.153 -		
   5.154  		# Display white list users or give settings info
   5.155  		if [ -f "$white_list" ]; then
   5.156 +			users=$(wc -l < $white_list)
   5.157  			cat  ${white_list}
   5.158 +			echo -e "\nAllowed users: $users"
   5.159  		else
   5.160 -			get_value "white-list"
   5.161 +			get_key "white-list"
   5.162  			colorize 031 "White list file is not activated $val"
   5.163  		fi
   5.164  		
   5.165 @@ -192,9 +196,9 @@
   5.166  		
   5.167  		colorize 032 "Server properties"
   5.168  		for var in gamemode server-port level-name difficulty max-players \
   5.169 -			allow-flight
   5.170 +			allow-flight white-list
   5.171  		do
   5.172 -			get_value ${var}
   5.173 +			get_key ${var}
   5.174  		done
   5.175  		newline
   5.176  		
     6.1 --- a/web/tazcraft.cgi	Sun Mar 19 17:44:13 2017 +0100
     6.2 +++ b/web/tazcraft.cgi	Sun Mar 19 22:29:36 2017 +0100
     6.3 @@ -11,9 +11,10 @@
     6.4  home="/home/minecraft"
     6.5  server="$home/server"
     6.6  config="$server/server.properties"
     6.7 +whitelist="${server}/whitelist.json"
     6.8  
     6.9 -# Get a value in
    6.10 -get_value() {
    6.11 +# Get a key value from server config file
    6.12 +get_key() {
    6.13  	val=$(grep ^${1}= ${config} | cut -d "=" -f 2)
    6.14  	cat << EOT
    6.15  <tr>
    6.16 @@ -23,50 +24,116 @@
    6.17  EOT
    6.18  }
    6.19  
    6.20 +# HTML footer
    6.21 +html_footer() {
    6.22 +	cat << EOT
    6.23 +</div>
    6.24 +<footer style="text-align: center; margin: 10px; color: #888;">
    6.25 +	&copy; $(date '+%Y') <a href="http://www.slitaz.org">SliTaz GNU/Linux</a>
    6.26 +</footer>
    6.27 +</body>
    6.28 +</htnl>
    6.29 +EOT
    6.30 +}
    6.31 +
    6.32  # HTML header
    6.33 -cat << EOT
    6.34 +html_header() {
    6.35 +	cat << EOT
    6.36  <!DOCTYPE html>
    6.37  <html>
    6.38  <head>
    6.39  	<meta charset="utf-8" />
    6.40 -	<title>Tazcraft</title>
    6.41 +	<title>Tazcraft - $1</title>
    6.42  	<link rel="stylesheet" href="http://play.slitaz.me/style.css" />
    6.43  </head>
    6.44  <body>
    6.45  <header>
    6.46  	<div id="logo"></div>
    6.47  	<div id="network">
    6.48 +		<a href="tazcraft.cgi">Tazcraft</a>
    6.49 +		<a href="tazcraft.cgi?README">README</a>
    6.50 +		<span style="color: #682368;">&hearts;</span> 
    6.51  		<a href="http://play.slitaz.me">play.SliTaz.me</a>
    6.52 -		<a href="http://www.slitaz.org">SliTaz.org</a>
    6.53  	</div>
    6.54  	<h1>Tazcraft Server</h1>
    6.55  </header>
    6.56  <div id="content">
    6.57 +EOT
    6.58 +}
    6.59  
    6.60 +#
    6.61 +# Handle GET commands
    6.62 +#
    6.63 +
    6.64 +case " $(GET) " in
    6.65 +	
    6.66 +	*\ README\ *)
    6.67 +		
    6.68 +		if [ -f "../README" ]; then
    6.69 +			README="../README"
    6.70 +		else
    6.71 +			README="/usr/share/doc/slitaz/tazcraft.txt"
    6.72 +		fi
    6.73 +		
    6.74 +		html_header "README"
    6.75 +		echo "<h2>README</h2>"
    6.76 +		echo "<pre>"
    6.77 +		# Let have a few color in README
    6.78 +		cat ${README} | sed \
    6.79 +			-e "/^====.*/"d -e "/^----.*/"d \
    6.80 +			-e s"#==\([^']*\)==#<h3 style='margin: 0;'>\1</h3>#"g \
    6.81 +			-e s"#^	[\#|\$|\/]\([^']*\)#<span style='color: green;'>\0</span>#"g \
    6.82 +			-e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g
    6.83 +		echo "</pre>"
    6.84 +		html_footer 
    6.85 +		exit 0 ;;
    6.86 +	
    6.87 +esac
    6.88 +
    6.89 +#
    6.90 +# Home page with server information and configuration
    6.91 +#
    6.92 +html_header "Welcome"
    6.93 +
    6.94 +uptime=$(ps | grep minecraft_server | grep -v grep | awk '{print $3}')
    6.95 +if [ ! "$uptime" ]; then
    6.96 +	uptime="Not running"
    6.97 +fi
    6.98 +
    6.99 +cat << EOT
   6.100  <h2>Welcome to Tazcraft</h2>
   6.101 -<p>A SliTaz GNU/Linux Minecraft server</p>
   6.102 +<p>
   6.103 +	A SliTaz GNU/Linux Minecraft server
   6.104 +	- Uptime: <span style="color: green;">$uptime</span>
   6.105 +</p>
   6.106 +
   6.107  <pre>
   6.108 -<img src="minecraft.png" alt="*" />Server address: <b>play.slitaz.me</b>
   6.109 +<img src="minecraft.png" alt="*" />Server address: \
   6.110 +<span style="color: green; font-size: 20px;">play.slitaz.me</span>
   6.111  </pre>
   6.112  
   6.113  <h3>Configuration</h3>
   6.114  <table>
   6.115  	<thead>
   6.116 -		<td>$(gettext "Variable")</td>
   6.117 +		<td>$(gettext "Key")</td>
   6.118  		<td>$(gettext "Value")</td>
   6.119  	</thead>
   6.120  EOT
   6.121  
   6.122 -for var in gamemode server-port level-name difficulty max-players; do
   6.123 -	get_value ${var}
   6.124 +for var in gamemode server-port level-name difficulty max-players \
   6.125 +	allow-flight white-list
   6.126 +do
   6.127 +	get_key ${var}
   6.128  done
   6.129 +echo "</table>"
   6.130  
   6.131 -# HTML footer
   6.132 -cat << EOT
   6.133 -</table>
   6.134 -</div>
   6.135 -<footer></footer>
   6.136 -</body>
   6.137 -</htnl>
   6.138 -EOT
   6.139 +# White listed users names
   6.140 +if grep -q "white-list=true" ${config}; then
   6.141 +	echo "<h3>White list</h3>"
   6.142 +	echo "<pre>"
   6.143 +	fgrep name ${whitelist} | cut -d '"' -f 4
   6.144 +	echo "</pre>"
   6.145 +fi
   6.146 +
   6.147 +html_footer
   6.148  exit 0