Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix share.mod feature negotiation between bots #1629

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions src/mod/share.mod/uf_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,29 +234,36 @@ static void uff_deltable(uff_table_t *ut)
*/
static void uf_features_parse(int idx, char *par)
{
char *buf, *s, *p;
char *buf, *feature, *brkt;
uff_list_t *ul;
int len = 0;

uff_sbuf[0] = 0; /* Reset static buffer */
p = s = buf = nmalloc(strlen(par) + 1); /* Allocate temp buffer */
buf = nmalloc(strlen(par) + 1); /* Allocate temp buffer */
strcpy(buf, par);

/* Clear all currently set features. */
dcc[idx].u.bot->uff_flags = 0;

/* Parse string */
while ((s = strchr(s, ' ')) != NULL) {
*s = '\0';

for (feature = strtok_r(buf, " ", &brkt);
feature;
feature = strtok_r(NULL, " ", &brkt)) {
/* Is the feature available and active? */
ul = uff_findentry_byname(p);
ul = uff_findentry_byname(feature);
if (ul && (ul->entry->ask_func == NULL || ul->entry->ask_func(idx))) {
dcc[idx].u.bot->uff_flags |= ul->entry->flag; /* Set flag */
if (uff_sbuf[0])
strncat(uff_sbuf, " ", sizeof uff_sbuf - strlen(uff_sbuf) - 1);
strncat(uff_sbuf, ul->entry->feature, sizeof uff_sbuf - strlen(uff_sbuf) - 1); /* Add feature to list */
/* Add feature to list */
if (dcc[idx].u.bot->numver >= 1100001) {
if (len)
uff_sbuf[len++] = ' ';
len += strlcpy(uff_sbuf + len, ul->entry->feature, (sizeof uff_sbuf) - len);
} else {
/* quirk workaround: add trailing whitespace */
len += strlcpy(uff_sbuf + len, ul->entry->feature, (sizeof uff_sbuf) - len);
uff_sbuf[len++] = ' ';
}
}
p = ++s;
}
nfree(buf);

Expand All @@ -270,35 +277,44 @@ static void uf_features_parse(int idx, char *par)
static char *uf_features_dump(int idx)
{
uff_list_t *ul;
int len = 0;

uff_sbuf[0] = 0;
for (ul = uff_list.start; ul; ul = ul->next)
for (ul = uff_list.start; ul && (((sizeof uff_sbuf) - len) > 2);
ul = ul->next)
if (ul->entry->ask_func == NULL || ul->entry->ask_func(idx)) {
if (uff_sbuf[0])
strncat(uff_sbuf, " ", sizeof uff_sbuf - strlen(uff_sbuf) - 1);
strncat(uff_sbuf, ul->entry->feature, sizeof uff_sbuf - strlen(uff_sbuf) - 1); /* Add feature to list */
/* Add feature to list */
if (dcc[idx].u.bot->numver >= 1100001) {
if (len)
uff_sbuf[len++] = ' ';
len += strlcpy(uff_sbuf + len, ul->entry->feature, (sizeof uff_sbuf) - len);
} else {
/* quirk workaround: add trailing whitespace */
len += strlcpy(uff_sbuf + len, ul->entry->feature, (sizeof uff_sbuf) - len);
uff_sbuf[len++] = ' ';
}
}
return uff_sbuf;
}

static int uf_features_check(int idx, char *par)
{
char *buf, *s, *p;
char *buf, *feature, *brkt;
uff_list_t *ul;

uff_sbuf[0] = 0; /* Reset static buffer */
p = s = buf = nmalloc(strlen(par) + 1); /* Allocate temp buffer */
buf = nmalloc(strlen(par) + 1); /* Allocate temp buffer */
strcpy(buf, par);

/* Clear all currently set features. */
dcc[idx].u.bot->uff_flags = 0;

/* Parse string */
while ((s = strchr(s, ' ')) != NULL) {
*s = '\0';

for (feature = strtok_r(buf, " ", &brkt);
feature;
feature = strtok_r(NULL, " ", &brkt)) {
/* Is the feature available and active? */
ul = uff_findentry_byname(p);
ul = uff_findentry_byname(feature);
if (ul && (ul->entry->ask_func == NULL || ul->entry->ask_func(idx)))
dcc[idx].u.bot->uff_flags |= ul->entry->flag; /* Set flag */
else {
Expand All @@ -312,11 +328,9 @@ static int uf_features_check(int idx, char *par)
putlog(LOG_BOTS, "*", "Bot %s tried unsupported feature!", dcc[idx].nick);
dprintf(idx, "s e Attempt to use an unsupported feature\n");
zapfbot(idx);

nfree(buf);
return 0;
}
p = ++s;
}
nfree(buf);
return 1;
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
*/

#define EGG_STRINGVER "1.10.0"
#define EGG_NUMVER 1100000
#define EGG_PATCH "alpha"
#define EGG_NUMVER 1100001
#define EGG_PATCH "sharefeature"