Jump to content
Sign in to follow this  
TheRevenor

[Feature] - Close Emulator When No Connection Internet

Recommended Posts

This is more a feature for MOD authors than users. This is for you. :peace:

Inspired by: https://mybot.run/forums/index.php?/topic/17358-shut-down-pc-when-no-internet/

Function: When Not Connection Internet It Will close Emulator To Save RAM Usage And Will Be Back Open Emulator And Start CoC When Internet Reconnected:thumbsup:

 

Update For v6.2.x

 

xp9f7E9.png

 

Users can disable the Check Internet Connection by going to the Bot tab and toggling the "Check Internet Connection" option.

See the results log Like This:

3ctpiC0.png

Step 1:  Open MBR GUI Design Child Bot - Options.au3 (Folder 'COCBot\GUI') 

Spoiler

Replace:

Local $x = 20, $y = 95
$grpOnLoadBot = GUICtrlCreateGroup(GetTranslated(636,2, "When Bot Loads"), $x - 20, $y - 20, 210, 100)
	$y -= 4

With:

Local $x = 20, $y = 70
$grpOnLoadBot = GUICtrlCreateGroup(GetTranslated(636,2, "When Bot Loads"), $x - 20, $y - 20, 210, 120)
	$y -= 4
	$chkConnection = GUICtrlCreateCheckbox("Check Internet Connection", $x, $y, -1, -1)
		$txtTip = "Check if your Internet Connection Lost Will Close Emulator" & @CRLF & _
				"     AND IF YOUR INTERNET RECONNECTED, WILL BE BACK START EMULATOR"
		_GUICtrlSetTip(-1, $txtTip)
		GUICtrlSetState(-1, $GUI_CHECKED)
	$y += 20

 

Step 2: Open MBR GUI Design Child Bot.au3 (Folder 'COCBot\GUI')

Spoiler

Replace:

Global $chkVersion, $chkDeleteLogs, $chkDeleteTemp, $chkDeleteLoots

With:

Global $chkConnection, $chkVersion, $chkDeleteLogs, $chkDeleteTemp, $chkDeleteLoots

 

Step 3: Open MBR Global Variables.au3 (Folder 'CocBot')

Spoiler

Replace:

;TH Snipe Before Attack
Global $THSnipeBeforeDBEnable = 0 , $THSnipeBeforeLBEnable = 0
Global $THSnipeBeforeDBTiles = 0 , $THSnipeBeforeLBTiles = 0
Global $THSnipeBeforeDBScript = 0 , $THSnipeBeforeLBScript = 0

With:

;TH Snipe Before Attack
Global $THSnipeBeforeDBEnable = 0 , $THSnipeBeforeLBEnable = 0
Global $THSnipeBeforeDBTiles = 0 , $THSnipeBeforeLBTiles = 0
Global $THSnipeBeforeDBScript = 0 , $THSnipeBeforeLBScript = 0

; Check Connections - by TheRevenor
Global $ichkConnection = 1

 

Step 4: Open MBR Functions.au3 (Folder 'CocBot')

Spoiler

Replace:

#include "functions\Other\CloseRunningBot.au3"

With:

#include "functions\Other\CloseRunningBot.au3"

; Check Connections - Added by TheRevenor
#include "functions\Other\CheckConnection.au3"

 

Step 5: Open applyConfig.au3 (Folder 'COCBot\functions\Config')

Spoiler

Replace:

; apply bot options -----------------------------------------------------------------

With:

; apply bot options -----------------------------------------------------------------

; Check Connections - Added by TheRevenor
	If $ichkConnection = 1 Then
		GUICtrlSetState($chkConnection, $GUI_CHECKED)
	Else
		GUICtrlSetState($chkConnection, $GUI_UNCHECKED)
	EndIf

 

Step 6: Open readConfig.au3 (Folder 'COCBot\functions\Config')

Spoiler

Replace:

$ichkLanguage = IniRead($config, "General", "ChkLanguage", "1")

With:

$ichkLanguage = IniRead($config, "General", "ChkLanguage", "1")

; Check Connections - Added by TheRevenor
$ichkConnection = IniRead($config, "general", "ChkConnect", "1")

 

Step 7: Open saveConfig.au3 (Folder 'COCBot\functions\Config')

Spoiler

Replace:

; bot options gui -> variables ----------------------------------------------------

With:

; bot options gui -> variables ----------------------------------------------------
; Check Connections - Added by TheRevenor
If GUICtrlRead($chkConnection) = $GUI_CHECKED Then
	$ichkConnection = 1
Else
	$ichkConnection = 0
EndIf
IniWriteS($config, "general", "ChkConnect", $ichkConnection)

 

Step 8: Open checkObstacles.au3 (Folder 'COCBot\functions\MainScreen')

Spoiler

Replace:

SetLog("Connection lost, Reloading CoC...", $COLOR_RED)

With:

SetLog("Connection lost, Reloading CoC...", $COLOR_RED)
ChckInetCon()

 

Step 9: Add CheckConnection.au3 to (folder 'COCBot\functions\Other')

Spoiler
; #FUNCTION# ====================================================================================================================
; Name ..........: Check Connection
; Description ...: Close Emulator When Connection Lost
; Syntax ........:
; Parameters ....:
; Return values .: None
; Author ........: TheRevenor(July, 2016)
; Modified ......:
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2016
;                  MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================

#include <MsgBoxConstants.au3>

Func ChckInetCon()
Local $i = 0
If GUICtrlRead($chkConnection) = $GUI_CHECKED Then
	;$ichkConnection = 1
	;MsgBox($MB_SYSTEMMODAL, "Close Emulator", "No Internet Connection Will Close Emulator", 5)
	SetLog("Lost Internet Connection Waiting Few Sec Before Close Emulator", $COLOR_RED)
	While $i < 5
		$ping = Ping("8.8.8.8")
		If $ping = 0 Then
			$i = $i + 1
			SetLog("My Ping: " & $Ping & "ms.", $COLOR_RED)
		ElseIf $ping > 0 Then
			SetLog("My Ping: " & $Ping & "ms.", $COLOR_GREEN)
			SetLog("Internet Reconnected Close Emulator Canceled", $COLOR_GREEN)
		ExitLoop
		Else
			$i = 0
		EndIf
		Sleep(4500)
	WEnd
Else
	If $debugsetlog = 1 Then Setlog("Check Internet Connections skip", $COLOR_PURPLE)
	Return ; exit func if no checkmarks
EndIf
; If the script gets here, we missed 5 pings - take action.
If $ping = 0 Then
	If $AndroidEmbedded = True Then
		btnEmbed()
	EndIf
	If _Sleep(5000) Then Return
	CloseAndroid()	 ; Close Emulator
	If _Sleep(4000) Then Return
	SetLog("Waiting Internet Connection..", $COLOR_BLUE)
	CheckConnection()
EndIf
EndFunc ;==>ChckInetCon

Func CheckConnection()
Local $AmIConnected = "init"
While $AmIConnected <> "True"
	$ping = Ping("8.8.8.8")
	If $ping = 0 Then
		SetLog("My Ping: " & $Ping & "ms.", $COLOR_RED)
	ElseIf $ping > 0 Then
		SetLog("My Ping: " & $Ping & "ms.", $COLOR_GREEN)
		$AmIConnected = "True"
	EndIf
	Sleep(5000)
WEnd
SetLog("Internet Reconnected Will Start Emulator", $COLOR_BLUE)
StartAndroidCoC()	; Open Emulator
_PushToPushBullet(@HOUR & ":" & @MIN &" - " & $iOrigPushBullet & " | Internet Reconnected After Lost Connection - Open Emulator and CoC..")
EndFunc ;==>CheckConnection

 

Finish and Enjoy it :thumbsup:

And Give Me Feedback ;)

Edited by TheRevenor
New Update For v6.2.2
  • Upvote 11

Share this post


Link to post
Share on other sites
hace 43 minutos, gamer0308 dijo:

Cool but is there any way i can change this to reboot the pc?

If _Sleep(5000) Then Return
	CloseAndroid()	 ; Close Emulator

 

You need to add Shutdown (2) to restart normally, but if you want to force applications to close you should use Shutdown (6).

 
  • Upvote 1

Share this post


Link to post
Share on other sites
58 minutes ago, Finijumper said:

 

You need to add Shutdown (2) to restart normally, but if you want to force applications to close you should use Shutdown (6).

 

Okee do i need to replace the close android line with the shutdown(6) command?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...