Posted: Mon May 26, 2003 3:52 pm Post subject: [source code] The best and the only chat....
hi....
This is just part pf my chat code from my last semester project
(i didn't include filetransfer, port scanner and advnced features srry)
hope you like it
It has:
-NICK SUPPORT
-2-WAY CHAT
-INCOMING SOUNDS
-"QUIT" command
-CLIENT/HOST COLOR
(TEST by runnig 2 instances & connecting to(127.0.0.1))
code:
%-------------------------------------------START MAIN CHAT MODULE---------------------
%--------------OPEN NEW WINDOW=-------------
var window : int
window := Window.Open ("title:Chat Main By:Hez,graphics:700;200,nobuttonbar,position:center;center")
%-------------------VERY IMPORTANT CHAT-MODULE VARIABLES--------------
%------0 = NO PROFILE SET 1= PROFILE SET
var setok : int := 0
%---PORT to conenct to---
var p1 : int := 28000
%----for the menu-----
var choice : int
%-----for your nick------
var nick : string := ""
%------for clients nick--------
var nick1 : string
%--------------------------------------MENU----------------------
loop
locate (3, 1)
put "Your TCP/IP Adress: ", Net.LocalAddress, " on ", Net.LocalName
put "1 -- Host a Chat Server"
put "2 -- Join an Existing Chat Server"
put "3 -- Quit Chat"
put "Selection: " ..
get choice
exit when choice = 1 or choice = 2 or choice = 3
end loop
%--------------------------------------VARIABLES----------------------
%-------To OPen 2-way conenctions
var netStream, netStream2 : int := 0
%------------To store ip in
var netAddress : string := ""
%---------------mi=HOST COLOR TEXT / mo=CLIENT COLOR TEXT
var mi : int := 1
var mo : int := 2
%--------BACK SOUND~---
process rec
play ("aabb")
end rec
%----------------------------SET UP CONFIG.INI FILE WITH BINARY/TEXT------------
procedure setall ()
var c1 : string
put "Enter Nick.."
get nick
nick1 := nick + " : "
end setall
procedure setall2 ()
var c1 : string
put "Enter Nick.."
get nick
nick1 := nick + " : "
cls
put "Enter the (HOST) address to connect to: " ..
get c1
netAddress := c1
end setall2
%important ip storing variable...
var ip : string
procedure start ()
%---------GETTING READY TO CHAT-------------------------
var hostAddr : string := netAddress
%--------------------------------------MAIN CHAT----------------------
%--------VARIABLES for storing /loging text written 2-way
var ch1, ch2 : string
var str : string
str := ""
View.Set ("noecho")
%--------------------------new window-----------------------------
var inp : int
inp := Window.Open ("title:Chat,position:center;center,graphics:500;500")
Window.Close (window)
%--------------------------------------CHAT STUFF----------------------
Draw.Cls
put "You Are Chatting With ->", netAddress, ":", p1
put "Hostname: ", Net.HostNameFromAddress (hostAddr)
put "TYPE QUIT to quit"
put "On: ", Time.Date
for i : 1 .. 62
put "-" ..
end for
put ""
put ""
%-----------DELAY to Verify stability for conenction---------
for i : 1 .. 10
put "Verifying connection... ", i
delay (500)
locate (whatrow - 1, 1)
put " "
locate (whatrow - 1, 1)
end for
%-----------sound of verification-------------
play ("8aaaabbbbaaaaaa")
%---------------------START CHATTING----MAIN MODULE------------
loop
%--------------GET READY TO SEND TEXT IF KEY AVAILABLE-----------
if hasch then
Window.Select (inp)
get ch1 : *
put : netStream, nick1 + ch1
locate (whatrow - 1, 1)
color (mi)
put nick1, ch1, str
%----------------QUIT TELLS THE 2nd USER YOU HAVE DISCONNECTED------------
if ch1 = "quit" then
put : netStream, nick, ", ( ", Net.LocalAddress, " )", "has Disconnected.."
Window.Close (inp)
exit
end if
end if
%------------------------CHECKS EVERYTIME FOR NEW LINE------------------------
if Net.LineAvailable (netStream) then
get : netStream, ch2 : *
color (mo)
put ch2, str
fork rec
end if
%--------------------------------------SERVER SETUP----------------------
if choice = 1 then
cls
setall ()
cls
put "Waiting for incoming conenctions..."
put "Your Hosting Address => ", Net.LocalAddress, ":", p1
netStream := Net.WaitForConnection (p1, netAddress)
put ""
put ""
start ()
end if
if choice = 2 then
cls
setall2 ()
cls
put "The Host be Ready To Accept your connection..."
put "Conncting in 5 secs.. Please Wait.."
delay (5000)
netStream := Net.OpenConnection (netAddress, p1)
if netStream <= 0 then
put "Unable to connect to ", netAddress
return
end if
start ()
%---------------------------------------QUIT------------------------------
elsif choice = 3 then
%-------------GET READY TO QUIT-----------
quit
end if
Sponsor Sponsor
PaddyLong
Posted: Sat May 31, 2003 12:57 pm Post subject: (No subject)
how can you run two instances?
Tony
Posted: Sat May 31, 2003 1:12 pm Post subject: (No subject)
Posted: Sat May 31, 2003 1:15 pm Post subject: (No subject)
I tired that but when I try to compile it it says no dice because this version doesn't have that capabilities... it's the turing 4.01p from the turing submissions section
Tony
Posted: Sat May 31, 2003 1:27 pm Post subject: (No subject)
you gotta get the patch to upgrade to v4.0.4[random letter]
Posted: Sat May 31, 2003 2:30 pm Post subject: (No subject)
oh oops
here u go hez have some bits...
+10 bits to hez
make a nice gui for it and i'll give u some more bits
Sponsor Sponsor
Mephi
Posted: Sat May 31, 2003 2:43 pm Post subject: (No subject)
isnt there one of those in truing examples? i dunno, but i remember seeing it...
PaddyLong
Posted: Sat May 31, 2003 2:50 pm Post subject: (No subject)
ok thanks for the informations on updating the Turing to the new version
Homer_simpson
Posted: Sat May 31, 2003 3:14 pm Post subject: (No subject)
there is a chat example in turing but i dont think hez has used that...
Chimaera
Posted: Mon Oct 20, 2003 1:35 pm Post subject: (No subject)
How would you be able to modify the program to have multi-way chat and 1 host? I'm trying to get it to be able to have 1 computer to host and have multiple clients connect to the same host but so far it doesn't make sense to me as to how I can get 2+ computers onto the same connection.
Andy
Posted: Sun Nov 09, 2003 5:28 pm Post subject: (No subject)
i dont think what ur trying to do is possible... however, what u can do is have everybody connect to one comp and send all messages to that comp then from that comp send the message out to everybody. gonna take a lot of work to pull this one off, post it here if u manage to get it working
Chimaera
Posted: Mon Nov 10, 2003 8:56 pm Post subject: (No subject)
How would one get that to work? Considering the source code posted above is supposed to work on that principle of having 1 host and 1 client, the idea of a relaying the messages to alternate clients doesn't go through. My friends and I tried to use this program to have more than 2 people per chat but they could join, type stuff in but it wouldn't get sent to us so what you guys suggested doesn't seem to work. Perhaps it's just me XD
Catalyst
Posted: Mon Nov 10, 2003 9:16 pm Post subject: (No subject)