cli for Client
This commit is contained in:
@@ -4,6 +4,8 @@ import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.util.Objects;
|
||||
import java.util.Scanner;
|
||||
|
||||
import network.protocol.packets.*;
|
||||
|
||||
@@ -14,7 +16,11 @@ public class Client {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Client client = new Client(new InetSocketAddress("localhost", 6665));
|
||||
client.SendChatMessage("Hello");
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
while(true) {
|
||||
String message = scanner.nextLine();
|
||||
client.visitMessage(message);
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -25,6 +31,30 @@ public class Client {
|
||||
login("Moi");
|
||||
}
|
||||
|
||||
public void visitMessage(String message){
|
||||
try {
|
||||
if(message.startsWith("/")){
|
||||
if(message.startsWith("/createRoom")) {
|
||||
String roomName = message.substring(12).trim();
|
||||
SendCreateRoom(roomName);
|
||||
} else if(message.startsWith("/listRooms")) {
|
||||
RequestRoomList();
|
||||
} else if(message.startsWith("/joinRoom")) {
|
||||
String roomName = message.substring(10).trim();
|
||||
SendJoinRoom(roomName);
|
||||
} else if(message.startsWith("/leaveRoom")) {
|
||||
SendLeaveRoom();
|
||||
} else {
|
||||
System.out.println("Unknown command");
|
||||
}
|
||||
} else {
|
||||
SendChatMessage(message);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void login(String pseudo) {
|
||||
try {
|
||||
this.connexion.sendPacket(new LoginPacket(pseudo));
|
||||
@@ -49,6 +79,22 @@ public class Client {
|
||||
}
|
||||
}
|
||||
|
||||
public void SendJoinRoom(String roomName) {
|
||||
try {
|
||||
this.connexion.sendPacket(new JoinRoomPacket(roomName));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void SendLeaveRoom() {
|
||||
try {
|
||||
this.connexion.sendPacket(new LeaveRoomPacket());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestRoomList() {
|
||||
try {
|
||||
this.connexion.sendPacket(new RequestRoomListPacket());
|
||||
|
||||
Reference in New Issue
Block a user