]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
IRC callbacks and built-ins. Some fixes here and there.
authornitroxis <nitroxis@wtwrp.de>
Sun, 16 Feb 2014 18:37:23 +0000 (19:37 +0100)
committernitroxis <nitroxis@wtwrp.de>
Sun, 16 Feb 2014 18:37:23 +0000 (19:37 +0100)
dpdefs/menudefs.qc
dpdefs/progsdefs.qc
irc.c
irc.h
lhnet.c
prvm_cmds.c
prvm_cmds.h
prvm_offsets.h
svvm_cmds.c

index 1f817cd2029de82d68bba5731993800a9d778ea0..46e7fe97b169d79540df1fe060e8724d70a28faf 100644 (file)
@@ -530,6 +530,11 @@ float FIELD_FUNCTION = 6;
 //getentityfieldstring returns data as would be written to a savegame, eg... "0.05" (float), "0 0 1" (vector), or "Hello World!" (string). Function names can also be returned.
 //putentityfieldstring puts the data returned by getentityfieldstring back into the entity.
 
+//IRC
+void irc_connect() = #550;
+void irc_disconnect() = #551;
+void irc_write(string line) = #552;
+
 // assorted undocumented extensions
 string(string, float) netaddress_resolve = #625;
 string(string search, string replace, string subject) strreplace = #484;
index 2ccd843145b0db8807a777d9285bf2e5e60478b8..8adafba26801c2dbce075bbdcbc607b1063ffa92 100644 (file)
@@ -504,4 +504,9 @@ void(entity e) setspawnparms                = #78;          // set parm1... to the
                                                                                                // values at level start
                                                                                                // for coop respawn
 
+//IRC
+void irc_connect() = #550;
+void irc_disconnect() = #551;
+void irc_write(string line) = #552;
+                                                                                               
 //============================================================================
diff --git a/irc.c b/irc.c
index f2736d8ef1675932fdfee18f8413a0f84e28fbb7..b7dca0d27bd5d43524172854551cd558f603524e 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -30,14 +30,14 @@ static ircnetbuffer_t irc_outgoing;
 static qboolean irc_registered;
 static qboolean irc_connected;
 
+static cvar_t irc_server = { CVAR_SAVE, "irc_server", "", "the address of the IRC server to connect to." };
 static cvar_t irc_nickname = { CVAR_SAVE, "irc_nickname", "darkplaces", "nickname to use when connecting to IRC" };
 static cvar_t irc_username = { CVAR_SAVE, "irc_username", "darkplaces", "username/ident to use when connecting to IRC" };
 static cvar_t irc_realname = { CVAR_SAVE, "irc_realname", "darkplaces", "realname to use when connecting to IRC" };
 
 static mempool_t *irc_mempool;
 
-
-static void IRC_Disconnect(void)
+void IRC_Disconnect(void)
 {
        if (irc_socket)
        {
@@ -53,7 +53,7 @@ static void IRC_Disconnect(void)
        irc_connected = false;
 }
 
-static int IRC_Connect(const char *addr)
+int IRC_Connect(void)
 {
        lhnetaddress_t address;
        lhnetaddress_t peeraddress;
@@ -67,9 +67,9 @@ static int IRC_Connect(const char *addr)
                return 0;
        }
 
-       if (!LHNETADDRESS_FromString(&peeraddress, addr, 6667))
+       if (!LHNETADDRESS_FromString(&peeraddress, irc_server.string, 6667))
        {
-               Con_Printf("[IRC] Bad server address: %s.\n", addr);
+               Con_Printf("[IRC] Bad server address: %s.\n", irc_server.string);
                return 0;
        }
 
@@ -80,12 +80,12 @@ static int IRC_Connect(const char *addr)
                return 0;
        }
        
-       Con_Printf("[IRC] Connecting to %s...\n", addr);
+       Con_Printf("[IRC] Connecting to %s...\n", irc_server.string);
        irc_connected = true;
        return 1;
 }
 
-static void IRC_AddMessage(const char *message)
+void IRC_AddMessage(const char *message)
 {
        size_t len = strlen(message);
 
@@ -231,6 +231,7 @@ static void IRC_DumpMessage(const ircmessage_t *msg)
 static void IRC_ProcessMessage(const char *line)
 {
        ircmessage_t *msg;
+       prvm_prog_t *prog;
 
        if ((msg = IRC_ParseMessage(line)))
        {
@@ -309,9 +310,21 @@ static void IRC_ProcessMessage(const char *line)
                        IRC_AddMessage(va(vabuf, sizeof(vabuf), "PONG :%s", msg->args[0]));
                }
 
-               IRC_DumpMessage(msg);
+               //IRC_DumpMessage(msg);
                IRC_FreeMessage(msg);
        }
+
+       prog = SVVM_prog;
+       if (PRVM_serverfunction(IRC_Parse))
+       {
+               int restorevm_tempstringsbuf_cursize;
+               restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
+               PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, line);
+               PRVM_serverglobalfloat(time) = sv.time;
+               PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(host_client->edict);
+               prog->ExecuteProgram(prog, PRVM_serverfunction(IRC_Parse), "QC function IRC_Parse is missing");
+               prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
+       }
 }
 
 static void IRC_ProcessAllMessages(void)
@@ -432,13 +445,7 @@ static void IRC_Register(void)
 
 static void IRC_Connect_f(void)
 {
-       if (Cmd_Argc() != 2)
-       {
-               Con_Print("ircconnect <address> : connect to an IRC server\n");
-               return;
-       }
-
-       if (IRC_Connect(Cmd_Argv(1)))
+       if (IRC_Connect())
                IRC_Register();
 }
 
@@ -447,7 +454,7 @@ static void IRC_Disconnect_f(void)
        IRC_Disconnect();
 }
 
-static void IRC_IRC_f(void)
+static void IRC_Write_f(void)
 {
        if (Cmd_Argc() < 2)
        {
@@ -465,13 +472,14 @@ void IRC_Init(void)
 {
        irc_mempool = Mem_AllocPool("IRC", 0, NULL);
        
+       Cvar_RegisterVariable(&irc_server);
        Cvar_RegisterVariable(&irc_nickname);
        Cvar_RegisterVariable(&irc_username);
        Cvar_RegisterVariable(&irc_realname);
 
        Cmd_AddCommand("ircconnect", IRC_Connect_f, "connect to an IRC server");
        Cmd_AddCommand("ircdisconnect", IRC_Disconnect_f, "disconnect from an IRC server");
-       Cmd_AddCommand("irc", IRC_IRC_f, "send raw messages to a connected IRC server");
+       Cmd_AddCommand("irc", IRC_Write_f, "send raw messages to a connected IRC server");
 
        irc_connected = false;
 }
diff --git a/irc.h b/irc.h
index 98f9262284015401b2b5decec96aee8cfa034f39..6cffee5ce7de55a02940d9cf8fda640586ffc104 100644 (file)
--- a/irc.h
+++ b/irc.h
@@ -5,4 +5,8 @@ void IRC_Init(void);
 void IRC_Frame(void);
 void IRC_Shutdown(void);
 
+int IRC_Connect(void);
+void IRC_Disconnect(void);
+void IRC_AddMessage(const char* message);
+
 #endif
diff --git a/lhnet.c b/lhnet.c
index 3d12d9da56cd85fac4c4362849e714627bc6d8bd..b6d5977768e6a0cf63c0050a46d077f4ff06a9df 100644 (file)
--- a/lhnet.c
+++ b/lhnet.c
@@ -873,10 +873,11 @@ static int LHNETSOCKET_TryBind(lhnetsocket_t *lhnetsocket, lhnetaddress_t *addre
 {
        SOCKLEN_T namelen;
        int bindresult;
+       lhnetaddressnative_t *localaddress;
        if (!address)
                return 0;
        lhnetsocket->address = *address;
-       lhnetaddressnative_t *localaddress = (lhnetaddressnative_t *)&lhnetsocket->address;
+       localaddress = (lhnetaddressnative_t *)&lhnetsocket->address;
 #ifdef SUPPORTIPV6
        if (address->addresstype == LHNETADDRESSTYPE_INET6)
        {
@@ -900,9 +901,10 @@ static int LHNETSOCKET_TryConnect(lhnetsocket_t *lhnetsocket, lhnetaddress_t *ad
 {
        SOCKLEN_T namelen;
        int connectresult;
+       lhnetaddressnative_t *peeraddress;
        if (!address)
                return 0;
-       lhnetaddressnative_t *peeraddress = (lhnetaddressnative_t *)address;
+       peeraddress = (lhnetaddressnative_t *)address;
 #ifdef SUPPORTIPV6
        if (address->addresstype == LHNETADDRESSTYPE_INET6)
        {
@@ -925,10 +927,11 @@ static int LHNETSOCKET_TryConnect(lhnetsocket_t *lhnetsocket, lhnetaddress_t *ad
 lhnetsocket_t *LHNET_OpenSocket(lhnetaddress_t *address, lhnetaddress_t *peeraddress, int use_tcp, int use_blocking, int register_for_select)
 {
        lhnetsocket_t *lhnetsocket, *s;
+       int addresstype;
        if (!address && !peeraddress)
                return NULL;
 
-       int addresstype = address ? address->addresstype : peeraddress->addresstype;
+       addresstype = address ? address->addresstype : peeraddress->addresstype;
        if (peeraddress && addresstype != peeraddress->addresstype)
        {
                Con_Printf("Cannot connect different address types.\n");
@@ -1032,8 +1035,7 @@ lhnetsocket_t *LHNET_OpenSocket(lhnetaddress_t *address, lhnetaddress_t *peeradd
                                                        )
 #endif
                                        {
-                                               int bindresult;
-
+                                               
 #if defined(SOL_RFC1149) && defined(RFC1149_1149ONLY)
                                                // we got reports of massive lags when this protocol was chosen as transport
                                                // so better turn it off
@@ -1268,12 +1270,12 @@ int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentleng
                return -1;
        if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_LOOP)
        {
+               lhnetpacket_t *p;
                if (!address)
                {
                        Con_DPrintf("LHNET_Write: destination address required on LHNETADDRESSTYPE_LOOP\n", LHNETPRIVATE_StrError());
                        return -1;
                }
-               lhnetpacket_t *p;
                p = (lhnetpacket_t *)Z_Malloc(sizeof(*p) + contentlength);
                p->data = (void *)(p + 1);
                memcpy(p->data, content, contentlength);
index 00c9ede9fcd5dc6ad0fa253d6ede33caf399fa0b..f8366039f7a8a9c0f0463ee8e2bb0a4054cc6122 100644 (file)
@@ -15,6 +15,7 @@
 #include "csprogs.h"
 #include "ft2.h"
 #include "mdfour.h"
+#include "irc.h"
 
 extern cvar_t prvm_backtraceforwarnings;
 #ifdef USEODE
@@ -7340,3 +7341,22 @@ void VM_physics_addtorque(prvm_prog_t *prog)
        VectorCopy(PRVM_G_VECTOR(OFS_PARM1), f.v1);
        VM_physics_ApplyCmd(ed, &f);
 }
+
+
+void VM_irc_connect(prvm_prog_t *prog)
+{
+       IRC_Connect();
+}
+
+void VM_irc_disconnect(prvm_prog_t *prog)
+{
+       IRC_Disconnect();
+}
+
+void VM_irc_write(prvm_prog_t *prog)
+{
+       char string[VM_STRINGTEMP_LENGTH];
+
+       VM_VarString(prog, 0, string, sizeof(string));
+       IRC_AddMessage(string);
+}
\ No newline at end of file
index e21a393f6e0860b0a5a3e8b8a6660719ad2028e3..143319a7ce8371945fdfe7905f643d805a22bbfc 100644 (file)
@@ -484,4 +484,8 @@ void VM_physics_enable(prvm_prog_t *prog);
 void VM_physics_addforce(prvm_prog_t *prog);
 void VM_physics_addtorque(prvm_prog_t *prog);
 
+// irc
+void VM_irc_connect(prvm_prog_t *prog);
+void VM_irc_disconnect(prvm_prog_t *prog);
+void VM_irc_write(prvm_prog_t *prog);
 #endif
index 36256c5fb3dc8116178a031c23850c6c13c9e57d..5821c90d3f13e2ac21cedae81ff002cf41bc8e54 100644 (file)
@@ -429,6 +429,7 @@ PRVM_DECLARE_function(SV_ParseClientCommand)
 PRVM_DECLARE_function(SV_PausedTic)
 PRVM_DECLARE_function(SV_PlayerPhysics)
 PRVM_DECLARE_function(SV_Shutdown)
+PRVM_DECLARE_function(IRC_Parse)
 PRVM_DECLARE_function(SetChangeParms)
 PRVM_DECLARE_function(SetNewParms)
 PRVM_DECLARE_function(StartFrame)
@@ -789,6 +790,7 @@ PRVM_DECLARE_serverfunction(SV_ParseClientCommand)
 PRVM_DECLARE_serverfunction(SV_PausedTic)
 PRVM_DECLARE_serverfunction(SV_PlayerPhysics)
 PRVM_DECLARE_serverfunction(SV_Shutdown)
+PRVM_DECLARE_serverfunction(IRC_Parse)
 PRVM_DECLARE_serverfunction(SetChangeParms)
 PRVM_DECLARE_serverfunction(SetNewParms)
 PRVM_DECLARE_serverfunction(StartFrame)
index c75dd07740ae4599409952601096c7937909179e..3909b42806c85426cdaa9fa3e8fe8f096403dc64 100644 (file)
@@ -3732,9 +3732,9 @@ NULL,                                                     // #546
 NULL,                                                  // #547
 NULL,                                                  // #548
 NULL,                                                  // #549
-NULL,                                                  // #550
-NULL,                                                  // #551
-NULL,                                                  // #552
+VM_irc_connect,                                        // #550
+VM_irc_disconnect,                             // #551
+VM_irc_write,                                  // #552
 NULL,                                                  // #553
 NULL,                                                  // #554
 NULL,                                                  // #555