summaryrefslogtreecommitdiff
path: root/src/tool/adduser.cpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2012-08-30 16:16:25 -0700
committerBen Longbons <b.r.longbons@gmail.com>2012-08-30 17:03:31 -0700
commit41974ae5265fbc23a06f276f9e008d5dad020e0b (patch)
tree9d595215172e87e2d83b74f7bf3430b3040e780e /src/tool/adduser.cpp
parent21742909143df9159b2401c3e2a39cc0b2bad620 (diff)
downloadtmwa-41974ae5265fbc23a06f276f9e008d5dad020e0b.tar.gz
tmwa-41974ae5265fbc23a06f276f9e008d5dad020e0b.tar.bz2
tmwa-41974ae5265fbc23a06f276f9e008d5dad020e0b.tar.xz
tmwa-41974ae5265fbc23a06f276f9e008d5dad020e0b.zip
Rename files for C++ conversion. Does not compile.
After updating, you can remove these files, as shown in 'git status': Untracked files: (use "git add <file>..." to include in what will be committed) src/map/magic-interpreter-lexer.c src/map/magic-interpreter-parser.c src/map/magic-interpreter-parser.h
Diffstat (limited to 'src/tool/adduser.cpp')
-rw-r--r--src/tool/adduser.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/tool/adduser.cpp b/src/tool/adduser.cpp
new file mode 100644
index 0000000..1954b66
--- /dev/null
+++ b/src/tool/adduser.cpp
@@ -0,0 +1,115 @@
+/*
+ This program adds an user to account.txt
+ Don't usr it When login-sever is working.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *account_txt = "../save/account.txt";
+
+//-----------------------------------------------------
+// Function to suppress control characters in a string.
+//-----------------------------------------------------
+int remove_control_chars (unsigned char *str)
+{
+ int i;
+ int change = 0;
+
+ for (i = 0; str[i]; i++)
+ {
+ if (str[i] < 32)
+ {
+ str[i] = '_';
+ change = 1;
+ }
+ }
+
+ return change;
+}
+
+int main (int argc, char *argv[])
+{
+
+ char username[24];
+ char password[24];
+ char sex[2];
+
+ int next_id, id;
+ char line[1024];
+
+ // Check to see if account.txt exists.
+ printf ("Checking if '%s' file exists...\n", account_txt);
+ FILE *FPaccin = fopen (account_txt, "r");
+ if (FPaccin == NULL)
+ {
+ printf ("'%s' file not found!\n", account_txt);
+ printf ("Run the setup wizard please.\n");
+ exit (0);
+ }
+
+ next_id = 2000000;
+ while (fgets (line, sizeof (line) - 1, FPaccin))
+ {
+ if (line[0] == '/' && line[1] == '/')
+ {
+ continue;
+ }
+ if (sscanf (line, "%d\t%%newid%%\n", &id) == 1)
+ {
+ if (next_id < id)
+ {
+ next_id = id;
+ }
+ }
+ else
+ {
+ sscanf (line, "%i%[^ ]", &id);
+ if (next_id <= id)
+ {
+ next_id = id + 1;
+ }
+ }
+ }
+ fclose (FPaccin);
+ printf ("File exists.\n");
+
+ printf ("Don't create an account if the login-server is online!!!\n");
+ printf
+ ("If the login-server is online, press ctrl+C now to stop this software.\n");
+ printf ("\n");
+
+ strcpy (username, "");
+ while (strlen (username) < 4 || strlen (username) > 23)
+ {
+ printf ("Enter an username (4-23 characters): ");
+ scanf ("%s", &username);
+ username[23] = 0;
+ remove_control_chars (username);
+ }
+
+ strcpy (password, "");
+ while (strlen (password) < 4 || strlen (password) > 23)
+ {
+ printf ("Enter a password (4-23 characters): ");
+ scanf ("%s", &password);
+ password[23] = 0;
+ remove_control_chars (password);
+ }
+
+ strcpy (sex, "");
+ while (strcmp (sex, "F") != 0 && strcmp (sex, "M") != 0)
+ {
+ printf ("Enter a gender (M for male, F for female): ");
+ scanf ("%s", &sex);
+ }
+
+ FILE *FPaccout = fopen (account_txt, "r+");
+ fseek (FPaccout, 0, SEEK_END);
+ fprintf (FPaccout, "%i %s %s - %s -\r\n", next_id, username,
+ password, sex);
+ fclose (FPaccout);
+
+ printf ("Account added.\n");
+}