diff --git a/RPIAN Vartalap Server/src/rpian/vartalap/server/Conversation.java b/RPIAN Vartalap Server/src/rpian/vartalap/server/Conversation.java index 16fc995..a5eed70 100644 --- a/RPIAN Vartalap Server/src/rpian/vartalap/server/Conversation.java +++ b/RPIAN Vartalap Server/src/rpian/vartalap/server/Conversation.java @@ -7,39 +7,24 @@ import java.io.PrintWriter; import java.net.Socket; -public class Conversation extends Thread { +public class Conversation extends Thread +{ Socket soc; - static int LOGIN_RETRY_COUNTER = 3; // TODO: move this to configuration file or DB - public Conversation(Socket soc) { + public Conversation(Socket soc) + { this.soc = soc; } - - private boolean authenticateUserPassword(String strArgument) { - - Thread t = Thread.currentThread(); - - boolean flagAuth = false; - - for (String a : RPIANVartalapServer.userArrayList) { - System.out.println(t.getName() + " authenticateUserPassword(): Loop: String a :" + a); - // TODO: Move authentication from array to DB - if (strArgument.equals(a)) { - flagAuth = true; - break; - } - } // User authentication complete.. - - return flagAuth; - } + @Override - public void run() { - Thread t = Thread.currentThread(); - System.out.println(t.getName() + " Signing On"); + public void run() + { + System.out.println(this.getName() + " Signing On"); - try { + try + { BufferedReader nis = new BufferedReader( new InputStreamReader( soc.getInputStream() @@ -53,45 +38,33 @@ public void run() { ), true ); RPIANVartalapServer.nosArrayList.add(nos); - boolean flagAuth = false; - int retryCounter = 0; - String strInput = null; - - while (retryCounter < LOGIN_RETRY_COUNTER) { - strInput = nis.readLine(); - flagAuth = authenticateUserPassword(strInput); - if (flagAuth == true) { - break; - } else { - nos.println("AuthFailed-Retry"); - } - retryCounter++; // increment retry counter on user authentication failure - }// while login retry block ends - if (flagAuth == true) { - // perform chat conversation with Authorized user - nos.println("Authenticated"); + // perform chat conversation with Authorized user + nos.println("Authenticated"); + String strInput = nis.readLine(); + while (!strInput.equals("End")) + { + System.out.println("Server recieved = "+strInput); + RPIANVartalapServer.q.enqueue(strInput); strInput = nis.readLine(); - while (!strInput.equals("End")) { - RPIANVartalapServer.q.enqueue(strInput); - strInput = nis.readLine(); - } // until the user closes the conversation with an "End" - } else { - nos.println("Failed to Authenticate"); - strInput = "End"; // Forcefully terminating the chat with client connection - }// flag false ends here + } // until the user closes the conversation with an "End" - if ("End".equals(strInput)) { + if ("End".equals(strInput)) + { nos.println(strInput); // if u dont send "End" to respective client, its chat window wont terminate RPIANVartalapServer.nosArrayList.remove(nos); - System.out.println(t.getName() + " Chat client terminated"); + System.out.println(this.getName() + " Chat client terminated"); } - } catch (Exception e) { - System.out.println(t.getName() + " Exception occured\nClient Seems to have abruptly closed the connection\n" + e); - } finally { + } + catch (Exception e) + { + System.out.println(this.getName() + " Exception occured\nClient Seems to have abruptly closed the connection\n" + e); + } + finally + { // TODO : release resources and connections - System.out.println(t.getName() + " Signing Off"); + System.out.println(this.getName() + " Signing Off"); } }// run ends -} \ No newline at end of file +}