Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Xbox Lve Generator v3
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
Socket Loop, Need Constant Function
<pre class='prettyprint' language='php'><?php function ircinit() { global $con, $CONFIG, $channels, $last_chat; /* We need this to see if we need to JOIN (the channel) during the first iteration of the main loop */ $firstTime = true; /* Connect to the irc server */ $con['socket'] = fsockopen($CONFIG['server'], $CONFIG['port']); /* Check that we have connected */ if (!$con['socket']) { print ("\nCould not connect to: ". $CONFIG['server'] ." on port ". $CONFIG['port']); } else { /* Send the username and nick */ cmd_send("USER ". $CONFIG['nick'] ." roleplaygateway.com roleplaygateway.com :". $CONFIG['name']); cmd_send("NICK ". $CONFIG['nick'] ." roleplaygateway.com"); /* Here is the loop. Read the incoming data (from the socket connection) */ while (!feof($con['socket'])) { /* Think of $con['buffer']['all'] as a line of chat messages. We are getting a 'line' and getting rid of whitespace around it. */ $con['buffer']['all'] = trim(fgets($con['socket'], 4096)); /* Pring the line/buffer to the console I used <- to identify incoming data, -> for outgoing. This is so that you can identify messages that appear in the console. */ print date("[d/m @ H:i]")."<- ".$con['buffer']['all'] ."\n"; /* If the server is PINGing, then PONG. This is to tell the server that we are still here, and have not lost the connection */ if(substr($con['buffer']['all'], 0, 6) == 'PING :') { /* PONG : is followed by the line that the server sent us when PINGing */ cmd_send('PONG :'.substr($con['buffer']['all'], 6)); /* If this is the first time we have reached this point, then JOIN the channel */ if ($firstTime == true){ //cmd_send("JOIN ". $CONFIG['channel']); // for all the channels we want to join foreach ($channels as $chan) { cmd_send("JOIN ".$chan); } /* The next time we get here, it will NOT be the firstTime */ $firstTime = false; } } elseif (preg_match("/:NickServ!services@services.SC.net NOTICE HAL :This nickname is registered and protected./",$con['buffer']['all'])) { /* Need to register */ register(); /* Make sure that we have a NEW line of chats to analyse. If we don't, there is no need to parse the data again */ } elseif ($old_buffer != $con['buffer']['all']) { /* Determine the patterns to be passed to parse_buffer(). buffer is in the form: :username!~identd@hostname JOIN :#php :username!~identd@hostname PRIVMSG #PHP :action text :username!~identd@hostname command channel :text */ // log the buffer to "log.txt" (file must have // already been created). //log_to_file($con['buffer']['all']); // make sense of the buffer parse_buffer(); // now process any commands issued to the bot process_commands(); } update_http(); $old_buffer = $con['buffer']['all']; } } } ?></pre> <a href="http://www.refactormycode.com/codes/250-socket-loop-need-constant-function" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>