[Add] Adding IRC network handling.

This commit is contained in:
Ritchie Cunningham 2024-11-23 21:25:51 +00:00
parent adba9189df
commit 94dbf32103
6 changed files with 69 additions and 2 deletions

View File

@ -1,4 +1,4 @@
SRC = config.c plugin.c
SRC = config.c plugin.c network.c
CFLAGS += -fPIC -shared -Wl,-soname,config.so -O3
LDFLAGS += -ldl

View File

@ -1,9 +1,20 @@
#include "config.h"
void configProcess(const char* command, const char* arg1, const char* arg2) {
if(strcmp(command, "plugin") == 0) {
char network[64];
*network = 0;
if(strcmp(command, "}") == 0)
*network = 0;
else if(strlen(network) != 0) {
/* TODO: Add network setup params. */
} else if(strcmp(command, "plugin") == 0) {
if(strcmp(arg1, "scan") == 0)
pluginCrawl(arg2);
} else if(strcmp(command, "network") == 0) {
strncpy(network, arg1, 64);
networkAdd(arg1);
}
return;
@ -13,6 +24,8 @@ int configRead(const char* path) {
FILE* fp;
char command[64], arg1[128], arg2[128], buff[512];
networkInit();
if((fp = fopen(path, "r")) == NULL) {
fprintf(stderr, "[CONFIG] Unable to open configuration file %s. We're screwed\n", path);
return -1;

View File

@ -9,9 +9,11 @@
#include "api.h"
#include "plugin.h"
#include "network.h"
typedef struct {
PLUGIN plugin;
struct NETWORK_ENTRY* network;
} CONFIG;
CONFIG* config;

27
base/config/network.c Normal file
View File

@ -0,0 +1,27 @@
#include "config.h"
void networkAdd(const char* name) {
struct NETWORK_ENTRY* network;
if((network = malloc(sizeof(struct NETWORK_ENTRY))) == NULL)
return;
strncpy(network->name, name, 64);
*network->host = *network->layer = 0;
network->port = 6667;
strncpy(network->nick, "C-3PO", 64);
network->network_handle = NULL;
network->next = 0;
network->next = config->network;
config->network = network;
fprintf(stderr, "Debug: Added network %s\n", name);
return;
}
void networkInit() {
config->network = NULL;
return;
}

24
base/config/network.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
struct NETWORK_CHANNEL {
char name[128];
char key[128];
int last_sent;
int cap;
struct NETWORK_CHANNEL* next;
};
struct NETWORK_ENTRY {
char name[64];
char host[128];
int port;
char nick[64];
char layer[64];
void* network_handle;
struct NETWORK_CHANNEL* channel;
struct NETWORK_ENTRY* next;
};
void networkAdd(const char* name);
void networkInit();

View File

@ -2,6 +2,7 @@ plugin scan base
plugin scan extra
network Libera {
layer plain
server irc.libera.chat
port 6667
nick C-3PO