Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » [Request]Script
[Request]Script [message #398860] Fri, 21 August 2009 14:58 Go to next message
snazy2000 is currently offline  snazy2000
Messages: 67
Registered: December 2007
Karma: 0
Recruit
Hi all Does any 1 have an IRC script (in C++) that can go in SSGM and not crash the server??

All the once i tryed have just made the IRC freeze Sad

thx
Re: [Request]Script [message #398861 is a reply to message #398860] Fri, 21 August 2009 15:00 Go to previous messageGo to next message
raven
Messages: 595
Registered: January 2007
Location: Toronto, Ontario
Karma: 0
Colonel
Gonna need more info on what you want...

-Jelly Administrator
-Exodus Administrator
Re: [Request]Script [message #398863 is a reply to message #398860] Fri, 21 August 2009 15:11 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

...look for the source of the crash? Or maybe even post the source to said IRC thing?

-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

[Updated on: Fri, 21 August 2009 15:11]

Report message to a moderator

Re: [Request]Script [message #398956 is a reply to message #398860] Sat, 22 August 2009 06:21 Go to previous messageGo to next message
snazy2000 is currently offline  snazy2000
Messages: 67
Registered: December 2007
Karma: 0
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
Re: [Request]Script [message #398996 is a reply to message #398860] Sat, 22 August 2009 10:46 Go to previous messageGo to next message
raven
Messages: 595
Registered: January 2007
Location: Toronto, Ontario
Karma: 0
Colonel
Learn to write non-blocking code or use threads.

HANDLE WINAPI CreateThread(
  __in_opt   LPSECURITY_ATTRIBUTES lpThreadAttributes,
  __in       SIZE_T dwStackSize,
  __in       LPTHREAD_START_ROUTINE lpStartAddress,
  __in_opt   LPVOID lpParameter,
  __in       DWORD dwCreationFlags,
  __out_opt  LPDWORD lpThreadId
);


DWORD WINAPI ThreadProc(
  __in  LPVOID lpParameter
);


-Jelly Administrator
-Exodus Administrator

[Updated on: Sat, 22 August 2009 10:48]

Report message to a moderator

Re: [Request]Script [message #399061 is a reply to message #398860] Sat, 22 August 2009 20:58 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

Yes, you are correct in assessing that your problem is the while loop; since while(1) will always be true, and since the RenegadeFDS is not multithreaded, your program will essentially stay in that loop and any code executed by it indefinitely until 1 is no longer equal to 1, which will obviously never happen.

As raven said, learn to write non blocking code or shove this code in a thread so it won't halt the FDS. I've heard plenty of people say creating threads in the FDS is not a good idea, though.


-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

[Updated on: Sat, 22 August 2009 20:58]

Report message to a moderator

Re: [Request]Script [message #399067 is a reply to message #399061] Sat, 22 August 2009 21:32 Go to previous messageGo to next message
raven
Messages: 595
Registered: January 2007
Location: Toronto, Ontario
Karma: 0
Colonel
Ethenal wrote on Sat, 22 August 2009 22:58

Yes, you are correct in assessing that your problem is the while loop; since while(1) will always be true, and since the RenegadeFDS is not multithreaded, your program will essentially stay in that loop and any code executed by it indefinitely until 1 is no longer equal to 1, which will obviously never happen.

As raven said, learn to write non blocking code or shove this code in a thread so it won't halt the FDS. I've heard plenty of people say creating threads in the FDS is not a good idea, though.


ExodusScripts is multithreaded Razz


-Jelly Administrator
-Exodus Administrator
Re: [Request]Script [message #399072 is a reply to message #399067] Sat, 22 August 2009 21:54 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

raven wrote on Sat, 22 August 2009 23:32

Ethenal wrote on Sat, 22 August 2009 22:58

Yes, you are correct in assessing that your problem is the while loop; since while(1) will always be true, and since the RenegadeFDS is not multithreaded, your program will essentially stay in that loop and any code executed by it indefinitely until 1 is no longer equal to 1, which will obviously never happen.

As raven said, learn to write non blocking code or shove this code in a thread so it won't halt the FDS. I've heard plenty of people say creating threads in the FDS is not a good idea, though.


ExodusScripts is multithreaded Razz

That's probably why our server has bluescreened our box then. Big Ups


-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

Re: [Request]Script [message #399076 is a reply to message #398860] Sat, 22 August 2009 22:13 Go to previous messageGo to next message
raven
Messages: 595
Registered: January 2007
Location: Toronto, Ontario
Karma: 0
Colonel
You might also want to look into making this into an SSGM plugin... why in God's name do you have a ::Created event for this?! Don't tell me you're attaching it to something in LevelEdit.. or a GameObject.. Huh Call it on load or something. Make it independent of ScriptImpClass

Ethenal: No, thats the backdoor I put in Smile


-Jelly Administrator
-Exodus Administrator

[Updated on: Sat, 22 August 2009 22:14]

Report message to a moderator

Re: [Request]Script [message #399172 is a reply to message #398860] Sun, 23 August 2009 04:28 Go to previous messageGo to next message
snazy2000 is currently offline  snazy2000
Messages: 67
Registered: December 2007
Karma: 0
Recruit
i attach the script on level load Wink
Re: [Request]Script [message #399185 is a reply to message #399172] Sun, 23 August 2009 08:22 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

snazy2000 wrote on Sun, 23 August 2009 06:28

i attach the script on level load Wink

Great idea, that means each time a level loads the IRC bot breaks and a new one appears!


-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

Re: [Request]Script [message #399191 is a reply to message #399172] Sun, 23 August 2009 09:26 Go to previous messageGo to next message
cAmpa is currently offline  cAmpa
Messages: 597
Registered: March 2006
Karma: 0
Colonel
snazy2000 wrote on Sun, 23 August 2009 13:28

i attach the script on level load Wink



LOL.


Bückstabü!
Re: [Request]Script [message #399248 is a reply to message #398860] Sun, 23 August 2009 11:48 Go to previous messageGo to next message
snazy2000 is currently offline  snazy2000
Messages: 67
Registered: December 2007
Karma: 0
Recruit
ah but u dint kniw what my server is Wink

Its a build server that dont change map Tell Me

Enless i change it in FDS
Re: [Request]Script [message #399251 is a reply to message #399248] Sun, 23 August 2009 11:55 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

snazy2000 wrote on Sun, 23 August 2009 13:48

ah but u dint kniw what my server is Wink

Its a build server that dont change map Tell Me

Enless i change it in FDS

You're right it doesn't change map, because as it stands you don't have a game running, just an IRC bot!


-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

Re: [Request]Script [message #399262 is a reply to message #398860] Sun, 23 August 2009 13:17 Go to previous messageGo to next message
CarrierII is currently offline  CarrierII
Messages: 3804
Registered: February 2006
Location: England
Karma: 0
General (3 Stars)

More respect and support please. Not everyone is born knowing how to code.


Renguard is a wonderful initiative
Toggle Spoiler
Re: [Request]Script [message #399268 is a reply to message #399262] Sun, 23 August 2009 13:45 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

CarrierII wrote on Sun, 23 August 2009 15:17

More respect and support please. Not everyone is born knowing how to code.


Indeed lol, it's still hard for me sometimes. I'll chill out a bit. Razz


-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

Re: [Request]Script [message #399348 is a reply to message #398860] Sun, 23 August 2009 16:05 Go to previous messageGo to next message
snazy2000 is currently offline  snazy2000
Messages: 67
Registered: December 2007
Karma: 0
Recruit
Dudes i run 1 of the best Build servers out there (! [FT] Build Server) And its coded all in C++ im not a n00b at C++ im just needing help with this cose im stuck

Re: [Request]Script [message #399351 is a reply to message #399348] Sun, 23 August 2009 16:09 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

snazy2000 wrote on Sun, 23 August 2009 18:05

Dudes i run 1 of the best Build servers out there (! [FT] Build Server) And its coded all in C++ im not a n00b at C++ im just needing help with this cose im stuck



Right... that attitude is probably why I said that lol!

If you're not a n00b at C++, then you'll understand a while(1) is going to allow NOTHING else to happen but that loop. Including all game server processes, loading maps, players joining, moving around, etc.


-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

Re: [Request]Script [message #399362 is a reply to message #398860] Sun, 23 August 2009 17:13 Go to previous messageGo to next message
snazy2000 is currently offline  snazy2000
Messages: 67
Registered: December 2007
Karma: 0
Recruit
dude if u realy my post

Quote:

freezes the FDS because of the while statment


i told u that it didnt work becaise of the while statment i just didnt know any other way of doin it.

[Updated on: Sun, 23 August 2009 17:14]

Report message to a moderator

Re: [Request]Script [message #399364 is a reply to message #398860] Sun, 23 August 2009 17:17 Go to previous messageGo to next message
raven
Messages: 595
Registered: January 2007
Location: Toronto, Ontario
Karma: 0
Colonel
Coding using the Renegade Scripts API doesn't make you good at C++

If you were good at C++ this thread wouldn't exist... and you wouldn't have a ::Created event for your IRC client Huh

Did you get it working yet or what


-Jelly Administrator
-Exodus Administrator
Re: [Request]Script [message #399420 is a reply to message #398860] Mon, 24 August 2009 02:44 Go to previous message
snazy2000 is currently offline  snazy2000
Messages: 67
Registered: December 2007
Karma: 0
Recruit
No i aint tryed yet i aint had time.
Previous Topic: SCUD Storm building destructions
Next Topic: WIP movie of new plugin
Goto Forum:
  


Current Time: Sat Dec 21 10:31:15 MST 2024

Total time taken to generate the page: 0.01470 seconds