Home » Renegade Discussions » Mod Forum » [Request]Script
[Request]Script [message #398860] |
Fri, 21 August 2009 14:58 |
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
thx
|
|
|
|
Re: [Request]Script [message #398863 is a reply to message #398860] |
Fri, 21 August 2009 15:11 |
|
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
|
[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 |
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 |
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 |
|
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
|
[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 |
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
-Jelly Administrator
-Exodus Administrator
|
|
|
Re: [Request]Script [message #399072 is a reply to message #399067] |
Sat, 22 August 2009 21:54 |
|
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
|
That's probably why our server has bluescreened our box then.
-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
|
|
|
|
Re: [Request]Script [message #399076 is a reply to message #398860] |
Sat, 22 August 2009 22:13 |
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.. Call it on load or something. Make it independent of ScriptImpClass
Ethenal: No, thats the backdoor I put in
-Jelly Administrator
-Exodus Administrator
[Updated on: Sat, 22 August 2009 22:14] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: [Request]Script [message #399348 is a reply to message #398860] |
Sun, 23 August 2009 16:05 |
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 #399364 is a reply to message #398860] |
Sun, 23 August 2009 17:17 |
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
Did you get it working yet or what
-Jelly Administrator
-Exodus Administrator
|
|
|
|
Goto Forum:
Current Time: Thu Dec 19 02:44:25 MST 2024
Total time taken to generate the page: 0.01110 seconds
|