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.plugin.opennap.user.OpenNapUser;
23  import org.xnap.util.QuotedStringTokenizer;
24  
25  public class WhoisResponseMessage extends ServerMessage {
26  
27      //--- Constant(s) ---
28  
29      public static final int TYPE = 604;
30  
31      //--- Data Field(s) ---
32  
33      public String nick;
34      public String userLevel;
35      public int connectDuration;
36      public String channels;
37      public String status;
38      public int sharedCount;
39      public int downloadCount;
40      public int uploadCount;
41      public int linkSpeed;
42      public String clientInfo;
43      public int totalDownload;
44      public int totalUploads;
45      public String ip;
46      public int connectingPort;
47      public int dataPort;
48      public String email;
49      public boolean extendedInfo = false;
50  
51      //--- Constructor(s) ---
52  
53      public WhoisResponseMessage(String data) throws InvalidMessageException 
54      {
55  		super(TYPE, data, 10);
56      }
57  
58      //--- Method(s) ---
59  
60      protected void parse(QuotedStringTokenizer t)
61      {
62  		nick = t.nextToken();
63  		userLevel = t.nextToken();
64  		connectDuration = (new Long(t.nextToken())).intValue();
65  		channels = t.nextToken();
66  		status = t.nextToken();
67  		sharedCount = Integer.parseInt(t.nextToken());
68  		downloadCount = Integer.parseInt(t.nextToken());
69  		uploadCount = Integer.parseInt(t.nextToken());
70  		linkSpeed = Integer.parseInt(t.nextToken());
71  		clientInfo = t.nextToken();
72  
73  		if (t.countTokens() >= 6) {
74  			extendedInfo = true;
75  			totalDownload = Integer.parseInt(t.nextToken());
76  			totalUploads = Integer.parseInt(t.nextToken());
77  			ip = t.nextToken();
78  			connectingPort = Integer.parseInt(t.nextToken());
79  			dataPort = Integer.parseInt(t.nextToken());
80  			email = t.nextToken();
81  		}
82      }
83  
84      public void received()
85      {
86  		OpenNapUser u = server.getUser(nick);
87  		u.setClientInfo(clientInfo);
88  		u.setConnectDuration(connectDuration);
89  		u.setDownloadCount(downloadCount);
90  		u.setFileCount(sharedCount);
91  		u.setHost(ip);
92  		u.setLevel(userLevel);
93  		u.setLinkSpeed(linkSpeed);
94  		u.setStatus(status);
95  		u.setUploadCount(uploadCount);
96  
97  		u.notifyWhoisReceived();
98  	
99  		StringBuffer sb = new StringBuffer();
100 		sb.append("=== whois " + nick + " ===");
101 		sb.append(nick);
102 		sb.append("server: ");
103 		sb.append(server);
104 		sb.append("\nuser: ");
105 		sb.append(nick);
106 		sb.append("\nuser level: ");
107 		sb.append(userLevel);
108 		sb.append("\nconnect duration: ");
109 		sb.append(connectDuration);
110 		sb.append("\nchannels: ");
111 		sb.append(channels);
112 		sb.append("\nstatus: ");
113 		sb.append(status);
114 		sb.append("\nshared: ");
115 		sb.append(sharedCount);
116 		sb.append("\ndownloads: ");
117 		sb.append(downloadCount);
118 		sb.append("\nuploads: ");
119 		sb.append(uploadCount);
120 		sb.append("\nlink speed: ");
121 		sb.append(linkSpeed);
122 		sb.append("\nclient: ");
123 		sb.append(clientInfo);
124 
125 		//  	Console.getInstance().println(sb.toString());
126     }
127 
128 }