Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.20 KB | None | 0 0
  1. ;-------------------------
  2. ;IRC Chat Window Socket
  3. ;Script, for RPGenerator
  4. ;-------------------------
  5.  
  6. #include <ButtonConstants.au3>
  7. #include <EditConstants.au3>
  8. #include <GUIConstantsEx.au3>
  9. #include <GUIListBox.au3>
  10. #include <WindowsConstants.au3>
  11. #include <IE.au3>
  12. #include <ListboxConstants.au3>
  13.  
  14.  
  15. ;Misc Startup
  16. _IEErrorHandlerRegister()
  17. OnAutoItExitRegister("CloseCon")
  18.  
  19. ;IRC Variables
  20. #Region
  21. Global $ip = "irc.esper.net"
  22. Global $port = 6667
  23. Global $channel = "#DarkCastle"
  24. Global $nickname = "Testing_Console"
  25. Global $username = "Testing_Console"
  26. Global $realname = "Testing_Console"
  27. Global $sock
  28. Global $connected = False
  29. Global $mList
  30. Global $OnChannel = False
  31. Global $OldNick
  32. Global $NickInUse = False
  33. #EndRegion
  34.  
  35. ;IE Chat window variables
  36. $HTML = "<HTML>" & @CR
  37. $HTML &= "<HEAD>" & @CR
  38. $HTML &= '<style type="text/css"><!-- body { margin: 4px; line-height: 16px;} --></style>'
  39. $HTML &= "</HEAD>" & @CR
  40. $HTML &= "<BODY>"
  41. $HTML &= "</BODY>"
  42. $HTML &= "</HTML>"
  43.  
  44. $IEChatBox = _IECreateEmbedded()
  45.  
  46. ;Chat window GUI
  47. #Region
  48. Opt("GUIOnEventMode", 1)
  49. $DCRPG = GUICreate("DarkCastle RPG - Chat", 850, 500, 192, 114)
  50. $ConButton = GUICtrlCreateButton("Connect", 9, 3, 80, 23)
  51. GUICtrlSetOnEvent($ConButton, "CheckConnection")
  52. $ChatBox = GUICtrlCreateObj($IEChatBox, 9, 29, 685, 380)
  53. $NickList = GUICtrlCreateList("", 700, 28, 140, 390, $LBS_SORT)
  54. $EditBox = GUICtrlCreateInput("", 8, 424, 545, 21)
  55. $SendText = GUICtrlCreateButton("Send", 560, 424, 65, 25, BitOR($WS_GROUP, $BS_DEFPUSHBUTTON))
  56. GUICtrlSetOnEvent($SendText, "SendText")
  57. GUISetOnEvent($GUI_EVENT_CLOSE, "CloseDown")
  58. GUISetState(@SW_SHOW)
  59. #EndRegion
  60.  
  61. ;IE Chat window stuff
  62. _IENavigate($IEChatBox, "about:blank")
  63. _IEDocWriteHTML($IEChatBox, $HTML)
  64. _IEHeadInsertEventScript($IEChatBox, "document", "oncontextmenu", "return false")
  65.  
  66. ;Main Loop
  67. While 1
  68. ;GUI Stuff
  69. ;$nMsg = GUIGetMsg()
  70. ;Switch $nMsg
  71. ; Case $GUI_EVENT_CLOSE
  72. ; Exit
  73.  
  74. ; Case $NickList
  75. ; Case $SendText
  76. ;EndSwitch
  77. ;Sleep(1000)
  78.  
  79. ;IRC Stuff - thanks to Kealper of EsperNET for helping with the IRC Section!
  80. If Not $connected Then
  81. Sleep(500)
  82. ContinueLoop
  83. EndIf
  84. $receive = TCPRecv($sock, 8192)
  85. If @error Then ErrorMsg("001")
  86. If Not $receive Then ContinueLoop
  87. $sData = StringSplit($receive, @CRLF, 1)
  88. ;ShowText("Normal", "" & $receive)
  89. ;If Not $sData[2] = "372" Then ShowText("Normal", "" & $receive)
  90. For $i = 1 To $sData[0]
  91. $sTemp = StringSplit($sData[$i], " ")
  92. If $sTemp[1] = "PING" Then TCPSend($sock, "PONG " & $sTemp[2] & @CRLF)
  93. If $sTemp[0] < 3 Then ContinueLoop
  94. Switch $sTemp[2]
  95. Case "372"
  96. $message = StringMid($sData[$i], StringInStr($sData[$i], ":", 0, 2) + 1)
  97. ShowText("Info", "" & $message)
  98. Case "PRIVMSG"
  99. $nick = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2)
  100. $message = StringMid($sData[$i], StringInStr($sData[$i], ":", 0, 2) + 1)
  101. $chan = $sTemp[3]
  102. $smsg = StringSplit($message, " ")
  103. If $smsg[1] = Chr(1) & "ACTION" Then
  104. $length = StringLen($message)
  105. $message1 = StringLeft($message, Number($length - 1))
  106. ShowText("Action", "* " & $nick & " " & StringRight($message1, Number($length - 9)))
  107. Else
  108. ShowText("Normal", "<" & $nick & "> " & $message)
  109. EndIf
  110. Case "NOTICE"
  111. $nick = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2)
  112. $message = StringMid($sData[$i], StringInStr($sData[$i], ":", 0, 2) + 1)
  113. $chan = $sTemp[3]
  114. ShowText("Notice", "<" & $nick & "> " & $message)
  115. Case "PART"
  116. $nick = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2)
  117. $chan = $sTemp[3]
  118. ShowText("Mode", "* " & $nick & " has left " & $chan)
  119. NickListRemove("" & $nick)
  120. Case "JOIN"
  121. $nick = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2)
  122. $chan = $sTemp[3]
  123. ShowText("Mode", "* " & $nick & " has joined " & $chan & ".")
  124. NickListAdd("" & $nick)
  125. Case "KICK"
  126. $nick = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2)
  127. $message = StringMid($sData[$i], StringInStr($sData[$i], ":", 0, 2) + 1)
  128. $chan = $sTemp[3]
  129. $knick = $sTemp[4]
  130. ShowText("Mode", "* " & $nick & " has kicked " & $knick & " from " & $chan & " (" & $message & ")")
  131. If $knick = $nickname Then
  132. Kicked()
  133. Else
  134. NickListRemove("" & $knick)
  135. EndIf
  136. Case "TOPIC"
  137. $nick = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2)
  138. $topic = StringMid($sData[$i], StringInStr($sData[$i], ":", 0, 2) + 1)
  139. $chan = $sTemp[3]
  140. ShowText("Mode", "* " & $nick & " changes the topic to: " & $topic)
  141. Case "MODE"
  142. $nick = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2)
  143. $chan = $sTemp[3]
  144. ShowText("Mode", "* " & $nick & " sets mode " & StringTrimLeft($sData[$i], StringInStr($sData[$i], " ", 0, 3)))
  145. If $sTemp[4] = "+o" Then NickListMode("@", "" & $sTemp[5])
  146. If $sTemp[4] = "+v" Then NickListMode("+", "" & $sTemp[5])
  147. If $sTemp[4] = "-o" Then NickListUnMode("@", "" & $sTemp[5])
  148. If $sTemp[4] = "-v" Then NickListUnMode("+", "" & $sTemp[5])
  149. Case "004"
  150. JoinChannel($channel)
  151. Case "332"
  152. $topic = ""
  153. $tData = StringSplit($sData[$i], " ")
  154. For $tN = 5 to $tData[0]
  155. If Not $topic AND $tn = 5 Then
  156. $topic = StringTrimLeft($tData[$tN], 1)
  157. ContinueLoop
  158. ElseIf $topic Then
  159. $topic = $topic & " " & $tData[$tN]
  160. ContinueLoop
  161. EndIf
  162. Next
  163. ShowText("Info", "* " & $topic)
  164. Case "353"
  165. NickListSet($sData[$i])
  166. $OnChannel = True
  167. Case "404"
  168. If $OnChannel = True Then
  169. ShowText("Notice", "Unable to send message, chat is on mute.")
  170. ElseIf $onChannel = False Then
  171. ShowText("Notice", "You are not in chat.")
  172. EndIf
  173. Case "433"
  174. ShowText("Notice", "The nickname " & $nickname & " is currently in use.")
  175. ChangeNick("" & $OldNick)
  176. Case "NICK"
  177. ;:Neo`Nemesis!Z31@67-135-195-93.dia.static.qwest.net NICK :Testing
  178. $nData = StringSplit($sData[$i], "!")
  179. $OldUser = StringTrimLeft($nData[1], 1)
  180. $nData = StringSplit($sData[$i], " ")
  181. $NewUser = StringTrimLeft($nData[3], 1)
  182. ShowText("Mode", "* " & $OldUser & " is now known as " & $NewUser)
  183. $nData = StringSplit($mList, " ")
  184. For $nN = 1 To $nData[0]
  185. If "@" & $OldUser = $nData[$nN] Then
  186. $NewUser = "@" & $NewUser
  187. ExitLoop
  188. ElseIf "+" & $OldUser = $nData[$nN] Then
  189. $NewUser = "+" & $NewUser
  190. ExitLoop
  191. EndIf
  192. Next
  193. NickListRemove($OldUser)
  194. NickListAdd($NewUser)
  195. Case "471"
  196. ShowText("Notice", "Unable to join, chat is full.")
  197. Case "473"
  198. ShowText("Notice", "Unable to join, chat is set to invite only.")
  199. Case "474"
  200. ShowText("Notice", "Unable to join, you are banned from chat.")
  201. Case "475"
  202. ShowText("Notice", "Unable to join, chat is locked.")
  203. Case "477"
  204. ShowText("Notice", "Unable to join, chat is set to registered users only.")
  205. EndSwitch
  206. Next
  207. WEnd
  208.  
  209. ;-------------------------
  210. ;GUI Functions
  211. ;-------------------------
  212.  
  213. ;Showing text in the IE Chat window
  214. Func ShowText($event, $text)
  215. $text = HTMLencode(UniConvert($text))
  216. $display = _IEBodyReadHTML($IEChatBox)
  217. If $display == 0 Then $display = ""
  218. If $event = "Mode" Then $color = "5AA05A"
  219. If $event = "Action" Then $color = "6C2DC7"
  220. If $event = "Notice" Then $color = "C11B17"
  221. If $event = "Normal" Then $color = "000000"
  222. If $event = "Info" Then $color = "2B65EC"
  223. _IEBodyWriteHTML($IEChatBox, $display & "<font face=""FixedSys"" color=""#" & $color & """ size=""1"">[" & @HOUR & ":" & @MIN & "]</font> <font face=""FixedSys"" color=""#" & $color & """ size=""-1""> " & $text & "</font><br>")
  224. Scroll()
  225. ;Flash()
  226. EndFunc ;==>ShowText
  227.  
  228. ;Auto Scrolling in IE chat window
  229. Func Scroll()
  230. $scrollH = $IEChatBox.document.body.scrollHeight
  231. $IEChatBox.document.parentWindow.scrollTo(0, $scrollH)
  232. EndFunc ;==>Scroll
  233.  
  234. ;HTML encoding for ShowText()
  235. Func HTMLencode($encode)
  236. $Len = StringLen($encode)
  237. Local $Num
  238. If $Len = 0 Then Return ''
  239. For $i = 1 To $Len
  240. $Char = StringMid($encode, $i, 1)
  241. $Num &= '&#' & AscW($Char) & ';'
  242. Next
  243. Return $Num
  244. EndFunc ;==>HTMLencode
  245.  
  246. ;ANSII to Unicode converting for ShowText()
  247. Func UniConvert($convert)
  248. $bin = StringToBinary($convert)
  249. $uni = BinaryToString($bin, 4)
  250. Return $uni
  251. EndFunc ;==>UniConvert
  252.  
  253. ;Exiting proggy
  254. Func CloseDown()
  255. Exit
  256. EndFunc ;==>CloseDown
  257. ;-------------------------
  258. ;IRC Functions
  259. ;-------------------------
  260.  
  261. ;open Connection (CheckConnection(), ConnectToServer(), Connect())
  262. Func CheckConnection()
  263. If $connected = True Then
  264. CloseCon()
  265. ElseIf $connected = False Then
  266. ConnectToServer()
  267. EndIf
  268. EndFunc ;==>CheckConnection
  269. Func ConnectToServer()
  270. TCPStartup()
  271. $sock = Connect($ip, $port, $nickname, $username, $realname)
  272. $connected = True
  273. EndFunc ;==>ConnectToServer
  274.  
  275. Func Connect($sIP, $iPort, $sNick, $sUser, $sReal)
  276. ShowText("Info", "* Connecting to server...")
  277. GUICtrlSetData($ConButton, "Disconnect")
  278. $sIP = TCPNameToIP($sIP) ;Resolve the given hostname to a real IP address
  279. Local $iSock = TCPConnect($sIP, $iPort) ;Connect to the given IP address and port
  280. TCPSend($iSock, "NICK " & $sNick & @CRLF) ;Request the requested nickname
  281. TCPSend($iSock, "USER " & $sUser & " 0 0 " & $sReal & @CRLF) ;Send info about the bot, the two zeros are just placeholders for optional data in this example.
  282. Return $iSock
  283. EndFunc ;==>Connect
  284.  
  285. ;Close Connection
  286. Func CloseCon()
  287. TCPCloseSocket($sock)
  288. TCPShutdown()
  289. If $connected = True Then
  290. ShowText("Info", "* Disconnected...")
  291. GUICtrlSetData($ConButton, "Connect")
  292. GUICtrlSetData($NickList, "")
  293. $connected = False
  294. $mList = ""
  295. $OnChannel = False
  296. EndIf
  297. EndFunc ;==>CloseCon
  298.  
  299. ;IRC ErrorMsg()
  300. Func ErrorMsg($eNum)
  301. If $eNum = "001" Then
  302. ShowText("Notice", "ERROR 001: Server not responding.")
  303. CloseCon()
  304. EndIf
  305. EndFunc ;==>ErrorMsg
  306.  
  307. ;Join Channel
  308. Func JoinChannel($sChannel)
  309. TCPSend($sock, "JOIN " & $sChannel & @CRLF)
  310. EndFunc ;==>JoinChannel
  311.  
  312. ;Leave Channel
  313. Func LeaveChannel($cChannel, $pMsg)
  314. TCPSend($sock, "PART " & $cChannel & "" & $pMsg & @CRLF)
  315. EndFunc ;==>LeaveChannel
  316.  
  317. ;Change Nickname
  318. Func ChangeNick($newnick)
  319. $OldNick = $nickname
  320. If $sock Then TCPSend($sock, "NICK :" & $newnick & @CRLF)
  321. ShowText("Mode", "* You are now using the nickname " & $newnick)
  322. If $OnChannel = True Then
  323. NickListRemove($nickname)
  324. NickListAdd($newnick)
  325. EndIf
  326. $nickname = $newnick
  327. EndFunc ;==>ChangeNick
  328.  
  329. ;Nick List Functions
  330. Func NickListUpdate($uList)
  331. GUICtrlSetData($NickList, "")
  332. $SuList = StringSplit($uList, " ")
  333. For $un = 1 To $SuList[0]
  334. If $SuList[$un] = ":" & $nickname Then
  335. GUICtrlSetData($NickList, $nickname)
  336. Else
  337. GUICtrlSetData($NickList, $SuList[$un])
  338. EndIf
  339. Next
  340. EndFunc ;==>NickListUpdate
  341.  
  342. Func NickListSet($members)
  343. $MemberList = StringSplit($members, " ")
  344. For $Num = 6 To $MemberList[0]
  345. If Not $mList Then
  346. $mList = $MemberList[$Num]
  347. ElseIf $mList Then
  348. $mList = $mList & " " & $MemberList[$Num]
  349. EndIf
  350. Next
  351. NickListUpdate($mList)
  352. EndFunc ;==>NickListSet
  353.  
  354. Func NickListAdd($aUser)
  355. If Not $mList Then
  356. $mList = $aUser
  357. ElseIf $mList Then
  358. $mList = $mList & " " & $aUser
  359. EndIf
  360. NickListUpdate($mList)
  361. EndFunc ;==>NickListAdd
  362.  
  363. Func NickListRemove($rUser)
  364. $rList = StringSplit($mList, " ")
  365. $mList = ""
  366. For $n = 1 To $rList[0]
  367. If $rList[$n] = $rUser Or StringTrimLeft($rList[$n], 1) = $rUser Then
  368. $mList = $mList
  369. Else
  370. $mList = $mList & " " & $rList[$n]
  371. EndIf
  372. Next
  373. NickListUpdate($mList)
  374. EndFunc ;==>NickListRemove
  375.  
  376. Func NickListMode($mode, $mUser)
  377. $RepNick = $mode & $mUser
  378. NickListRemove($mUser)
  379. NickListAdd($RepNick)
  380. EndFunc ;==>NickListMode
  381.  
  382. Func NickListUnMode($unmode, $unUser)
  383. $RepUnNick = $unmode & $unUser
  384. NickListRemove($RepUnNick)
  385. NickListAdd($unUser)
  386. EndFunc ;==>NickListUnMode
  387.  
  388. ;Kicked() function, for when you are kicked from chat!
  389. Func Kicked()
  390. GUICtrlSetData($NickList, "")
  391. ShowText("Mode", "* You have been kicked from chat, please use the /rejoin command to rejoin.")
  392. $OnChannel = False
  393. EndFunc ;==>Kicked
  394.  
  395. ;Send message
  396. Func SendMsg($sChannel, $smsg)
  397. TCPSend($sock, "PRIVMSG " & $sChannel & " :" & $smsg & @CRLF)
  398. EndFunc ;==>SendMsg
  399.  
  400. ;Sending text and command interpreter.
  401. Func SendText()
  402. If Not $sock And $OnChannel = False Then
  403. If Not $sock And Not GUICtrlRead($EditBox) Then
  404. Sleep(10)
  405. ElseIf Not $sock Then
  406. ShowText("Notice", "* You are not connected...")
  407. ElseIf $OnChannel = False Then
  408. ShowText("Notice", "* You are not in chat.")
  409. EndIf
  410. Else
  411. If Not GUICtrlRead($EditBox) Then
  412. Sleep(1000)
  413. Else
  414. $cText = StringSplit(GUICtrlRead($EditBox), " ")
  415. If StringLeft($cText[1], 1) = "/" Then
  416. SendCommand(GUICtrlRead($EditBox))
  417. Else
  418. $sText = "<" & $nickname & "> " & GUICtrlRead($EditBox)
  419. SendMsg($channel, "" & GUICtrlRead($EditBox))
  420. ShowText("Normal", "" & $sText)
  421. EndIf
  422. GUICtrlSetData($EditBox, "")
  423. EndIf
  424. EndIf
  425. EndFunc ;==>SendText
  426.  
  427. Func SendCommand($cmd)
  428. $cmdText = StringSplit($cmd, " ")
  429. ;/me <action>
  430. If $cmdText[1] = "/me" Then
  431. If $cmdText[0] > 2 OR $cmdText[0] < 2 Then
  432. ShowText("Info", "" & $cmdText[1] & ": Invalid parameters")
  433. ElseIf $cmdText[0] = 2 Then
  434. ShowText("Action", "* " & $nickname & " " & StringRight("" & $cmd, Number(StringLen("" & $cmd) - 4)))
  435. TCPSend($sock, "PRIVMSG " & $channel & " :" & Chr(1) & "ACTION " & StringRight("" & $cmd, Number(StringLen("" & $cmd) - 4)) & Chr(1) & @CRLF)
  436. EndIf
  437. ;/quit <quit message>
  438. ElseIf $cmdText[1] = "/quit" Then
  439. If Not StringRight("" & $cmd, Number(StringLen("" & $cmd) - 6)) Then
  440. $qMsg = "Quit: DarkCastle RPG - User has logged out of chat."
  441. Else
  442. $qMsg = StringRight("" & $cmd, Number(StringLen("" & $cmd) - 6))
  443. EndIf
  444. TCPSend($sock, "QUIT :" & $qMsg & @CRLF)
  445. ShowText("Info", "* You have logged out of chat.")
  446. CloseCon()
  447. ;/rejoin
  448. ElseIf $cmdText[1] = "/rejoin" Then
  449. JoinChannel("" & $channel)
  450. ;/nickserv <paramter1 ... parameterN>
  451. ElseIf $cmdText[1] = "/nickserv" Then
  452. If Not $cmdText[2] Then
  453. ShowText("Info", "" & $cmdText[1] & ": Invalid parameters")
  454. Else
  455. $nsText = StringRight("" & $cmd, Number(StringLen("" & $cmd) - 10))
  456. TCPSend($sock, "PRIVMSG NickServ :" & $nsText & @CRLF)
  457. EndIf
  458. ;/chanserv <paramter1 ... parameterN>
  459. ElseIf $cmdText[1] = "/chanserv" Then
  460. If Not $cmdText[2] Then
  461. ShowText("Info", "" & $cmdText[1] & ": Invalid parameters")
  462. Else
  463. $csText = StringRight("" & $cmd, Number(StringLen("" & $cmd) - 10))
  464. TCPSend($sock, "PRIVMSG ChanServ :" & $csText & @CRLF)
  465. EndIf
  466. ;/nick <nickname> <password
  467. ElseIf $cmdText[1] = "/nick" Then
  468. If $cmdText[0] < 2 OR $cmdtext[0] > 2 Then
  469. ShowText("Info", "" & $cmdText[1] & ": Invalid parameters")
  470. ElseIf $cmdtext[0] = 2 Then
  471. If $cmdText[2] = $nickname Then
  472. ShowText("Info", "* You are already using that nickname.")
  473. Else
  474. $nListed = StringSplit($mList, " ")
  475. For $nL = 1 To $nListed[0]
  476. If $nListed[$nL] = $cmdtext[2] OR $nListed[$nL] = "@" & $cmdtext[2] OR $nListed[$nL] = "+" & $cmdtext[2] Then
  477. ShowText("Info", "The nickname " & $cmdtext[2] & " is currently in use.")
  478. $NickInUse = True
  479. ExitLoop
  480. EndIf
  481. Next
  482. If $NickInUse = False Then ChangeNick("" & $cmdText[2])
  483. EndIf
  484. $NickInUse = False
  485. EndIf
  486. ;/login <password>
  487. ElseIf $cmdText[1] = "/login" Then
  488. If $cmdText[0] > 2 Or $cmdText[0] < 2 Then
  489. ShowText("Info", "" & $cmdText[1] & ": Invalid parameters")
  490. ElseIf $cmdText[0] = 2 Then
  491. TCPSend($sock, "PRIVMSG Boris :LOGIN " & $cmdText[2] & @CRLF)
  492. EndIf
  493. ;/register <nickname> <password> <e-mail>
  494. ElseIf $cmdText[1] = "/register" Then
  495. If $cmdText[0] < 4 Or $cmdText[0] > 4 Then
  496. ShowText("Info", "" & $cmdText[1] & ": Invalid parameters")
  497. ElseIf $cmdText[0] = 4 Then
  498. If Not $nickname = $cmdText[2] Then
  499. ChangeNick("" & $cmdText[2])
  500. TCPSend($sock, "PRIVMSG Nickserv :REGISTER " & $cmdText[3] & " " & $cmdText[4] & @CRLF)
  501. TCPSend($sock, "PRIVMSG Boris :REGISTER " & $cmdText[3] & @CRLF)
  502. EndIf
  503. EndIf
  504. ;/connect
  505. ElseIf $cmdText[1] = "/connect" Then
  506. ConnectToServer()
  507. Else
  508. ShowText("Info", "* " & $cmdText[1] & ": Unknown command.")
  509. EndIf
  510. EndFunc ;==>SendCommand
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement