added OPER support (let the bots try to op themselves)
[NeonServV5.git] / src / modules / NeonFun.mod / bot_NeonFun.c
index f203f9114eb99e99f4f949a50a967d467a2750af..e5706ae8cc875f2d059f01a23a2e73817270fce9 100644 (file)
@@ -38,6 +38,7 @@
 #include "../../EventLogger.h"
 #include "../../bots.h"
 #include "game_uno.h"
+#include "game_4wins.h"
 
 #define BOTID NEONFUN_BOTID
 #define BOTALIAS "NeonFun"
@@ -46,9 +47,12 @@ static void neonfun_bot_ready(struct ClientSocket *client) {
     MYSQL_RES *res;
     MYSQL_ROW row;
     
-    printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
+    printf_mysql_query("SELECT `automodes`, `oper_user`, `oper_pass` FROM `bots` WHERE `id` = '%d'", client->clientid);
     res = mysql_use();
     if ((row = mysql_fetch_row(res)) != NULL) {
+        if(row[1] && row[2]) {
+            putsock(client, "OPER %s %s", row[1], row[2]);
+        }
         putsock(client, "MODE %s +%s", client->user->nick, row[0]);
     }
     
@@ -123,14 +127,17 @@ static void start_bots(int type) {
 
 static void neonfun_parted(struct ChanUser *chanuser, char *reason) {
     uno_event_part(chanuser);
+    fourwins_event_part(chanuser);
 }
 
 static void neonfun_quitted(struct UserNode *user, char *reason) {
     uno_event_quit(user);
+    fourwins_event_quit(user);
 }
 
 static int neonfun_freechan(struct ChanNode *chan) {
     uno_event_freechan(chan);
+    fourwins_event_freechan(chan);
     return 0;
 }
 
@@ -232,5 +239,42 @@ void uno_reply(struct uno_game *game, struct UserNode *user, const char *text, .
     write_socket(client, sendBuf, pos+1);
 }
 
+void fourwins_reply(struct fourwins_game *game, const char *text, ...) {
+    struct ClientSocket *client = game->textbot;
+    struct fourwins_guest *guest;
+    int guest_count = 0;
+    for(guest = game->guests; guest; guest = guest->next) {
+        guest_count++;
+    }
+    struct ChanUser *chanusers[guest_count + 2];
+    chanusers[0] = game->player[0];
+    chanusers[1] = game->player[1];
+    guest_count = 0;
+    for(guest = game->guests; guest; guest = guest->next) {
+        chanusers[2 + (guest_count++)] = guest->chanuser;
+    }
+    int i;
+    guest_count += 2;
+    for(i = 0; i < guest_count; i++) {
+        const char *reply_format = get_language_string(chanusers[i]->user, text);
+        if(reply_format == NULL)
+            reply_format = text;
+        char formatBuf[MAXLEN];
+        sprintf(formatBuf, "NOTICE %s :[4WINS] %s", chanusers[i]->user->nick, reply_format);
+        va_list arg_list;
+        char sendBuf[MAXLEN];
+        int pos;
+        if (!(client->flags & SOCKET_FLAG_CONNECTED)) return;
+        sendBuf[0] = '\0';
+        va_start(arg_list, text);
+        pos = vsnprintf(sendBuf, MAXLEN - 2, formatBuf, arg_list);
+        va_end(arg_list);
+        if (pos < 0 || pos > (MAXLEN - 2)) pos = MAXLEN - 2;
+        sendBuf[pos] = '\n';
+        sendBuf[pos+1] = '\0';
+        write_socket(client, sendBuf, pos+1);
+    }
+}
+
 #undef BOTID
 #undef BOTALIAS