diff --git a/cs654/proj1/KaZaServer.java b/cs654/proj1/KaZaServer.java index 6fea03a..9437100 100644 --- a/cs654/proj1/KaZaServer.java +++ b/cs654/proj1/KaZaServer.java @@ -45,13 +45,15 @@ public class KaZaServer implements Runnable private class ClientInfo { - String userName; + String userName = "Anonymous"; + HashMap files = new HashMap(); } private class ClientHandler implements Runnable { private Socket m_socket; private String m_clientIP; + ClientInfo m_clientInfo; public ClientHandler(Socket socket) { @@ -64,6 +66,7 @@ public class KaZaServer implements Runnable m_clientData.put(socket.getInetAddress().getHostAddress(), new ClientInfo()); } + m_clientInfo = m_clientData.get(m_clientIP); } } @@ -85,10 +88,35 @@ public class KaZaServer implements Runnable continue; String opCode = tokens.nextToken(); - opCode.toLowerCase(); + opCode.toUpperCase(); if (opCode.equals("HELO")) { /* user is announcing his or her username */ + synchronized (m_clientData) + { + m_clientInfo.userName = inLine.substring(5); + } + } + else if (opCode.equals("DESC")) + { + /* user is giving us a description of a file */ + String fileName = inLine.substring(5); + String fileDesc = ""; + boolean first = true; + for (;;) + { + String descLine = br.readLine(); + if (descLine.equals(".")) + break; + if (!first) + fileDesc += "\n"; + fileDesc += descLine; + first = false; + } + synchronized (m_clientData) + { + m_clientInfo.files.put(fileName, fileDesc); + } } } } catch (Exception e) { }