Location: PHPKode > scripts > OekakiPoteto > oekakipoteto/newchat/chat.php
<?
//IP Banning
include('banscript.php');	
include('dbconn.php');
if(isset($OekakiU)) {
	$testrslt = mysql_query("SELECT usrname, usrpass, usrflags FROM ".$OekakiPoteto_MemberPrefix."oekaki WHERE usrname='$OekakiU'");
	
	//extract the fields selected above into variables
	@extract(mysql_fetch_array($testrslt));
	
	//check if passwords are correct and that the user is a non-pending member
	if (($OekakiPass !== $usrpass) || !strstr($usrflags,"G")) {
		unset($OekakiU);
		unset($OekakiPass);
		header ('Location: error.php?error='.urlencode("You do not have access as a registered member to use the chat."));
	}
}

	///////////////////////////////////////////////////////////////////////////////
	// Main code
	//

	ignore_user_abort(1);
	set_time_limit(0);
	error_reporting(0);

?><html>
<head><script><!--
var cancel = false;
  function o(url) {
	  window.open("profile.php?user="+url, 'profileWin', "width=300,height=400,resizable=yes,scrollbars=yes,status=no,menubar=no,toolbar=no,location=no");
	  return false;
  }
	function s(force) {
		if (force) {
			scroll(0,10000000000000);
			scrollTo(0,10000000000000);
			return;
		}
		var posx=0,posy=0,pageheight=-1;
		if (document.body && document.body.clientHeight) {
			posx = document.body.scrollLeft;
			posy = document.body.scrollTop+document.body.clientHeight;
			pageheight = document.body.scrollHeight;
		} else if (window.innerHeight) {
			posx = window.pageXOffset;
			posy = window.pageYOffset + window.innerHeight;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			posx = document.documentElement.scrollLeft;
			posy = document.documentElement.scrollTop+document.documentElement.offsetHeight;
			pageheight = document.body.scrollHeight;
		}
		if (posy+80>=pageheight || pageheight <= 0) {
			if (posy<100000000) posy=100000000;
			posy+=50;
			scroll(posx,posy);
			scrollTo(posx,posy);
		}
	}
  function u() {window.parent.userList.location='chatusers.php';}
  function load() {if (cancel) return; document.open(); document.writeln('<hr><table width="95%" border="0" cellspacing="0" cellpadding="0" class="infotable" align="left"><tr> <td><b>Chat ended. <a href="chatbox.php" target="_top">Reconnect</a></b></td></tr></table><SCRIPT>s();cancel=true;</SCRIPT>'); }
//--></script>
<?
function rootpath(){
	global $DOCUMENT_ROOT;
	$rootdir = $DOCUMENT_ROOT;
	if ($DOCUMENT_ROOT[strlen($DOCUMENT_ROOT)] == "/"){
		return $rootdir;
	} else {
		$rootdir = $rootdir."/";
		return $rootdir;
	}
}

$refresh = 1;
include('config.php');
include('dbconn.php');
include('niftytoo.php');
include('online.php');

?>
</head>
<?
	$testrslt = mysql_query("SELECT usrname, usrpass, templatesel, usrflags FROM ".$OekakiPoteto_MemberPrefix."oekaki WHERE usrname='$OekakiU'");
	
	//extract the fields selected above into variables
	$user_array = mysql_fetch_array($testrslt);

if($OekakiU == ""){
	include("templates/".$template.".php");
	} else {
	include("templates/".$user_array[templatesel].".php");
}

$User_isAdmin = eregi('A',$user_array[usrflags]);
?>

<body bgcolor="<?=$bgColor?>" text="<?=$textColor?>" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" background="templates/<?=$bgImage?>" link="<?=$link?>" vlink="<?=$vLink?>" alink="<?=$aLink?>" onLoad="load()">
<table width="95%" border="0" cellspacing="0" cellpadding="0" class="infotable" align="left">
<tr>
  <td><b>Conversation</b> - OekakiPoteto Chat MOD v1.12 (stable) by <a href="http://2draw.net/" target="_blank">marcello</a></td>
</tr>
</table>
<br>
<hr>
<? 

	$last_time = time()-300; // backbuffer 5 minutes (300 seconds)
	$first_time=true;
	
	function write_user($row,$guest) {
		?><a <?if($guest){?>href="mailto:<?=$row[email];?>"<?}else{?>href="#" onClick="return o('<?=urlencode($row[usrname])?>')"<?}?>><ACRONYM TITLE="<?=$row[IP];?> / <?=$row[hostname];?>"><?=$row[$guest?'postname':'usrname'];?></ACRONYM></a><?
	}
	
	$connected=true;

	if (!isset($OekakiU)) {?>You must login to enter the chat!<hr><br></body></html><?; exit; }
	
	if (($result = mysql_query("SELECT lastmessage,afk FROM ".$OekakiPoteto_MemberPrefix."oekakichatmodusers WHERE usrname = '$OekakiU'"))&&($row = mysql_fetch_array($result))) {
		//mysql_query("INSERT into ".$OekakiPoteto_MemberPrefix."oekakichatmod SET command='QUIT',usrname='$OekakiU', comment='User reloaded.',hostname='$hostname', IP='$REMOTE_ADDR'");		
		mysql_query("INSERT into ".$OekakiPoteto_MemberPrefix."oekakichatmod SET command='RELOAD',usrname='$OekakiU', comment='',hostname='$hostname', IP='$REMOTE_ADDR'");		
		mysql_query("UPDATE ".$OekakiPoteto_MemberPrefix."oekakichatmodusers SET lastmessage=NOW() WHERE usrname='$OekakiU'");
	} else {
		mysql_query("INSERT INTO ".$OekakiPoteto_MemberPrefix."oekakichatmodusers SET usrname = '$OekakiU',lastmessage=NOW()");
		mysql_query("INSERT into ".$OekakiPoteto_MemberPrefix."oekakichatmod SET command='JOIN',usrname='$OekakiU', comment='',hostname='$hostname', IP='$REMOTE_ADDR'");
	}

	$user_rejoined = false;
	$load_counter = 0;
	
	// Just a dirty loop
	while ($connected && $load_counter <= 30) {
		if ($chattype) $load_counter++;
		
		$result = mysql_query("SELECT usrname,command,comment,hostname,UNIX_TIMESTAMP(posttime) AS post_time,postname,email,url,IP FROM ".$OekakiPoteto_MemberPrefix."oekakichatmod WHERE UNIX_TIMESTAMP(posttime) > $last_time ORDER BY posttime");
		
		
		// Check connection and mysql result
		if (($connection_status=connection_status())||!$result) {
			if (!$user_rejoined && isset($OekakiU)) {
				$send_message='Connection closed.';
				if ($connection_status&1) // user aborted (clicked stop)
					$send_message='User lost connection';
				if ($connection_status&2) // user timed out (some other thing)s
					$send_message='User timed out';
				mysql_query("DELETE FROM ".$OekakiPoteto_MemberPrefix."oekakichatmodusers WHERE usrname='{$OekakiU}'");
				mysql_query("INSERT into ".$OekakiPoteto_MemberPrefix."oekakichatmod SET command='QUIT',usrname='$OekakiU', comment='$send_message',hostname='$hostname', IP='$REMOTE_ADDR'");
			}
			// break out of loop to prevent PHP from running on forever
			break;
		}
		
		$message=false;
		
		// Read in new chat lines
		while ($row = mysql_fetch_array($result)) {
			// Update last time, so we aren't getting the same message twice.
			// Possible bug, two messages submitted at exactly the same time
			if ($last_time < $row[post_time]) $last_time = $row[post_time];
			
			$update_users=false;
			
			$guest = eregi('^Guest$',$row[usrname]);
			$color=false;
			$bold=false;
			$command = $row[command];
			if (strstr($command,'*')) {
				$update_users=true;
				$command=str_replace('*','',$command);
			}
			$invisible_command = false;
			
			switch (strtoupper($command)) {
				case 'RELOAD':
					if (!$first_time && $row[usrname]==$OekakiU)
						$user_rejoined=true;
					$invisible_command=true;
					break;
				case 'OACTION':
				case 'OMESSAGE':
					$invisible_command=!($User_isAdmin||$row[usrname]==$OekakiU);
					break;
				case 'AWAY':
				case 'BACK':
				case 'KICK':
				case 'JOIN':
				case 'QUIT':
				case 'UQUIT':
					$bold=true;
				case 'ACTION':
					$color=$link;
					break;
			}
			
			if (!$invisible_command) {

				?><font class="infotable"<?if($color){?> color="<?=$color?>"<?}?>> [<?=date("H:i",$row[post_time])?>] <?if($bold){?><b><?}?><?


				switch (strtoupper($command)) {
					case 'AWAY':
						?>** <?write_user($row,$guest)?> is away! <?if($row[comment]){?> (<?=nifty2_convert($row[comment])?>)<?}
						$update_users=true;
						break;
					case 'JOIN':
						?>*** <?write_user($row,$guest)?> has joined chat.<?
						if (!$first_time && $row[usrname]==$OekakiU)
							$user_rejoined=true;
						$update_users=true;
						break;
					case 'KICK':
						if (!preg_match('/^"([^"]*?)"\s*(.*)/',$row[comment],$match))
							preg_match('/^([^\s]*)\s*(.*)/',$row[comment],$match);
						$kicked_user = $match[1];
						$message = $match[2];
						if (!$first_time && strtolower($kicked_user) == strtolower($OekakiU) && isset($OekakiU)) {
							$connected=false;
						}
						?>*** <?=$kicked_user?> was kicked by <?write_user($row,$guest)?>. <?if($message){?> (<?=nifty2_convert($message)?>)<?}
						$update_users=true;
						break;
					case 'UQUIT':
						if (!$first_time && $row[usrname]==$OekakiU && isset($OekakiU)) {
							$connected=false;
						}
						?>*** <?write_user($row,$guest)?> has left chat. <?if($row[comment]){?> (<?=nifty2_convert($row[comment])?>)<?}
						$update_users=true;
						break;
					case 'QUIT':
						?>*** <?write_user($row,$guest)?> has quit chat. <?if($row[comment]){?> (<?=nifty2_convert($row[comment])?>)<?}
						$update_users=true;
						break;
					case 'OACTION':
						?>[%] <i>* <?write_user($row,$guest)?>&nbsp;<?=nifty2_convert($row[comment])?></i><?
						break;
					case 'OMESSAGE':
						?>[%] <i>&lt;<?write_user($row,$guest)?>&gt;&nbsp;<?=nifty2_convert($row[comment])?></i><?
						break;
					case 'ACTION':
						?>* <?write_user($row,$guest)?>&nbsp;<?=nifty2_convert($row[comment]);
						break;
					default:
						?>&lt;<?write_user($row,$guest)?>&gt;&nbsp;<?=nifty2_convert($row[comment]);
						break;
				}
				if($bold){?></b><?}
				echo "</font><br>\n";
				$message=true;
			}
		}
		
		// Use javascript to make sure the page is always scrolled nicely
		// (Only if there are new lines of course)
		if ($message) {
			?>
<?if($first_time){?><hr><?}?>
<SCRIPT>s(<?if($first_time){?>true<?}?>)<?if($update_users){?>;u()<?}?></SCRIPT>
			
<?
			flush();
		}
		
		$first_time=false;	
			
		// Let the server rest so it doesn't blow up.
		if ($connected) sleep(1);
	}
?> 
<hr>
<br>
<table width="95%" border="0" cellspacing="0" cellpadding="0" class="infotable" align="left"><tr> <td><b>Chat ended. <a href="chatbox.php" target="_top">Reconnect</a></b></td></tr></table>
<SCRIPT>s(true);cancel=true;</SCRIPT>
</body>
</html>
Return current item: OekakiPoteto