Added a not yet fully operational ServerData class.

This commit is contained in:
Deathsbreed 2014-05-09 16:53:06 -05:00
parent b4b2dfa8fc
commit 66fabecfaf
2 changed files with 40 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import java.util.*;
public class Server implements Runnable {
private String version = "v1.0";
private ArrayList<ServerThread> clients = new ArrayList<ServerThread>();
private ServerData data = null;
private ServerSocket sSocket = null;
private Thread thread = null;
private int clientCount = 0;
@ -63,6 +64,8 @@ public class Server implements Runnable {
thread = new Thread(this);
thread.start();
}
data = new ServerData(this);
}
// Stop the server thread and all other threads

View File

@ -0,0 +1,37 @@
import java.io.*;
/**
* @author Nicolás A. Ortega
* @license GNU GPLv3
* @year 2014
*
* For details on the copyright, look at the COPYRIGHT file that came with
* this program.
*
*/
public class ServerData {
private File admin = null;
private FileWriter adminOut = null;
private BufferedReader adminIn = null;
public ServerData(Server server) {
admin = new File("adminpasswd.data");
if(!admin.exists()) {
try {
admin.createNewFile();
adminOut = new FileWriter(admin, true);
adminOut.append(server.getPasswd());
} catch(IOException e) {
System.out.println("Error writing to admin file: " + e.getMessage());
}
} else {
try {
adminIn = new BufferedReader(new FileReader(admin));
server.setPasswd(adminIn.readLine());
System.out.println(server.getPasswd());
} catch(IOException e) {
System.out.println("Error reading admin file: " + e.getMessage());
}
}
}
}