home *** CD-ROM | disk | FTP | other *** search
- <[
- // WINC - Chat Command
- // (c) 1997 SmartDesk, Inc., All Rights Reserved
-
-
- FUNCTION AddChatRecord( session, filename, name, msg )
-
- local data, x, z, id, rc
-
- rc = 1
-
- x = chr( 1 ) // field delimeter
- z = chr( 2 ) // record delimeter
-
- data = date( "YYYYMMDD" ) + x + time( ) + x + name + x + msg + z
- id = "CHATBUF." + filename
-
- if ( ! sessionDataAppend( session.websrvr, -1, id, data ) )
- sessionDataFlushRecords( session.websrvr, -1, id, filename, z, 0 )
- rc = sessionDataAppend( session.websrvr, -1, id, data )
- end
-
- return( rc )
- END
-
- // MAIN
-
- _apGenerate( )
-
- TRY
-
- websrvr = 0 + param( 1 )
- sessionId = 0 + param( 2 )
-
- session = new( "session", websrvr, sessionId )
- channel = session.data( "winc_channel" )
- if ( channel < 1 )
- channel = 1
- end
-
- filename = fileFixPath( webServerHome( websrvr ) + "\\chat\\chan" + channel + ".dat" )
-
- chatname = session.data( "winc_alias" )
- if ( strempty( chatname ) )
- session._redir( "One Moment Please...", "logon.ap" )
- return( 0 )
- end
-
- // convert cmd from referer...unless the logoff command...
- if ( session.var( "cmd" ) == "logoff" )
- cmd = "logoff"
- else
- data = lower( session.data( "REFERER" ) )
- if ( strat( "chat1.ap", data ) )
- cmd = "chat"
- elseif ( strat( "logon.ap", data ) )
- cmd = "logon"
- elseif ( strat( "dir.ap", data ) )
- cmd = "logon"
- elseif ( strat( "images.ap", data ) )
- cmd = "image"
- elseif ( strat( "links.ap", data ) )
- cmd = "link"
- elseif ( strat( "sounds.ap", data ) )
- cmd = "sound"
- elseif ( strat( "prefer.ap", data ) )
- cmd = "preferences"
- elseif ( strat( "comments.ap", data ) )
- cmd = "comment"
- elseif ( strat( "trans.ap", data ) )
- cmd = "transcript"
- else
- cmd = ""
- end
- end
-
- switch ( cmd )
- case "logon"
- if ( session.data( "winc_islogged" ) != "1" )
- AddChatRecord( session, filename, "ADMIN", "Welcome <B>" + chatname + " (<FONT COLOR=red>" + session.data( "winc_name" ) + "</FONT>)</B> to the conversation." )
- session.data( "winc_islogged", "1" )
- end
- session.data( "winc_cmd", "" )
- break
- case "logoff"
- AddChatRecord( session, filename, "ADMIN", "<B>" + chatname + " (<FONT COLOR=red>" + session.data( "winc_name" ) + "</FONT>)</B> has left the conversation." )
- session.data( "winc_islogged", "0" )
- session.response( "HTTP/1.0 302 Redirect\r\nDate: " + webGMT( ) + "\r\nServer: SmartDesk Personal Web Server v1.0\r\nLocation: /chat/dir.ap\r\n\r\n" )
- return( 1 )
- case "chat"
- msg = session.var( "msg" )
- if ( ! strempty( msg ) )
- AddChatRecord( session, filename, chatname, msg )
- end
- session.data( "winc_cmd", "" )
- break
- case "image"
- desc = session.var( "image" )
- if ( ( ! strempty( desc ) ) && ( left( desc + " ", 4 ) != "----" ) )
- file = fileFixPath( webServerHome( websrvr ) + "\\chat\\chan" + channel + ".cfg" )
- channelData = new( "iniFile", file )
- if ( type( channelData ) == "O" )
- data = channelData.getItems( "Images" )
- cnt = chrcount( ";", data ) + 1
- for ( i=1; i<=cnt; i++ )
- item = strextract( data, ";", i )
- if ( strempty( item ) )
- continue
- end
- line = channelData.getString( "Images", item )
- if ( desc == strextract( line, "|", 1 ) )
- // AddChatRecord( session, filename, chatname, "<IMG BORDER=0 SRC=\"" + strextract( line, "|", 2 ) + "\">" )
- AddChatRecord( session, filename, chatname, "<A HREF=\"" + strextract( line, "|", 2 ) + "\">" + strextract( line, "|", 1 ) + "</A>" )
- end
- end
- end
- end
- session.data( "winc_cmd", "" )
- break
- case "link"
- desc = session.var( "link" )
- if ( ( ! strempty( desc ) ) && ( left( desc + " ", 4 ) != "----" ) )
- file = fileFixPath( webServerHome( websrvr ) + "\\chat\\chan" + channel + ".cfg" )
- channelData = new( "iniFile", file )
- if ( type( channelData ) == "O" )
- data = channelData.getItems( "Links" )
- cnt = chrcount( ";", data ) + 1
- for ( i=1; i<=cnt; i++ )
- item = strextract( data, ";", i )
- if ( strempty( item ) )
- continue
- end
- line = channelData.getString( "Links", item )
- if ( desc == strextract( line, "|", 1 ) )
- AddChatRecord( session, filename, chatname, "<A HREF=\"" + strextract( line, "|", 2 ) + "\" TARGET=\"_top\">" + desc + "</A>" )
- end
- end
- end
- end
- session.data( "winc_cmd", "" )
- break
- case "sound"
- desc = session.var( "sound" )
- if ( ( ! strempty( desc ) ) && ( left( desc + " ", 4 ) != "----" ) )
- file = fileFixPath( webServerHome( websrvr ) + "\\chat\\chan" + channel + ".cfg" )
- channelData = new( "iniFile", file )
- if ( type( channelData ) == "O" )
- data = channelData.getItems( "Sounds" )
- cnt = chrcount( ";", data ) + 1
- for ( i=1; i<=cnt; i++ )
- item = strextract( data, ";", i )
- if ( strempty( item ) )
- continue
- end
- line = channelData.getString( "Sounds", item )
- if ( desc == strextract( line, "|", 1 ) )
- AddChatRecord( session, filename, chatname, "<<< <A HREF=\"" + strextract( line, "|", 2 ) + "\">" + desc + "</A> >>>" )
- end
- end
- end
- end
- session.data( "winc_cmd", "" )
- break
- case "transcript"
-
- if ( sessionDataGet( websrvr, -1, "IsInTranscript" ) == "1" )
- break
- end
- sessionDataGet( websrvr, -1, "IsInTranscript", "1" )
-
- if ( fileExists( filename ) )
- ferase( filename )
- end
- hfile = fileCreate( filename )
- if ( hfile < 1 )
- break
- end
-
- data = sessionDataGet( websrvr, -1, "CHATBUF." + filename )
- data = chrswap( data, chr( 1 ), "," )
- data = strswap( data, chr( 2 ), "\r\n" )
-
- fwrite( hfile, data, len( data ) )
- fclose( hfile )
-
- webServerSendFile( websrvr, hsock, filename )
-
- sessionDataGet( websrvr, -1, "IsInTranscript", 0 )
-
- session.data( "winc_cmd", "" )
- session.redir( "", "/chat/chan" + channel + ".dat" )
- return( 1 )
-
- break
- case "preferences"
- session.data( "winc_reload_time", session.var( "freq" ) )
- session.data( "winc_pglen", session.var( "pglen" ) )
- session.data( "winc_cmd", "" )
- break
- case "comment"
- str = session.var( "comment" )
- str2 = ""
- if ( left( str + " ", 4 ) != "----" )
- str2 = str
- end
-
- str = session.var( "action" )
- if ( left( str + " ", 4 ) != "----" )
- switch ( upper( str ) )
- case "USER NAME"
- str = session.data( "winc_name" )
- break
- case "ALIAS"
- str = session.data( "winc_alias" )
- break
- case "EMAIL ADDRESS"
- str = session.data( "winc_email_addr" )
- str = "<A HREF=\"mailto: " + str + "\">" + str + "</A>"
- break
- case "TIME STAMP"
- str = cdow( jdate( ) ) + date( ", MMMM DDDD, YYYY at " ) + timetostr( time( ), 0 ) + "m"
- break
- case "DATE"
- str = cdow( jdate( ) ) + date( ", MMMM DDDD, YYYY at " )
- break
- case "TIME"
- str = timetostr( time( ), 0 ) + "m"
- break
- end
- if ( ! strempty( str2 ) )
- str2 += " " + str
- else
- str2 = str
- end
- end
-
- str = session.var( "icon" )
- if ( left( str + " ", 4 ) != "- Em" ) // emoticons
- if ( ! strempty( str2 ) )
- str2 += " " + str
- else
- str2 = str
- end
- end
- if ( ! strempty( str2 ) )
- AddChatRecord( session, filename, chatname, str2 )
- end
- session.data( "winc_cmd", "" )
- break
- end
-
- session.redir( "", "chattext.ap" )
-
- return( 1 )
-
- CATCH ( err )
- msgDelay( 3000, "Error [" + err.errornum + "] at line #" + err.errorline + " (" + ErrorAsText( err.errornum ) + ")" )
- println( "Error [" + err.errornum + "] at line #" + err.errorline + " (" + ErrorAsText( err.errornum ) + ")" )
- return( 0 )
- END
- ]>
-