1 /* cmd_neonserv_rename.c - NeonServ v5.4
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_neonserv.h"
25 struct neonserv_cmd_rename_cache {
26 struct ClientSocket *client, *textclient;
27 struct UserNode *user;
29 char *oldauth, *newauth;
32 static AUTHLOOKUP_CALLBACK(neonserv_cmd_rename_auth_lookup);
33 static void neonserv_cmd_rename_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct Event *event, char *oldauth, char *newauth);
35 CMD_BIND(neonserv_cmd_rename) {
36 struct neonserv_cmd_rename_cache *cache = malloc(sizeof(*cache));
38 perror("malloc() failed");
41 cache->client = client;
42 cache->textclient = getTextBot();
45 cache->oldauth = strdup(argv[0]);
46 cache->newauth = strdup(argv[1]);
47 lookup_authname(argv[1], module_id, neonserv_cmd_rename_auth_lookup, cache);
50 static AUTHLOOKUP_CALLBACK(neonserv_cmd_rename_auth_lookup) {
51 struct neonserv_cmd_rename_cache *cache = data;
54 reply(cache->textclient, cache->user, "NS_AUTH_UNKNOWN", cache->newauth);
56 neonserv_cmd_rename_async1(cache->client, cache->textclient, cache->user, cache->event, cache->oldauth, auth);
62 static void neonserv_cmd_rename_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct Event *event, char *oldauth, char *newauth) {
63 if(renameAccount(oldauth, newauth)) {
64 reply(textclient, user, "NS_RENAME_DONE", oldauth, newauth);
66 reply(textclient, user, "NS_RENAME_FAIL", oldauth);