chat.php

Started on the old forum in May 2010 · view the original in the archive · old links redirect here

7 replies · 2,029 views · started 16 years ago · 1 min read

5 participants
crazybrumi Super moderator Principal · 1,064 posts #1
<?php
define('WCS',true);
include('../core/main.inc');
header_type();
cleardata();
if(ipbanned(ip(),browser())){
if(!shield(getuid_sid($sid))){
echo head_tag("Ip Blocked",0,0);
echo ipbanned_msg();
echo foot_tag();
exit();
}
}
if(!islogged($sid)){
echo head_tag("Error",0,0);
echo session_expired();
echo foot_tag();
exit();
}
if(banned(getuid_sid($sid))){
echo head_tag("Error",1,getnick_sid($sid));
echo banned_msg($sid);
echo foot_tag();
exit();
}
if(chatbanned(getuid_sid($sid))){
echo head_tag("Error",1,getnick_sid($sid));
echo chatbanned_msg($sid);
echo foot_tag();
exit();
}
mysql_query("UPDATE users SET browser='".browser()."', ipaddress='".ip()."', host='".subno()."' WHERE id='".getuid_sid($sid)."'");

/////////////////////////CHAT/////////////////////////

if($pass!=""){$pw="&pass=$pass";}
$roomname=mysql_fetch_array(mysql_query("SELECT id, name FROM chatrooms WHERE id='".$rid."'"));
$title="<b>".getnick_sid($sid)."@$roomname[1]</b>";
$isroom=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM chatrooms WHERE id='".$rid."'"));
if($isroom[0]==0){
echo head_tag(getnick_sid($sid)."@".$roomname[1],1,getnick_sid($sid));

?>
<p align="left"><b>Room Doesn't Exist</b><br/>You can't enter this room</p>
<a  href=\"../inbox/inbox.php?sid=<?php echo($sid) ?>\">Inbox</a>
<a  href=\"../buds/buds.php?sid=<?php echo($sid) ?>\">BuddyList</a>
<a href=\"./public.php?sid=<?php echo($sid) ?>\">Chat</a>
<a  href=\"../forums/forums.php?sid=<?php echo($sid) ?>\">Forums</a>
<a href="../main.php?sid=<?php echo($sid) ?>">Main Menu</a>
<?php
echo foot_tag();
exit;
}

$passworded=mysql_fetch_array(mysql_query("SELECT password FROM chatrooms WHERE id='".$rid."'"));
if($passworded[0]!=""){
if($pass!=$passworded[0]){
echo head_tag(getnick_sid($sid)."@".$roomname[1],1,getnick_sid($sid));

?><p align=\"left\"><b>Enter Password</b></p><?php
echo"<div class=\"left\">
<form action=\"chat.php?sid=<?php echo($sid) ?>&rid=$roomname[0]\" method=\"post\">
<b>Room Name:</b><br/>$roomname[1]<br/>
<b>Password:</b><br/><input name=\"pass\" maxlength=\"10\"/><br/>
<input type=\"submit\" Value=\"Enter\"/>
</form>
</div>\n";
?>
<a  href=\"../inbox/inbox.php?sid=<?php echo($sid) ?>\">Inbox</a>
<a  href=\"../buds/buds.php?sid=<?php echo($sid) ?>\">BuddyList</a>
<a  href=\"./public.php?sid=<?php echo($sid) ?>\">Chat</a>
<a  href=\"../forums/forums.php?sid=<?php echo($sid) ?>\">Forums</a>
<a  href="../main.php?sid=<?php echo($sid) ?>">Main Menu</a>
<?php
echo foot_tag();
exit;
}
}

if(!canenter(getuid_sid($sid),$rid))
{
echo head_tag(getnick_sid($sid)."@".$roomname[1],1,getnick_sid($sid));
?>
<p align="left"><img src="../images/error.gif" alt="[x]"><b>Permission denied</b><br/>You can't enter this room</p>
<a  href=\"../inbox/inbox.php?sid=<?php echo($sid) ?>\">Inbox</a>
<a  href=\"../buds/buds.php?sid=<?php echo($sid) ?>\">BuddyList</a>
<a href=\"./public.php?sid=<?php echo($sid) ?>\">Chat</a>
<a  href=\"../forums/forums.php?sid=<?php echo($sid) ?>\">Forums</a>
<a href="../main.php?sid=<?php echo($sid) ?>">Main Menu</a>
<?php
echo foot_tag();
exit;
}

addtochat(getuid_sid($sid),$rid);
$timeto=300;
$timenw=time();
$timeout=$timenw-$timeto;
$deleted=mysql_query("DELETE FROM chat WHERE timesent<".$timeout."");
$rooms=mysql_fetch_array(mysql_query("SELECT id, name FROM chatrooms WHERE id='".$rid."'"));
$rname=$rooms[1];

echo "<head><title>".getnick_sid($sid)."@$roomname[1]</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"../style.php?uid=".getnick_sid($sid)."\"/>\n";
if($count_popup[0]<1){
echo "<meta http-equiv=\"refresh\" content=\"20; url=chat.php?sid=$sid&rid=$rid$pw\"/>\n";
}
echo "</head><body>\n";

?><div class="div">Welcome to <?php echo($roomname[1])?> Chatroom</div><?php

addonline(getuid_sid($sid),"Chatting In ".$roomname[1],"chat/chat.php?rid=<?php echo($rid) ?><?php echo($pw) ?>");
if($count_popup[0]>0){
$rname=mysql_fetch_array(mysql_query("SELECT name FROM chatrooms WHERE id='".$rid."'"));
$popsenabled=mysql_fetch_array(mysql_query("SELECT popups FROM users WHERE id='".getuid_sid($sid)."'"));
$pminfo=mysql_fetch_array(mysql_query("SELECT id, text, byid, timesent, toid, reported FROM popups WHERE unread='1' AND toid='".getuid_sid($sid)."'"));
mysql_query("UPDATE popups SET unread='0' WHERE id='".$pminfo[0]."'");
if(isspam($pminfo[1])){mysql_query("UPDATE popups SET reported='1' WHERE id='".$pminfo[0]."'");}
$sex=mysql_fetch_array(mysql_query("SELECT sex, image FROM profiles WHERE uid='".$pminfo[2]."'"));
if($sex[0]=="M"){$usersex="<img src=\"../images/male.gif\" alt=\"(M)\"/>";$color="#0000FF";}
if($sex[0]=="F"){$usersex="<img src=\"../images/female.gif\" alt=\"(F)\"/>";$color="#FF0066";}
if($sex[1]!=""){$usersex=getbbcode($sex[1],$sid,1);}

?><div class=\"left\"><b>Popup Message<br/><?php

echo "From $usersex<span style=\"color:$color;\">".getnick_uid($pminfo[2])."</span></b><br/>
<small>(".date("H:i-D jS M y",$pminfo[3]).")</small><br/>\n";
echogetbbcode($pminfo[1],$sid,1)."
<form action=\"../popups.php?send=1&who=$pminfo[2]&msgid=$pminfo[0]&sid=<?php echo($sid) ?>\" method=\"post\">
<b>Reply</b><br/>
<input name=\"message\" maxlength=\"500\"/><br/>
<input type=\"submit\" value=\"Send\"/>
</form>";
?>
<a href="./chat.php?rid=<?php echo($rid) ?>&sid=<?php echo($sid) ?><?php echo($pw) ?>">Skip Msg</a>
</div>
<?php
}

?><a name="top" id="top" href="write.php?sid=<?php echo($sid) ?>&rid=<?php echo($rid) ?><?php echo($pw) ?>">Write</a><br/><?php

$unreadinbox=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM inbox WHERE unread='1' AND toid='".getuid_sid($sid)."'"));
$unrd="".$unreadinbox[0]."";
if($unreadinbox[0]>0){
$inbox="Inboxes";
if($unreadinbox[0]==1)$inbox="Inbox";
echo"<a  href=\"../inbox/inbox.php?sid=$sid&rid=$rid$pw\">$unrd New $inbox</a><br/>\n";
}
echo"<a  href=\"./chat.php?sid=$sid&rid=$rid$pw\">Refresh</a><br/>\n";
$message=$_POST["message"];
$who=$_POST["who"];
$rinfo=mysql_fetch_array(mysql_query("SELECT censored, freaky FROM chatrooms WHERE id='".$rid."'"));
if(trim($message)!=""){
if(!blocked_site($message,getuid_sid($sid)))
{
if($to_user=="*")$to_user="";
$chatok=mysql_query("INSERT INTO chat SET uid='".getuid_sid($sid)."', toid='".$to_user."', timesent='".time()."', text='".$message."', rid='".$rid."'");
$points=mysql_fetch_array(mysql_query("SELECT points FROM profiles WHERE uid='".getuid_sid($sid)."'"));
$update=$points[0]+1;
$point=mysql_query("UPDATE profiles SET points='".$update."' WHERE uid='".getuid_sid($sid)."'");
$lstmsg=mysql_query("UPDATE chatrooms SET lastmsg='".time()."' WHERE id='".$rid."'");
$hehe=mysql_fetch_array(mysql_query("SELECT chatmsgs FROM profiles WHERE uid='".getuid_sid($sid)."'"));
$totl=$hehe[0]+1;
$msgst=mysql_query("UPDATE profiles SET chatmsgs='".$totl."' WHERE uid='".getuid_sid($sid)."'");
$clubid=mysql_fetch_array(mysql_query("SELECT clubid FROM chatrooms WHERE id='".$rid."'"));
$pts=mysql_fetch_array(mysql_query("SELECT points FROM clubs WHERE id='".$clubid[0]."'"));
if($clubid[0]!=0){mysql_query("UPDATE clubs SET points='".($pts[0]+1)."' WHERE id='".$clubid[0]."'");}
}else{
$bantime=time()+(30*24*60*60);
echo"<img src=\"images/notok.gif\" alt=\"X\"/><br/>Can't Post Msg<br/>
You just tried sending a msg with a link to one of the crapiest sites on earth<br/>
The members of these sites spam here a lot, so go to that site and stay there if you don't like it here<br/>
as a result of your stupid action:<br/>
1. you have lost your sheild<br/>
2. you have lost all your plusses<br/>
3. You are BANNED";
mysql_query("INSERT INTO logs SET action='autoban', details='<b>".getnick_uid(1)."</b> auto banned ".getnick_sid($sid)." for spamming chat', date='".time()."'");
mysql_query("INSERT INTO banned SET uid='".getuid_sid($sid)."', penalty='3', byid='1', remaining='".$bantime."', reason='Banned: Automatic Ban for spamming for a crap site'");
mysql_query("UPDATE profiles SET points='0', WHERE uid='".getuid_sid($sid)."'");
mysql_query("INSERT INTO inbox SET text='[b](forwarded spam via chat)[/b][br/]".$message."', byid='".getuid_sid($sid)."', toid='1', reported='1', timesent='".time()."'");
echo xhtml($sid,$title,0,0,0,0,0,0,0,0,0,$main);
echo foot_tag();
exit;
}

if($rinfo[1]==2){
$botid="eeb070e74e366473";
$hostname="www.pandorabots.com";
$hostpath="/pandora/talk-xml";
$sendData="botid=".$botid."&input=".urlencode($message)."&custid=".$custid;
$result=PostToHost($hostname, $hostpath, $sendData);
$pos=strpos($result, "custid=\"");
$pos=strpos($result, "<that>");
if($pos===false){$reply="";}
else{
$pos+=6;
$endpos=strpos($result, "</that>", $pos);
$reply=substr($result, $pos, $endpos - $pos);
$reply=mysql_escape_string($reply);
}
$chatok=mysql_query("INSERT INTO chat SET uid='1', toid='', timesent='".time()."', text='".$reply." @".getnick_uid(getuid_sid($sid))."', rid='".$rid."';");
}
$message="";
}
echo"<p>\n";
$chats=mysql_query("SELECT uid, toid, timesent, text, exposed FROM chat WHERE rid='".$rid."' ORDER BY timesent DESC, id DESC");
$counter=0;
while($chat=mysql_fetch_array($chats)){
$canc=true;
if($counter<40){
/*if(ignored($chat[0],getuid_sid($sid))){$canc=false;}*/
if($chat[0]!=getuid_sid($sid)){
if($chat[1]!=0){
if($chat[1]!=getuid_sid($sid)){$canc=false;}
}
}
if(($chat[4]=='1')&&(ismod(getuid_sid($sid)))){$canc=true;}
if($canc){
$sex=mysql_fetch_array(mysql_query("SELECT sex, image FROM profiles WHERE uid='$chat[0]'"));
if($sex[0]=="M"){$usersex="<img src=\"../images/male.gif\" alt=\"(M)\"/>";$color=" style=\"color:#0000FF\"";}
if($sex[0]=="F"){$usersex="<img src=\"../images/female.gif\" alt=\"(F)\"/>";$color=" style=\"color:#FF0066\"";}
if($sex[0]==""){$usersex="";}
if($sex[1]!=""){$usersex=getbbcode($sex[1],$sid,1);}
$chnick=getnick_uid($chat[0]);
$optlink=$usersex.$chnick;
if(($chat[1]!=0)&&($chat[0]==getuid_sid($sid))){$optlink="<img src=\"../images/out.gif\" alt=\"\"/>Pm To ".getnick_uid($chat[1])."";}
if($chat[1]==getuid_sid($sid)){$optlink="<img src=\"../images/in.gif\" alt=\"\"/>Pm By ".getnick_uid($chat[0])."";}
if($chat[4]=='1'){$optlink="<img src=\"../images/point.gif\" alt=\"\"/>".getnick_uid($chat[0])."<img src=\"../images/in.gif\" alt=\"\"/>".getnick_uid($chat[1])."";}
if(isspam(getbbcode($chat[3],$sid,1))){echo"<b>Chat System»<i>oi ".getnick_uid($chat[0]).", no spamming</i></b><br/>";}
else if(substr_count(getbbcode($chat[3],$sid,1),"<img src=")>2){echo"<b>Chat System»<i>hey ".getnick_uid($chat[0]).", you can only use 2 smilies per msg</i></b><br/>";}
else{
$flood=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM chat WHERE text='".htmlspecialchars($chat[3],ENT_QUOTES)."' AND uid='".$chat[0]."'"));
if(substr($chat[3],0,3)=="/me"){echo"<b>$chnick»<i>".getbbcode(substr($chat[3],4,strlen($chat[3])-3),$sid,1)."</i></b><br/>";}
else if($flood[0]>1){echo"<b>Chat System»<i>hey ".getnick_uid($chat[0]).", U Cannot Flood This Room</i></b><br/>";
$points=mysql_fetch_array(mysql_query("SELECT points FROM profiles WHERE uid='".$chat[0]."'"));
$update=$points[0]-1;
$point=mysql_query("UPDATE profiles SET points='".$update."' WHERE uid='".$chat[0]."'");
mysql_query("DELETE FROM chat WHERE text='".$chat[3]."' AND uid='$chat[0]' LIMIT 1");
}
else if($chat[3]!=""){
if($rinfo[0]==0){$tosay=getbbcode($chat[3],$sid,0);}
else{$tosay=getbbcode($chat[3],$sid,1);}
if($rinfo[1]==1){$tosay=strrev($tosay);}
echo"<a href=\"./pm.php?who=$chat[0]&sid=$sid&rid=<?php echo($rid) ?>$pw\"$color>$optlink</a> - $tosay<br/>\n";
}
}
$counter++;
}
}
}

$chatters=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM chatonline where rid='".$rid."'"));

?></p>
<a name="opt" id="opt" href="./chat.php?sid=<?php echo($sid) ?>&rid=<?php echo($rid) ?><?php echo($pw) ?>">Refresh</a><br/>
<a href="./write.php?sid=<?php echo($sid) ?>&rid=<?php echo($rid) ?><?php echo($pw) ?>">Write</a><br/>
<a href="./settings.php?sid=<?php echo($sid) ?>&rid=<?php echo($rid) ?><?php echo($pw) ?>">Settings</a><br/>
<a href="./inside.php?sid=<?php echo($sid) ?>&rid=<?php echo($rid) ?><?php echo($pw) ?>">Whos Inside <? echo $chatters[0] ?></a><br/>
<a href="./public.php?sid=<?php echo($sid) ?>">Chat</a><br/>
<a href="../main.php?sid=<?php echo($sid) ?>">Main Menu</a>
<div class="div">
blah blah
</div>
<?php

echo foot_tag();
?>

this is my old chat.php can anyone look throught to see what is actually wrong here everything will work but its really slow. also when about 10 people come on it becomes really really slow. i think it maybe something in the loop ?

Want something coded email me at sales@webnwaphost.com for a prices.

http://flagcounter.com/more/W80q

syrus Junior · 44 posts #3

crazybrumi wrote: would be usefull if someone tries this on there site on there own server because if this work it maybe an appache problem or sumathin.

and how do u expect someone to test that? By the way u ask whats wrong with it well everything is wrong,broken,bad everything thats bad would describe it

Mysterio Lead · 630 posts #4

lol @ syrus, why not test it? Is that lava based? I am in bed now but i will test it when i be in the office tomorrow.

mysterio.al - programming is a functional art

syrus Junior · 44 posts #5

Mysterio3 wrote: lol @ syrus, why not test it? Is that lava based? I am in bed now but i will test it when i be in the office tomorrow.

simply, its imposable to test that stand alone page as is. Am asuiming it belongs to 1 of those mods from the look of it with so many unwanted functions, vars, resource eating queries etc

crazybrumi Super moderator Principal · 1,064 posts #6

syrus wrote: simply, its imposable to test that stand alone page as is. Am asuiming it belongs to 1 of those mods from the look of it with so many unwanted functions, vars, resource eating queries etc

yeh it is wapdesire but theres 1 or two additional functions if that. so it should work , u just need to replace the chat.php

Want something coded email me at sales@webnwaphost.com for a prices.

http://flagcounter.com/more/W80q

BioBeo Developer · 67 posts #7

u guys r talking on a wasted thing which lava php chat... lol.. sucks.g

No one could help you If you don't help yourself. My facebook

something else Fellow · 2,296 posts #8

Few things you can try to do to make it faster is things like cut down on the number of calls to the database eg:

These 3 lines could have been called all at once rather than 3 seperate calls to db

$rooms=mysql_fetch_array(mysql_query("SELECT id, name FROM chatrooms WHERE id='".$rid."'"));
$rname=mysql_fetch_array(mysql_query("SELECT name FROM chatrooms WHERE id='".$rid."'"));
$rinfo=mysql_fetch_array(mysql_query("SELECT censored, freaky FROM chatrooms WHERE id='".$rid."'"));

also these lines:

$points=mysql_fetch_array(mysql_query("SELECT points FROM profiles WHERE uid='".getuid_sid($sid)."'"));
$update=$points[0]+1;
$point=mysql_query("UPDATE profiles SET points='".$update."' WHERE uid='".getuid_sid($sid)."'");
$hehe=mysql_fetch_array(mysql_query("SELECT chatmsgs FROM profiles WHERE uid='".getuid_sid($sid)."'"));
$totl=$hehe[0]+1;
$msgst=mysql_query("UPDATE profiles SET chatmsgs='".$totl."' WHERE uid='".getuid_sid($sid)."'");

could all be done in 1 line eg:

mysql_query("UPDATE profiles SET chatmsgs=chatmsg+1, points=points+1  WHERE uid='".getuid_sid($sid)."'");

This Form looks wrong to me:

echo"<div class=\"left\">
<form action=\"chat.php?sid=<?php echo($sid) ?>&rid=$roomname[0]\" method=\"post\">  
<b>Room Name:</b><br/>$roomname[1]<br/>
<b>Password:</b><br/><input name=\"pass\" maxlength=\"10\"/><br/>
<input type=\"submit\" Value=\"Enter\"/>
</form>
</div>\n";

Your opening php in the line:

 form action=\"chat.php?sid=<?php echo($sid) ?>&rid=$roomname[0]\" method=\"post\">  

when it is already open

and also possibly cut down on more echo`s (even tho a lot of them are removed already) eg: change:

?><div class="div">Welcome to <?php echo($roomname[1])?> Chatroom</div><?php

To:

?><div class="div">Welcome to <?=$roomname[1]?> Chatroom</div><?php

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close