SRL Archive - Research & Development Lounge

New CrashSmart function!


Home

2012-03-23 03:52:34

Hello, this is new CrashSmart function. I know that there is already like 3 ways of doing it but here is my version.


function WriteToFile(Text, FileName: string) :Boolean;
var
iFile: Integer;
begin
try
iFile := RewriteFile(ScriptPath + FileName, False);
Result := WriteFileString(iFile, Text);
CloseFile(iFile);
except
end;
end;

procedure CrashSmart(ScriptName :String);
var
T :TSysProcArr;
Pid, I :Integer;
Title :String;

begin
Disguise(ScriptName);

T := GetProcesses;
for I := 0 to High(T) do
If T[I].Title = ScriptName then
begin
Pid := T[I].Pid;
Title := T[I].Title;
Break;
end;

If FileExists(ScriptPath + 'RestartSimba' + ScriptName + IntToStr(PID) + '.cmd') then
begin
WriteLn('Calling Crash Smart File. Name : RestartSimba' + IntToStr(PID) + '.cmd');
OpenWebPage(ScriptPath + 'RestartSimba' + ScriptName + IntToStr(PID) + '.cmd');
WriteLn('Current Simba / Script Title : ' + Title + ' PID : ' + IntToStr(PID));
TerminateScript;
end;

WriteLn('Current Simba / Script Title : ' + Title + ' PID : ' + IntToStr(PID));

If WriteToFile('Taskkill /F /PID ' + IntToStr(PID) + #13 + #10 + 'cd ' + AppPath + #13 + #10 + 'Simba.exe -o ' + ScriptPath + ScriptName + ' -r' + #13 + #10 +
'ping -n 02 127.0.0.1 >NUL' + #13 + #10 + 'DEL ' + ScriptPath + 'RestartSimba' + ScriptName + IntToStr(PID) + '.cmd', 'RestartSimba' + ScriptName + IntToStr(PID) + '.cmd') then
WriteLn('Crash Smart File Created. Name : RestartSimba' + IntToStr(PID) + '.cmd');
end;



So how does this work.

It will Get current script Process ID and kills it after that it restarts simba and cleans traces after.

CrashSmart('NarclesFastFighter.simba');
You need to input your script name into CrashSmart. That's all.
If you Download script that has Spaces and stuff. Rename it.
Ex.
WRONG. Narcles Fast Fighter.simba
CORRECT. NarclesFastFighter.simba


Usage: Ex. Script.



function WriteToFile(Text, FileName: string) :Boolean;
var
iFile: Integer;
begin
try
iFile := RewriteFile(ScriptPath + FileName, False);
Result := WriteFileString(iFile, Text);
CloseFile(iFile);
except
end;
end;

procedure CrashSmart(ScriptName :String);
var
T :TSysProcArr;
Pid, I :Integer;
Title :String;

begin
Disguise(ScriptName);

T := GetProcesses;
for I := 0 to High(T) do
If T[I].Title = ScriptName then
begin
Pid := T[I].Pid;
Title := T[I].Title;
Break;
end;

If FileExists(ScriptPath + 'RestartSimba' + ScriptName + IntToStr(PID) + '.cmd') then
begin
WriteLn('Calling Crash Smart File. Name : RestartSimba' + IntToStr(PID) + '.cmd');
OpenWebPage(ScriptPath + 'RestartSimba' + ScriptName + IntToStr(PID) + '.cmd');
WriteLn('Current Simba / Script Title : ' + Title + ' PID : ' + IntToStr(PID));
TerminateScript;
end;

WriteLn('Current Simba / Script Title : ' + Title + ' PID : ' + IntToStr(PID));

If WriteToFile('Taskkill /F /PID ' + IntToStr(PID) + #13 + #10 + 'cd ' + AppPath + #13 + #10 + 'Simba.exe -o ' + ScriptPath + ScriptName + ' -r' + #13 + #10 +
'ping -n 02 127.0.0.1 >NUL' + #13 + #10 + 'DEL ' + ScriptPath + 'RestartSimba' + ScriptName + IntToStr(PID) + '.cmd', 'RestartSimba' + ScriptName + IntToStr(PID) + '.cmd') then
WriteLn('Crash Smart File Created. Name : RestartSimba' + IntToStr(PID) + '.cmd');
end;

procedure RestartIt;
begin
CrashSmart('Home21200Run.simba');
end;



begin
CrashSmart('Home21200Run.simba');
Smart_Server := 39;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
SetupSRL;
SRL_Procs[srl_OnRSUpdate] := @RestartIt;
DeclarePlayers;
LoginPlayer;
end;


Ask questions if any.
Future update when newest Simba is released to you don't have to input Script Name anymore.




~Home

Abu

2012-03-23 04:01:29

I'll let you know if this works nicely in 6 hours time :)

Home

2012-03-23 04:03:15

From: abu_jwka
I'll let you know if this works nicely in 6 hours time :)



Please try it couple times before running :P

~Home

Abu

2012-03-23 12:31:33

I'm sorry but I get an error when trying to put it in my script:

[Error] (285:40): colon (':') expected at line 284

That's basically where I enter my Script name, like this:
procedure CrashSmart(AbusAirKrafterVersion2.simba); 


In fact, when I put in any script name, even NarclesFastFighter it won't work - I still get this error.

Sex

2012-03-23 12:38:24

From: abu_jwka
I'm sorry but I get an error when trying to put it in my script:

[Error] (285:40): colon (':') expected at line 284

That's basically where I enter my Script name, like this:
procedure CrashSmart(AbusAirKrafterVersion2.simba); 


In fact, when I put in any script name, even NarclesFastFighter it won't work - I still get this error.


That line declares the procedure and will need to stay as:
procedure CrashSmart(ScriptName : string);
Then when you call it in your script, you just do
CrashSmart('AbusAirKrafterVersion2.simba');

On a side note, when the next version of Simba is released, a GetProcessID function has been added as well as a ScriptFile constant :).

Abu

2012-03-23 14:09:27

From: Sex
That line declares the procedure and will need to stay as:
procedure CrashSmart(ScriptName : string);
Then when you call it in your script, you just do
CrashSmart('AbusAirKrafterVersion2.simba');


And where would I call this?

Sex

2012-03-23 14:13:06

I don't know, really. Home doesn't explain it. Maybe at the beginning of your script? Or every 6 hours? Not quite sure.

i3egoHan

2012-03-23 14:37:04

Make sure you have taskill first… Else this wont work.

Home

2012-03-23 14:50:40

From: i3egoHan
Make sure you have taskill first… Else this wont work.


It has Taskkill first ;)


And how does this work.

1. You put it in your MainLoop. Before anything.
2. It will create an CMD file which has your current Simba PID, Script Name, + File path where we created current CMD file.
3. You can call it whenever you wan't again. Ex. If not loggedin Then CrashSmart;
4. When you Call Procedure again it will Run CMD file and restart simba and clean the old CMD file (This is little bit bugged, I will find solution for this later).


There is no need to use it. SmartManager is extremely nice piece of program, but I just thought that if people wan't to do it without modifying plugins and just with simba. It can be done.


~Home

Brandon

2012-03-23 15:13:57

I'd rather do AddOnTerminate(CrashSmart); compared to being logged in..
Should put this into an extension with the ScriptName feature that Simba has?

Can always do GetModuleFileName(….); extern std_call or whatever.. it'll give u the script location and name. That is if you decide to do this as an extension or purely Simba.

Home

2012-03-23 16:50:40

From: ggzz
I'd rather do AddOnTerminate(CrashSmart); compared to being logged in..
Should put this into an extension with the ScriptName feature that Simba has?

Can always do GetModuleFileName(….); extern std_call or whatever.. it'll give u the script location and name. That is if you decide to do this as an extension or purely Simba.


I'v been thinking about it. ggzz you can freely edit code and make it extension and so on : ) This was more like that it can be done via script.

So all of you can improve it and so on :)

~Home

bg5

2012-03-23 22:43:30

Well ,I was thinking about something like that before ,but didn't know the way how to execute file by Simba. So I was mucking with sending signal from simba to external application ,which would run cmd/bat.
But you can simply execute file using OpenWebPage ,lol I'm amazed.

And good job:)

kunzy

2012-03-25 01:33:26

works, good job very smart =D

jkmp

2012-05-10 17:08:36

does simba have to be open or can it be minimized?

Abu

2012-05-12 08:07:21

From: jkmp
does simba have to be open or can it be minimized?


As long as it's running it should work.

Adamcoled

2012-05-12 08:45:52

So I could use this in a script without having to use smart manager to get past the 6 hour limit?

bg5

2012-05-12 09:21:54

From: Adamcoled22
So I could use this in a script without having to use smart manager to get past the 6 hour limit?


yes

@Topic

I think .simba should be added here, to patch:
  If WriteToFile('Taskkill /F /PID ' + IntToStr(PID) +  #13 + #10 + 'cd ' + AppPath + #13 + #10 + 'Simba.exe -o ' + ScriptPath + ScriptName + ' -r' + #13 + #10 +

  If WriteToFile('Taskkill /F /PID ' + IntToStr(PID) +  #13 + #10 + 'cd ' + AppPath + #13 + #10 + 'Simba.exe -o ' + ScriptPath + ScriptName +'.simba'+ ' -r' + #13 + #10 +