]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - irc.c
Merge remote branch 'origin/master' into akari/irc
[xonotic/darkplaces.git] / irc.c
diff --git a/irc.c b/irc.c
index e6cc353d69c0822137dd82f7c9e6a658520df8e0..cd06928f66b5c8f8a86b29d09eb3713a83e55d21 100755 (executable)
--- a/irc.c
+++ b/irc.c
@@ -23,7 +23,7 @@ cvar_t irc_server = {CVAR_SAVE, "irc_server", "", "IRC server to connect to"};
 cvar_t irc_port = {CVAR_SAVE, "irc_port", "6667", "Port of the IRC server"};
 cvar_t irc_password = {CVAR_SAVE, "irc_password", "", "IRC server password"};
 cvar_t irc_nick = {CVAR_SAVE, "irc_nick", "", "Your nickname to use on IRC. Note: this cvar only defines your prefered nick, do NOT use this to change your nickname while connected, use irc_chnick instead"};
-cvar_t irc_connected = {CVAR_READONLY, "irc_connected", "0", "IRC connection state (0 = not connected, 1 = connecting, 2 = connected)"};
+cvar_t irc_connected = {CVAR_READONLY, "irc_connected", "0", "IRC connection state (0 = not connected, 1 = connecting, 2 = connected, 3 = disconnecting)"};
 cvar_t irc_msgprefix = {CVAR_SAVE, "irc_msgprefix", "^5IRC^0|^7", "What all IRC events will be prefixed with when printed to the console"};
 cvar_t irc_chatwindow = {CVAR_SAVE, "irc_chatwindow", "2", "0 = IRC messages will be printed in the console only, 1 = IRC messages will go to the chat window, 2 = Only hilights and private messages will appear in the chat window"};
 cvar_t irc_numeric_errorsonly = {CVAR_SAVE, "irc_numeric_errorsonly", "0", "If 1, any numeric event below 400 won't be printed'"};
@@ -78,6 +78,12 @@ static void IRC_Thread(void *p)
 {
     if(irc_run(irc_session_global))
     {
+        if(irc_connected.integer == 3) //irc_disconnect
+        {
+            Cvar_SetQuick(&irc_connected, "0");
+            return;
+        }
+        
         Con_Printf("%s^1Error: ^7%s\n",
             irc_msgprefix.string,
             irc_strerror(irc_errno(irc_session_global))
@@ -151,6 +157,7 @@ static void CL_Irc_Connect_f(void)
     cb.event_kick    = event_kick;
     cb.event_notice  = event_notice;
     cb.event_invite  = event_invite;
+    cb.event_ctcp_action = event_ctcp_action;
 
     Cvar_SetQuick(&irc_current_nick, irc_nick.string);
 
@@ -189,11 +196,9 @@ static void CL_Irc_Disconnect_f(void)
     }
     
     Con_Printf("^1Disconnected from the IRC server\n");
+    Cvar_SetQuick(&irc_connected, "3");
     irc_cmd_quit(irc_session_global, "Disconnected");
-    
     irc_destroy_session(irc_session_global);
-
-    Cvar_SetQuick(&irc_connected, "0");
 }
 
 static void CL_Irc_Say_Universal_f(void)
@@ -272,8 +277,22 @@ static void CL_Irc_Say_Universal_f(void)
             
             break;
         
-        case MSGMODE_ACTION: //to-do
+        case MSGMODE_ACTION:
             irc_cmd_me(irc_session_global, dest, message);
+            
+            if(ISCHANNEL(dest)) Con_Printf("%s%s^3%s^0| ^2* %s ^7%s\n",
+                watched? "\001" : CHATWINDOW,
+                irc_msgprefix.string,
+                dest,
+                irc_current_nick.string,
+                message
+            ); else Con_Printf("%s%s^1Privmsg to ^2%s^7: ^2* %s ^3%s\n",
+                CHATWINDOW_URGENT,
+                irc_msgprefix.string,
+                dest,
+                irc_current_nick.string,
+                message
+            );
             break;
     }
 }
@@ -658,6 +677,65 @@ IRCEVENT(event_invite)
     );
 }
 
+IRCEVENT(event_ctcp_action)
+{
+    char* msgstr = "";
+    qboolean watched;
+    
+    if(!ISCHANNEL(params[0]))
+    {
+        event_ctcp_action_priv(session, event, origin, params, count);
+        return;
+    }
+    
+    if(count > 1)
+        msgstr = irc_color_strip_from_mirc(params[1]);
+    
+    watched = Irc_IsWatchedChannel(params[0]);
+    
+    if(Irc_CheckHilight(msgstr))
+    {   
+        UPDATETARGET(params[0])
+        
+        Con_Printf("%s%s^3%s^0| ^1* %s ^7%s\n",
+            watched? "\001" : CHATWINDOW_URGENT,
+            irc_msgprefix.string,
+            params[0],
+            origin,
+            msgstr
+        );
+    }
+    else Con_Printf("%s%s^3%s^0| ^2* %s ^7%s\n",
+        watched? "\001" : CHATWINDOW,
+        irc_msgprefix.string,
+        params[0],
+        origin,
+        msgstr
+    );
+    
+    if(count > 1) free(msgstr);
+}
+
+//called by event_ctcp_action
+IRCEVENT(event_ctcp_action_priv)
+{
+    char* msgstr = "";
+    
+    if(count > 1)
+        msgstr = irc_color_strip_from_mirc(params[1]);
+    
+    UPDATETARGET(origin)
+    
+    Con_Printf("%s%s^1Privmsg^7: ^2* %s ^3%s\n",
+        CHATWINDOW_URGENT,
+        irc_msgprefix.string,
+        origin,
+        msgstr
+    );
+    
+    if(count > 1) free(msgstr);
+}
+
 //
 //  Function that checks if a message contains hilights
 //