View previous topic :: View next topic |
Author |
Message |
FreezingFire Admin Team
Joined: 23 Jun 2002 Posts: 3508
|
Posted: Fri Feb 21, 2003 9:06 pm Post subject: VDS Chat Project |
|
|
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.
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. _________________ 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 |
|
|
FreezingFire Admin Team
Joined: 23 Jun 2002 Posts: 3508
|
Posted: Fri Feb 21, 2003 11:32 pm Post subject: |
|
|
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. _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
Back to top |
|
|
marty Professional Member
Joined: 10 May 2001 Posts: 789
|
Posted: Mon Oct 20, 2003 12:52 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
PGWARE Web Host
Joined: 29 Dec 2001 Posts: 1563
|
Posted: Mon Oct 20, 2003 2:37 pm Post subject: |
|
|
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 |
|
|
marty Professional Member
Joined: 10 May 2001 Posts: 789
|
Posted: Mon Oct 20, 2003 3:49 pm Post subject: |
|
|
Yea.. was coming to write that.. I simply forgot spaces are replaced by %20 in URLS .. Thanks PK.
Thanks...
Now to learn a bit of PHP to modify this code to get the online user list..
|
|
Back to top |
|
|
Skit3000 Admin Team
Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Mon Oct 20, 2003 6:09 pm Post subject: |
|
|
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 |
|
|
FreezingFire Admin Team
Joined: 23 Jun 2002 Posts: 3508
|
Posted: Mon Oct 20, 2003 8:06 pm Post subject: |
|
|
Wow! Glad someone finally got interested!
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.
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. _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
Back to top |
|
|
PGWARE Web Host
Joined: 29 Dec 2001 Posts: 1563
|
Posted: Mon Oct 20, 2003 8:08 pm Post subject: |
|
|
You might want to try the latest vdsipp, I think I fixed the issue with the POST problem. |
|
Back to top |
|
|
marty Professional Member
Joined: 10 May 2001 Posts: 789
|
Posted: Tue Oct 21, 2003 1:37 am Post subject: |
|
|
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
Thanks Skit BTW |
|
Back to top |
|
|
FreezingFire Admin Team
Joined: 23 Jun 2002 Posts: 3508
|
Posted: Tue Oct 21, 2003 10:18 am Post subject: |
|
|
I'll take another look at this very soon. _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
Back to top |
|
|
marty Professional Member
Joined: 10 May 2001 Posts: 789
|
Posted: Tue Oct 21, 2003 12:33 pm Post subject: |
|
|
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
Thanks. |
|
Back to top |
|
|
|
|
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
|
|