Last active
June 21, 2020 14:39
-
-
Save Cvar1984/64e152ae1caa0e85abb2a27e30057fb1 to your computer and use it in GitHub Desktop.
Simple Internet Relay Chat PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function read_socket($socket) | |
| { | |
| while($rawData = fgets($socket)) { | |
| $data .= $rawData; | |
| } | |
| return $data; | |
| } | |
| function send_message(string $channel, string $message) | |
| { | |
| global $irc; | |
| fprintf($irc, "PRIVMSG #%s :%s\n", $channel, $message); | |
| } | |
| $host = 'irc.freenode.net'; | |
| $port = '6667'; | |
| $nick = 'Menhera_bot'; | |
| $param = 'Linux 127.0.0.1 localhost'; | |
| $channel = 'BHSec'; | |
| $irc = fsockopen($host, $port, $errno, $errstr, 30); | |
| stream_set_blocking($irc, 0); | |
| if($irc) { | |
| fprintf($irc, "USER %s\n", $param); | |
| sleep(5); | |
| fprintf($irc, "NICK %s\n", $nick); | |
| echo read_socket($irc); | |
| sleep(5); | |
| fprintf($irc, "JOIN #%s\n", $channel); | |
| echo read_socket($irc); | |
| sleep(5); | |
| while(1) | |
| { | |
| $msg = readline('IRC: '); | |
| $msg = trim($msg); | |
| if(empty($msg)) { | |
| echo read_socket($irc); | |
| } else { | |
| send_message($channel, $msg); | |
| } | |
| } | |
| } | |
| fclose($irc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment