forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


VDS Chat Project

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript Open Source Projects
View previous topic :: View next topic  
Author Message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Fri Feb 21, 2003 9:06 pm    Post subject: VDS Chat Project Reply with quote

Here's something that is quite simple, but could be improved upon over
time. It's a simple VDS chat client/PHP chat server program. Notice that
the message has been submitted via the GET command because I was
still having trouble with the VDSIPP.DLL POST command. Sad

Client code:

Code:
Title VDSWORLD Chat Client
OPTION ERRORTRAP,Error
EXTERNAL VDSIPP.DLL
INTERNET HTTP,CREATE,1
INTERNET HTTP,THREADS,1,OFF
INTERNET HTTP,PROTOCOL,1,1
INTERNET HTTP,USERAGENT,1,"VDSWORLD Chat Client"

  DIALOG CREATE,VDSWORLD Chat Client,-1,0,388,246,RESIZABLE
  DIALOG ADD,STYLE,BOLD,,,B,,
  DIALOG ADD,TEXT,TEXT1,188,12,,,User name:
  DIALOG ADD,TEXT,TEXT2,10,12,,,Chat text:
  DIALOG ADD,EDIT,username,186,70,180,21,@iniread(settings,username)
  DIALOG ADD,LIST,session,25,13,356,130
  LIST ADD,SESSION,>> Welcome to the VDSWORLD Chat Client!
  LIST ADD,SESSION,>> Please wait while we retreive chat data...
  DIALOG ADD,TEXT,TEXT3,162,12,,,Input:
  DIALOG ADD,EDIT,input,160,42,328,21
  DIALOG ADD,BUTTON,Send,185,254,116,24,Send,,BOLD
  DIALOG ADD,BUTTON,Print,212,86,64,24,Print
  DIALOG ADD,BUTTON,Clear,212,12,64,24,Clear
  DIALOG ADD,BUTTON,About,212,158,64,24,About
  DIALOG ADD,BUTTON,Help,212,232,64,24,Help
  DIALOG ADD,BUTTON,Exit,212,306,64,24,Exit
  DIALOG SHOW
  DIALOG FOCUS,INPUT
  GOSUB GetData
:Evloop
  wait event,5
  goto @event()
 
:Timer
  GOSUB GetData
  goto evloop
 
:GetData
  INTERNET HTTP,GET,1,http://www.vdsworld.com/~freezingfire/chatter/session.chat
  DIALOG SET,SESSION,@INTERNET(HTTP,CONTENT,1)
  EXIT
 
:Resize
REM -- Apparently this doesn't work --
%W = @DLGPOS(W)
%H = @DLGPOS(H)
  DIALOG SETPOS,TEXT1,188,12,@DIFF(%W,200),@DIFF(%H,234)
  DIALOG SETPOS,TEXT2,10,12,@DIFF(%W,378),@DIFF(%H,234)
  DIALOG SETPOS,USERNAME,186,70,@DIFF(%W,202),@DIFF(%H,176)
  GOTO EVLOOP
 
:SendBUTTON
  IF @NOT(@dlgtext(input))
  WARN You must enter a message
  GOTO Evloop
  END
  IF @NOT(@dlgtext(username))
  WARN You must enter a username
  GOTO Evloop
  END
  INTERNET HTTP,GET,1,http://www.vdsworld.com/~freezingfire/chatter/chat.php?message=@dlgtext(input)&user=@dlgtext(username)
  goto timer
:PrintBUTTON
  list print,session
  goto evloop
:ClearBUTTON
  dialog clear,input
  goto evloop
:AboutBUTTON
  info VDSWORLD Chat Client BETA v1.0
  goto evloop
:HelpBUTTON
  warn Help coming soon...
  goto evloop
:Error
  warn Error @error(e) at line @error(n)! Please post this at http://forum.vdsworld.com.
:ExitBUTTON
:Close
  INTERNET HTTP,DESTROY,1
  exit


PHP Server Code: (extremely simple but it's all I had time for.)

Code:
<?php
$filename = "session.chat";
$date = date("h:i:s");
$IP = $REMOTE_ADDR;
$string = "<$user $date> $message\n";
$user = StrToUpper($user);

// Check for illegal names
if($user == "ADMIN"){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == "ADMIN."){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == "ADMINISTRATOR"){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == "WEBMASTER"){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == "SERVER"){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == ""){
$string = ">> PLEASE NOTE: No null usernames are allowed.\n";
}

$fp = fopen( $filename, "a" ) or die("ERROR: Couldn't open file! Please inform the webmaster.");
fwrite( $fp, $string );
fclose( $fp );
?>


I'm hoping that it can be improved upon; this could be a very good
asset to the VDS communtity. Very Happy

_________________
FreezingFire
VDSWORLD.com
Site Admin Team


Last edited by FreezingFire on Fri May 02, 2003 9:04 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Fri Feb 21, 2003 11:32 pm    Post subject: Reply with quote

Oh, BTW: Feel free to just try it out; it's already been "pre-wired".
Everything should be pretty much ready to go and try out. Wink

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Mon Oct 20, 2003 12:52 pm    Post subject: Reply with quote

Yo FF! Nice! I just noticed this piece of code...

Juts tried it and it works like a charm.

But one thing I'm having a problem with is when I have a message with spaces in it, it gets cut off..

Example:

Message: "Hello my friends"

Results in "Hello" on the server side

Is there a way around this?

Thanks. Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1537

PostPosted: Mon Oct 20, 2003 2:37 pm    Post subject: Reply with quote

More then likely the script will need to code spaces and other special characters. The special char for a space is %20.
Back to top
View user's profile Send private message
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Mon Oct 20, 2003 3:49 pm    Post subject: Reply with quote

Yea.. was coming to write that.. I simply forgot spaces are replaced by %20 in URLS .. Wink Thanks PK.

Thanks...

Now to learn a bit of PHP to modify this code to get the online user list..

Laughing
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Mon Oct 20, 2003 6:09 pm    Post subject: Reply with quote

Marty, I don't think you can get an online userlist with FreezingFire's code, because he only saves usernames when you say something. I guess you should make a script which loads a site (like onlineusers?myusername=Skit3000) every minute, and save it into a database. That way you can get and retreive the online users...
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Mon Oct 20, 2003 8:06 pm    Post subject: Reply with quote

Wow! Glad someone finally got interested! Very Happy

I'll be more than happy to continue developing this PHP/VDS script
with people if wanted. The reason this example uses the HTTP GET
protocol is because there was a bug with VDSIPP that the POST
protocol didn't work correctly due to the component used with it. Smile

Also we will be able to do an online user list and maybe even
conevert this to using UDP or TCP or something for sending and
receiving messages and maybe even make both a public and private
chat system. Smile

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1537

PostPosted: Mon Oct 20, 2003 8:08 pm    Post subject: Reply with quote

You might want to try the latest vdsipp, I think I fixed the issue with the POST problem.
Back to top
View user's profile Send private message
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Tue Oct 21, 2003 1:37 am    Post subject: Reply with quote

Great FF!

I started looking at PHP, and manage to get a user list.. But now I need to find how to delete the username when the client closes the connection.. Probably by sending something, username, to a delete.php. But I dnt know how yet.. I just started looking at the PHP syntax Wink

Thanks Skit BTW Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Tue Oct 21, 2003 10:18 am    Post subject: Reply with quote

I'll take another look at this very soon. Very Happy
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Tue Oct 21, 2003 12:33 pm    Post subject: Reply with quote

Ok, here's an small updated version of the original VDS code and PHP server file.

Update:
VDSCODE:
- Spaces in messages are replaced by %20
- Added an Online user list (still needs work)

PHP CODE:
- Added an extra file called onlineuser.chat were the variable user$ is stored.

Now I will try to find a way to delete the user$, when the VDS client disconnects. Also need to find a way to check if username is already taken. Probably by the client it can be done.

Code:
Title VDSWORLD Chat Client
rem Original code by FreezingFire
rem Updated by Marty
rem All credits goes to FreezingFire.

OPTION ERRORTRAP,Error

EXTERNAL VDSIPP.DLL
INTERNET HTTP,CREATE,1
INTERNET HTTP,THREADS,1,OFF
INTERNET HTTP,PROTOCOL,1,1
INTERNET HTTP,USERAGENT,1,"VDSWORLD Chat Client"

  DIALOG CREATE,VDSWORLD Chat Client,-1,0,546,246,RESIZABLE
REM *** Modified by Dialog Designer on 21/10/2003 - 07:51 ***
  DIALOG ADD,STYLE,BOLD,,,B,,
  DIALOG ADD,TEXT,TEXT1,188,12,,,User name:
  DIALOG ADD,TEXT,TEXT2,10,12,,,Chat text:
  DIALOG ADD,EDIT,username,186,70,180,21,@iniread(settings,username)
  DIALOG ADD,LIST,session,25,13,356,130
  LIST ADD,SESSION,>> Welcome to the VDSWORLD Chat Client!
  LIST ADD,SESSION,>> Please wait while we retreive chat data...
  DIALOG ADD,TEXT,TEXT3,162,12,,,Input:
  DIALOG ADD,EDIT,input,160,42,328,21
  DIALOG ADD,BUTTON,Send,185,254,116,24,Send,,BOLD
  DIALOG ADD,BUTTON,Print,212,86,64,24,Print
  DIALOG ADD,BUTTON,Clear,212,12,64,24,Clear
  DIALOG ADD,BUTTON,About,212,158,64,24,About
  DIALOG ADD,BUTTON,Help,212,232,64,24,Help
  DIALOG ADD,BUTTON,Exit,212,306,64,24,Exit
  DIALOG ADD,LIST,ONLINE,27,381,148,180
  DIALOG ADD,TEXT,TEXT4,9,382,,,Users Online:
  DIALOG SHOW
  DIALOG FOCUS,INPUT
  GOSUB GetData
:Evloop
  wait event,5
  goto @event()
 
:Timer
  GOSUB GetData
  goto evloop
 
:GetData
  INTERNET HTTP,GET,1,http://www.extremesenses.com/extrememedia/xchat/session.chat
 
  DIALOG SET,SESSION,@INTERNET(HTTP,CONTENT,1)
  INTERNET HTTP,GET,1,http://www.extremesenses.com/extrememedia/xchat/onlineuser.chat
  DIALOG SET,ONLINE,@INTERNET(HTTP,CONTENT,1)
  EXIT
 
:Resize
REM -- Apparently this doesn't work --
%W = @DLGPOS(W)
%H = @DLGPOS(H)
  DIALOG SETPOS,TEXT1,188,12,@DIFF(%W,200),@DIFF(%H,234)
  DIALOG SETPOS,TEXT2,10,12,@DIFF(%W,378),@DIFF(%H,234)
  DIALOG SETPOS,USERNAME,186,70,@DIFF(%W,202),@DIFF(%H,176)
  GOTO EVLOOP
 
:SendBUTTON
  IF @NOT(@dlgtext(input))
  WARN You must enter a message
  GOTO Evloop
  END
  IF @NOT(@dlgtext(username))
  WARN You must enter a username
  GOTO Evloop
  END
 
  gosub replacespaces
 
  INTERNET HTTP,GET,1,http://www.extremesenses.com/extrememedia/xchat/chat.php?message=%%newstring&user=@dlgtext(username)
  goto timer
:PrintBUTTON
  list print,session
  goto evloop
:ClearBUTTON
  dialog clear,input
  goto evloop
:AboutBUTTON
  info VDSWORLD Chat Client BETA v1.0
  goto evloop
:HelpBUTTON
  warn Help coming soon...
  goto evloop
:replacespaces
  %%index = 0
  list create,1
  list add,1,@dlgtext(input)
  repeat
    %%instring = @dlgtext(input)
    %%newstring = ""
   %R = "%20"
   %S = @chr(32)
    repeat
      %%pos = @pos(%S,%%instring)
      if @greater(%%pos,0)
        if @equal(%%pos,1)
          %%newstring = %%newstring%R
        else
          %%newstring = %%newstring@substr(%%instring,1,@pred(%%pos))%R
        end
        %%instring = @strdel(%%instring,1,@pred(@sum(%%pos,@len(%S))))
      end
    until @equal(%%pos,0)
    %%newstring = %%newstring%%instring
    list put,1,%%newstring
    %%index = @succ(%%index)
  until @equal(%%index,@count(1))
 
  list close,1
  exit

:Error
  warn Error @error(e) at line @error(n)! Please post this at http://forum.vdsworld.com.
:ExitBUTTON
:Close
  INTERNET HTTP,DESTROY,1
  exit



PHP Code:
Code:
<?php
$useronline = "onlineuser.chat";
$filename = "session.chat";
$date = date("h:i:s");
$IP = $REMOTE_ADDR;
$string = "<$user $date> $message\n";
$user = StrToUpper($user);
$username = "$user\n";

// Check for illegal names
if($user == "ADMIN"){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == "ADMIN."){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == "ADMINISTRATOR"){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == "WEBMASTER"){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == "SERVER"){
$string = ">> A user with the IP address of $IP attempted to use the name \"$user\". This name has disallowed and should not be used.\n";
}
elseif($user == ""){
$string = ">> PLEASE NOTE: No null usernames are allowed.\n";
}

$fp = fopen( $filename, "a" ) or die("ERROR: Couldn't open file! Please inform the webmaster.");
$fpu = fopen( $useronline, "a" ) or die("ERROR: Couldn't open file! Please inform the webmaster.");
fwrite( $fp, $string );
fwrite( $fpu, $username );
fclose( $fp );
fclose( $fpu );
?>



And like I said PHP is very NEW to me. So I'm experimenting Wink

Thanks.
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript Open Source Projects All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum




Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group