added 4wins game
[NeonServV5.git] / src / modules / NeonFun.mod / bot_NeonFun.c
index f203f9114eb99e99f4f949a50a967d467a2750af..ebb0cc58dc4ac17d7d2cdffcb060d41b468a874f 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"
@@ -123,14 +124,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 +236,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