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 END = 4;
private static final byte WAIT_ACK_REQUESTDIRFILES = 5; private static final byte WAIT_ACK_REQUESTDIRFILES = 5;
private static final byte RETRY_REQUESTDIRFILES = 6; 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 * 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 * 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. * usuario, en función del estado del autómata en el que nos encontramos.
*/ */
private boolean canProcessCommandInCurrentState() { private boolean canProcessCommandInCurrentState() {
/* /*
* TODO: (Boletín Autómatas) Para cada comando tecleado en el shell * 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 * serán válidos en cualquier estado. Este método NO debe modificar
* clientStatus. * clientStatus.
*/ */
boolean commandAllowed = true; boolean commandAllowed = true;
switch (currentCommand) { switch (currentCommand) {
// Comandos SIEMPRE permitidos // Comandos SIEMPRE permitidos
case NFCommands.COM_MYFILES: case NFCommands.COM_MYFILES:
case NFCommands.COM_QUIT: case NFCommands.COM_QUIT:
case NFCommands.COM_HELP: case NFCommands.COM_HELP:
case NFCommands.COM_NICK:
commandAllowed = true; commandAllowed = true;
break; break;
//Comandos permitidos:OFFLINE
// Comandos permitidos: solo en OFFLINE
case NFCommands.COM_PING: case NFCommands.COM_PING:
commandAllowed = (currentState == OFFLINE); commandAllowed = (currentState == OFFLINE);
if (!commandAllowed) { if (!commandAllowed) {
System.err.println("* Ya estás conectado al directorio. No necesitas hacer ping de nuevo."); System.err.println("* Ya estás conectado al directorio. No necesitas hacer ping de nuevo.");
} }
break; 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_FILELIST_DIR:
case NFCommands.COM_PEERLIST: case NFCommands.COM_PEERLIST:
case NFCommands.COM_SERVE:
case NFCommands.COM_DOWNLOAD_DIR: case NFCommands.COM_DOWNLOAD_DIR:
case NFCommands.COM_FILELIST_PEER: case NFCommands.COM_FILELIST_PEER:
case NFCommands.COM_DOWNLOAD_PEER: case NFCommands.COM_DOWNLOAD_PEER:
commandAllowed = (currentState == ONLINE); commandAllowed = (currentState == ONLINE || currentState == SERVING);
System.out.println("allowed = " + commandAllowed);
if (!commandAllowed) { if (!commandAllowed) {
System.err.println("* Comando no permitido en estado OFFLINE. Haz un 'ping' primero."); System.err.println("* Comando no permitido en estado OFFLINE. Haz un 'ping' primero.");
} }
@@ -277,10 +297,14 @@ public class NFController {
switch (currentCommand) { switch (currentCommand) {
case NFCommands.COM_PING: case NFCommands.COM_PING:
System.out.println("updateCurrentState ping"); // System.out.println("updateCurrentState ping");
currentState = ONLINE; currentState = ONLINE;
break; break;
case NFCommands.COM_SERVE:
currentState = SERVING;
break;
case NFCommands.COM_QUIT: case NFCommands.COM_QUIT:
currentState = OFFLINE; currentState = OFFLINE;
break; break;
@@ -288,8 +312,8 @@ public class NFController {
default: default:
/* /*
* Los únicos comandos que cambian el estado del autómata son el * Los únicos comandos que cambian el estado del autómata son el
* 'ping' para ponerlo en ONLINE, y el 'quit' para ponerlo en * 'ping' para ponerlo en ONLINE, 'quit' para ponerlo en OFFLINE,
* OFFLINE, por lo tanto, los demás comandos no alterarán el * y 'serve', por lo tanto, los demás comandos no alterarán el
* estado del autómata * estado del autómata
*/ */
break; break;