Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » [Request]Script
Re: [Request]Script [message #398956 is a reply to message #398860] Sat, 22 August 2009 06:21 Go to previous messageGo to previous message
snazy2000 is currently offline  snazy2000
Messages: 67
Registered: December 2007
Karma:
Recruit
SOCKET sock;

    char *server = "irc.ft-gaming.com"; 
    int port = 6667;
    char *nick = "FBot";
    char *chan = "#bottest";
    char buff[4096];
    char tmp[4096]; 
    char name[256];
    bool spam;
    char ID[256];


int irc_connect()//char server[256], char channel[256], char name[256], int port
{

    
    
   WSADATA WSAData;
   WSAStartup(MAKEWORD(2,0), &WSAData);
   SOCKADDR_IN sin;
   sock = socket(AF_INET, SOCK_STREAM, 0);
   sin.sin_addr.s_addr            = inet_addr(server);
   sin.sin_family                = AF_INET;
   sin.sin_port                = htons(port);
   connect(sock, (SOCKADDR *)&sin, sizeof(sin));
    
   memset(tmp,0,255);
   sprintf(tmp,"USER %s 0 0 :%s%c",nick,nick,10);
   send(sock,tmp,strlen(tmp),0);
   printf("Sent-> %s", tmp);

   memset(tmp,0,255);


   BotId = (rand() % 100);
   sprintf(ID,"!%d",BotId);
   sprintf(name,"%s[%d]",nick,BotId);
   sprintf(tmp,"NICK %s%c",name,10);
   send(sock,tmp,strlen(tmp),0);
   printf("Sent-> %s", tmp);

   
   Sleep(100);
    
   memset(tmp,0,255);
   sprintf(tmp,"JOIN %s%c",chan,10);
   send(sock,tmp,strlen(tmp),0);
   printf("Sent-> %s", tmp);

   sprintf(tmp,"PRIVMSG %s :Hello %s!%c",chan,chan,10);
   send(sock,tmp,strlen(tmp),0);
   printf("Sent-> %s", tmp);

   printf("Name-> %s\n", name);

memset(buff,0,255);

   return 0;
}

void StayAlive()
{
    char buff[2048];
    char msg[256];
    char tmp[256];
    char BotName[64];
    memset(msg,0,255);
    memset(BotName,0,64);
    sprintf(BotName, "!%s", name);

    while (1)
    {
        memset(buff,0,255);
        memset(tmp,0,255);
        recv( sock,buff,255,0);



        if(strlen(buff) != 0)
        {
            printf("Received-> %s\n", buff);
            //send(sock,"PONG :\r\n",6,0);
            //printf("Sent-> Pong");
        

            if (strncmp(buff,"PING", 4) == 0 )
            {
                buff[1] = 'O';
                send(sock,buff,strlen(buff),0);
                printf("Sent-> %s\n", buff);
            }

            if (strncmp(buff,"QUIT", 4) == 0 )
            {
                irc_connect();
                printf("Bot-> Reconnecting\n");
            }

            else if(strstr(buff, "PRIVMSG") != NULL)
            {
                memset(tmp,0,255);
                sprintf(tmp, "PRIVMSG %s :Got a message!%c",chan,10);
                //send(sock,tmp,strlen(tmp),0);
                printf("Sent-> %s\n", tmp);
            


            }


        }



        if ( strlen(buff) == 0 ) {

            closesocket(sock);
        break;
        }
    }






}


void IRC::Created(GameObject *obj) {
srand(GetTickCount());

    UpTimeS = GetTickCount();

    if(irc_connect() != 0)
        Console_Input("msg ERROR");
    StayAlive();
    
    getchar();
    WSACleanup();
}

ScriptRegistrant<IRC> IRC_Registrant("IRC","");



Thats the code that freezes the FDS because of the while statment
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: SCUD Storm building destructions
Next Topic: WIP movie of new plugin
Goto Forum:
  


Current Time: Sat Dec 21 21:05:49 MST 2024

Total time taken to generate the page: 0.01054 seconds