
-----------------------------------
hez
Mon May 26, 2003 3:52 pm

[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  :P 

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))



%-------------------------------------------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

    end loop


    %---------------------------------------------------ENDCHAT MODULE------------------------------------

end start


%--------------------------------------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 