return;
}
case PACKET_SRVIDCHANGE: {
byte client_id[] = new byte[4];
packet_data.get(client_id);
ClientID clientID = new ClientID(client_id);
int server_features = packet_data.getInt();
Set<ServerFeatures> features = Utils
.scanTCPServerFeatures(server_features);
_network_manager.receivedIDChangeFromServer(clientID, features);
return;
}
case PACKET_SRVSTATUS: {
int user_count = packet_data.getInt();
int file_count = packet_data.getInt();
_network_manager.receivedServerStatus(user_count, file_count);
return;
}
case OP_SERVERLIST: {
int server_count = packet_data.get();
List<String> ip_list = new LinkedList<String>();
List<Integer> port_list = new LinkedList<Integer>();
for (int i = 0; i < server_count; i++) {
byte address[] = new byte[4];
int port;
packet_data.get(address);
port = Convert.shortToInt(packet_data.getShort());
ip_list.add(Convert.IPtoString(address));
port_list.add(port);
}
_network_manager.receivedServerList(ip_list, port_list);
return;
}
case PACKET_SRVSEARCHRESULT: {
int result_count = packet_data.getInt();
SearchResultItemList searchResults = new SearchResultItemList();
for (int i = 0; i < result_count; i++) {
byte fileHash[] = new byte[16];
packet_data.get(fileHash);
byte clientID[] = new byte[4];
packet_data.get(clientID);
short clientPort = packet_data.getShort();
SearchResultItem result = new SearchResultItem(
new FileHash(fileHash), new ClientID(clientID),
clientPort);
int tag_count = packet_data.getInt();
for (int j = 0; j < tag_count; j++) {
Tag tag = TagScanner.scanTag(packet_data);
result.addTag(tag);
}
// transform Server's file rating into eMule file rating
if (result.hasTag(FT_FILERATING)) {
Tag tag = result.getTag(FT_FILERATING);
try {
int data = (Integer) tag.getValue();
data = Convert.byteToInt(Misc.getByte(data, 0));
int rating_value = data / SERVER_SEARCH_RATIO;
tag.setValue(rating_value);
} catch (Throwable e) {
e.printStackTrace();
}
}
searchResults.add(result);
}
_network_manager.receivedSearchResult(searchResults);
return;
}
case PACKET_SRVFOUNDSOURCES: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
int source_count = Convert.byteToInt(packet_data.get());
List<String> client_ip_list = new LinkedList<String>();
List<Integer> port_list = new LinkedList<Integer>();
byte[] peerID = new byte[4];
int peerPort;
ByteBuffer data = Misc.getByteBuffer(4);
for (int i = 0; i < source_count; i++) {
for (int j = 0; j < 4; j++) {
data.clear();
data.rewind();
byte b = packet_data.get();
data.put(b);
peerID[j] = Convert.intToByte(data.getInt(0));
}
byte[] portArray = new byte[2];
packet_data.get(portArray);
ByteBuffer tmpData = Misc.getByteBuffer(4);
tmpData.put(portArray);
tmpData.position(0);
peerPort = tmpData.getInt();
ClientID cid = new ClientID(peerID);
// if (PeerManagerFactory.getInstance().hasPeer(cid))
// continue;
// if (PeerManagerFactory.getInstance().isFull()) continue;
client_ip_list.add(cid.getAsString());
port_list.add(peerPort);
}
_network_manager.receivedSourcesFromServer(new FileHash(
file_hash), client_ip_list, port_list);
return;