Sorry should have posted it earlier, anyway here it is:
SYNC ON
SYNC RATE 30
` Keep track of what was said and who said it.
DIM ChatText$(32)
DIM PlayersName$(1)
DIM NumberOfPlayers(1)
DIM LastNumberOfPlayers(1)
` Find the TCP/IP connection number
TcpIpNumber = FindTCPIPConnectionNumber()
PRINT "Simple network chat client!"
PRINT
SYNC
` Get their Name
INPUT "Please Enter Your Name: ", MyName$
PlayersName$(1) = MyName$
SYNC
IF MyName$ = ""
PRINT "You need to enter a name!"
WAIT KEY
END
ENDIF
` Find out who the host and clients are..
PRINT "(1) I'm the Host"
PRINT "(2) I'm the Client"
SYNC
A$ = ""
Answer = 0
` Get Host or Client
WHILE Answer = 0
A$ = INKEY$()
IF A$ = "1" THEN Answer = 1
IF A$ = "2" THEN Answer = 2
ENDWHILE
` Do this if I'm the host..
IF Answer = 1
PRINT "Creating net session. Please wait"
SYNC
Sleep 200
SET NET CONNECTION TcpIpNumber, " "
CREATE NET GAME "Sample Net session", MyName$, 16, 1
ENDIF
` Do this if I'm the client.
IF Answer = 2
Input "Please enter the Hosts IP Address: ",AddressData$
PRINT "Connecting to net session. Please wait"
SYNC
SET NET CONNECTION TcpIpNumber, AddressData$
PERFORM CHECKLIST FOR NET SESSIONS
NumberOfGames =CHECKLIST QUANTITY()
IF NumberOfGames = 0
PRINT "No session found at that address"
SYNC
WAIT KEY
END
ENDIF
JOIN NET GAME 1, MyName$
PRINT "Connected to session!"
SYNC
ENDIF
` Do the chat client
ChatClient()
END
` Ths function will determine which NET CONNECTION number
` is TCP/IP.
FUNCTION FindTCPIPConnectionNumber()
FLAG = 0
CLS
PERFORM CHECKLIST FOR NET CONNECTIONS
FOR X = 1 TO CHECKLIST QUANTITY()
Service$ = CHECKLIST STRING$(X)
IF LEFT$(Service$,15)="Internet TCP/IP"
FLAG = X
ENDIF
NEXT X
ENDFUNCTION FLAG
` This function does all the chat client functionality.
FUNCTION ChatClient()
` Clears the chat text from the array..
ClearChatText()
` Displays the initial players in the room.
PERFORM CHECKLIST FOR NET PLAYERS
NumberOfPlayers(1) = CHECKLIST QUANTITY()
FOR X = 1 to NumberOfPlayers(1)
AddUserMessage(CHECKLIST STRING$(X))
NEXT X
` Send a comming in message
C$ = PlayersName$(1)+" has joined."
SEND NET MESSAGE STRING 0,C$
` Displays the chat text..
DisplayChatText()
` Set the entry buffers.
A$ = ""
B$ = ""
C$ = ""
CLEAR ENTRY BUFFER
` Capture Text Input and process it accordingly
WHILE ESCAPEKEY()=0
CheckIncomingMessages()
A$ = INKEY$()
IF ASC(A$) = 8
C$ = C$ + ENTRY$()
C$ = LEFT$(C$,LEN(C$)-1)
CLEAR ENTRY BUFFER
CLS
DisplayChatText()
ENDIF
B$ = C$ + ENTRY$()
TEXT 10,460,B$
IF RETURNKEY()=1 and B$ <> ""
SLEEP 250
` Send Remote Message
D$ = PlayersName$(1)+": "+B$
SEND NET MESSAGE STRING 0,D$
` Display Local Message
AddStringToChat(D$)
D$ = ""
B$ = ""
C$ = ""
CLEAR ENTRY BUFFER
` Display New Chat Window
DisplayChatText()
ENDIF
SYNC
ENDWHILE
ENDFUNCTION
` Scans the incoming messages for strings
` and displays them.
FUNCTION CheckIncomingMessages()
GET NET MESSAGE
IF NET MESSAGE EXISTS()=0 THEN EXITFUNCTION
WHILE NET MESSAGE EXISTS()<>0
MsgType = NET MESSAGE TYPE()
IF MsgType = 3
Msg$ = NET MESSAGE STRING$()
AddStringToChat(Msg$)
DisplayChatText()
ENDIF
GET NET MESSAGE
ENDWHILE
ENDFUNCTION
` Message to display if a User has joined
FUNCTION AddUserMessage(Name$)
NewString$ = Name$+" is here."
AddStringToChat(NewString$)
ENDFUNCTION
` Adds a string to the ChatText$ array
FUNCTION AddStringToChat(a$)
FOR X = 1 to 32
IF ChatText$(X) = ""
ChatText$(X) = a$
EXITFUNCTION
ENDIF
NEXT X
FOR X = 32 TO 2
Y = X - 1
ChatText$(Y) = ChatText$(X)
NEXT X
ChatText$(32) = a$
ENDFUNCTION
` Clears the ChatText$ Variables
FUNCTION ClearChatText()
FOR X = 1 to 32
ChatText$(X) = ""
NEXT X
ENDFUNCTION
` Displays the chat text on the screen
FUNCTION DisplayChatText()
CLS
SET CURRENT BITMAP 0
CENTER TEXT 320,10,"Chat Client"
FOR X = 1 To 32
TEXT 10,10+(X*15),ChatText$(X)
NEXT X
ENDFUNCTION
Don't look behind you.