Closed Thread Icon

Topic awaiting preservation: Live chat script. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12916" title="Pages that link to Topic awaiting preservation: Live chat script. (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Live chat script. <span class="small">(Page 1 of 1)</span>\

 
amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 10-06-2003 02:55

Hi, if anyone can improve on this, I'd be very greatful.
It's an application for a live chat, where the messages are updated imidiatly, and where you can send messages inbetween users as well.
- Ideas anyone??

The first part is the clientside code, and the other is the server-file.
It's just one, and it's using ASP.

<pre>


<html>
<head>
<title>Live_chat v.1.0</title>
<script
id="register"
mode="chat"
template="<br><font style='color:black;border:solid black 2px;width:200;padding:3px;font-face:verdana;font-size:10pt;'><b>[TITLE]</b><br><span style='text-align:center;margin:1px;font-family:verdana;font-size:9px;cursor:hand;color:black;background-color:buttonhighlight;border:solid black 1px;width:70;font-size:9px;display:block' onclick='callUp()' visitor='[THE_ID]'>Send to..</span><br><span id='account'><span onclick='parent.viewTheCodeNow(this.parentElement.children(1).innerText)' style='text-align:center;margin:1px;border:black 1px solid;background-color:buttonhighlight;font-family:verdana;font-size:9px;cursor:hand;display:block;width:70'>Codeview</span><span>[POST]</span></span>&lt ;/font>";
src="http://www.naltabyte.se/rent_a_chat/files/mail.asp">
</script>
</head>
<body >

<center>

<table style="width:100%;height:100%;background-color:butt****ce;border utset 2px;z-index:8;padding:10">
<tr valign="top" style="width:100%;height:100%">
<td align="right" style="width:30%;height:100%">

<input type="text" id="title" style="background-color:white;border:solid butt****ce 1px;width:100%"><b>Name:</b><br />
<textarea id="post" style="background-color:white;border:solid butt****ce 1px;width:100%;height:70%"></textarea>
<br />
&nbsp;<button onclick="Call()" style="height:20;width:50;font-size:10">Post</button>
</td>
<td style="width:50%;height:100%;border-left:dotted butt****ce 1px">
<div id="printOut" style="position:relative;top:3;left:0;padding:15;background-color:white;width:100%;height:100%;overflow:scroll">
</div>
</td>
</tr>
<tr>
<td colspan="2" align="right" style="width:100%;height:100%">
</td>
</tr>
</table>
</center>

</body>
</html>

</pre>


And the server-part.


<pre>

<% @ LANGUAGE=JScript %>

<% Response.ContentType = "application/x-javascript .js" %>

<%

ForAppending=8;
ForWriting=2;
ForReading=1;

tribuned=new String(Request.Querystring);
tribuned=tribuned.split("<cut>");

if(!tribuned[1])
{

%>

reply="";
num="";
adress="liquid21";

document.write("<script id='call'><"+"/script>");
window.onload=signOn;

function thePackage()
{
str=document.all.register.template;
if(str=="0"){str="<br/><font style='color:black;border:solid black 2px;width:200;padding:3px;font-face:verdana;font-size:10pt;'><b>[TITLE]</b><br/><b style='cursor:hand;color:black;background-color:silver;border:solid red 1px;padding:2px;height:15;overflow:hidden;width:70;font-size:9px' onclick='callUp()' visitor='[THE_ID]'>Send to..</b><br/><br/>Post: <span id='account'>[POST]</span></font>";}
if(document.all.title){str=str.replace("[TITLE]",document.all.title.value);}
if(document.all.post){str=str.replace("[POST]",document.all.post.value);}
if(document.all.link_to){str=str.replace("[LINK_TO]",document.all.link_to.value);}
if(document.all.mail){str=str.replace("[MAIL_TO]",document.all.mail.value);}
str=str.replace("[THE_ID]",document.body.timestamp);
package=escape(str);
return package
}
function Call()
{
document.all.post.active="yes";
validate(document.all.post.value);
conn="http://www.naltabyte.se/rent_a_chat/files/mail.asp?the_mail_out<cut>";
num++;
thePackage();
act=adress+"<cut>"+package+"<cut> 'the_"+num+"'";
document.all.call.src=conn+act;
document.all.post.value="";
if(reply==""){return false;}
else
{
num++;
reply="";
setTimeout('CallOne(0)',2000);
}
}

function CallOne(addon)
{
conn="http://www.naltabyte.se/rent_a_chat/files/mail.asp?the_mail_in<cut>";
num++;
act=addon+"<cut>"+document.body.setTime+"<cut>"+document.all.post.value+"<cut>-<cut> 'the_"+num+"'";

call.src=conn+act;
if(reply==""){return false;}
else
{
num++;
reply="";
}
}
function signOn()
{
if(document.all.post){document.all.post.active="no";}
document.onkeypress=SetAt;
day=new Date();
day=day.toGMTString();
day=day.replace(/:/g,".");

if(!document.body.timestamp)
{
document.body.timestamp=day;
document.body.setTime="0";
setInterval('CallOne(0)',2000)
}
}
function SetAt(){if(document.all.post){document.all.post.active='no';}}

function validate(data)
{

ndata=document.all.post.value;
for(i=0;i < ndata.length;i++)
{
ndata=ndata.replace("<","<");
ndata=ndata.replace(">",">");
ndata=ndata.replace("(","acccc");
ndata=ndata.replace(")","cccca");
ndata=ndata.replace('"','&quot;');
}
document.all.post.value=ndata;
}
function callUp()
{
document.body.setTime=event.srcElement.visitor;
CallOne('send');
document.all.post.active='yes';
}

<%
}

if(tribuned[0]=="the_mail_out"){finish();}
if(tribuned[0]=="the_mail_in"){startup();}
if(tribuned[1]=="send"){sender();}

function finish()
{
strFil="";
indata=" ";
Fsave=" ";
Fstore="";

fso=new ActiveXObject("Scripting.FileSystemObject");

if(fso.FileExists(Server.MapPath("liquid21")))
{
ofil=fso.OpenTextFile(Server.MapPath("liquid21"), ForReading, true);
while(!ofil.AtEndOfStream){strFil+=ofil.ReadLine();}

var x=unescape(strFil);
x=x.split("#");
for(i=0;i < 5;i++){if(!x[i]){break;}indata+=x[i]+"#";}
ofil.Close();

File=fso.OpenTextFile(Server.MapPath("liquid21"), ForWriting, true);
Fsave+=tribuned[2];
Fsave+="<span style='visibility:hidden'>#</span><br>";
File.WriteLine(unescape(Fsave));
File.Write(unescape(indata));
File.Close();
}
if(!fso.FileExists(Server.MapPath("liquid21")))
{
objFile=fso.CreateTextFile(Server.MapPath("liquid21"), true);
objFile.Write(" ")
objFile.Close();
}

%>

<%
}

function startup()
{
strFil="";
indata="";

fso=new ActiveXObject("Scripting.FileSystemObject");
if(fso.FileExists(Server.MapPath("liquid21")))
{
ofil=fso.OpenTextFile(Server.MapPath("liquid21"), ForReading, true);
while(!ofil.AtEndOfStream){strFil+=ofil.ReadLine();}
ofil.Close();

x=unescape(strFil);
x=x.split("#");

for(i=0;i < 6;i++){if(!x[i]){break;}indata+=x[i];}

str="";
fso=new ActiveXObject("Scripting.FileSystemObject");
ofile=fso.OpenTextFile(Server.MapPath("mail.txt"));
while(!ofile.AtEndOfStream) {str += ofile.ReadLine();}
ofile.Close();

%>

printoutdata="<% Response.Write(indata) %>";

printoutdata1=printoutdata.replace(/acccc/g, "(");
printoutdata1=printoutdata1.replace(/cccca/g, ")");

document.all.printOut.innerHTML=printoutdata1;
reply="Success";

recalling();

function recalling()
{
x="<% Response.Write(str) %>";
identity=x.split("<cut>");
if(identity[0]==document.body.timestamp && document.all.post.active=="yes")
{
document.all.post.value=identity[1];
}
}


<%
}
}

function sender()
{
objFSO=new ActiveXObject("Scripting.FileSystemObject");
objFile=objFSO.CreateTextFile(Server.MapPath("mail.txt"), true);
objFile.Write(unescape(tribuned[2])+"<cut>"+unescape(tribuned[3]))
objFile.Close();
}

%>

</pre>

(^-^)b

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-06-2003 03:32

amikael: What improvements were you looking for? Are there any problems with this script?

___________________
Emps

The Emperor dot org

amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 10-06-2003 03:38

I have a feeling that there are a lot of redundant code in here, stuff that repeats itself or does things in a too complicated manner.
I would also like to shorten it, and as you can see, it uses one textfile to save the current state of the chat, and one textfile to tempsave individual messages.
I would like to have both strings in the same file somehow, so that the app only needs one tempfile while running, instead of two.
Also, the mechanism to alert the user of an individual message is a bit unreliable, as it requires him/her to send something before they recieve their 'mail'.
Perhaps a popup-window would be better??

-- Comments??


(^-^)b

amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 10-06-2003 07:06

If it's cleaned up enough, it might be a good thing, since some people here have asked about something like this, and this is basically how our auction was done, found at http://www.naltabyte.com/body/main/auction.htm

I'm thinking it might be expanded into something nice, adding some features, like logging in/out, checking if you're online/offline, etc, while made publically availiable here, as open source.

Any takers?


(^-^)b

amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 10-12-2003 06:09

Come on, anyone???

(^-^)b

amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 10-19-2003 23:25

I've added a few things, like a popup-window that opens with private messages being sent, but it's still IE5x only, and it should work for Opera and Mozilla as well.
I have hit a few snags there, especially with Opera.
Whats up with their implementation of innerHTML and string-attributes???

(^-^)b

amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 10-19-2003 23:26

Um, the current version of the chat is found at http://www.naltabyte.se/liquid, under 'Contact us..'
It's also implemented in the editor featured at the same site.

(^-^)b

« BackwardsOnwards »

Show Forum Drop Down Menu