Distributed programming/AutoHotkey: Difference between revisions
Distributed programming/AutoHotkey (view source)
Revision as of 13:04, 1 September 2022
, 1 year agoFixed syntax highlighting.
No edit summary |
m (Fixed syntax highlighting.) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1:
{{libheader|
WinSock2 library created by derRaphael. Basic code structure created by Trikster.
<div style="clear:both;width:full;overflow:scroll"><
#Persistent
#SingleInstance, force
#Include, WinSock2.ahk
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
Line 13:
Gui, Add, DropDownList, vDDL1 gDDL1, Select something!||One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten
Gui, Add, Button, gB3, Click me!
Server := "irc.freenode.net"
Port := "6667"
Channel := "#
Nick := "
Pass := "
Name := "distributed program"
BotCmd := "!"
OtherBotCmd := "~"
OnExit, CleanUp
WS2_CleanUp()
Line 33:
MsgBox, 16, Error!, An error occured wilist connecting to %Connection%
}
; Set OnMessage function
WS2_AsyncSelect(Socket, "DataProcess")
; Send AUTH info to the server
; USER A-trivial-nickname a-domain-like-google.com some-trivial-stuff :your-real-name
WS2_SendData(Socket, "USER " . Nick . " google.com AHKBOT :" . Name . "`n") ; All data send to the server must be
; followed by a newline.
; PASS A-trivial-pass
WS2_SendData(Socket, "PASS " . Pass . "`n")
; NICK A-trivial-nick
WS2_SendData(Socket, "NICK " . Nick . "`n")
; Join channel
; JOIN A-trivial-channel
WS2_SendData(Socket, "JOIN " . Channel . "`n")
Gui, Show
Return
DataProcess(Socket, Data) ; OnMessage function
{
Line 62:
StringReplace, Command, Param5, % Chr(10),, All
StringReplace, Command, Command, % Chr(13),, All
If (Param1 == "PING")
WS2_SendData(Socket, "PONG " . Param2 . "`n")
Else If (RegExMatch(Data, ":\" . BotCMD . " "))
{
If (Command == "B1")
MsgBox, The other person pressed Button Number One
Else If (Command == "
{
out :=
MsgBox, The other person typed in Edit One then pressed Button Two▼
Loop
{
If (A_Index <
continue
If Param%A_Index%
Line 81:
break
}
}
Else If (Command == "DDL1")
MsgBox, The other person selected %Param6% %Param7% in the drop-down-list.
Else If (Command == "B3")
MsgBox, The other person clicked Button Three.
Line 91 ⟶ 92:
}
B1:
WS2_SendData(Socket, "PRIVMSG " . Channel . " :" . OtherBotCmd . " B1`n")
return
B2:
Gui, Submit, NoHide
WS2_SendData(Socket, "PRIVMSG " . Channel . " :" . OtherBotCmd . "
return
DDL1:
Gui, Submit, NoHide
WS2_SendData(Socket, "PRIVMSG " . Channel . " :" . OtherBotCmd . " DDL1 " . DDL1 . "`n")
return
B3:
WS2_SendData(Socket, "PRIVMSG " . Channel . " :" . OtherBotCmd . " B3" . "`n")
return
CleanUp:
GuiClose:
WS2_CleanUp()
ExitApp</
Put the above on one computer, and run it. Then put the below on a different computer (no need for a network, just add Internet!) and run it.
<div style="width:full;overflow:scroll"><
#Persistent
#SingleInstance, force
#Include WinSock2.ahk
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
Line 121 ⟶ 122:
Gui, Add, DropDownList, vDDL1 gDDL1, Select something!||One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten
Gui, Add, Button, gB3, Click me!
Server := "irc.freenode.net"
Port := "6667"
Channel := "#
Nick := "
Pass := "
Name := "distributed program"
BotCmd := "~"
OtherBotCmd := "!"
OnExit, CleanUp
WS2_CleanUp()
Line 141 ⟶ 142:
MsgBox, 16, Error!, An error occured wilist connecting to %Connection%
}
; Set OnMessage function
WS2_AsyncSelect(Socket, "DataProcess")
; Send AUTH info to the server
; USER A-trivial-nickname a-domain-like-google.com some-trivial-stuff :your-real-name
WS2_SendData(Socket, "USER " . Nick . " google.com AHKBOT :" . Name . "`n") ; All data send to the server must be
; followed by a newline.
; PASS A-trivial-pass
WS2_SendData(Socket, "PASS " . Pass . "`n")
; NICK A-trivial-nick
WS2_SendData(Socket, "NICK " . Nick . "`n")
; Join channel
; JOIN A-trivial-channel
WS2_SendData(Socket, "JOIN " . Channel . "`n")
Gui, Show
Return
DataProcess(Socket, Data) ; OnMessage function
{
Line 170 ⟶ 171:
StringReplace, Command, Param5, % Chr(10),, All
StringReplace, Command, Command, % Chr(13),, All
If (Param1 == "PING")
WS2_SendData(Socket, "PONG " . Param2 . "`n")
Else If (RegExMatch(Data, ":\" . BotCMD . " "))
{
If (Command == "B1")
MsgBox, The other person pressed Button Number One
Else If (Command == "
{
out :=
MsgBox, The other person typed in Edit One then pressed Button Two▼
Loop
{
If (A_Index <
continue
If Param%A_Index%
Line 189 ⟶ 190:
break
}
}
Else If (Command == "DDL1")
MsgBox, The other person selected %Param6% %Param7% in the drop-down-list.
Else If (Command == "B3")
MsgBox, The other person clicked Button Three.
Line 199 ⟶ 201:
}
B1:
WS2_SendData(Socket, "PRIVMSG " . Channel . " :" . OtherBotCmd . " B1`n")
return
B2:
Gui, Submit, NoHide
WS2_SendData(Socket, "PRIVMSG " . Channel . " :" . OtherBotCmd . "
return
DDL1:
Gui, Submit, NoHide
WS2_SendData(Socket, "PRIVMSG " . Channel . " :" . OtherBotCmd . " DDL1 " . DDL1 . "`n")
return
B3:
WS2_SendData(Socket, "PRIVMSG " . Channel . " :" . OtherBotCmd . " B3" . "`n")
return
CleanUp:
GuiClose:
WS2_CleanUp()
ExitApp</
|