1 /* HandleInfoHandler.c - NeonServ v5.0
2 * Copyright (C) 2011 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 "HandleInfoHandler.h"
19 #include "ClientSocket.h"
21 #include "IRCEvents.h"
24 #define AUTHSERV_NICK "AuthServ"
26 struct HandleInfoQueueEntry {
27 struct ClientSocket *client;
31 struct HandleInfoQueueEntry *next;
34 static struct HandleInfoQueueEntry *first_entry = NULL, *last_entry = NULL;
36 static struct HandleInfoQueueEntry* addHandleInfoQueueEntry(struct ClientSocket *client) {
37 struct HandleInfoQueueEntry *entry = malloc(sizeof(*entry));
40 perror("malloc() failed");
44 entry->client = client;
46 last_entry->next = entry;
54 static struct HandleInfoQueueEntry* getNextHandleInfoQueueEntry(struct ClientSocket *client, int freeEntry) {
55 if(!first_entry) return NULL;
56 struct HandleInfoQueueEntry *entry;
57 for(entry = first_entry; entry; entry = entry->next) {
58 if(entry->client == client)
61 if(entry == NULL) return NULL;
63 if(entry == first_entry)
64 first_entry = entry->next;
65 if(entry == last_entry) {
66 struct HandleInfoQueueEntry *last;
67 for(last = first_entry; last; last = last->next)
68 if(last->next == NULL) break;
75 void lookup_authname(char *auth, authlookup_callback_t callback, void *data) {
76 struct ClientSocket *bot;
77 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
78 if(bot->flags & SOCKET_FLAG_PREFERRED)
81 if(bot == NULL) return;
82 struct HandleInfoQueueEntry* entry = addHandleInfoQueueEntry(bot);
83 entry->callback = callback;
85 putsock(bot, "PRIVMSG " AUTHSERV_NICK " :ACCOUNTINFO *%s", auth);
88 static void recv_notice(struct UserNode *user, struct UserNode *target, char *message) {
89 if(stricmp(user->nick, AUTHSERV_NICK)) return;
90 struct ClientSocket *bot;
91 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
92 if(bot->user == target) break;
96 int do_match = 0, exists = 0;
99 // Account * has not been registered.
100 // Account information for Skynet:
101 if(!match("Account * has not been registered.", message)) {
103 tmp = strstr(message, "\002");
105 tmp = strstr(auth, "\002");
108 if(!match("Account information for *", message)) {
111 tmp = strstr(message, "\002");
113 tmp = strstr(auth, "\002");
117 struct HandleInfoQueueEntry* entry = getNextHandleInfoQueueEntry(bot, 1);
118 authlookup_callback_t *callback = entry->callback;
119 callback(auth, exists, entry->data);
124 void init_handleinfohandler() {
125 bind_privnotice(recv_notice);
128 void free_handleinfohandler() {
129 struct HandleInfoQueueEntry *entry, *next;
130 for(entry = first_entry; entry; entry = next) {