ESTADO SERVING

This commit is contained in:
Mongolila-098
2026-04-29 18:31:10 +02:00
parent 6cad874746
commit eedfcab3ad
7 changed files with 84 additions and 60 deletions

View File

@@ -18,6 +18,7 @@ public class NFController {
private static final byte END = 4;
private static final byte WAIT_ACK_REQUESTDIRFILES = 5;
private static final byte RETRY_REQUESTDIRFILES = 6;
private static final byte SERVING = 7;
/*
* DONE: (Boletín Autómatas) Añadir más constantes que representen los estados
@@ -220,6 +221,7 @@ public class NFController {
* Método que comprueba si se puede procesar un comando introducidos por un
* usuario, en función del estado del autómata en el que nos encontramos.
*/
private boolean canProcessCommandInCurrentState() {
/*
* TODO: (Boletín Autómatas) Para cada comando tecleado en el shell
@@ -228,31 +230,49 @@ public class NFController {
* serán válidos en cualquier estado. Este método NO debe modificar
* clientStatus.
*/
boolean commandAllowed = true;
switch (currentCommand) {
//Comandos SIEMPRE permitidos
// Comandos SIEMPRE permitidos
case NFCommands.COM_MYFILES:
case NFCommands.COM_QUIT:
case NFCommands.COM_HELP:
case NFCommands.COM_NICK:
commandAllowed = true;
break;
//Comandos permitidos:OFFLINE
// Comandos permitidos: solo en OFFLINE
case NFCommands.COM_PING:
commandAllowed = (currentState == OFFLINE);
if (!commandAllowed) {
System.err.println("* Ya estás conectado al directorio. No necesitas hacer ping de nuevo.");
}
break;
//Comandos permitidos:ONLINE
// Comandos permitidos: OFFLINE Y ONLINE (no en SERVING)
case NFCommands.COM_NICK:
commandAllowed = (currentState == OFFLINE || currentState == ONLINE);
if (!commandAllowed) {
System.err.println("* No puedes cambiar tu nick mientras estás sirviendo ficheros.");
}
break;
// Comandos permitidos: solo en ONLINE
case NFCommands.COM_SERVE:
commandAllowed = (currentState == ONLINE);
if (currentState == OFFLINE) {
System.err.println("* Comando no permitido en estado OFFLINE. Haz un 'ping' primero.");
} else if (currentState == SERVING) {
System.err.println("* Ya estás sirviendo ficheros. No puedes iniciar el servidor de nuevo.");
}
break;
// Comandos permitidos: ONLINE Y SERVING
case NFCommands.COM_FILELIST_DIR:
case NFCommands.COM_PEERLIST:
case NFCommands.COM_SERVE:
case NFCommands.COM_DOWNLOAD_DIR:
case NFCommands.COM_FILELIST_PEER:
case NFCommands.COM_DOWNLOAD_PEER:
commandAllowed = (currentState == ONLINE);
System.out.println("allowed = " + commandAllowed);
commandAllowed = (currentState == ONLINE || currentState == SERVING);
if (!commandAllowed) {
System.err.println("* Comando no permitido en estado OFFLINE. Haz un 'ping' primero.");
}
@@ -272,15 +292,19 @@ public class NFController {
* siguiente estado y así permitir unos u otros comandos en cada caso.
*/
if (!success) {
return; //Si falla, no cambiamos de estado
return; // Si falla, no cambiamos de estado
}
switch (currentCommand) {
case NFCommands.COM_PING:
System.out.println("updateCurrentState ping");
// System.out.println("updateCurrentState ping");
currentState = ONLINE;
break;
case NFCommands.COM_SERVE:
currentState = SERVING;
break;
case NFCommands.COM_QUIT:
currentState = OFFLINE;
break;
@@ -288,8 +312,8 @@ public class NFController {
default:
/*
* Los únicos comandos que cambian el estado del autómata son el
* 'ping' para ponerlo en ONLINE, y el 'quit' para ponerlo en
* OFFLINE, por lo tanto, los demás comandos no alterarán el
* 'ping' para ponerlo en ONLINE, 'quit' para ponerlo en OFFLINE,
* y 'serve', por lo tanto, los demás comandos no alterarán el
* estado del autómata
*/
break;