-
Notifications
You must be signed in to change notification settings - Fork 0
/
Room.java
61 lines (47 loc) · 1.02 KB
/
Room.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.io.*;
import java.net.*;
import java.util.*;
public class Room {
private String name = null;
boolean setName(String name){
this.name = name;
return true;
}
String getName(){
return this.name;
}
boolean talk(BufferedReader in, PrintWriter out, String userName, Socket socket){
try {
out.print("Input message : ");
out.flush();
String line = in.readLine();
while(!"quit".equals(line)){
ChatServer.sendAll(userName + "@" + name + " : " + line);
out.print("Input message : ");
out.flush();
line = in.readLine();
}
} catch(IOException e) {
e.printStackTrace();
}
return true;
}
}
class Rooms{
private List<Room> rooms = new ArrayList<Room>();
private BufferedReader in;
private PrintWriter out;
public Rooms(BufferedReader in, PrintWriter out){
this.in = in;
this.out = out;
}
public List<Room> getRooms(){
return rooms;
}
public boolean createRoom(String name){
Room room = new Room();
room.setName(name);
rooms.add(room);
return true;
}
}