|
@@ -34,12 +34,15 @@
|
|
|
#include <arpa/inet.h>
|
|
#include <arpa/inet.h>
|
|
|
#include <poll.h>
|
|
#include <poll.h>
|
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
|
|
|
+#include <getopt.h>
|
|
|
|
|
|
|
|
#include <klist.h>
|
|
#include <klist.h>
|
|
|
#include <vcc/vcc.h>
|
|
#include <vcc/vcc.h>
|
|
|
#include <vcc/version.h>
|
|
#include <vcc/version.h>
|
|
|
#include <vcc/pretty.h>
|
|
#include <vcc/pretty.h>
|
|
|
#include <vcc/defserv.h>
|
|
#include <vcc/defserv.h>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/* we tried to use libreadline, but after using that, we feel strange
|
|
/* we tried to use libreadline, but after using that, we feel strange
|
|
|
* because... because of what? i don't know. */
|
|
* because... because of what? i don't know. */
|
|
|
|
|
|
|
@@ -63,7 +66,14 @@ int do_cmd_lself(char *);
|
|
|
|
|
|
|
|
int init_socket(const char *server_addr, int server_port);
|
|
int init_socket(const char *server_addr, int server_port);
|
|
|
|
|
|
|
|
-int fd;
|
|
|
|
|
|
|
+int fd;
|
|
|
|
|
+
|
|
|
|
|
+/* normally. it belongs to the foreground pgroup, all messages write to terminal. */
|
|
|
|
|
+#define MODE_NORMAL 1
|
|
|
|
|
+/* robot mode. we run in the background pgroup, and give all the messages to the plugin specified. */
|
|
|
|
|
+#define MODE_ROBOT 2
|
|
|
|
|
+int mode = MODE_NORMAL;
|
|
|
|
|
+struct plugin *plgctl;
|
|
|
|
|
|
|
|
char usrname[USRNAME_SIZE];
|
|
char usrname[USRNAME_SIZE];
|
|
|
struct klist_node banned_people = KLIST_NODE_INIT(&banned_people);
|
|
struct klist_node banned_people = KLIST_NODE_INIT(&banned_people);
|
|
@@ -72,17 +82,61 @@ extern int crypt_disabled;
|
|
|
extern int current_sid;
|
|
extern int current_sid;
|
|
|
|
|
|
|
|
static char const *help_msg = {
|
|
static char const *help_msg = {
|
|
|
- "Usage: vcc [-up] [server]\n"
|
|
|
|
|
|
|
+ "Usage: vcc [-auprh] [server]\n"
|
|
|
"Options: \n"
|
|
"Options: \n"
|
|
|
" -u --user Set the username on the server. "
|
|
" -u --user Set the username on the server. "
|
|
|
"If unspecified, you must input it interatively. \n"
|
|
"If unspecified, you must input it interatively. \n"
|
|
|
" -p --port Specified the port on the server. "
|
|
" -p --port Specified the port on the server. "
|
|
|
"Default port is 46. You must keep this as same "
|
|
"Default port is 46. You must keep this as same "
|
|
|
"as the port on the server. \n"
|
|
"as the port on the server. \n"
|
|
|
- " [server] Address of the server. "
|
|
|
|
|
|
|
+ " -r --robot Enter the robot mode. \n"
|
|
|
|
|
+ " -a --address Address of the server. "
|
|
|
"As default, server is " VCC_DEFSERV ". \n"
|
|
"As default, server is " VCC_DEFSERV ". \n"
|
|
|
|
|
+ " -h --help Show this help information. \n"
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+static struct option longopts[] = {
|
|
|
|
|
+ {
|
|
|
|
|
+ .name = "address",
|
|
|
|
|
+ .has_arg = 1,
|
|
|
|
|
+ .flag = NULL,
|
|
|
|
|
+ .val = 'a',
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ .name = "user",
|
|
|
|
|
+ .has_arg = 1,
|
|
|
|
|
+ .flag = NULL,
|
|
|
|
|
+ .val = 'u'
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ .name = "port",
|
|
|
|
|
+ .has_arg = 1,
|
|
|
|
|
+ .flag = NULL,
|
|
|
|
|
+ .val = 'p'
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ .name = "robot",
|
|
|
|
|
+ .has_arg = 0,
|
|
|
|
|
+ .flag = NULL,
|
|
|
|
|
+ .val = 'r'
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ .name = "help",
|
|
|
|
|
+ .has_arg = 0,
|
|
|
|
|
+ .flag = NULL,
|
|
|
|
|
+ .val = 'h'
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ NULL, 0, NULL, 0
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+
|
|
|
static int usage(void) {
|
|
static int usage(void) {
|
|
|
fputs(help_msg, stderr);
|
|
fputs(help_msg, stderr);
|
|
|
return 1;
|
|
return 1;
|
|
@@ -143,45 +197,40 @@ int vos_login(void) {
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int parse_args(char **argv, int *port, char **ip) {
|
|
|
|
|
- int i = 1;
|
|
|
|
|
- /*
|
|
|
|
|
- * unknown: 0
|
|
|
|
|
- * usrname: 1
|
|
|
|
|
- * port: 2
|
|
|
|
|
- */
|
|
|
|
|
- int type = 0;
|
|
|
|
|
- int got_usrname = 0;
|
|
|
|
|
- char *arg;
|
|
|
|
|
-
|
|
|
|
|
- while (argv[i]) {
|
|
|
|
|
- arg = argv[i];
|
|
|
|
|
- switch (type) {
|
|
|
|
|
- case 0:
|
|
|
|
|
- if (!strcmp(arg, "-u") || !strcmp(arg, "--user")) {
|
|
|
|
|
- type = 1;
|
|
|
|
|
- } else if (!strcmp(arg, "-p") || !strcmp(arg, "--port")) {
|
|
|
|
|
- type = 2;
|
|
|
|
|
- } else if (arg[0] != '-') {
|
|
|
|
|
- *ip = arg;
|
|
|
|
|
- } else {
|
|
|
|
|
- exit(usage());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+int parse_args(int argc, char **argv, int *port, char **ip) {
|
|
|
|
|
+ int i, c, got_usrname = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while ((c = getopt_long(argc, argv, "a:u:p:rh", longopts, &i)) != -1) {
|
|
|
|
|
+ switch (c) {
|
|
|
|
|
+ case 'a':
|
|
|
|
|
+ *ip = strdup(optarg);
|
|
|
|
|
+ printf("%s\n", *ip);
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
- case 1:
|
|
|
|
|
- strcpy(usrname, arg);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ case 'u':
|
|
|
|
|
+ strcpy(usrname, optarg);
|
|
|
got_usrname = 1;
|
|
got_usrname = 1;
|
|
|
- type = 0;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ printf("%s\n", usrname);
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
- case 2:
|
|
|
|
|
- *port = atoi(arg);
|
|
|
|
|
- type = 0;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ case 'p':
|
|
|
|
|
+ *port = atoi(optarg);
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
|
|
+ case 'r':
|
|
|
|
|
+ mode = MODE_ROBOT;
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case 'h':
|
|
|
default:
|
|
default:
|
|
|
- abort();
|
|
|
|
|
|
|
+ exit(usage());
|
|
|
}
|
|
}
|
|
|
- ++i;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return got_usrname;
|
|
return got_usrname;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -217,7 +266,7 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
printf(VCC_VERSION "\n");
|
|
printf(VCC_VERSION "\n");
|
|
|
|
|
|
|
|
- got_usrname = parse_args(argv, &port, &ip);
|
|
|
|
|
|
|
+ got_usrname = parse_args(argc, argv, &port, &ip);
|
|
|
init_socket(ip, port);
|
|
init_socket(ip, port);
|
|
|
printf("Connected to server. \n");
|
|
printf("Connected to server. \n");
|
|
|
|
|
|