Просмотр исходного кода

Added new options for voting

master
Emil 9 месяцев назад
Родитель
Сommit
9dc569a55c
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 5432DB986FDBCF8A
2 измененных файлов: 52 добавлений и 8 удалений
  1. +1
    -1
      CHANGELOG
  2. +51
    -7
      src/irc.c

+ 1
- 1
CHANGELOG Просмотреть файл

@@ -12,7 +12,7 @@ VERSION 2


Moved NVULN to config.h Moved NVULN to config.h
Added option -identify Added option -identify
Added commands !magic, !say
Added commands !magic, !say, !poll N, !vote y|n|u
Added ENABLE_SSL=1 to enable SSL non-functional support Added ENABLE_SSL=1 to enable SSL non-functional support
Added libircclient submodule Added libircclient submodule
Fixed some error return values being too high Fixed some error return values being too high


+ 51
- 7
src/irc.c Просмотреть файл

@@ -4,6 +4,8 @@


#define IRCMSG(msg) irc_cmd_msg(session, creds.channel, msg) #define IRCMSG(msg) irc_cmd_msg(session, creds.channel, msg)


#define MAX(a,b) (a) > (b)

typedef struct typedef struct
{ {
char * username; char * username;
@@ -83,7 +85,7 @@ ircmsg(char const * reciever, char const * fmt,
do do
{ {
swp = irc_color_convert_to_mirc(data); swp = irc_color_convert_to_mirc(data);
irc_cmd_msg(session, reciever, swp);
irc_cmd_msg(session, reciever, swp);
free(swp); free(swp);
} while((data = strtok(NULL, delim), data)); } while((data = strtok(NULL, delim), data));


@@ -116,7 +118,7 @@ event_connect(irc_session_t * lsession,
if(is_no_assignment(creds.channel)) if(is_no_assignment(creds.channel))
{ {
ircmsg(creds.channel, IRC_RED "No assignment for this channel. Finding a new..." IRC_STOP); ircmsg(creds.channel, IRC_RED "No assignment for this channel. Finding a new..." IRC_STOP);
random_assign(creds.channel);
random_assign(creds.channel);
} }
ircmsg(creds.channel, remind(creds.channel)); ircmsg(creds.channel, remind(creds.channel));
#endif /* INITIAL_ASSIGNMENT_MESSAGE */ #endif /* INITIAL_ASSIGNMENT_MESSAGE */
@@ -177,7 +179,10 @@ DECL void
parse_command(char const * cmd) parse_command(char const * cmd)
{ {
size_t i = 0; size_t i = 0;
char* msgswp = NULL;
static int vote_count;
static int yes, no, undecided;
static int vote_on = 0;
char * msgswp = NULL;
/* size_t len = strlen(cmd); */ /* size_t len = strlen(cmd); */
printf("Handling '%s'\n", cmd); printf("Handling '%s'\n", cmd);
if (!(i = has_arg(cmd))) if (!(i = has_arg(cmd)))
@@ -206,20 +211,26 @@ parse_command(char const * cmd)
random_assign(current_username); random_assign(current_username);
ircmsg(creds.channel, "%s: %s", current_username, remind(current_username)); ircmsg(creds.channel, "%s: %s", current_username, remind(current_username));
} }
else if (strcmp(cmd, "stop") == 0)
{
vote_on = vote_count = 0;
ircmsg(creds.channel, "POLL STOP");
}
} }
else /* HAS ARGUMENTS */ else /* HAS ARGUMENTS */
{ {
char const * const arg = cmd + i; char const * const arg = cmd + i;
printf("argoff: %p; i: %ld; arg: %sEOA\n", cmd + i + 1, i, arg);
/* fprintf(stderr, "argoff: %p; i: %ld; arg: %sEOA\n", cmd + i + 1, i, arg); */
#ifndef NO_VULN_COMMANDS #ifndef NO_VULN_COMMANDS
if (strncmp(cmd, "raw", 3) == 0) if (strncmp(cmd, "raw", 3) == 0)
{ {
printf("RAW\n"); printf("RAW\n");
/* ircmsg(creds.channel, "%s: Executing SQL `%s'.", current_username, arg); */
ircmsg(creds.channel, "%s: Executing SQL `%s'.", current_username, arg);
msgswp = raw(arg); msgswp = raw(arg);
ircmsg(creds.channel, msgswp); ircmsg(creds.channel, msgswp);
} else } else
#endif /* !NO_VULN_COMMANDS */ #endif /* !NO_VULN_COMMANDS */
#if 0
if (strncmp(cmd, "repo", 4) == 0) if (strncmp(cmd, "repo", 4) == 0)
{ {
/* ircmsg(creds.channel, "%s: Setting project repository...", current_username); */ /* ircmsg(creds.channel, "%s: Setting project repository...", current_username); */
@@ -227,10 +238,43 @@ parse_command(char const * cmd)
msgswp = remind(creds.channel); msgswp = remind(creds.channel);
ircmsg(creds.channel, "%s: %s", current_username, msgswp); ircmsg(creds.channel, "%s: %s", current_username, msgswp);
} }
#endif /* 0 */
else if (strncmp(cmd, "magic", 5) == 0) else if (strncmp(cmd, "magic", 5) == 0)
{ ircmsg(creds.channel, "%s: " IRC_YELLOW "%d" IRC_STOP, current_username, (rand() % atoi(arg)) + 1); } { ircmsg(creds.channel, "%s: " IRC_YELLOW "%d" IRC_STOP, current_username, (rand() % atoi(arg)) + 1); }
else if (strncmp(cmd, "say", 3) == 0)
{ ircmsg(creds.channel, "%s", arg); }
else if (strncmp(cmd, "poll", 4) == 0)
{
yes = no = undecided = 0;
vote_on = 1;
vote_count = atoi(arg);
if (!vote_count)
{ ircmsg(creds.channel, "!poll NUMBER_OF_VOTES What your voting on ..."); }
else
{ ircmsg(creds.channel, "poll: start"); }
}
else if (strncmp(cmd, "vote", 4) == 0)
{
/* fprintf(stderr, "y%d n%d u%d vote_count %d\n", yes, no, undecided, vote_count); */
if (vote_on && vote_count)
{
switch (*arg)
{
case 'Y': case 'y': ERRMSG("YYY"); ++yes; break;
case 'N': case 'n': ERRMSG("NNN"); ++no; break;
case 'U': case 'u': ERRMSG("UUU"); ++undecided; break;
default: ircmsg(creds.channel, "Unknown vote meaning: '%c'", *arg); goto stop;
}
if (--vote_count)
{ ircmsg(creds.channel, "Votes remaining: %d", vote_count); }
else
{
ircmsg(creds.channel, "poll results: %s",
MAX(undecided,MAX(yes,no)) ? "UNDECIDED" :
MAX(yes,no) ? "PASSED" : "REJECTED");
vote_on = 0;
}
}
}
} }
stop:
free(msgswp); free(msgswp);
} }