War2.ru Slogan
News: Back by popular demand, the SMF Arcade!!!
PLAY NOW!!!!!!!!!!!!!!!!!!!!!!!!


Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Welcome to the forums! We're glad to have you here! :) You can register your account here, then feel free to introduce yourself in the Server.War2.ru board & let us know who you are on the server.

GameBot source code 21275  74

Administrator Ogre Posts: 1390 Karma: +135/-9 *****

iL

  • Administrator
  • Ogre
  • *****
  • *
  • Posts: 1390
    • View Profile
*

iL

GameBot source code
« on: July 27, 2015, 07:23:40 AM »
Well, let me publish the gamebot source code here to let you deploy it on your own hardware.

gamebot is something you can deploy yourself and i have no time to work on that.

So, it has 3 parts in it:
1. stealthbot script () - used to receive commands from users.
2. war2 - creates games, presses start, exits the game.
3. nncron script - clicks mouse and keyboard on war2 screen.
nncron uses forth language, so that is quite specific language, i hope that is resolvable problem. Feel free to rewrite it to something well-known, like autoit or w/e.

stealthbot interconnects with nncron via emtpy files appeared on the same computer. Each file update activates a trigger to start some action for nncron. Then nncron enforces some action on war2 screen (keyboard clicks most likely).
There's almost to feedback from nncron+war2 to stealtbot. Exception is the gamebot appearing on the server.

So, example on how it works:
- you whisper gow ef to stealthbot.
- stealthbot creates the file "c:\nnCron\gowef.sem"
- nncron catches that file change and enforces create_game 1 event.
- nncron begin to click different buttons with some timeouts to create game with the required properties.
- then stealthbot waits for 30 sec and creates the file "c:\nnCron\gamestep4.sem"
- nncron generates the message: "The game will be autostarted in 1.5 min".
- if game owner whispers "start", stealthbot creates "c:\nnCron\startwar2.sem" file, then nncron starts the game, then waits, then trying to exit the game and trying to exit the game creation.

- also, if gamebot doesn't appear in chat for the expected period of time, stealthbot creates the file "c:\nnCron\resetwar2.sem", then nncron kills war2 process (if existing) and starts it again.

To be continued...
Administrator Ogre Posts: 1390 Karma: +135/-9 *****

iL

  • Administrator
  • Ogre
  • *****
  • *
  • Posts: 1390
    • View Profile
*

iL

Re: GameBot source code
« Reply #1 on: July 27, 2015, 09:23:35 AM »
Well, no idea about the license to cover gamebot, let that be released under GPL license.
Stealthbot script:
Code: [Select]
' *
' * Copyright (C) 2015 il
' *
' * This program is free software; you can redistribute it and/or
' * modify it under the terms of the GNU General Public License
' * as published by the Free Software Foundation; either version 2
' * of the License, or (at your option) any later version.
' *
' * This program is distributed in the hope that it will be useful,
' * but WITHOUT ANY WARRANTY; without even the implied warranty of
' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' * GNU General Public License for more details.
' *
' * You should have received a copy of the GNU General Public License
' * along with this program; if not, write to the Free Software
' * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

'il
'1.0
'&il_GameCreator:il

Public BotInChat, IsFirstJoin, TimerCheckAction, CheckActionAction, IsInGame, GameOwner
CreateObj "Timer", "TimerCheckAction"

Public BotInWork
BotInWork=0
' ----------------- Create file -------------------------------
Sub CreateFile(Filename)
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set file = fso.OpenTextFile(Filename,8,True)
  file.close
End Sub
' ----------------- Delete file -------------------------------
Sub DeleteFile(Filename)
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set file = fso.DeleteFile(Filename)
  file.close
End Sub
' ----------------- Write to file -----------------------------
Sub WriteToFile(Filename,Message)
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set file = fso.OpenTextFile(Filename, 2, False)
  file.WriteLine Message
  file.Close
End Sub
' ----------------- log ---------------------------------------
Sub Log(Message)
 AddQ "/w il " & Message
End Sub
' ----------------- Timer to check if command is finished -----
Sub TimerCheckAction_Timer()
  Log "timer event handled: " & CheckActionAction
  If IsInGame = 0 Then
    TimerCheckAction.Enabled = False
    WriteToFile  "c:\nnCron\resetwar2.sem", ""
    Init
  Else
    WriteToFile "c:\nnCron\gamestep" & IsInGame & ".sem", ""
    IsInGame = IsInGame - 1
  End If
End Sub
' ----------------- Start timer to check required action ------
Sub CheckAction(Interval, Action)
  Log "starting timer"
  TimerCheckAction.Interval = Interval
  CheckActionAction = Action
  TimerCheckAction.Enabled = True
End Sub
' ----------------- Init --------------------------------------
Sub Init()
  BotInChat = 0
  IsFirstJoin = 1
  IsInGame = 0
  CheckAction 20000, "IsFirstJoin"
End Sub
' ----------------- user whispers command ---------------------
Sub il_Event_WhisperFromUser(Username, Flags, Message, Ping)


If BotInWork = 0 Then

 Select Case Message
  Case "gow ef"
   If BotInChat = 1 Then
    WriteToFile "c:\nnCron\gowef.sem", ""
    AddQ Username & " requested gow ef, join"
    AddQ "/w " & Username & " please, whisper 'start' when ready, autostart in 2 min"
    CheckAction 30000, "PlayersWaiting"
    IsInGame = 4
    BotInChat = 0
    GameOwner = Username
   Else
    AddQ "/w " & Username & " please, wait GameBot on channel"
   End If
  Case "gow f"
   If BotInChat = 1 Then
    WriteToFile "c:\nnCron\gowf.sem", ""
    AddQ Username & " requested gow f, join"
    AddQ "/w " & Username & " please, whisper 'start' when ready, autostart in 2 min"
    CheckAction 30000, "PlayersWaiting"
    IsInGame = 4
    BotInChat = 0
    GameOwner = Username
   Else
    AddQ "/w " & Username & " please, wait GameBot on channel"
   End If
  Case "chop"
   If BotInChat = 1 Then
    WriteToFile "c:\nnCron\chop.sem", ""
    AddQ Username & " requested chop, join"
    AddQ "/w " & Username & " please, whisper 'start' when ready, autostart in 2 min"
    CheckAction 30000, "PlayersWaiting"
    IsInGame = 4
    BotInChat = 0
    GameOwner = Username
   Else
    AddQ "/w " & Username & " please, wait GameBot on channel"
   End If
  Case "start"
   If IsInGame > 0 Then
    Select Case Username
     Case GameOwner
      AddQ "/w " & Username & " starting game now"
      WriteToFile "c:\nnCron\gamestep1nc.sem", "" ' start, without cancel if failed
      CreateFile "c:\nnCron\mute.sem"
     Case Else
      AddQ "/w " & Username & " you are not game owner to start it"
    End Select
   Else
    AddQ "/w " & Username & " game is not requested, nothing to start"
   End If
  Case "resetwar2"
   Log "User " & Username & " restarted war2"
   TimerCheckAction.Enabled = False
   WriteToFile  "c:\nnCron\resetwar2.sem", ""
   Init
   
  Case Else
   AddQ "/w " & Username & " Please type 'gow ef', 'gow f' or 'chop'"
 
 End Select

 Else ' BotInWork=1
  AddQ "/w " & Username & " Sorry, bot in work, try later"
 End If ' BotInWork
End Sub

' ----------------- bot joins channel -------------------------
Sub il_Event_UserJoins(Username, Flags, Message, Ping, Product, Level, OriginalStatString, Banned)
 Select Case Username
  Case "GameBot"
   BotInChat = 1
   If IsFirstJoin = 1 Then
'    WriteToFile "c:\nnCron\echo.sem", "/away Whisper to 'bot', please, I just create games, I'm a host bot"
    IsFirstJoin = 0
    TimerCheckAction.Enabled = False
    Log "Timer stopped: " & CheckActionAction
   Else
    TimerCheckAction.Enabled = False
    IsInGame = 0
    DeleteFile "c:\nnCron\mute.sem"
    Log "Timer stopped: " & CheckActionAction
   End If
'   AddQ Username & " joined channel"
 End Select

End Sub
' ----------------- bot leaves channel ------------------------
Sub il_Event_UserLeaves(Username, Flags)
 Select Case Username
  Case "GameBot"
   If BotInChat <> 0 Then
    TimerCheckAction.Enabled = False
    CheckAction 30000, "UserLeavesNoReason"
    Log "User leaved with no reason, timer started"
   End If
   BotInChat = 0
'   AddQ Username & " leaved channel"
 End Select

End Sub
' ----------------- start system ------------------------------
Sub il_Event_LoggedOn(Username, Product)
 If BotInWork = 0 Then
    WriteToFile  "c:\nnCron\startwar2.sem", ""
    Init
 End If ' BotInWork
End Sub

nncron script:
Code: [Select]
# *
# * Copyright (C) 2015 il
# *
# * This program is free software; you can redistribute it and/or
# * modify it under the terms of the GNU General Public License
# * as published by the Free Software Foundation; either version 2
# * of the License, or (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#CRONTAB FILE
# Classic crontab format:
# Minutes Hours Days Months WeekDays Years Command
# see 'example.tab'

#( purge-cron-log
    Time: 0 12 * * 5 *
    Action: PURGE-OLD: "log\*.log" 7
)#
#( mainsection

 VARIABLE SEM1 \ semaphore - 1 object - transaction for several clicks or keys

 : Click ( x y -- ) \ click to x y coords
  MOUSE-MOVE
  MOUSE-LBCLK
\  1000 PAUSE \ wait 1 second
 ;
 : enter_chat ( )
 SEM1 GET
 1000 PAUSE
 425 25 Click
 2000 PAUSE
 SEND-KEYS: "{ENTER}{DELAY 2000}{ENTER}{DELAY 200}m{DELAY 200}e{DELAY 1000}c{DELAY 3000}pAsSwOrD12{DELAY 200}GameBot{ENTER}"
 5000 PAUSE
 SEND-KEYS: "/away Whisper to 'bot', please, I just create games, I'm a host bot{ENTER}"
 SEM1 RELEASE
 ;
 : create_game ( gamename -- )
 SEM1 GET
 CASE
 1 OF \ 1=gowef
  SEND-KEYS: "@c{DELAY 1000}gow ef " \ create name browse classic gow
  10 RANDOM N>S SEND-KEYS \ name + random digit
  SEND-KEYS: "@b{DELAY 200}c{ENTER}{DELAY 200}g{ENTER}{DELAY 200}" \ browse classic gow
  SEND-KEYS: "@t{DELAY 200}{DOWN}{UP}{UP}{UP}{UP}{UP}{UP}{DOWN}{ENTER}" \ type melee
  SEND-KEYS: "@s{DELAY 200}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{LEFT}" \ speed ef
  SEND-KEYS: "@r{DELAY 200}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}" \ res high
  SEND-KEYS: "@i{DELAY 200}{DOWN}{UP}{UP}{UP}{UP}{UP}{ENTER}" \ tileset default
  SEND-KEYS: "{ENTER}" \ ok
 ENDOF
 2 OF \ 2=gowf
  SEND-KEYS: "@c{DELAY 1000}gow f " \ create name browse classic gow
  10 RANDOM N>S SEND-KEYS \ name + random digit
  SEND-KEYS: "@b{DELAY 200}l{ENTER}{DELAY 200}g{ENTER}{DELAY 200}" \ browse ladder gowbne
  SEND-KEYS: "@t{DELAY 200}{DOWN}{UP}{UP}{UP}{UP}{UP}{UP}{DOWN}{ENTER}" \ type melee
  SEND-KEYS: "@s{DELAY 200}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}" \ speed f
  SEND-KEYS: "@r{DELAY 200}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}" \ res high
  SEND-KEYS: "@i{DELAY 200}{DOWN}{UP}{UP}{UP}{UP}{UP}{ENTER}" \ tileset default
  SEND-KEYS: "{ENTER}" \ ok
 ENDOF
 3 OF \ 3=chop
  SEND-KEYS: "@c{DELAY 1000}chop " \ create name browse classic gow
  10 RANDOM N>S SEND-KEYS \ name + random digit
  SEND-KEYS: "@b{DELAY 200}o{ENTER}{DELAY 200}c{ENTER}{DELAY 200}" \ browse other chopfarms
  SEND-KEYS: "@t{DELAY 200}{DOWN}{UP}{UP}{UP}{UP}{UP}{UP}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}" \ type mapdef
  SEND-KEYS: "@s{DELAY 200}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}" \ speed f
  SEND-KEYS: "@r{DELAY 200}{DOWN}{UP}{UP}{UP}{UP}{ENTER}" \ res default
  SEND-KEYS: "@i{DELAY 200}{DOWN}{UP}{UP}{UP}{UP}{UP}{ENTER}" \ tileset default
  SEND-KEYS: "{ENTER}" \ ok
 ENDOF
 ENDCASE
 SEM1 RELEASE
 ;

 : gamestep4 ( )
 SEM1 GET
 FILE-EXIST: "c:\nnCron\mute.sem" IF
  EXIT
 THEN
 SEND-KEYS-DELAY: 20 0
 SEND-KEYS: "The game will be autostarted in 1.5 min{ENTER}"
 200 PAUSE
 SEND-KEYS: "I will leave after game start, i'm host bot{ENTER}"
 SEM1 RELEASE
 ;
 : gamestep3 ( )
 SEM1 GET
 FILE-EXIST: "c:\nnCron\mute.sem" IF
  EXIT
 THEN
 SEND-KEYS-DELAY: 20 0
 SEND-KEYS: "The game will be autostarted in 1 min{ENTER}"
 200 PAUSE
 SEND-KEYS: "I will leave after game start, i'm host bot{ENTER}"
 SEM1 RELEASE
 ;
 : gamestep2 ( )
 SEM1 GET
 FILE-EXIST: "c:\nnCron\mute.sem" IF
  EXIT
 THEN
 SEND-KEYS-DELAY: 20 0
 SEND-KEYS: "The game will be autostarted in 30 sec{ENTER}"
 200 PAUSE
 SEND-KEYS: "I will leave after game start, I'm host bot{ENTER}"
 SEM1 RELEASE
 ;
 : gamestep1nc ( )
 SEM1 GET
 SEND-KEYS-DELAY: 20 0
 SEND-KEYS: "@o{DELAY 200}{ENTER}" \ ok and close the msgbox if appeared
 10000 PAUSE
 10 10 Click
 SEND-KEYS: "{DELAY 200}e{DELAY 200}q{DELAY 200}q{DELAY 200}{BS}{BS}{BS}{DELAY 5000}{ENTER}" \ exit the game if started or del eqq if not
 SEM1 RELEASE
 ;
 : gamestep1 ( ) \ force exit if unable to start
 SEM1 GET
 SEND-KEYS-DELAY: 20 0
 SEND-KEYS: "@o{DELAY 200}{ENTER}" \ ok and close the msgbox if appeared
 10000 PAUSE
 10 10 Click
 SEND-KEYS: "{DELAY 200}e{DELAY 200}q{DELAY 200}q{DELAY 5000}{ENTER}" \ exit the game if started or del eqq if not
 SEND-KEYS: "{DELAY 2000}@c{DELAY 200}{ESC}" \ cancel game creation if no players joined
 SEM1 RELEASE
 ;
\ RunOnce
NoDel
Time: 0 0 21 5 * 2009
\ WatchHotKey: "^1"
Action:
 
)#
#( startwar2
NoDel
SingleInstance
WatchFile: "c:\nnCron\startwar2.sem"
Action:
   enter_chat
)#
#( resetwar2
NoDel
SingleInstance
WatchFile: "c:\nnCron\resetwar2.sem"
Action:
 SEM1 GET
   KILL: "Warcraft II BNE.exe"
   3000 PAUSE
 SEM1 RELEASE
   enter_chat
)#

#( gowef
NoDel
SingleInstance
WatchFile: "c:\nnCron\gowef.sem"
Action:
   1 create_game
)#

#( gowf
NoDel
SingleInstance
WatchFile: "c:\nnCron\gowf.sem"
Action:
   2 create_game
)#

#( chop
NoDel
SingleInstance
WatchFile: "c:\nnCron\chop.sem"
Action:
   3 create_game
)#
#( gamestep1nc_a
NoDel
WatchFile: "c:\nnCron\gamestep1nc.sem"
Action:
   gamestep1nc
)#
#( gamestep1_a
NoDel
SingleInstance
WatchFile: "c:\nnCron\gamestep1.sem"
Action:
   gamestep1
)#
#( gamestep2_a
NoDel
SingleInstance
WatchFile: "c:\nnCron\gamestep2.sem"
Action:
   gamestep2
)#
#( gamestep3_a
NoDel
SingleInstance
WatchFile: "c:\nnCron\gamestep3.sem"
Action:
   gamestep3
)#
#( gamestep4_a
NoDel
WatchFile: "c:\nnCron\gamestep4.sem"
Action:
   gamestep4
)#


#( echo
NoDel
SingleInstance
WatchFile: "c:\nnCron\echo.sem"
Action:
 SEM1 GET
 SEND-KEYS: "{DELAY 200}"
' SEND-KEYS: "/w il "
' S" c:\nnCron\echo.sem" FILE + 0 SEND-KEYS
 SEM1 RELEASE

)#

Fell free to ask any questions about that project if you want to implement it.
(ง︡'-'︠)ง "Bitchin!" ®©℗™ Dragon Posts: 6059 Karma: +135/-70 "It's going to be Legen-(wait for it......)-DARY!" **********

EviL~Ryu

  • (ง︡'-'︠)ง "Bitchin!" ®©℗™
  • Dragon
  • **********
  • *
  • Posts: 6059
  • "It's going to be Legen-(wait for it......)-DARY!"
    • View Profile
    • Clan EviL Official Page
Re: GameBot source code
« Reply #2 on: July 27, 2015, 11:07:11 AM »
Excellent you finally posted it.


Sent from my Motorola DynaTAC 8000X using Tapatalk
Death Knight Posts: 2567 Karma: +82/-4 *********

tupac

  • Death Knight
  • *********
  • *
  • Posts: 2567
    • View Profile
Re: GameBot source code
« Reply #3 on: July 27, 2015, 12:41:47 PM »
Very nice !!! So il you wrote this or claw??
Ogre Mage Posts: 2345 Karma: +123/-179 ********

I hate naggers

  • Ogre Mage
  • ********
  • *
  • Posts: 2345
    • View Profile
Re: GameBot source code
« Reply #4 on: July 27, 2015, 12:43:34 PM »
il wrote this. i used caughtphrases.htm and parsing, he used file creation
Death Knight Posts: 2567 Karma: +82/-4 *********

tupac

  • Death Knight
  • *********
  • *
  • Posts: 2567
    • View Profile
Re: GameBot source code
« Reply #5 on: July 27, 2015, 12:47:19 PM »
Ohhh okay! All 3 of ours look similar lol

I just didn't add a command engine.
Berserker Posts: 712 Karma: +32/-3 *****

{Lance}

  • Berserker
  • *****
  • Posts: 712
    • View Profile
Re: GameBot source code
« Reply #6 on: July 27, 2015, 01:20:10 PM »
Thanks for following through on my request iL, much appreciated :)  This should help push things in the right direction as far as the lack of hosts as of late.  I plan to use this as is and extend it to suit my own needs with several of the idle vps's I have access to.  I'll publish any useful mods here,  encourage others to do the same.
Death Knight Posts: 2567 Karma: +82/-4 *********

tupac

  • Death Knight
  • *********
  • *
  • Posts: 2567
    • View Profile
Re: GameBot source code
« Reply #7 on: July 27, 2015, 06:07:21 PM »
Thanks for following through on my request iL, much appreciated :)  This should help push things in the right direction as far as the lack of hosts as of late.  I plan to use this as is and extend it to suit my own needs with several of the idle vps's I have access to.  I'll publish any useful mods here,  encourage others to do the same.
welcome to the mods section! ;)
(ง︡'-'︠)ง "Bitchin!" ®©℗™ Dragon Posts: 6059 Karma: +135/-70 "It's going to be Legen-(wait for it......)-DARY!" **********

EviL~Ryu

  • (ง︡'-'︠)ง "Bitchin!" ®©℗™
  • Dragon
  • **********
  • *
  • Posts: 6059
  • "It's going to be Legen-(wait for it......)-DARY!"
    • View Profile
    • Clan EviL Official Page
Re: GameBot source code
« Reply #8 on: July 27, 2015, 08:09:38 PM »
Long overdue...


Sent from my Motorola DynaTAC 8000X using Tapatalk
Death Knight Posts: 2567 Karma: +82/-4 *********

tupac

  • Death Knight
  • *********
  • *
  • Posts: 2567
    • View Profile
Re: GameBot source code
« Reply #9 on: July 27, 2015, 08:46:57 PM »
I don't get why il involved the mouse click when it could of been done with hotkeys.
Administrator Ogre Posts: 1390 Karma: +135/-9 *****

iL

  • Administrator
  • Ogre
  • *****
  • *
  • Posts: 1390
    • View Profile
*

iL

Re: GameBot source code
« Reply #10 on: July 28, 2015, 01:18:41 AM »
I don't get why il involved the mouse click when it could of been done with hotkeys.
Just to click icon to start war2 should be located on 425 25. :)
Was too lazy to use hotkey for that...

Also to click menu when levaing the game. F10 not working  on pause for unknown reason.
Death Knight Posts: 2567 Karma: +82/-4 *********

tupac

  • Death Knight
  • *********
  • *
  • Posts: 2567
    • View Profile
Re: GameBot source code
« Reply #11 on: July 28, 2015, 01:26:33 AM »
Okay sounds about right.
Ogre Mage Posts: 2345 Karma: +123/-179 ********

I hate naggers

  • Ogre Mage
  • ********
  • *
  • Posts: 2345
    • View Profile
Re: GameBot source code
« Reply #12 on: July 28, 2015, 02:35:41 AM »
Also to click menu when levaing the game. F10 not working  on pause for unknown reason.
damn, stupid w2. i think id rather use the unpause - leave game hotkey sequence
ctrl+p -> wait 1s -> alt+q -> q
Administrator Ogre Posts: 1390 Karma: +135/-9 *****

iL

  • Administrator
  • Ogre
  • *****
  • *
  • Posts: 1390
    • View Profile
*

iL

Re: GameBot source code
« Reply #13 on: July 28, 2015, 02:46:12 AM »
ctrl+p -> wait 1s -> alt+q -> q
Also note that you are not able to know if pause if enabled or not.
You should follow exit sequence, then ctrl+p and repeat exit sequence.
Also 1s is quite long to let them pause again.
Also maybe there were some reason to pause.
Also there's no problem to mouse-click menu, fortunately it's always located in the same place and not clickable in game lobby.

BTW i didn't check alt+q, maybe it works on pause, need to try.
Death Knight Posts: 2567 Karma: +82/-4 *********

tupac

  • Death Knight
  • *********
  • *
  • Posts: 2567
    • View Profile
Re: GameBot source code
« Reply #14 on: July 28, 2015, 03:05:36 AM »
I just forced the bot to loss and he leaves like he lost when activated. No hotkeys necessary to leave game!

That's why i love how i could read/write memory with macros.