aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/fics_addplayer.c
blob: 14172510997e5011c8fad379217697eed70a61d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* fics_addplayer.c
 *
 */

/*
    fics - An internet chess server.
    Copyright (C) 1994  Richard V. Nash

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
*/

/* Revision history:
   name		email		yy/mm/dd	Change
   Richard Nash	              	94/03/07	Created
   Markus Uhlin			23/12/09	Revamped the file
   Markus Uhlin			23/12/23	Fixed crypt()
*/

#include "stdinclude.h"

#include "command.h"
#include "common.h"
#include "playerdb.h"
#include "utils.h"

#define PASSLEN 4

PRIVATE char *funame = NULL;
PRIVATE char *fname = NULL;
PRIVATE char *email = NULL;

PRIVATE int local = 1;

PRIVATE void
usage(char *progname)
{
	fprintf(stderr, "Usage: %s [-l] [-n] UserName FullName EmailAddress\n",
	    progname);
	exit(1);
}

PUBLIC int
main(int argc, char *argv[])
{
	char	 password[PASSLEN + 1];
	char	 salt[6];
	char	 text[2048];
	int	 i;
	int	 p;

	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			switch (argv[i][1]) {
			case 'l':
				local = 1;
				break;
			case 'n':
				local = 0;
				break;
			default:
				usage(argv[0]);
				break;
			}
		} else {
			if (!funame)
				funame = argv[i];
			else if (!fname)
				fname = argv[i];
			else if (!email)
				email = argv[i];
			else
				usage(argv[0]);
		}
	}
	if (!funame || !fname || !email)
		usage(argv[0]);

	/* Add the player here */
	if (strlen(funame) >= MAX_LOGIN_NAME) {
		fprintf(stderr, "Player name is too long\n");
		exit(0);
	}
	if (strlen(funame) < 3) {
		fprintf(stderr, "Player name is too short\n");
		exit(0);
	}
	if (!alphastring(funame)) {
		fprintf(stderr, "Illegal characters in player name. "
		    "Only A-Za-z allowed.\n");
		exit(0);
	}

	player_init(0);
	srand(time(0));
	p = player_new();
	if (!player_read(p, funame)) {
		fprintf(stderr, "%s already exists.\n", funame);
		exit(0);
	}
	parray[p].name = xstrdup(funame);
	parray[p].login = xstrdup(funame);
	stolower(parray[p].login);
	parray[p].fullName = xstrdup(fname);
	parray[p].emailAddress = xstrdup(email);
	for (i = 0; i < PASSLEN; i++) {
		password[i] = 'a' + rand() % 26;
	}
	password[i] = '\0';
	salt[0] = '$';
	salt[1] = '1';
	salt[2] = '$';
	salt[3] = ('a' + rand() % 26);
	salt[4] = ('a' + rand() % 26);
	salt[5] = '\0';
	parray[p].passwd = xstrdup(crypt(password, salt));
	parray[p].registered = 1;
//	parray[p].network_player = !local;
	parray[p].rated = 1;
	player_save(p);

	printf("Added player account: >%s< >%s< >%s< >%s<\n",
	       funame, fname, email, password);

	snprintf(text, sizeof text,
	    "\nYour player account has been created.\n\n"
	    "Login Name: %s\n"
	    "Full Name: %s\n"
	    "Email Address: %s\n"
	    "Initial Password: %s\n\n"

	    "If any of this information is incorrect, please\n"
	    "contact the administrator to get it corrected.\n\n"

	    "You may change your password with the password\n"
	    "command on the server.\n\n"

	    "Please be advised that if this is an unauthorized\n"
	    "duplicate account for you, by using it you take\n"
	    "the risk of being banned from accessing this chess\n"
	    "server.\n\n"

	    "To connect to the server and use this account:\n\n"
	    "\ttelnet %s 5000\n\n"
	    "and enter your handle name and password.\n\n"

	    "Regards,\n\nThe FICS admins\n", funame, fname, email, password,
	    fics_hostname);

	mail_string_to_address(email, "FICS Account Created", text);
	exit(0);
}