remember to set faction.lastorders (NMR count was off).

checker just removes comments now.
This commit is contained in:
Enno Rehling 2018-10-04 04:47:20 +02:00
parent bbd57b6ae9
commit 6b983079b7
2 changed files with 48 additions and 3 deletions

View File

@ -2,10 +2,50 @@
#include <platform.h> #include <platform.h>
#endif #endif
#include "util/parser.h" #include "util/order_parser.h"
#include <stdio.h> #include <stdio.h>
typedef struct parser_state {
FILE * F;
} parser_state;
static void handle_order(void *userData, const char *str) {
parser_state * state = (parser_state*)userData;
fputs(str, state->F);
fputc('\n', state->F);
}
int parsefile(FILE *F) {
OP_Parser parser;
char buf[1024];
int done = 0, err = 0;
parser_state state = { NULL };
state.F = stdout;
parser = OP_ParserCreate();
OP_SetOrderHandler(parser, handle_order);
OP_SetUserData(parser, &state);
while (!done) {
size_t len = (int)fread(buf, 1, sizeof(buf), F);
if (ferror(F)) {
/* TODO: error message */
err = errno;
break;
}
done = feof(F);
if (OP_Parse(parser, buf, len, done) == OP_STATUS_ERROR) {
/* TODO: error message */
err = (int)OP_GetErrorCode(parser);
break;
}
}
OP_ParserFree(parser);
return err;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
FILE * F = stdin; FILE * F = stdin;
if (argc >= 1) { if (argc >= 1) {
@ -15,8 +55,10 @@ int main(int argc, char **argv) {
perror(filename); perror(filename);
return -1; return -1;
} }
}
parsefile(F);
if (F != stdin) {
fclose(F); fclose(F);
} }
return 0; return 0;
} }

View File

@ -245,7 +245,10 @@ static void handle_faction(void *userData, int no, const char *password) {
log_debug("orders for unknown faction %s", itoa36(no)); log_debug("orders for unknown faction %s", itoa36(no));
} }
else { else {
if (!checkpasswd(f, password)) { if (checkpasswd(f, password)) {
f->lastorders = turn;
}
else {
log_debug("invalid password for faction %s", itoa36(no)); log_debug("invalid password for faction %s", itoa36(no));
ADDMSG(&f->msgs, msg_message("wrongpasswd", "password", password)); ADDMSG(&f->msgs, msg_message("wrongpasswd", "password", password));
} }