This commit is contained in:
anon 2023-08-04 15:53:41 +02:00
commit 69bf57ed38
8 changed files with 11 additions and 66 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ config.h
.gdb_history
*.sqlite
build.sh
Makefile

View File

@ -9,6 +9,3 @@ probotic: $(SRC) $(HDR)
# do nothing but update them...
$(SRC) $(HDR):
run:
./probotic -server irc.rizon.net -port 6664 -username probotic -channel '#/g/chad' -db bootstrap/probotic_data.sqlite

View File

@ -1,5 +1,5 @@
#!/bin/sh
DBFILE=probotic_data.sqlite
rm "$DBFILE"
rm -f "$DBFILE"
sqlite3 "$DBFILE" -init bootstrap.sql -line '.quit'

View File

@ -1,6 +1,3 @@
server=irc.rizon.net
username=probotic
port=6667
;admins=anon8697 emilemilemil fa11_1eaf
; these arent comments, but they work because
; the parser is broken enough to make it just werk

View File

@ -20,7 +20,6 @@ DECL char * raw(char const * const sql);
DECL char * remind(char * who);
DECL char * slurp(char const * fn);
DECL int is_admin(char const * user);
DECL void parse_admins(char * admin_string);
DECL int parse_pair(char const * buf, size_t const len);
DECL void creds_free_password(void);
DECL void creds_free_rest(void);

View File

@ -99,7 +99,7 @@ event_connect(irc_session_t * session,
/* msg ChanServ IDENTIFY? */
irc_cmd_join(session, creds.channel, 0);
if(is_no_assignment(creds.channel)){
ircmsg(IRC_RED "No assignment for this channel. Finding a new...");
ircmsg(IRC_RED "No assignment for this channel. Finding a new..." IRC_STOP);
random_assign(creds.channel);
}
ircmsg(remind(creds.channel));

View File

@ -82,9 +82,6 @@ main (int argc,
{ free(creds.username); creds.username = strdup(argv[1]); }
else if (strcmp(arg, "password") == 0)
{ free(creds.password); creds.password = strdup(argv[1]); }
else if (strcmp(arg, "admin") == 0)
/* argv isn't constant :>, this can make even valgrind shutter */
{ free(creds.admins); parse_admins(argv[1]); }
else if (strcmp(arg, "auth") == 0)
{
authfile = argv[1];

View File

@ -22,28 +22,29 @@
enum cred_names_map
{
DATABASE,
USERNAME,
PASSWORD,
CHANNEL,
SERVER,
PORT,
ADMINS
PORT
};
VARDECL char const * cred_names[] =
{
"database",
"username",
"password",
"channel",
"server",
"port",
"admins"
"port"
};
VARDECL size_t const cred_names_len[] =
{
8,
8,
8,
7,
6,
4,
@ -211,7 +212,6 @@ DECL int
parse_pair(char const * buf, size_t len)
{
size_t i, f, x;
char * adm;
/* fprintf(stderr, "ENT len:%ld buf:%sEOF\n", len, buf); */
for (i = 0; buf[i] &&
i < len; ++i)
@ -238,15 +238,12 @@ parse_pair(char const * buf, size_t len)
}
switch (f)
{
case DATABASE: db = strndup(buf,x); break;
case USERNAME: creds.username = strndup(buf,x); break;
case PASSWORD: creds.password = strndup(buf,x); break;
case CHANNEL: creds.channel = strndup(buf,x); break;
case SERVER: creds.server = strndup(buf,x); break;
case PORT: creds.port = atoi(buf); break;
case ADMINS: adm = strndup(buf,x);
parse_admins(adm);
free(adm);
break;
}
if (x + 2 < len)
{ buf += x + 1; }
@ -261,54 +258,11 @@ parse_pair(char const * buf, size_t len)
return 0;
}
/* FIXME MAKE parse_admins constant! */
/* WARNING: admin_string WILL be changed */
DECL void
parse_admins(char * admin_string)
{
#define ADMIN_LIST_INIT_SIZE 8
/* prealloc with 8 */
size_t current_array_size = ADMIN_LIST_INIT_SIZE;
size_t i = 0;
char * token = NULL;
creds.admins = calloc(ADMIN_LIST_INIT_SIZE, sizeof(char *));
while ((token = strtok(admin_string, " ")))
{
if (++i > current_array_size)
{
/* double the space */
current_array_size *= 2;
creds.admins = realloc(creds.admins, current_array_size);
}
creds.admins[i - 1] = strdup(token);
}
/* set up array end marker for proper clean-up later */
if (i + 1 > current_array_size)
{
creds.admins = realloc(creds.admins, current_array_size + 1);
}
creds.admins[i] = NULL;
}
DECL int
is_admin(char const * user)
{
/* No Gods or Kings, Only Man */
if (creds.admins == NULL)
{ return 0; }
for (size_t i = 0; creds.admins[i]; ++i)
{
if (!strcmp(creds.admins[i], user))
{ return 1; }
}
return 0;
/* No Gods or Kings, Only size_t */
return 1;
}
void