Skip to content
This repository
Browse code

Switch to Ruby and MineQuery to remove an extra plugin dependency

Most servers have minequery installed already, no need to also have OnlinePlayers when this is what MineQuery was built for.
  • Loading branch information...
commit bc344d005e731314506273cb4646f89dd72f8cec 1 parent ddc46f8
Matt Stith authored March 05, 2012

Showing 1 changed file with 33 additions and 29 deletions. Show diff stats Hide diff stats

  1. 62  plugins/minecraft/minecraft-users
62  plugins/minecraft/minecraft-users
... ...
@@ -1,32 +1,36 @@
1  
-#!/bin/sh
  1
+#!/usr/local/bin/ruby
2 2
 # Config:
3  
-# [minecraft_players
4  
-# playerfile /etc/minecraft/players.txt
5  
-# subtract true
  3
+# [minecraft_users]
  4
+# env.host awesomeserver.com
  5
+# env.port 25566
6 6
 #
7  
-# playerfile - location of player list file, for example from the OnlineUsers
8  
-#	plugin
9  
-# subtract - OnlineUsers has a header above the user list, set this to true
10  
-#	to subtract 1 from the output to compensate
11  
-case $1 in
12  
-	config)
13  
-		cat <<'EOM'
14  
-graph_title Connected players
15  
-graph_vlabel players
16  
-players.label players
17  
-graph_info Number of players connected to Minecraft
18  
-graph_category Minecraft
19  
-EOM
20  
-	exit 0;;
21  
-esac
22  
-
23  
-echo -n "players.value "
24  
-
25  
-count=`wc -l ${playerfile} | cut -d' ' -f1`
26  
-if [ $subtract="true" ];
27  
-then
28  
-	echo -n "$(($count - 1))"
29  
-else
30  
-	echo $count
31  
-fi
32 7
 
  8
+require 'socket'
  9
+
  10
+if ARGV[0] == 'config'
  11
+    puts "graph_title Connected players"
  12
+    puts "graph_vlabel players"
  13
+    puts "players.label players"
  14
+    puts "graph_info Number of players connected to Minecraft"
  15
+    puts "graph_category Minecraft"
  16
+    exit
  17
+end
  18
+
  19
+host = ENV['host']
  20
+host = 'localhost' unless host
  21
+
  22
+port = ENV['port']
  23
+port = '25566' unless port
  24
+
  25
+socket = TCPSocket.new(host, port)
  26
+socket.puts "QUERY"
  27
+
  28
+response = socket.read
  29
+response = response.split("\n")
  30
+
  31
+server_port = response[0].split(" ", 2)[1].to_i
  32
+player_count = response[1].split(" ", 2)[1].to_i
  33
+max_players = response[2].split(" ", 2)[1].to_i
  34
+player_list = response[3].split(" ", 2)[1].chomp[1..-2]
  35
+
  36
+puts "players.value #{player_count}"

0 notes on commit bc344d0

Please sign in to comment.
Something went wrong with that request. Please try again.