Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Instant message System

ocYrusocYrus Member Posts: 15
Ok im writing this script for a module on h3c, Everythign is working except one minor thing, When people send messages to each other and then hit enter a couple of times, the person they sent it to can't see there messages until they clear their messages. Heres the code,


#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print header;
#Variables
$pwfile121 = "password.dat"; #password file
$messages = "data/"; #messages go in here
$error = 0;
use CGI qw(param);
$user = param("user");
$pass = param("pass");
$action = param("action");
$to = param("to");
$message = param("message");
if($user eq "") {
&error("Missing Username");
}
if($pass eq "") {
&error("Missing Password");
}
open(DATA, "$pwfile121");
$data = ;
close(DATA);
@lines = split(/&/,$data);
$logged = "OUT";
foreach $line (@lines) {
($tmpuser,$tmppass) = split(/|/,$line);
if($user eq $tmpuser) {
if($pass eq $tmppass){
$logged = "IN";
}
}
}
if($logged eq "OUT") { &error("Login information Not correct, contact ocYrus"); }
if($error == 0) {
if($action eq "send") {
if($message eq ""){ print "You must type something" }
$sending = 0;
foreach $line (@lines){
($tmpuser,$tmppass) = split(/|/,$line);
if($tmpuser eq $to){
$sending = 1;
}
}
if($sending == 1){
if($message =~ /s[a-zA-Z0-9]/){
open(SEND, ">>$messages$to");
print SEND "$user|$message&";
close(SEND);
}
else{
print "Invalid Characters";
}
}
else {
print "User Not Found";
} } elsif($action eq "clear") {
open(DEL, ">$messages$user");
print DEL "";
close(DEL);
} elsif ($action eq "get") {
} elsif ($action eq "users"){
print "User List";
foreach $line (@lines){
($tmpuser,$tmppass) = split(/|/,$line);
print "$tmpuser

";
}

exit(0);
}

print<<HTML;
<html>Logged In: $user



Messages:

HTML
open(MESSAGE, "$messages$user");
$tmpmess = ;
close(MESSAGE);
@messages1 = split(/&/, $tmpmess);
foreach $mess (@messages1){
($tmpfrom,$tmpmessage) = split(/|/,$mess);
print "From: $tmpfrom
";
print "Message:
$tmpmessage

";
}
print


Clear


Get Messages


User List




Send Message:



To:


Message:








HTML2
}
sub error {
$msg = shift(@_);
++$error;
if($error == 1) {
print<<HTML3;
H3C Text Messenger, To get a user email ocyrus@imagine-webdesigns.com
<html> ERROR:



Username:

Password:





HTML3
}
print "$msg";
}

Comments

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    _______ / http://forcoder.org / free ebooks and video tutorials about [ C++, Go, Java, Scratch, Swift, PHP, MATLAB, Objective-C, PL/SQL, Delphi, Perl, Assembly, C#, Python, JavaScript, Visual Basic .NET, Ruby, C, Visual Basic, R VBScript, Scheme, F#, SAS, Lua, Crystal, Lisp, Rust, ML, Alice, Prolog, ABAP, Dart, Erlang, Fortran, Bash, D, LabVIEW, Awk, Clojure, Hack, Apex, Kotlin, Julia, Logo, Transact-SQL, Scala, Ada, FoxPro, COBOL ] _____

Sign In or Register to comment.