Skip to content

Instantly share code, notes, and snippets.

@davorb
Created July 21, 2011 11:47
Show Gist options
  • Save davorb/1097028 to your computer and use it in GitHub Desktop.
Save davorb/1097028 to your computer and use it in GitHub Desktop.
dfstat -- pop up message if and when server goes online
import java.net.*;
import java.io.*;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.*;
public class DFStat {
public static void main(String[] args) {
URL darkfallSite;
BufferedReader reader;
Pattern pattern2 = Pattern.compile("ONLINE");
Pattern pattern = Pattern.compile("testers: <font color=\"#FFFF00\" size=\"3\">");
Matcher matcher;
boolean warned=false;
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
java.util.Date date;
//JOptionPane.showMessageDialog(null, "Starting Darkfall Server Status watcher.", "DFStat -- (c) Vodnik", JOptionPane.INFORMATION_MESSAGE);
try {
while(!warned) {
darkfallSite = new URL("http://www.eu1.darkfallonline.com/news/");
reader = new BufferedReader(new InputStreamReader(darkfallSite.openStream()));
String inputLine;
while ((inputLine = reader.readLine()) != null)
{
String[] test = pattern.split(inputLine);
for(int i=0; i<test.length; i++) {
matcher = pattern2.matcher(test[i]);
if(test.length>1 ) {
if(matcher.find()) {
date = new java.util.Date();
JOptionPane.showMessageDialog(null, "Servers online at "+dateFormat.format(date), "DFStat -- (c) Vodnik", JOptionPane.INFORMATION_MESSAGE);
warned=true;
} else {
date = new java.util.Date();
System.out.println("Servers offline at " + dateFormat.format(date));
Thread.sleep(8000);
}
}
}
}
reader.close();
}
} catch (Exception ex){
}
System.out.println("Exiting program.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment