Jump to content

Finding and acting upon a command.


Drew
 Share

Recommended Posts

Alright I'm working on a program that will help some of my buddies who run a server which hosts a game for public use. The problem? Occasionally the game server, D2CS, will crash and needs to be rebooted. I'm writing a program that will coincide with a bot to allow certain, trusted, users to restart the game server in a safe manner without having to grant them server access.

The bot, one I did not write, accepts commands starting with " . ". ( A period. Ie: .say Hello )

Since I do not want users to know what command actually triggers this, I'm going to have a " . " command make the bot talk to itself, sending itself a message containing the text I want to trigger to restart the GS.

For Example:

A trusted user types: .GS

I want the bot to msg itself containing a passcode if you will, that my AutoIt program will act upon. ( When the bot msg's itself, the msg still pops up on the screen for AutoIt Window Info tool to read. ) Restarting the GS is a simple task, but the person doing it has alot of access to alot of other things some may not be trusted with.

~~~~~~~~~~~~~~~~~~~~

What I mainly need to know , is how can I set the program to react to a certain text line. AutoIt Window Info Tool reads the text just fine, so I don't think a OCR is necessary. If the Window Tool could read it, I suppose a program could just as easily only will react to certain things.

Please let me know how I should do this. If theres a place in the Help File that I'm missing but would help me out please say so. I'll go look again, but I've looked many times. If someone can help me get walking on this, I'll be running in no time.

Thanks again,

*Drew

Edited by Drew
Link to comment
Share on other sites

Why isn't the reboot taking place automatically? If its a Windows server you can set it to automatically reboot if it blue-screens.

If its not blue-screening and your program is just crashing I would first try to fix it rather than rebooting constantly and if all else fails write a script to watch your program to determine if its unresponsive.

Link to comment
Share on other sites

It only reboots automatically if it was crashed under natural ( if you'd call it that ) causes. It crashes due to hacking. ( Packet senders, etc. )

I'm currently working on a anti-hack program to do away with that as well, but I need this in the time being because me and the owners of the server can't be online at all times in case the game server goes down.

I found a way where I can have the text in the bots screen into a MsgBox, but it doesn't just get certain text... It gets it all.

Example:

AutoItSetOption("WinDetectHiddenText", 1)

$GS = WinGetText( "[Disconnected] - StealthBot v2.6 Revision 3", ".GS")

MsgBox( 1, "GS", $GS)

Heres the help file command I'm going off of: WinGetTitle ( "title" [, "text"] )

I thought the "text" part would be what it would look for, and if it finds it to return it in the MsgBox.

Link to comment
Share on other sites

Maybe you would be better off using an e-mail method for this. Have a special email account setup that a script on the server checks every 5 minutes or so. The script will look for a predefined key code in the body of the e-mail which tells it to restart. This will allow to share a key with people and change it as you see fit.

Link to comment
Share on other sites

Alright, heres a rather obvious finding.

If WinGetText finds it, it "can" return it all... But if it doesn't, it returns a 0. I just needed to know if it found it or not, it returning the info isn't necessary.

Alright so now I have that and heres my current script:

AutoItSetOption("WinDetectHiddenText", 1)

While 1

$GS = WinGetText( "[Disconnected] - StealthBot v2.6 Revision 3", "All connections closed.")

If @error = 0 Then 
    Sleep( 60000)
EndIf
If Not @Error Then
;
;
;This is where you make the bot check if its running, and if not, restart it.
;
;
EndIf
WEnd
Link to comment
Share on other sites

The description of the code you are already using is poor. It sounds like you may be using the simple chat example for the Tcp* functions in the help file. If that is the case you shouldn't be intercepting MsgBox() windows on the server.

The commands are already being sent to the running program, you just need to use StringInStr() to check that the sent string (TcpRecv) contains the passphrase. You shouldn't have MsgBox()'s popping up on your server when a user initiates the restart, maybe a traytip saying "The server will restart in 60 seconds".

Link to comment
Share on other sites

( I'm not using any examples, all of that was hand typed. Just ideas I'm coming up with how to go about this. If there is a easier, more productive way than please let me know. I'm not new to AutoIt in general, but don't know whole lot. )

No the MsgBox was just something I used to test if the script was picking up on the text it was supposed to trigger on.

Alright maybe I'm going about this COMPLETELY wrong, so I'm going to describe what I'm trying to do best I can.

When the game server crashes, It needs to be MANUALLY restarted; unless you write a program that simulates these manual procedures.

The Steps To Restarting the GameServer: ( Manual version )

Sign into the Gameserver using cmd , Telnet ( ip ) and than typing in the password.

And than you just type " restart ( seconds ) " and it restarts it in the number of seconds given. VERY simple , I just need to find a way where the program can DETECT this one of two ways or as a backup method, both.

First Detection Idea: Make the program search for a command, or certain phrase in text, that will trigger the start of the program that restarts the GS.

Second Detection Idea: Create a method for the program to detect if the GameServer is LIVE by automated, periodic checking. How to do this one I'm not sure of. I've never gotten into packets, and IP things like TcpRevc. Although very interested in it.

~~~~~

Any help is greatly appreciated. Been having a little trouble, had a working program earlier but it was a little sloppy and very undependable. I had that program set up to search for the command and when it found it to Run( cmd ) , and then use Send( "" ) to tell it how to sign in and etc. and then restart it. This would have to run on my computer, because all thats doing is just simulated the manual process but in a way which sacrifices my computer. ( Which I'm willing to do, as the program will only run while I'm away from the computer because In any other case, I restart it myself. This is meant for when I'm not able to do so. )

Link to comment
Share on other sites

Its a closed realm server for Diablo 2. I'm an administrator on this closed realm, and I'm doing multiple things to help make the place more enjoyable. ( Not going to post any links to it unless someone wants to verify me an Admin. )

Past Projects: Installer , to get new members started.

Roller ( Have to play the game to really get what this was for. Just made things better for the members. )

Current Project: This one.

Next Project ( Somewhat already started on. ): Anti-Hack / Warden of sorts. Make the realm hack-free.

Future Projects: Unknown at this time.

So a huge thanks to AutoIt and its creators for what I've been able to contribute to it as of now.

Link to comment
Share on other sites

If WinGetText finds it, it "can" return it all... But if it doesn't, it returns a 0. I just needed to know if it found it or not, it returning the info isn't necessary.

If the script runs locally on the server and autologon can be set, then just do a loop with WinExists() to monitor the window titles. Add a shortcut to the script to your startup folder. Then it could be automatic.

While 1
    Select
        Case WinExists("[Disconnected] - StealthBot v2.6 Revision 3", "All connections closed.")
            _reboot()
        Case WinExists("Another title")
            _reboot()
        Case WinExists("Yet another title")
            _reboot()
    EndSelect
    Sleep(5000)
WEnd

Func _reboot()
    ; Force reboot
    Shutdown(6)
EndFunc

:)

Edited by MHz
Link to comment
Share on other sites

There's a couple of methods you can use to determine if it has crashed.

I run a Garry's Mod server(HL2 mod), and I've created an extensive restarter script for it, some of the crash-detection features are:

Detection of server process(aka. hard crashes, using ProcessExists)

Detection of crash-windows(notifications from the server software itself, using WinExists)

Uses the WinApi function IsHungAppWindow to detect if the server-window is hung(doesn't seem to have any effect on a console window though).

And last feature uses the UDP functions to request some info from the server, and if it timeouts(during the request), or doesn't receive "valid" data, it assumes it has crashed.

Hope this gives you some ideas of how you can (automatically) detect if it has crashed. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...