2 #include "HandleInfoHandler.h"
3 #include "ClientSocket.h"
8 #define AUTHSERV_NICK "AuthServ"
10 struct HandleInfoQueueEntry {
11 struct ClientSocket *client;
15 struct HandleInfoQueueEntry *next;
18 static struct HandleInfoQueueEntry *first_entry = NULL, *last_entry = NULL;
20 static struct HandleInfoQueueEntry* addHandleInfoQueueEntry(struct ClientSocket *client) {
21 struct HandleInfoQueueEntry *entry = malloc(sizeof(*entry));
24 perror("malloc() failed");
28 entry->client = client;
30 last_entry->next = entry;
38 static struct HandleInfoQueueEntry* getNextHandleInfoQueueEntry(struct ClientSocket *client, int freeEntry) {
39 if(!first_entry) return NULL;
40 struct HandleInfoQueueEntry *entry;
41 for(entry = first_entry; entry; entry = entry->next) {
42 if(entry->client == client)
45 if(entry == NULL) return NULL;
47 if(entry == first_entry)
48 first_entry = entry->next;
49 if(entry == last_entry) {
50 struct HandleInfoQueueEntry *last;
51 for(last = first_entry; last; last = last->next)
52 if(last->next == NULL) break;
59 void lookup_authname(char *auth, authlookup_callback_t callback, void *data) {
60 struct ClientSocket *bot;
61 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
62 if(bot->flags & SOCKET_FLAG_PREFERRED)
65 if(bot == NULL) return;
66 struct HandleInfoQueueEntry* entry = addHandleInfoQueueEntry(bot);
67 entry->callback = callback;
69 putsock(bot, "PRIVMSG " AUTHSERV_NICK " :ACCOUNTINFO *%s", auth);
72 static void recv_notice(struct UserNode *user, struct UserNode *target, char *message) {
73 if(stricmp(user->nick, AUTHSERV_NICK)) return;
74 struct ClientSocket *bot;
75 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
76 if(bot->user == target) break;
80 int do_match = 0, exists = 0;
83 // Account * has not been registered.
84 // Account information for Skynet:
85 if(!match("Account * has not been registered.", message)) {
87 tmp = strstr(message, "\002");
89 tmp = strstr(auth, "\002");
92 if(!match("Account information for *", message)) {
95 tmp = strstr(message, "\002");
97 tmp = strstr(auth, "\002");
101 struct HandleInfoQueueEntry* entry = getNextHandleInfoQueueEntry(bot, 1);
102 authlookup_callback_t *callback = entry->callback;
103 callback(auth, exists, entry->data);
108 void init_handleinfohandler() {
109 bind_privnotice(recv_notice);
112 void free_handleinfohandler() {
113 struct HandleInfoQueueEntry *entry, *next;
114 for(entry = first_entry; entry; entry = next) {