Pol Ingame Restart text command

Post your Custom Scripts or Packages.

Moderator: POL Developer

Post Reply
Tomi
POL Developer
Posts: 475
Joined: Tue Feb 21, 2006 5:08 pm

Pol Ingame Restart text command

Post by Tomi » Thu Feb 26, 2009 7:23 am

I don't know how many will have nay help of this, but if you are running a local Mirc IRC client on your server this will do.
This has also a loop in Mirc that check the socket is open all the time so you don't have to do manually anything there.

auxsvc.cfg

Code: Select all

AuxService
{
	Port	5005
	Script	MircListener
}
MircListener.src

"Change the include "Include/Modules"; to use whatever em is needed, sorry Im too lazy to check because I use that include for all my scripts.

Code: Select all

include "Include/Modules";

program MircListener( connection )

	SetGlobalProperty( "AuxConnection", GetPid() );

	var ev;

	while ( connection )

		if ( connection.ip != "127.0.0.1" )
			continue;
		else
			Print( connection.ip );
			ev := wait_for_event( 5 );
		endif

		if ( ev )
			if ( ev.value == "Restart" )
				connection.transmit( "Restart " + CInt( ev.timer ) );
			else
				continue;
			endif
		endif
		Sleep( 1 );
	endwhile

	return 1;

endprogram
restart.src

Code: Select all

include "Include/Modules";

program Command_restart( character, text )

	var script := GetProcess( CInt( GetGlobalProperty( "AuxConnection" ) ) );

	var data   	:= struct;

	data.+type	:= "recv";
	data.+value 	:= "Restart";
	data.+timer	:= Cint( text );

	Print( data );

	script.sendevent( data );
	Start_Script( ":Commands:Control/Restart", array{ CInt( text ) } );

endprogram
Restart.src (Control script)

Code: Select all

include "Include/Modules";

program Control_Restart( param )

	var time := CInt( param +1 );

	Print( "Restart countdown started." );

	if ( time > 61 )
		time := 61;
	endif

	if ( time < 1 )
		time := 1;
	endif

	for( time; time >= 0; time -= 1 )
		if ( time > 0 )
			Print( "System Message: " + CStr( CInt( time ) ) + " minute(s) to restart!" );
			BroadCast( "[System]: " + CStr( CInt( time ) ) + " minute(s) to restart!" );
		endif
		Sleep( 60 );
	endfor

	Shutdown();

endprogram
Mirc Code

In Remote.ini

Code: Select all

on *:START: {
  sockopen Pol 127.0.0.1 5005
  sockettimer
}   

on *:SOCKREAD:Pol: {
  :n
  sockread %RestartTime 
  if $sockbr == 0 { 
    halt
  } 
  %RestartTime = $remove( %RestartTime, sRestart )
  %SleepTime = $calc( ( %RestartTime * 60 ) + 120 )
  timer 1 %SleepTime /startpol
  goto n  
  halt
}
In Aliases.ini

Code: Select all

/sockettimer /timer 0 10 /socketcheck
/socketcheck if $sock( Pol, 1 ) != Pol { sockopen Pol 127.0.0.1 5005 }
/startpol /run -p "Pol Directory\pol.exe"

User avatar
CWO
POL Expert
Posts: 1142
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA
Contact:

Re: Pol Ingame Restart text command

Post by CWO » Thu Feb 26, 2009 10:46 am

Did they actually fix sockets in mIRC? Last time I tried hooking an mIRC bot to POL, it wouldn't work on the same computer... I had to move it to another computer on the network in order to pull it off.

Another thing that kinda bothers me...

Code: Select all

   while ( connection )

      if ( connection.ip != "127.0.0.1" )
         continue;
if the IP isn't localhost, that would cause an infinite loop with no sleep as long as the connection stays open? "continue;" goes back to the beginning of the while...

Tomi
POL Developer
Posts: 475
Joined: Tue Feb 21, 2006 5:08 pm

Re: Pol Ingame Restart text command

Post by Tomi » Thu Feb 26, 2009 11:29 am

I got this working with the Mirc on localhost yes...

And for the IP check, better way is to add IPMatch entry to auxsvc.cfg and remove that check in the script.

Should probably clean up that code a bit because there are some unecessary Prints too left from my testing.

Post Reply