View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.opennap.net.msg.server;
21  
22  import org.xnap.net.NetHelper;
23  import org.xnap.plugin.opennap.user.OpenNapUser;
24  import org.xnap.util.*;
25  
26  public class SearchResponseMessage extends ServerMessage {
27  
28      //--- Constant(s) ---
29  
30      public static final int TYPE = 201;
31  
32      //--- Data Field(s) ---
33  
34      public String filename;
35      public String md5;
36      public long filesize;
37      public int bitrate;
38      public int frequency;
39      public int length;
40      public String nick;
41      public String ip;
42      public int linkSpeed;
43      public int weight;
44      public int queuePos;
45      public String clientInfo;
46  
47      //--- Constructor(s) ---
48  
49      public SearchResponseMessage(String data) throws InvalidMessageException 
50      {
51  		super(TYPE, data, 9);
52      }
53  
54      //--- Method(s) ---
55  
56      protected void parse(QuotedStringTokenizer t)
57      {
58  		filename = t.nextToken();
59  		md5 = t.nextToken();
60  		filesize = Long.parseLong(t.nextToken());
61  		bitrate = Integer.parseInt(t.nextToken());
62  		frequency = Integer.parseInt(t.nextToken());
63  		length = Integer.parseInt(t.nextToken());
64  		nick = t.nextToken();
65  		ip = NetHelper.toIP(t.nextToken());
66  		linkSpeed = Integer.parseInt(t.nextToken());
67  		
68  		weight = 0;
69  		queuePos = -1;
70  		if (t.countTokens() >= 2) {
71  			try {
72  				// could be set to "n/a"
73  				queuePos = Integer.parseInt(t.nextToken());
74  			}
75  			catch (NumberFormatException e) {
76  			}
77  			clientInfo = t.nextToken();
78  		}
79  		else if (t.hasMoreTokens()) {
80  			weight = Integer.parseInt(t.nextToken());
81  		}
82      }
83  
84      public void received()
85      {
86  		OpenNapUser user = server.getUser(nick);
87  		user.setHost(ip);
88  		user.setLinkSpeed(linkSpeed);
89  		if (clientInfo != null) {
90  			user.setClientInfo(clientInfo);
91  		}
92      }
93  
94  }
95