Page 1 of 10

Automatic 'login' script

Posted: Mon Feb 18, 2013 7:35 am
by rock5
Login.lua

This script automatically starts a client, clicks the account, selects the character and enters the game. Then it starts the bot and passes any left over arguments to the bot. This script is only required if you want to initially start the game client with a script.

Installation:
  • - Put login.lua in your 'rom' folder.
    - Put shortcut links to your game clients in your 'rom' folder, preferably renamed to something short, eg. rom4u. If you only use one client then name the link "rom" and it will be used by default. No need to use the "client" argument. If you want to change the default then change the variable at the top of the userfunction_login.lua file.
Requirements:
  • - A Version of my 'fastlogin' addon with the 65 or 108 login buttons.
    - The userfunction_login.lua installed in the userfunction folder.
Syntax:
    • rom/login acc:accountnum char:charnum client:shortcutname
    as well as the bot arguments such as 'path' and 'profile'. As usual, the order of the arguments doesn't matter.

    "acc" and "char" are mandatory but "client" is optional if the default link "rom" exists.
Examples:
  • From the Micromacro console

Code: Select all

rom/login acc:48 char:2 client:rom4u path:cot_tele
  • Or starting multiple clients from a batch file

Code: Select all

FOR /F "tokens=1 delims=" %%A in ('cd') do SET folder=%%A
START ../../micromacro.exe "%folder%/login.lua" acc:45 char:1 client:rom4u path:path1
START ../../micromacro.exe "%folder%/login.lua" acc:46 char:1 client:rom4u path:path2
START ../../micromacro.exe "%folder%/login.lua" acc:47 char:1 client:rom4u path:path3
Limitations:
  • As of version 3 there are no limitations. Clients can be started at the same time. The login script keeps track of which bot has the active window.
Features:
  • - It makes sure it connects to the just-started client. It wont get mixed up if other clients are already open.
    - Because __WIN and __PROC are already set, when the bot starts, it doesn't need the 'character' argument to know which client to connect to.
    - The mouse clicks are accurate regardless of the window shape or size.
    - The shortcuts don't need the NoCheckVersion set. The script handles it.
    - It avoids conflicts when multiple logins need the clients active at the same time, so you can start them at the same time.

userfunction_login.lua
  • This file has all the actual login functions. This is the only file required to make use of the new restart options available in the LoginNextChar userfunction.
Installation:
  • - Put shortcut links to your game clients in your 'rom' folder, preferably renamed to something short, eg. rom4u. If you only use one client then name the link "rom" and it will be used by default. No need to use the "client" argument. If you want to change the default then change the variable at the top of the file.
    - New option: I've added support for a server/link list. It will still default to 'rom' link so if you only use the one link you don't need to use the server/link list. But if you do use more than one link, you can include a file in the same folder as userfunction_login.lua, called 'ServerLinkList.lua', for the other links besides 'rom'. So you can still avoid having to use the client argument. Eg. mine looks like this

    Code: Select all

    ServerLinkList = {
       ["Sin City"] = "rom4u",
       ["Angel City"] = "rom4u",
    }
    - The userfunction.login.lua goes in the "userfunctions" folder.
Userfunction "login" syntax:
  • Changed in version 3 to be more user friendly.
    • login(charnum, accountnum, "shortcutname")
    This userfunction just starts the client. It does not use other bot arguments such as 'path' and 'profile', you can always follow it with a "loadPaths" and "loadProfile". The order of the arguments does matter.
Example:

Code: Select all

login( 2,48, "rom4u")
You can also use the killClient() command to kill the current client before you start another with the login function.

Re: Automatic 'login' script

Posted: Mon Feb 18, 2013 3:44 pm
by Ego95
Nice rock :)
It works fine, I just had to copy the micromacro folder onto the desktop because it errors if the micromacro folder is in a sub folder.
For which situations can this be used? Is it possible the start the client again if the game crashes?

AlterEgo95

Re: Automatic 'login' script

Posted: Tue Feb 19, 2013 12:41 am
by rock5
I wanted to do something more complete that could do that but there was no way to match up (well no easy way) to match up account and player names with the account number and character number. If the game crashed you would only potentially know the character name and account name. So after the client crashes you couldn't get the account number and character number.

If you don't change character and just want to reload the same character you might be able to do it. You would have to override the crash handler.

I'll do a bit of testing and get back to you.

Re: Automatic 'login' script

Posted: Tue Feb 19, 2013 3:01 am
by rock5
This is proving to be too diffcult to do. I can make it restart the client but it immediately has a memory read failure. I'm updating __WIN and __PROC but for some reason local proc variables get reset to nil. I can't figure it out. Maybe the atError function can't be recovered from.

Sorry.

Re: Automatic 'login' script

Posted: Tue Feb 19, 2013 11:32 am
by dx876234
I'm using something similar, to restart the client u can catch the error in rombot, check if client is running and call Rock's login script. Since your in MM u can get hold of account/character I guess, Im using fastlogin which keeps track of it.

Ex.

Code: Select all

-- PSEUDO CODE...

atError(autologErrorCallback)

function autologErrorCallback(script, line, message)
	yrest(secondsToTimer(30))
	if( not windowValid(getAttachedHwnd()) ) then		
		printf("No client attached, restarting client!\n")

               -- Fill in with correct account/character/client/script
		os.exec(rom/login acc:48 char:2 client:rom4u path:cot_tele")
		os.exit()
	end
end
But there is one cavat, rombot doesnt always trigger an error until the client window closes.

To make sure client closes on crashes I use aseparate lua session running the following to clean up crashed clients:

Code: Select all

	-- Keep watch for the RoM client Crash window
	-- and terminate when detected
	repeat
		local win = findWindow("Crash Report", "#32770")
		if( win > 0 ) then
			printf("Found window [%s/%s]\n", getWindowName(win), getWindowClassName(win))
			local pid = findProcessByWindow(win)
			os.execute("TASKKILL /PID " .. pid .. " /F")
		end
		yrest(secondsToTimer(5))
	until false
regards
DX

Re: Automatic 'login' script

Posted: Tue Feb 19, 2013 12:33 pm
by rock5
The separate session to clean up clients is a good idea. That was one of the problems I was having, the bot either didn't detect the crash or hung in a loop somewhere.

Re: Automatic 'login' script

Posted: Tue Feb 19, 2013 8:18 pm
by grande
You guys are awesome. Thanks for making the game even more enjoyable and easy to access. Very well done. Thanks rock5!

Re: Automatic 'login' script

Posted: Wed Feb 20, 2013 12:27 am
by kenzu38
Hoho, this is really cool. Thanks for this, rock! :D

Anyway, will you still work on the auto-detect thing when client crashes?

Re: Automatic 'login' script

Posted: Wed Feb 20, 2013 1:45 am
by rock5
Not at the moment, no. I'm doing other things now and don't have the time for it. The basics are there above so maybe someone else will figure it out. I might post the version of login I made that has the login function in a function that could be called from the error event. That might make it easier for someone to get it to work.

Re: Automatic 'login' script

Posted: Wed Feb 20, 2013 3:24 am
by kenzu38
Hey rock, tried version 2 just a while ago. It's giving me this error:

Code: Select all

functions.lua:277: bad argument #1 to 'windowValid' (number expected, got nil)
I looked into functions.lua and these seem to be the problem lines:

Code: Select all

function getProc()
	if( __PROC == nil or not windowValid(__WIN) ) then
		if( __PROC ) then closeProcess(__PROC) end;
		__PROC = openProcess( findProcessByWindow(getWin()) );
Made sure to follow instructions and all files are in the right place.

Any idea how I can fix this?

Thanks.

Re: Automatic 'login' script

Posted: Wed Feb 20, 2013 3:54 am
by rock5
I didn't say the login function would work, how ever you tried to use it. I did say above that I couldn't get rom to recover from a crashed client. I supplied version 2 so tinkerers would have another way of calling the function and maybe get it working themselves. Only the initial command works as it is at the moment.

It's also possible that you are trying to use the first command but have used an incorrect argument. In that case, just double check your arguments.

Re: Automatic 'login' script

Posted: Wed Feb 20, 2013 4:47 am
by kenzu38
Hmm, now I'm confused. I thought this was something I could use on my waypoint scripts to start another client for my KS farmer party.

So just to be clear, the code you posted:

Code: Select all

rom/login acc:48 char:2 client:rom4u path:cot_tele
Can I use the above in my waypoint scripts?

Re: Automatic 'login' script

Posted: Wed Feb 20, 2013 4:49 am
by lisa
kenzu38 wrote:Can I use the above in my waypoint scripts?
You need to put that code in a micromacro window that isn't doing anything else.

Re: Automatic 'login' script

Posted: Wed Feb 20, 2013 7:35 am
by kenzu38
Lol I see. So I guess I'll have to use os.execute to put this in a waypoint script?

Ok, thanks lisa for clearing it up. :)

EDIT: Ok just tested and os.execute works. Thanks again for this, rock! :)

Re: Automatic 'login' script

Posted: Tue Feb 26, 2013 6:08 pm
by Bot_romka
Automatic restart after crash.

Put this code in onload WP, or Profile onload.
_Sorry for my bad English. Пишу как могу, по английски я только читать умею ;)

Code: Select all

		local currAcc = RoMScript("LogID")
		local currChar = RoMScript("CHARACTER_SELECT.selectedIndex")
		local dirPath = getExecutionPath()
		local currPath = __WPL.FileName
		local Clientlink = false			-- specify you client shortcut links name if it not contains *client*

		if( Clientlink == false ) then
			local romdir = getDirectory(dirPath)
			for i,v in pairs(romdir) do
				local match = string.match(string.lower(v), "client(.*)%.lnk")
				if( match ~= nil ) then
					Clientlink = v
				end
			end
		end;
		cprintf(cli.white, "Current Acc: %s, Char: %s, Path: %s, dirPath: %s, Client: %s\n", currAcc, currChar, currPath, dirPath, Clientlink)

		function AutoRestartAfterCrash()
			yrest(secondsToTimer(30))
			if( not windowValid(getAttachedHwnd()) ) then
				-- Crash Log
				local filename = ""..dirPath.."/logs/CrashLog.log";
				local file, err = io.open(filename, "a+");
				if file then
					file:write("Account: "..currAcc.." \tName: " ..string.format("%-10s",player.Name ).." \tDate: "..os.date().." \tPath: "..currPath.." \n")
					file:close();
				end
				-- Restart client and Bot
				os.execute("START "..dirPath.."/../../micromacro.exe "..dirPath.."/login acc:"..currAcc.." char:"..currChar.." client:"..Clientlink.." path:"..currPath.."")
				os.exit()
			end
		end;

		if( Clientlink ) then
			atError(AutoRestartAfterCrash)
		end;

Re: Automatic 'login' script

Posted: Wed Feb 27, 2013 5:23 am
by kenzu38
Wow, I thought it would be more complicated than that when I read the other codes posted in this thread.

Will give this a try. Thanks for sharing your code Bot_romka! :D

EDIT: I suggest making this into an official userfunction since people will need this in every WP.

Or better yet, rock, what do you say about integrating it to the bot itself?

Re: Automatic 'login' script

Posted: Wed Feb 27, 2013 6:00 am
by rock5
Well, how about a description of what it does and how well it works first?

It relies on the login script so I wouldn't include it in the bot but it could be included in the login script.

Re: Automatic 'login' script

Posted: Wed Feb 27, 2013 6:37 am
by Bot_romka
I try this.
Code from userfunction_login.lua cant be used because after restart client Bot stops with an error message. Need to completely restart client and Bot with waypoint. Or do something to disable the error messages after restart cient.

Re: Automatic 'login' script

Posted: Wed Feb 27, 2013 6:47 am
by kenzu38
Ah yeah, this relies on the fastlogin addon.

Well anyway, I don't know how to force a crash so I'll have to wait for dailies to reset to test this script. Will just post the test results here.

Re: Automatic 'login' script

Posted: Wed Feb 27, 2013 8:51 am
by Bot_romka
For testing i manually crash client with ROMeo's Multihack. For kill client use Ctrl+K