2 #include "HandleInfoHandler.h"
3 #include "ClientSocket.h"
8 #define AUTHSERV_NICK "AuthServ"
10 struct HandleInfoQueueEntry {
15 static struct HandleInfoQueueEntry *first_entry = NULL, *last_entry = NULL;
17 static struct HandleInfoQueueEntry* addHandleInfoQueueEntry(struct ClientSocket *client) {
18 struct HandleInfoQueueEntry *entry = malloc(sizeof(*entry));
21 perror("malloc() failed");
25 entry->client = client;
27 last_entry->next = entry;
35 static struct HandleInfoQueueEntry* getNextHandleInfoQueueEntry(struct ClientSocket *client, int freeEntry) {
36 if(!first_entry) return NULL;
37 struct HandleInfoQueueEntry *entry;
38 for(entry = first_entry; entry; entry = entry->next) {
39 if(entry->client == client)
42 if(entry == NULL) return NULL;
44 if(entry == first_entry)
45 first_entry = entry->next;
46 if(entry == last_entry) {
47 struct HandleInfoQueueEntry *last;
48 for(last = first_entry; last; last = last->next)
49 if(last->next == NULL) break;
56 void lookup_authname(char *auth, authlookup_callback_t callback, void *data) {
57 struct ClientSocket *bot;
58 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
59 if(bot->flags & SOCKET_FLAG_PREFERRED)
62 if(bot == NULL) return;
63 struct HandleInfoQueueEntry* entry = addHandleInfoQueueEntry(bot);
64 entry->callback = callback;
66 putsock(bot, "PRIVMSG " AUTHSERV_NICK " :HANDLEINFO *%s", auth);
69 static void recv_notice(struct UserNode *user, struct UserNode *target, char *message) {
70 if(stricmp(user->nick, AUTHSERV_NICK)) return;
71 struct ClientSocket *bot;
72 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
73 if(bot->user == target) break;
77 int match = 0, exists = 0;
80 // Account * has not been registered.
81 // Account information for Skynet:
82 if(!match("Account * has not been registered.", message)) {
84 tmp = strstr(message, "\002");
86 tmp = strstr(auth, "\002");
89 if(!match("Account information for *", message)) {
92 tmp = strstr(message, "\002");
94 tmp = strstr(auth, "\002");
98 struct HandleInfoQueueEntry* entry = getNextHandleInfoQueueEntry(client, 1);
99 authlookup_callback_t *callback = entry->callback;
100 callback(auth, exists, entry->data);
105 void init_handleinfohandler() {
106 bind_privnotice(recv_notice);
109 void free_handleinfohandler() {
110 struct HandleInfoQueueEntry *entry, *next;
111 for(entry = first_entry; entry; entry = next) {