Add *.plist to .gitignore and change exit code (fix #29)

This commit is contained in:
Tiiffi
2019-10-15 15:11:04 +03:00
parent 4f791c5e54
commit 408ec3b1c1
2 changed files with 19 additions and 6 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@
*.project *.project
mcrcon mcrcon
todo todo
*.plist

View File

@ -100,7 +100,6 @@ int run_commands(int argc, char *argv[]);
rc_packet* packet_build(int id, int cmd, char *s1); rc_packet* packet_build(int id, int cmd, char *s1);
uint8_t *packet_build_malloc(size_t *size, int32_t id, int32_t cmd, char *string); uint8_t *packet_build_malloc(size_t *size, int32_t id, int32_t cmd, char *string);
void packet_print(rc_packet *packet); void packet_print(rc_packet *packet);
int rcon_auth(int sock, char *passwd); int rcon_auth(int sock, char *passwd);
int rcon_command(int sock, char *command); int rcon_command(int sock, char *command);
@ -213,21 +212,26 @@ int main(int argc, char *argv[])
// open socket // open socket
global_rsock = net_connect(host, port); global_rsock = net_connect(host, port);
int exit_code = EXIT_SUCCESS;
// auth & commands // auth & commands
if (rcon_auth(global_rsock, pass)) if (rcon_auth(global_rsock, pass))
{ {
if (terminal_mode) if (terminal_mode)
run_terminal_mode(global_rsock); run_terminal_mode(global_rsock);
else else
run_commands(argc, argv); exit_code = run_commands(argc, argv);
} }
else // auth failed else // auth failed
{
fprintf(stdout, "Authentication failed!\n"); fprintf(stdout, "Authentication failed!\n");
exit_code = EXIT_FAILURE;
}
net_close(global_rsock); net_close(global_rsock);
global_rsock = -1; global_rsock = -1;
return EXIT_SUCCESS; return exit_code;
} }
void usage(void) void usage(void)
@ -706,13 +710,21 @@ int rcon_command(int sock, char *command)
int run_commands(int argc, char *argv[]) int run_commands(int argc, char *argv[])
{ {
int i, ok = 1, ret = 0; int i, ok = 1, ret = EXIT_SUCCESS;
for (i = optind; i < argc && ok; i++) for (i = optind; i < argc && ok; i++)
{ {
ok = rcon_command(global_rsock, argv[i]); ok = rcon_command(global_rsock, argv[i]);
ret += ok; if (!ok) {
ret = EXIT_FAILURE;
break;
} }
++ret;
}
// Check if amount of successfully sent commands
// matches amount of requested commands
if (ret == optind) ret = EXIT_SUCCESS;
return ret; return ret;
} }