/// <summary> /// This function is used to determine whether the user is already logged in or not. /// </summary> /// <returns> If user is already logged-in returns the user-name, else returns null</returns> public string GetLoginStatus() { _action = ENUM.LoginActions.LoginStatus; NavigateThroughTread(_url.GetUrl(ENUM.Screens.LoginScreen)); return(_userId); }
/// <summary> /// This function is used to login to the game, It /// MUST be used after the credetials are entered. /// </summary> /// <returns> Returns the Token that instantiates other objects. /// Returns null if login-in fails</returns> public string Login() { // Logging into game _action = ENUM.LoginActions.Login; NavigateThroughTread(_url.GetUrl(ENUM.Screens.LoginScreen)); return(_sessionId); // return token }
/// <summary> /// This function performs logging-in using the user name and password information /// </summary> /// <param name="userName"> User name account </param> /// <param name="password"> password of account </param> /// <returns> Returns the username if logging-in is successfull, else it returns null </returns> public string EnterCredentials(string userName, string password) { _action = ENUM.LoginActions.EnterCredentials; // set username and password _userName = userName; _password = password; NavigateThroughTread(_url.GetUrl(ENUM.Screens.LoginScreen)); return(_userId); }
/// <summary> /// This event fires when the navigation inside theread is complete. The main actions are performed /// in this function. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PageLoaded(object sender, WebBrowserDocumentCompletedEventArgs e) { switch (_action) { case ENUM.LoginActions.LoginStatus: var worldLoginButton = Parser.FindActiveWorld(_wb, "Class", "world_button_active"); // check if the button exists // if button exists, user is already logged in, else is not _userId = worldLoginButton != null? Parser.FindNode(_wb, "name", "user").GetAttributeValue("value", "") : null; break; case ENUM.LoginActions.EnterCredentials: var mainLoginButton = Parser.FindSpanContains(_wb, "Giri"); Parser.SetValue(_wb, "User", _userName); // set user name Parser.SetValue(_wb, "Password", _password); // set password mainLoginButton.InvokeMember("click"); // Get the user id _userId = Parser.FindNode(_wb, "name", "user").GetAttributeValue("value", ""); break; case ENUM.LoginActions.Login: //Find the button to log-in var loginButton = Parser.FindSpanContains(_wb, "34."); // after loging in, continue to the next stage to enter the game _action = ENUM.LoginActions.EnterGame; loginButton.InvokeMember("click"); return; case ENUM.LoginActions.EnterGame: // check if loaded page is the correct page if (!_wb.Url.ToString().Contains("overview")) { return; } // after entering game, the next stage is to get the session id _action = ENUM.LoginActions.GetSessionId; if (_wb.Document != null) { var elementById = _wb.Document.GetElementById("map_main"); if (elementById != null) { elementById.InvokeMember("click"); // if you gett an error here check bot protection ! } } return; case ENUM.LoginActions.GetSessionId: // check if loaded page is the correct page if (!_wb.Url.ToString().Contains("main")) { return; } // get the session id which is located in the url _sessionId = Parser.GetBetween(_wb.Url.ToString(), "village=", "&screen"); _action = ENUM.LoginActions.Idle; return; case ENUM.LoginActions.Idle: // Do nothing _wb.Dispose(); break; } _action = ENUM.LoginActions.Idle; // before exiting the thread make sure the action is set back to idle Application.ExitThread(); // Stops the navigating thread }