Automatic 'login' script

Additional botting resources. Addons may be either for the game itself or for the RoM bot.
Forum rules
Only post additional bot resources here. Please do not ask unrelated questions.
Post Reply
Message
Author
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Automatic 'login' script

#1 Post by rock5 » Mon Feb 18, 2013 7:35 am

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.
Attachments
userfunction_login.lua
Version 3.5 - Saves current server and character to help with recovering from crashes.
- Added ServerLinkList.lua support
- Added a few improvements to make starting multiple clients at once.
- killClient now makes sure the client dies.
(10.29 KiB) Downloaded 781 times
login.lua
Version 3.1 - Fixed bug that caused the callback functions (such as pausing) to revert to default.
(1.32 KiB) Downloaded 734 times
userfunction_login.lua
Version 3.3 - Last version to support 65 login buttons.
(8.16 KiB) Downloaded 512 times
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
Ego95
Posts: 564
Joined: Tue Feb 28, 2012 12:38 pm
Contact:

Re: Automatic 'login' script

#2 Post by Ego95 » Mon Feb 18, 2013 3:44 pm

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

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatic 'login' script

#3 Post by rock5 » Tue Feb 19, 2013 12:41 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatic 'login' script

#4 Post by rock5 » Tue Feb 19, 2013 3:01 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

dx876234
Posts: 188
Joined: Sat Jul 24, 2010 6:13 am

Re: Automatic 'login' script

#5 Post by dx876234 » Tue Feb 19, 2013 11:32 am

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

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatic 'login' script

#6 Post by rock5 » Tue Feb 19, 2013 12:33 pm

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
grande
Posts: 261
Joined: Tue Jun 28, 2011 4:46 pm

Re: Automatic 'login' script

#7 Post by grande » Tue Feb 19, 2013 8:18 pm

You guys are awesome. Thanks for making the game even more enjoyable and easy to access. Very well done. Thanks rock5!

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Automatic 'login' script

#8 Post by kenzu38 » Wed Feb 20, 2013 12:27 am

Hoho, this is really cool. Thanks for this, rock! :D

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

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatic 'login' script

#9 Post by rock5 » Wed Feb 20, 2013 1:45 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Automatic 'login' script

#10 Post by kenzu38 » Wed Feb 20, 2013 3:24 am

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.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatic 'login' script

#11 Post by rock5 » Wed Feb 20, 2013 3:54 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Automatic 'login' script

#12 Post by kenzu38 » Wed Feb 20, 2013 4:47 am

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?

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Automatic 'login' script

#13 Post by lisa » Wed Feb 20, 2013 4:49 am

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.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Automatic 'login' script

#14 Post by kenzu38 » Wed Feb 20, 2013 7:35 am

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! :)

User avatar
Bot_romka
Posts: 96
Joined: Tue Apr 05, 2011 2:59 am
Location: Russia

Re: Automatic 'login' script

#15 Post by Bot_romka » Tue Feb 26, 2013 6:08 pm

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;
Last edited by Bot_romka on Wed Feb 27, 2013 12:54 pm, edited 9 times in total.

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Automatic 'login' script

#16 Post by kenzu38 » Wed Feb 27, 2013 5:23 am

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?

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatic 'login' script

#17 Post by rock5 » Wed Feb 27, 2013 6:00 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
Bot_romka
Posts: 96
Joined: Tue Apr 05, 2011 2:59 am
Location: Russia

Re: Automatic 'login' script

#18 Post by Bot_romka » Wed Feb 27, 2013 6:37 am

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.

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Automatic 'login' script

#19 Post by kenzu38 » Wed Feb 27, 2013 6:47 am

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.

User avatar
Bot_romka
Posts: 96
Joined: Tue Apr 05, 2011 2:59 am
Location: Russia

Re: Automatic 'login' script

#20 Post by Bot_romka » Wed Feb 27, 2013 8:51 am

For testing i manually crash client with ROMeo's Multihack. For kill client use Ctrl+K

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests