Fixed errors with server data thread

No longer crashes when finished sending server data.
This commit is contained in:
Aidan Brady 2012-08-17 19:53:42 -04:00
parent 60509d2d2f
commit 271335b1dd
3 changed files with 16 additions and 23 deletions

View file

@ -18,6 +18,7 @@ import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.server.FMLServerHandler;
import net.minecraft.src.*;
import net.uberkat.obsidian.client.ThreadServerData;
/**
* Official Obsidian Ingots utilities. All miscellaneous methods are located here.
@ -62,14 +63,6 @@ public class ObsidianUtils
return "There is no news to show.";
}
/**
* Sends Obsidian Ingots server information about this mod.
*/
public static void sendServerData()
{
new ThreadServerData();
}
/**
* Returns one line of HTML from the url.
* @param urlToRead - URL to read from.

View file

@ -117,7 +117,7 @@ public class ClientProxy extends CommonProxy
System.out.println("[ObsidianIngots] Beginning utility initiative...");
ObsidianIngots.latestVersionNumber = ObsidianUtils.getLatestVersion();
ObsidianIngots.recentNews = ObsidianUtils.getRecentNews();
ObsidianUtils.sendServerData();
new ThreadServerData();
System.out.println("[ObsidianIngots] Utility initiative complete.");
}

View file

@ -1,4 +1,4 @@
package net.uberkat.obsidian.common;
package net.uberkat.obsidian.client;
import java.io.IOException;
import java.io.PrintWriter;
@ -8,6 +8,8 @@ import java.net.Socket;
import cpw.mods.fml.client.FMLClientHandler;
import net.minecraft.src.ModLoader;
import net.uberkat.obsidian.common.ObsidianIngots;
import net.uberkat.obsidian.common.ObsidianUtils;
public class ThreadServerData extends Thread
{
@ -27,25 +29,23 @@ public class ThreadServerData extends Thread
InetAddress address = InetAddress.getByName(ObsidianIngots.hostIP);
Socket socket = new Socket(address, ObsidianIngots.hostPort);
PrintWriter writer = new PrintWriter(socket.getOutputStream());
if(ObsidianUtils.isMultiplayer())
{
writer.println("USER:server");
}
else {
if(FMLClientHandler.instance().getClient().thePlayer != null)
{
writer.println("USER:" + FMLClientHandler.instance().getClient().thePlayer.username);
}
else {
writer.println("USER:client");
}
}
writer.println("USER:" + FMLClientHandler.instance().getClient().session.username);
writer.println("DONE");
writer.close();
socket.close();
try {
finalize();
} catch (Throwable e) {
System.err.println("[ObsidianIngots] Could not end server thread, error was '" + e.getMessage() + ".'");
}
} catch (IOException e)
{
System.err.println("[ObsidianIngots] Could not connect to server, error was '" + e.getMessage() + ".'");
try {
finalize();
} catch (Throwable e1) {
System.err.println("[ObsidianIngots] Could not end server thread, error was '" + e.getMessage() + ".'");
}
}
}
}