Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
Tested 1.9, ready for release
Browse files Browse the repository at this point in the history
- Fixed a bug with logging exceptions
- Fixed small messups with the ProtcolHandler, but otherwise all worked
as I wrote it without testing! :D
- Added a jar description, since that's how I must test this now
- Updated to the latest protocol numbers
  • Loading branch information
tustin2121 committed Mar 31, 2013
1 parent c09c4bc commit 0699d2f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
18 changes: 18 additions & 0 deletions BuildJar.jardesc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
<jardesc>
<jar path="C:/Users/Tim/Desktop/MCSignOnDoor.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/MCSignOnDoor/BuildJar.jardesc" exportErrors="false" exportWarnings="false" includeDirectoryEntries="false" overwrite="false" saveDescription="false" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="false" manifestLocation="/MCSignOnDoor/MANIFEST" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
<file path="/MCSignOnDoor/README"/>
<javaElement handleIdentifier="=MCSignOnDoor/src"/>
<folder path="/MCSignOnDoor/META-INF"/>
</selectedElements>
</jardesc>
4 changes: 3 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Manifest-Version: 1.0
Class-Path: .
Created-By: 1.6.0_17 (Sun Microsystems Inc.)
Main-Class: org.digiplex.mcsod.MCSignOnDoor
Implementation-Vendor: Tustin2121
Specification-Version: 49
Specification-Version: 60

2 changes: 1 addition & 1 deletion META-INF/protocols.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Number of defined protocol handlers
handlers.count = 3
handlers.count=3

# Protocol Handlers must be in order of the protocols they handle
# McSod checks in backwards order from last handler to first to find a valid handler
Expand Down
5 changes: 4 additions & 1 deletion changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
- Changed the way protocols are handled, so now with a new protocol version, McSod
will just assume everything works from the previous protocol version.
- Current protocol version will still need to be updated for the server to not
show as out of date to a prospective client's server listing.
show as out of date to a prospective client's server listing.
- Fixed a bug with logging exceptions not printing the stack trace
- Made the project harder to debug in eclipse, but at the same time made it so I
won't have to actually use eclipse as much.
20 changes: 18 additions & 2 deletions src/org/digiplex/mcsod/MCSignOnDoor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.BindException;
import java.net.InetAddress;
Expand Down Expand Up @@ -55,7 +57,7 @@ public class MCSignOnDoor {

static { //static constructor
String protoversion = MCSignOnDoor.class.getPackage().getSpecificationVersion();
if (protoversion == null) protoversion = /****/ "49" /****/; //up to date protocol version - UPDATE MANIFEST TOO!
if (protoversion == null) protoversion = /****/ "60" /****/; //up to date protocol version - UPDATE MANIFEST TOO!
CURRENT_PROTOCOL_VERSION = Integer.parseInt(protoversion);
}

Expand Down Expand Up @@ -109,6 +111,16 @@ public static void main(String[] args) {
}
}

try {
ProtocolHandler.defineProtocols();
} catch (FileNotFoundException ex) {
LOG.log(Level.SEVERE, "Protocol file was not found in the META-INF directory! Cannot continue!"); System.exit(-1);
} catch (IOException ex) {
LOG.log(Level.SEVERE, "IOException while defining protocols! Cannot continue!", ex); System.exit(-1);
} catch (IllegalArgumentException ex) {
LOG.log(Level.SEVERE, "Error reading the protocol file! Cannot continue!", ex); System.exit(-1);
}

Runtime.getRuntime().addShutdownHook(new Thread(){
@Override public void run() {
LOG.info("Stopping message server.");
Expand Down Expand Up @@ -703,6 +715,7 @@ private static class ResponderThread extends Thread {
private BufferedOutputStream out;

ResponderThread(Socket s) {
super("Responder Thread");
sock = s;
try {
in = new BufferedInputStream(s.getInputStream());
Expand Down Expand Up @@ -1036,7 +1049,10 @@ public String format(LogRecord record) {
.append(" [").append(record.getLevel().getName()).append("]: ")
.append(this.formatMessage(record)).append('\n');
if (record.getThrown() != null){
buf.append('\t').append(record.getThrown().toString()).append('\n');
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
record.getThrown().printStackTrace(pw);
buf.append(sw.toString());
}
return buf.toString();
}
Expand Down
12 changes: 8 additions & 4 deletions src/org/digiplex/mcsod/ProtocolHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.digiplex.mcsod;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
Expand All @@ -9,6 +10,9 @@ final class ProtocolHandler {

public static void defineProtocols() throws IOException, NumberFormatException, IllegalArgumentException {
InputStream is = ProtocolHandler.class.getClassLoader().getResourceAsStream("META-INF/protocols.properties");
if (is == null)
throw new FileNotFoundException("Protocol properties not found!!");

Properties props = new Properties();
props.load(is);

Expand All @@ -22,10 +26,10 @@ public static void defineProtocols() throws IOException, NumberFormatException,

ph.protoMin = Integer.parseInt(props.getProperty(key+"protocols.min"));
ph.protoMax = Integer.parseInt(props.getProperty(key+"protocols.max"));
ph.handshakeResponse = Integer.parseInt(props.getProperty(key+"protocols.handshake"));
ph.disconnectResponse = Integer.parseInt(props.getProperty(key+"protocols.disconnect"));
ph.motdResponse = Integer.parseInt(props.getProperty(key+"protocols.motd"));
ph.encryptionResponse = Integer.parseInt(props.getProperty(key+"protocols.encryption"));
ph.handshakeResponse = Integer.parseInt(props.getProperty(key+"handshake"));
ph.disconnectResponse = Integer.parseInt(props.getProperty(key+"disconnect"));
ph.motdResponse = Integer.parseInt(props.getProperty(key+"motd"));
ph.encryptionResponse = Integer.parseInt(props.getProperty(key+"encryption"));

handlerStack[i] = ph;
}
Expand Down

0 comments on commit 0699d2f

Please sign in to comment.