+static void neonhelp_event_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
+ char logline[MAXLEN];
+ sprintf(logline, "<%s> %s", user->nick, message);
+ struct ClientSocket *client;
+ for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
+ if(client->botid == BOTID) {
+ struct NeonHelpNode *helpnode;
+ if(client->flags & SOCKET_HAVE_HELPNODE) {
+ for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
+ if(helpnode->logchan == chan && helpnode->status == 1) {
+ if(!helpnode->log) {
+ helpnode->log = calloc(LOGBUFFERLINES, sizeof(char*));
+ if(!helpnode->log) return;
+ }
+ int i;
+ for(i = 0; i < LOGBUFFERLINES; i++) {
+ if(!helpnode->log[i]) {
+ helpnode->log[i] = strdup(logline);
+ break;
+ }
+ }
+ if(i == LOGBUFFERLINES) {
+ //write buffer to database
+ char logbuff[MAXLEN * LOGBUFFERLINES];
+ int len = 0;
+ for(i = 0; i < LOGBUFFERLINES; i++) {
+ len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
+ free(helpnode->log[i]);
+ helpnode->log[i] = NULL;
+ }
+ printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+