processing opcodes, reading and storing file descriptions
git-svn-id: svn://anubis/gvsu@36 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
dd1e73971d
commit
321043b407
@ -45,13 +45,15 @@ public class KaZaServer implements Runnable
|
||||
|
||||
private class ClientInfo
|
||||
{
|
||||
String userName;
|
||||
String userName = "Anonymous";
|
||||
HashMap<String, String> files = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
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) { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user