v0.4 stabilization
This commit is contained in:
parent
9de9f8d36f
commit
cd1e70838c
4 changed files with 43 additions and 22 deletions
|
@ -25,7 +25,6 @@ public class PrivateMsgCommander { // T
|
|||
if (cmd.length > 1)
|
||||
cmd[1] = cmd[1].trim();
|
||||
|
||||
|
||||
switch (cmd[0]){
|
||||
case "tell":
|
||||
if ((cmd.length == 2) && (cmd[1].split("(\\s)|(\t)+?",2).length == 2)) {
|
||||
|
|
|
@ -35,20 +35,27 @@ public class BotDriver {
|
|||
case "zero":
|
||||
return new BotZeroWorker();
|
||||
default:
|
||||
System.out.println("Configuration issue: BotDriver->getWorker() can't find required driver \""
|
||||
System.out.println("BotDriver->getWorker(): Configuration issue: can't find required driver \""
|
||||
+serverDriver.get(serverName)[0][0]
|
||||
+"\".Using \"ZeroWorker\".");
|
||||
return new BotZeroWorker();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
System.out.println("BotDriver->getWorker(): Unknown issue: Channel exists for non-existing server.\n\tUsing ZeroWorker.");
|
||||
return new BotZeroWorker();
|
||||
}
|
||||
// If channel found that it's impossible to use defined worker from user settings and asking for use ZeroWorker
|
||||
public static synchronized Worker getZeroWorker(){
|
||||
return new BotZeroWorker();
|
||||
}
|
||||
private static Worker validateConstancy(Worker worker, String srv, String chan){ // synchronized?
|
||||
if (worker.isConsistent()){
|
||||
return worker;
|
||||
}
|
||||
else {
|
||||
System.out.println("BotDriver: Unable to use "+worker.getClass().getSimpleName()+" for "+srv+"/"+chan+". Using ZeroWorker instead.");
|
||||
System.out.println("BotDriver->validateConstancy(): Unable to use "
|
||||
+worker.getClass().getSimpleName()+" for "+srv+"/"+chan
|
||||
+". Using ZeroWorker instead.");
|
||||
return new BotZeroWorker();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,13 +54,16 @@ public class ChanConsumer implements Runnable {
|
|||
if (!trackUsers(dataStrings[0], dataStrings[1], dataStrings[2]))
|
||||
continue;
|
||||
|
||||
writerWorker.logAdd(dataStrings[0], dataStrings[1], dataStrings[2]);
|
||||
// Send to chanel commander thread
|
||||
chanelCommanderPipe.println(data);
|
||||
chanelCommanderPipe.flush();
|
||||
//System.out.println("|"+dataStrings[0]+"|"+dataStrings[1]+"|"+dataStrings[2]+"|");
|
||||
//System.out.println("Thread: "+this.channelName +"\n\tArray:"+ userList);
|
||||
|
||||
if (!writerWorker.logAdd(dataStrings[0], dataStrings[1], dataStrings[2])){ // Write logs, check if LogDriver consistent. If not:
|
||||
this.fixLogDriverIssues(dataStrings[0], dataStrings[1], dataStrings[2]);
|
||||
}
|
||||
|
||||
if (endThread) {
|
||||
reader.close();
|
||||
chanList.get(channelName).close();
|
||||
|
@ -69,7 +72,7 @@ public class ChanConsumer implements Runnable {
|
|||
}
|
||||
}
|
||||
} catch (java.io.IOException e){
|
||||
System.out.println("Internal issue: thread ChanConsumer->run() caused I/O exception:\n\t"+e); // TODO: reconnect
|
||||
System.out.println("ChanConsumer (@"+serverName+"/"+channelName+")->run(): Internal issue in thread: caused I/O exception:\n\t"+e); // TODO: reconnect
|
||||
}
|
||||
writerWorker.close();
|
||||
//Chanel commander thread's pipe should be closed
|
||||
|
@ -82,25 +85,25 @@ public class ChanConsumer implements Runnable {
|
|||
case "PRIVMSG": // most common, we don't have to handle anything else
|
||||
return true;
|
||||
case "JOIN":
|
||||
addUsers(initiatorArg);
|
||||
addUsers(simplifyNick(initiatorArg));
|
||||
return true;
|
||||
case "PART":
|
||||
delUsers(initiatorArg);
|
||||
delUsers(simplifyNick(initiatorArg)); // nick non-simple
|
||||
return true;
|
||||
case "QUIT": // TODO fix: use regex
|
||||
if (userList.contains(initiatorArg.replaceAll("!.+$", ""))) {
|
||||
delUsers(initiatorArg);
|
||||
case "QUIT":
|
||||
if (userList.contains(simplifyNick(initiatorArg))) {
|
||||
delUsers(simplifyNick(initiatorArg)); // nick non-simple
|
||||
return true;
|
||||
} else
|
||||
return false; // user quit, but he/she is not in this channel
|
||||
case "KICK":
|
||||
if (rejoin && nick.equals(subjectArg.substring(subjectArg.indexOf(" ") + 1, subjectArg.indexOf(" :"))))
|
||||
if (rejoin && nick.equals(subjectArg.replaceAll("(^.+?\\s)|(\\s.+$)", ""))) // if it's me and I have rejoin policy 'Auto-Rejoin on kick'.
|
||||
StreamProvider.writeToStream(serverName, "JOIN " + channelName);
|
||||
delUsers(subjectArg.substring(subjectArg.indexOf(" ") + 1, subjectArg.indexOf(" :")));
|
||||
delUsers(subjectArg.replaceAll("(^.+?\\s)|(\\s.+$)", "")); // nick already simplified
|
||||
return true;
|
||||
case "NICK":
|
||||
if (userList.contains(initiatorArg.replaceAll("!.+$", ""))) {
|
||||
swapUsers(initiatorArg, subjectArg);
|
||||
if (userList.contains(simplifyNick(initiatorArg))) {
|
||||
swapUsers(simplifyNick(initiatorArg), subjectArg);
|
||||
return true;
|
||||
} else {
|
||||
return false; // user changed nick, but he/she is not in this channel
|
||||
|
@ -111,19 +114,19 @@ public class ChanConsumer implements Runnable {
|
|||
}
|
||||
|
||||
private void addUsers(String user){
|
||||
if (!userList.contains(user.replaceAll("!.+$", "")))
|
||||
userList.add(user.replaceAll("!.+$", ""));
|
||||
if (!userList.contains(user))
|
||||
userList.add(user);
|
||||
}
|
||||
private void delUsers(String user){
|
||||
if (user.replaceAll("!.+$", "").equals(nick)) {
|
||||
if (user.equals(nick)) {
|
||||
endThread = true;
|
||||
}
|
||||
userList.remove(user.replaceAll("!.+$", ""));
|
||||
userList.remove(user);
|
||||
}
|
||||
private void swapUsers(String userNickOld, String userNickNew){
|
||||
userList.remove(userNickOld.replaceAll("!.+$", ""));
|
||||
userList.remove(userNickOld);
|
||||
userList.add(userNickNew);
|
||||
if (userNickOld.replaceAll("!.+$", "").equals(nick))
|
||||
if (userNickOld.equals(nick))
|
||||
this.nick = userNickNew;
|
||||
}
|
||||
// Create ChanelCommander
|
||||
|
@ -142,9 +145,19 @@ public class ChanConsumer implements Runnable {
|
|||
return new PrintWriter(streamOut);
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Internal issue: ChanConsumer->getChanelCommander() I/O exception while initialized child objects."); // caused by Socket
|
||||
System.out.println("ChanConsumer (@"+serverName+"/"+channelName+")->getChanelCommander(): Internal issue: I/O exception while initialized child objects:\n\t"+e); // caused by Socket
|
||||
endThread = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private String simplifyNick(String nick){ return nick.replaceAll("!.*$",""); }
|
||||
|
||||
private void fixLogDriverIssues(String a, String b, String c){
|
||||
System.out.println("ChanConsumer (@"+serverName+"/"+channelName+")->fixLogDriverIssues(): Some issues detected. Trying to fix...");
|
||||
this.writerWorker = BotDriver.getWorker(serverName, channelName); // Reset logDriver and try using the same one
|
||||
if (!writerWorker.logAdd(a,b,c)){ // Write to it what was not written (most likely) and if it's still not consistent:
|
||||
this.writerWorker = BotDriver.getZeroWorker();
|
||||
System.out.println("ChanConsumer (@"+serverName+"/"+channelName+")->fixLogDriverIssues(): failed to use defined LogDriver. Using ZeroWorker instead.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,9 @@ public class SystemConsumer implements Runnable{
|
|||
private PrivateMsgCommander commander;
|
||||
|
||||
SystemConsumer(BufferedReader streamReader, String userNick, Map<String, PrintWriter> map, StorageFile storage) {
|
||||
|
||||
this.writerWorker = BotDriver.getWorker(storage.getServerName(), "system");
|
||||
|
||||
this.nick = userNick;
|
||||
this.serverName = storage.getServerName();
|
||||
this.channelsMap = map;
|
||||
|
|
Loading…
Reference in a new issue