-/* DBHelper.c - NeonServ v5.3
- * Copyright (C) 2011 Philipp Kreil (pk910)
+/* DBHelper.c - NeonServ v5.5
+ * Copyright (C) 2011-2012 Philipp Kreil (pk910)
*
* 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
#include "tools.h"
#include "IRCEvents.h"
#include "HandleInfoHandler.h"
+#include "ClientSocket.h"
+#include "bots.h"
+#include "ConfigParser.h"
void _loadUserSettings(struct UserNode *user) {
+ SYNCHRONIZE(cache_sync);
MYSQL_RES *res;
MYSQL_ROW row;
printf_mysql_query("SELECT `user_lang`, `user_reply_privmsg`, `user_god`, `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
} else
user->language = get_default_language();
user->flags |= USERFLAG_LOADED_SETTINGS;
+ DESYNCHRONIZE(cache_sync);
}
int isGodMode(struct UserNode *user) {
}
void _loadChannelSettings(struct ChanNode *chan) {
+ SYNCHRONIZE(cache_sync);
MYSQL_RES *res;
MYSQL_ROW row;
printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(chan->name));
chan->channel_id = atoi(row[0]);
}
chan->flags |= CHANFLAG_REQUESTED_CHANINFO;
+ DESYNCHRONIZE(cache_sync);
}
//TODO: fix performance: we should cache the user access
//simply rename the account
printf_mysql_query("UPDATE `users` SET `user_user` = '%s' WHERE `user_id` = '%d'", escape_string(newauth), userid);
}
+ char *alertchan = get_string_field("General.CheckAuths.alertchan");
+ if(alertchan) {
+ struct ChanNode *alertchan_chan = getChanByName(alertchan);
+ struct ClientSocket *alertclient;
+ if(alertchan_chan && (alertclient = getChannelBot(alertchan_chan, 0)) != NULL) {
+ putsock(alertclient, "PRIVMSG %s :Renamed User %s to %s", alertchan_chan->name, oldauth, newauth);
+ }
+ }
return 1;
}
return 0;
static AUTHLOOKUP_CALLBACK(event_user_registered_auth_lookup);
struct event_user_registered_cache {
- struct UserNode *new_user;
+ struct UserNode *user;
char *oldauth;
};
-static int event_user_registered(struct UserNode *old_user, struct UserNode *new_user) {
+static void event_user_registered(struct UserNode *user, char *new_mask) {
//check if there is a fakehost on both sides...
- if(!isFakeHost(old_user->host) || !isFakeHost(new_user->host)) return 0;
+ //extract host from new_mask
+ char *new_host = strchr(new_mask, '@');
+ if(new_host)
+ new_host++;
+ else
+ return;
+ if(!isFakeHost(user->host) || !isFakeHost(new_host))
+ return;
//extract user names
char oldauth[AUTHLEN], newauth[AUTHLEN];
char *p;
- if((p = strstr(old_user->host, "."))) {
+ if((p = strstr(user->host, "."))) {
*p = '\0';
- strcpy(oldauth, old_user->host);
+ strcpy(oldauth, user->host);
*p = '.';
}
- if((p = strstr(new_user->host, "."))) {
+ if((p = strstr(new_host, "."))) {
*p = '\0';
- strcpy(newauth, new_user->host);
+ strcpy(newauth, new_host);
*p = '.';
}
if(!stricmp(oldauth, newauth))
- return 0;
+ return;
//check if we know this user; then check the new auth
MYSQL_RES *res;
MYSQL_ROW row;
struct event_user_registered_cache *cache = malloc(sizeof(*cache));
if (!cache) {
perror("malloc() failed");
- return 1;
+ return;
}
- cache->new_user = new_user;
+ cache->user = user;
cache->oldauth = strdup(oldauth);
- lookup_authname(newauth, event_user_registered_auth_lookup, cache);
+ lookup_authname(newauth, 0, event_user_registered_auth_lookup, cache);
}
- return 1;
+ return;
}
static AUTHLOOKUP_CALLBACK(event_user_registered_auth_lookup) {
struct event_user_registered_cache *cache = data;
if(exists) {
renameAccount(cache->oldauth, auth);
- strcpy(cache->new_user->auth, auth);
- cache->new_user->flags |= USERFLAG_ISAUTHED;
+ strcpy(cache->user->auth, auth);
+ cache->user->flags |= USERFLAG_ISAUTHED;
}
free(cache->oldauth);
+ free(cache);
+}
+
+void deleteUser(int userid) {
+ //simply delete the user
+ MYSQL_RES *res, *res2;
+ MYSQL_ROW row, row2;
+ printf_mysql_query("SELECT a.`chanuser_access`, a.`chanuser_cid`, (SELECT COUNT(*) FROM `chanusers` AS b WHERE b.`chanuser_cid` = a.`chanuser_cid` AND b.`chanuser_access` = 500) FROM `chanusers` AS a WHERE a.`chanuser_uid` = '%d'", userid);
+ res = mysql_use();
+ while((row = mysql_fetch_row(res))) {
+ if(!strcmp(row[0], "500") && !strcmp(row[2], "1")) {
+ //unregister channel
+ printf_mysql_query("SELECT `botid`, `channel_name` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `chanid` = '%s' AND `suspended` = '0'", row[1]);
+ res2 = mysql_use();
+ while((row2 = mysql_fetch_row(res2))) {
+ struct ClientSocket *bot;
+ int clientid = atoi(row2[0]);
+ for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+ if(bot->clientid == clientid)
+ putsock(bot, "PART %s :Channel unregistered.", row2[1]);
+ }
+ }
+ printf_mysql_query("DELETE FROM `bot_channels` WHERE `chanid` = '%s'", row[1]);
+ }
+ }
+ printf_mysql_query("DELETE FROM `chanusers` WHERE `chanuser_uid` = '%d'", userid);
+ printf_mysql_query("UPDATE `bans` SET `ban_owner` = 0 WHERE `ban_owner` = '%d'", userid);
+ printf_mysql_query("UPDATE `donotregister` SET `dnr_user` = 0 WHERE `dnr_user` = '%d'", userid);
+ printf_mysql_query("UPDATE `bans` SET `ban_owner` = 0 WHERE `ban_owner` = '%d'", userid);
+ printf_mysql_query("UPDATE `godlog` SET `godlog_uid` = 0 WHERE `godlog_uid` = '%d'", userid);
+ printf_mysql_query("DELETE FROM `noinvite` WHERE `uid` = '%d'", userid);
+ printf_mysql_query("UPDATE `owner_history` SET `owner_history_to_uid` = 0 WHERE `owner_history_to_uid` = '%d'", userid);
+ printf_mysql_query("UPDATE `owner_history` SET `owner_history_from_uid` = 0 WHERE `owner_history_from_uid` = '%d'", userid);
+ printf_mysql_query("UPDATE `channels` SET `channel_registrator` = 0 WHERE `channel_registrator` = '%d'", userid);
+ printf_mysql_query("DELETE FROM `users` WHERE `user_id` = '%d'", userid);
+ struct UserNode *user;
+ for(user = getAllUsers(NULL); user; user = getAllUsers(user)) {
+ if(user->flags & USERFLAG_HAS_USERID)
+ user->flags &= ~USERFLAG_HAS_USERID;
+ }
}
void init_DBHelper() {
- bind_registered(event_user_registered);
+ bind_registered(event_user_registered, 0);
}