+
+static AUTHLOOKUP_CALLBACK(event_user_registered_auth_lookup);
+
+struct event_user_registered_cache {
+ struct UserNode *new_user;
+ char *oldauth;
+};
+
+static int event_user_registered(struct UserNode *old_user, struct UserNode *new_user) {
+ //check if there is a fakehost on both sides...
+ if(!isFakeHost(old_user->host) || !isFakeHost(new_user->host)) return 0;
+ //extract user names
+ char oldauth[AUTHLEN], newauth[AUTHLEN];
+ char *p;
+ if((p = strstr(old_user->host, "."))) {
+ *p = '\0';
+ strcpy(oldauth, old_user->host);
+ *p = '.';
+ }
+ if((p = strstr(new_user->host, "."))) {
+ *p = '\0';
+ strcpy(newauth, new_user->host);
+ *p = '.';
+ }
+ //check if we know this user; then check the new auth
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(oldauth));
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) != NULL) {
+ struct event_user_registered_cache *cache = malloc(sizeof(*cache));
+ if (!cache) {
+ perror("malloc() failed");
+ return 1;
+ }
+ cache->new_user = new_user;
+ cache->oldauth = strdup(oldauth);
+ lookup_authname(newauth, event_user_registered_auth_lookup, cache);
+ }
+ return 1;
+}
+
+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;
+ }
+ free(cache->oldauth);
+}
+
+void init_DBHelper() {
+ bind_registered(event_user_registered);
+}
+