Pages: [1]
  Print  
Author Topic: Contribution: IRC Chat?  (Read 5163 times)
Kylratix
Nub


Cakes 0
Posts: 27



WWW
« on: January 11, 2007, 04:59:57 pm »

Hi,

I've always liked the ability to BS on IRC while I'm fragging. I moded the Q2 source a while back to do it and I'm interested in doing it with OpenArena.

If I were to write and maintain the code for it, would that be something that would be considered for inclusion in future releases of OA?
Logged

-- Roy 'Kylratix' Laurie
http://www.binarycult.com
Blaenk
more like blank dumb
Lesser Nub


Cakes 0
Posts: 135



« Reply #1 on: January 15, 2007, 07:46:19 pm »

Hey! I was thinking about writing that in my game hahaha. I don't know if it'll be 'in' though, ask fromhellfromhellololeila
Logged
Kylratix
Nub


Cakes 0
Posts: 27



WWW
« Reply #2 on: January 15, 2007, 08:15:49 pm »

Hmm... how were you planning on implementing it in your game? Just as a global chat sort of thing?
Logged

-- Roy 'Kylratix' Laurie
http://www.binarycult.com
Blaenk
more like blank dumb
Lesser Nub


Cakes 0
Posts: 135



« Reply #3 on: January 15, 2007, 09:47:28 pm »

Actually I wasn't sure.. :/

Maybe in the console or something, you can toggle irc mode where you see the messages and stuff, and then talk, then toggle it off to go back to normal console. Then again I was thinking about making some type of tabs for consoles, like in yakuake (http://kde-apps.org/content/show.php?content=29153), that'd be VERY cool, at least, I'd like it Cheesy

Or I might make some type of extra chat channel, like, there's team, public, private, then irc. I'm not sure, haha, it was just a thought.
Logged
Kylratix
Nub


Cakes 0
Posts: 27



WWW
« Reply #4 on: January 15, 2007, 10:37:01 pm »

That's sort of how I had the Q2 mod setup...

CVARS: irc_host, irc_port, irc_password, irc_nick, irc_channel
Client Commands: irc <command>:connect, disconnect, say <text>, msg <user> <text>

The messagemode commands were copied and altered to feed to the irc say and msg commands, so that it was differentiated from normal chat, like team chat is.

I think I might have the code somewhere...
Logged

-- Roy 'Kylratix' Laurie
http://www.binarycult.com
Kylratix
Nub


Cakes 0
Posts: 27



WWW
« Reply #5 on: January 16, 2007, 02:04:55 am »

Here it is ... a more basic version


Code:
#include "client.h"
#include "winsock.h"
#include "q2irc.h"


#define IRCSERVER "irc.efnet.pl"

qboolean irc_connected = false;
int irc_sock;
struct sockaddr_in irc_addr;
char ircin[1024];
int cur;
//static char[1024] ircin;
//int ircin_count;


void ShiftBuffer (char* end)
{
  char buf[1024];
  int i, len;


  strcpy(buf, end);
  strcpy(ircin, buf);
  cur=strlen(ircin);
  return;
}
   
 

// Attempts to connect to an IRC server
void CL_IRC (void)
{
  int err;
  char* ircserver;

  if (Cmd_Argc() < 2) {
    Com_Printf("usage: irc <server>\n");
    return;
  }

  ircserver = Cmd_Argv(1);

  if (irc_connected)
    CL_IRC_Disconnect();

  // Setup remote address
  if (!NET_StringToSockaddr (ircserver, &irc_addr)) {
    Com_Printf("IRC: Couldn't resolve %s\n", ircserver);
    return;
  }

irc_addr.sin_family = AF_INET;
irc_addr.sin_port = htons(6667);
memset(&irc_addr.sin_zero,0,8);

  irc_sock = socket(AF_INET, SOCK_STREAM, 0);
  if (irc_sock == -1) {
    Com_Printf ("IRC: Socket error.\n");
    return;
  }

  err = connect(irc_sock, (struct sockaddr*)&irc_addr, sizeof(struct sockaddr));
  if (err == -1) {
    Com_Printf("IRC: Connect failed to %s\n", Cmd_Argv(1));
    return;
  }

  // set non-blocking
  err = 1;
  ioctlsocket (irc_sock, FIONBIO, &err);

  irc_connected = true;
  cur=0;

//  sleep(2);

  send(irc_sock, "NICK Q2Irc\r\n", 12, 0);
  send(irc_sock, "USER q2irc 221.163.111.20 irc.efnet.pl : q2irc\r\n", 48, 0);
  send(irc_sock, "JOIN #klined\r\n", 14, 0);

  return;
}


void CL_IRC_Recv(void)
{
  char* end;
  char* tok;
  int err, ret;

  if (!irc_connected)
    return;

  ret = recv(irc_sock, ircin+cur, 1023-cur, 0);
  if (ret == -1) {
    err = WSAGetLastError();
if (err == WSAEWOULDBLOCK)
return;
    else {
      CL_IRC_Disconnect();
      return;
    }
  }

  cur += ret;
  ircin[cur] = 0;

  while ((end = strstr(ircin, "\r\n")))
  {
    (*end) = 0;
    *(end+1) = 0;
    if (strstr(ircin, "PRIVMSG")) {
      tok = strstr(ircin, "!");
      *tok = 0;
      Com_Printf("^1<%s>^r ", ircin+1);
      tok = (strstr(tok+1, ":"));
      Com_Printf("%s\n", tok+1);
    }

    ShiftBuffer(end+2);
  }
 


/*  if (strstr(ircin, "PING") == ircin) {
    send(irc_sock, ircin+5, strlen(ircin)-5, 0);
    return;
  }
*/



  return;
}


void CL_IRC_Disconnect(void) {
    Com_Printf("IRC: Disconnecting..");
    close(irc_sock);
    Com_Printf("OK\n");
    irc_connected = false;
    return;
}


void CL_IRC_Say(void) {
    char buf[1024];

    if (Cmd_Argc() < 2)
      return;

    sprintf(buf, "PRIVMSG #klined :%s\r\n", Cmd_Argv(1));
    if (send(irc_sock, buf, strlen(buf), 0) == -1) {
      CL_IRC_Disconnect();
      return;
    }
     
    Com_Printf("^1<%s>^r %s\n", "Q2Irc", Cmd_Argv(1));

    return;
}
Logged

-- Roy 'Kylratix' Laurie
http://www.binarycult.com
Pages: [1]
  Print  
 
Jump to: