1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package aigames.soccer.communication;
21
22 import snifos.common.UserId;
23
24 import java.nio.channels.SocketChannel;
25
26
27 /***
28 * Data associated with accepted client.
29 * @version $Id: ClientData.java,v 1.4 2004/05/08 21:55:26 mwerla Exp $
30 */
31 public class ClientData {
32 private SocketChannel socket;
33 private StringBuffer buffer;
34 private UserId userId;
35
36 /***
37 * Deafult constructor.
38 * @param socket socket channel
39 * @param userId UserId object
40 */
41 public ClientData(SocketChannel socket, UserId userId) {
42 this.socket = socket;
43 this.buffer = new StringBuffer();
44 this.userId = userId;
45 }
46
47 /***
48 * Appends a line to the client message buffer.
49 * @param message string from a socket
50 */
51 public void append(String message) {
52 buffer.append(message);
53 }
54
55 /***
56 * Getter for client message buffer.
57 * @return message buffer
58 */
59 public StringBuffer getBuffer() {
60 return buffer;
61 }
62
63 /***
64 * Getter for socket channel.
65 * @return socket channel
66 */
67 public SocketChannel getSocket() {
68 return socket;
69 }
70
71 /***
72 * Gettero for user id.
73 * @return UserId object
74 */
75 public UserId getUserId() {
76 return userId;
77 }
78
79 /***
80 * Clear processed part of the message buffer.
81 * @param position last processed byte of the buffer
82 */
83 public void clearBuffer(int position) {
84 String rest = buffer.substring(position);
85 buffer = new StringBuffer(rest);
86 }
87 }