Skip to content

Commit

Permalink
Added 'quit' command
Browse files Browse the repository at this point in the history
  • Loading branch information
CPunch committed Mar 22, 2022
1 parent e3b1cf5 commit 94bcaba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 9 additions & 2 deletions shell/include/sterm.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ typedef enum {
TERM_BRIGHT_WHITE
} TERM_COLOR;

#define PRINTTAG(color) shellT_printf("\r%s[~]%s ", shellT_getForeColor(color), shellT_getForeColor(TERM_BRIGHT_WHITE))

#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__); \
} while(0);

#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__); \
} while(0);

Expand Down
1 change: 1 addition & 0 deletions shell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ int main(int argv, char *argc[]) {
}

shellC_cleanup(&client);
PRINTERROR("Connection closed\n");
return 0;
}
12 changes: 10 additions & 2 deletions shell/src/scmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ int shellS_readInt(char *str) {

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[]) {
int i;

shellT_printf("\n");
for (i = 0; i < client->peerTblCount; i++) {
if (client->peerTbl[i]) {
shellT_printf("\n%04d ", i);
shellT_printf("%04d ", i);
shellP_printInfo(client->peerTbl[i]);
shellT_printf("\n");
}
}
shellT_printf("\n");
Expand Down Expand Up @@ -84,7 +90,7 @@ void openShell(tShell_client *client, int args, char *argc[]) {
shellT_resetTerm();
shellT_conioTerm();

PRINTSUCC("Shell closed!\n\n");
PRINTSUCC("Shell closed!\n");
}

/* =============================================[[ Command Table ]]============================================== */
Expand All @@ -93,6 +99,7 @@ void openShell(tShell_client *client, int args, char *argc[]) {

tShell_cmdDef shellS_cmds[] = {
CREATECMD("help", "Lists avaliable commands", helpCMD),
CREATECMD("quit", "Disconnects from CNC, closing panel", quitCMD),
CREATECMD("list", "Lists all connected peers to CNC", listPeers),
CREATECMD("shell", "Opens a shell on peer", openShell),
};
Expand Down Expand Up @@ -163,6 +170,7 @@ void shellS_runCmd(tShell_client *client, char *cmd) {
}

/* run command */
shellT_printf("\n");
if (setjmp(cmdE_err) == 0) {
cmdDef->callback(client, args, argc);
}
Expand Down

0 comments on commit 94bcaba

Please sign in to comment.