root/src/tool/adduser.c @ 6

Revision 1, 2.5 kB (checked in by jinshiro, 17 years ago)
Line 
1// (c) eAthena Dev Team - Licensed under GNU GPL
2// For more information, see LICENCE in the main folder
3
4/*
5        This program adds an user to account.txt
6        Don't usr it When login-sever is working.
7*/
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include <ctype.h>
13
14char *account_txt = "../save/account.txt";
15
16//-----------------------------------------------------
17// Function to suppress control characters in a string.
18//-----------------------------------------------------
19int remove_control_chars(char* str)
20{
21        int i;
22        int change = 0;
23
24        for(i = 0; str[i]; i++) {
25                if (iscntrl((unsigned char)(str[i]))) {
26                        str[i] = '_';
27                        change = 1;
28                }
29        }
30
31        return change;
32}
33
34int main(int argc, char *argv[])
35{
36        char username[24];
37        char password[24];
38        char sex[2];
39
40        int next_id, id;
41        char line[1024];
42        FILE *FPaccin,*FPaccout;
43
44        // Check to see if account.txt exists.
45        printf("Checking if '%s' file exists...\n", account_txt);
46        FPaccin = fopen(account_txt, "r");
47        if (FPaccin == NULL) {
48                printf("'%s' file not found!\n", account_txt);
49                printf("Run the setup wizard please.\n");
50                exit(EXIT_SUCCESS);
51        }
52
53        next_id = 2000000;
54        while(fgets(line, sizeof(line), FPaccin))
55        {
56                if (line[0] == '/' && line[1] == '/') { continue; }
57                if (sscanf(line, "%d\t%%newid%%\n", &id) == 1) {
58                        if (next_id < id) {
59                                next_id = id;
60                        }
61                } else {
62                        sscanf(line,"%i%[^      ]", &id);
63                        if (next_id <= id) {
64                                next_id = id +1;
65                        }
66                }
67        }
68        fclose(FPaccin);
69        printf("File exists.\n");
70
71        printf("Don't create an account if the login-server is online!!!\n");
72        printf("If the login-server is online, press ctrl+C now to stop this software.\n");
73        printf("\n");
74
75        strcpy(username, "");
76        while (strlen(username) < 4 || strlen(username) > 23) {
77                printf("Enter an username (4-23 characters): ");
78                scanf("%s", &username);
79                username[23] = 0;
80                remove_control_chars(username);
81        }
82
83        strcpy(password, "");
84        while (strlen(password) < 4 || strlen(password) > 23) {
85                printf("Enter a password (4-23 characters): ");
86                scanf("%s", &password);
87                password[23] = 0;
88                remove_control_chars(password);
89        }
90
91        strcpy(sex, "");
92        while (strcmp(sex, "F") != 0 && strcmp(sex, "M") != 0) {
93                printf("Enter a gender (M for male, F for female): ");
94                scanf("%s", &sex);
95        }
96
97        FPaccout = fopen(account_txt, "r+");
98        fseek(FPaccout, 0, SEEK_END);
99        fprintf(FPaccout, "%i   %s      %s      -       %s      -\r\n", next_id, username, password, sex);
100        fclose(FPaccout);
101
102        printf("Account added.\n");
103}
Note: See TracBrowser for help on using the browser.