Eevil Weevil, Thanks for the reply. I've written a chat server/client program and ready to move on to my next step in the development of my MMO. Just looking for a little more detail on the Net messages above to grasp the full context of their use.
`=========================================================================
`NED_NET by F.L. Taylor 10/05/07
`=========================================================================
`============================
`NED_NETSERVER CONSTANTS
`============================
#constant NED_NETSERVER_MAX 1
#constant NED_NETSERVER_TYPE_DEDICATED 1
#constant NED_NETSERVER_STATE_INACTIVE 0
#constant NED_NETSERVER_STATE_START 1
#constant NED_NETSERVER_STATE_STARTING 2
#constant NED_NETSERVER_STATE_STARTING1 3
#constant NED_NETSERVER_STATE_STARTING2 4
#constant NED_NETSERVER_STATE_STARTING3 5
#constant NED_NETSERVER_STATE_STARTING4 6
#constant NED_NETSERVER_STATE_ACTIVE 7
#constant NED_NETSERVER_STATE_STOPPING 8
#constant NED_NETSERVER_STATE_STOP 9
#constant NED_NETSERVER_STATE_IDLE 10
`============================
`NED_NETSERVER GLOBALS
`============================
`============================
`NED_NETSERVER OBJECTS
`============================
type NED_NetServer
`Purpose:
`Properties:
ID as integer
typeID as integer
name$ as string
session as integer
clients as integer
connection as integer
connection$ as string
host$ as string
netsession as integer
netsession$ as string
message$ as string
timeout as integer
state as integer
endtype
`============================
`NED_NETSERVER ARRAYS
`============================
dim NED_NetServer(NED_NETSERVER_MAX) as NED_NetServer
dim NED_NetServerIndex(NED_NETSERVER_MAX) as integer `Object Index Management Stack
dim NED_NetServerClient$(NED_NETSERVER_MAX,NED_NETCLIENT_MAX) as string
`============================
`NED_NETCLIENT CONSTANTS
`============================
#constant NED_NETCLIENT_MAX 16
#constant NED_NETCLIENT_TYPE_SERVER 1
#constant NED_NETCLIENT_TYPE_USER 2
#constant NED_NETCLIENT_STATE_INACTIVE 0
#constant NED_NETCLIENT_STATE_START 1
#constant NED_NETCLIENT_STATE_STARTING 2
#constant NED_NETCLIENT_STATE_ACTIVE 3
#constant NED_NETCLIENT_STATE_STOPPING 4
#constant NED_NETCLIENT_STATE_STOP 5
#constant NED_NETCLIENT_STATE_IDLE 6
`============================
`NED_NETCLIENT GLOBALS
`============================
`============================
`NED_NETCLIENT OBJECTS
`============================
type NED_NetClient
`Purpose:
`Properties:
ID as integer
typeID as integer
name$ as string
action as integer
timeout as integer
state as integer
endtype
`============================
`NED_NETCLIENT ARRAYS
`============================
dim NED_NetClient(NED_NETCLIENT_MAX) as NED_NetClient
dim NED_NetClientIndex(NED_NETCLIENT_MAX) as integer `Object Index Management Stack
`============================
`NED_NETCHAT CONSTANTS
`============================
#constant NED_NETCHAT_MAX 1
#constant NED_NETCHAT_LINES_MAX 28
#constant NED_NETCHAT_STATE_INACTIVE 0
#constant NED_NETCHAT_STATE_START 1
#constant NED_NETCHAT_STATE_STARTING 2
#constant NED_NETCHAT_STATE_STARTING2 3
#constant NED_NETCHAT_STATE_STARTING3 4
#constant NED_NETCHAT_STATE_STARTING4 5
#constant NED_NETCHAT_STATE_STARTING5 6
#constant NED_NETCHAT_STATE_STARTING6 7
#constant NED_NETCHAT_STATE_STARTING7 8
#constant NED_NETCHAT_STATE_ACTIVATING 9
#constant NED_NETCHAT_STATE_ACTIVE 10
#constant NED_NETCHAT_STATE_STOPPING 11
#constant NED_NETCHAT_STATE_STOP 12
#constant NED_NETCHAT_STATE_IDLE 13
#constant NED_NETCHAT_ACTION_START 1
#constant NED_NETCHAT_ACTION_FIND 2
`============================
`NED_NETCHAT GLOBALS
`============================
`============================
`NED_NETCHAT OBJECT
`============================
type NED_NetChat
`Purpose: NED_Net Chat Object
`Properties:
ID as integer
typeID as integer
chatflag$ as string
chatline$ as string
message$ as string
prevline as integer
nextline as integer
msgoutcount as integer
msgincount as integer
chatlinebase as integer
chatbase as integer
endofplayerlist as integer
action as integer
state as integer
endtype
`============================
`NED_NETCHAT ARRAYS
`============================
dim NED_NetChat(NED_NETCHAT_MAX) as NED_NetChat `OBJECT
dim NED_NetChatIndex(NED_NETCHAT_MAX) as integer `Object Index Management Stack
dim NED_NetChatKey$(NED_NETCHAT_MAX,1)
dim NED_NetChatLines$(NED_NETCHAT_MAX,NED_NETCHAT_LINES_MAX - NED_NETCLIENT_MAX)
`============================
`NED_EDITOR CONSTANTS
`============================
`============================
`NED_EDITOR GLOBALS
`============================
global NED_EditorRun
`============================
`NED_EDITOR OBJECTS
`============================
`============================
`NED_EDITOR ARRAYS
`============================
`============================
`NED_EDITOR METHODS
`============================
`========================================================
`NED_EDITOR MAIN
`========================================================
main()
end
`====================================================================================
`MAIN METHOD
`====================================================================================
function main()
`Purpose: Main Program
`Parameters:
`Return:
NED_EDITOR_START:
`to be set by Pepsi GUI
set display mode 800,600,32
set window on
sync on
sync rate 60
NED_NetServerStart()
NED_NetClientStart()
NED_NetChatStart()
`create a new instance of NED_NetServer
`only one server instance allowed
NED_NetServerNew(NED_NETSERVER_TYPE_DEDICATED,"NED - NETWORK EDITOR 1.0")
print "Server: ";NED_NetServer(1).name$
`create a new instance of NED_NetClient
NED_NetClientID = NED_NetClientNew(NED_NETCLIENT_TYPE_USER,"Tek")
print "Client: ";NED_NetClient(NED_NetClientID).name$
NED_EditorRun = 1
NED_EDITOR_UPDATE: `primary loop
while NED_EditorRun
NED_NetServerUpdate()
NED_NetClientUpdate()
NED_NetChatUpdate()
text 640,0,"Server State:"+str$(NED_NetServer(1).state) `TESTING
text 640,15,"Chat State:"+str$(NED_NetChat(1).state) `TESTING
NED_EditorTimer = NED_EditorTimer + 1
text 640,30,str$(NED_EditorTimer)
sync
endwhile
NED_EDITOR_STOP:
endfunction
`=========================================================================
`NED_NET by F.L. Taylor 10/05/07
`=========================================================================
`============================
`NED_NetServer FUNCTIONS
`============================
function NED_NetServerStart()
`Purpose: Initialize NED_NetServer Object
`Parameters: None
`Return: None
for NED_NetServerIndices = NED_NETSERVER_MAX to 1 step -1
add to stack NED_NetServerIndex()
NED_NetServerIndex()=NED_NetServerIndices
next NED_NetServerIndices
endfunction
function NED_NetServerStop()
`Purpose: Shutdown NED_NetServer, remove all NED_NetServer object.
`Parameters: None
`Return: None
endfunction
function NED_NetServerNew(NED_NetServerTypeID,NED_NetServerName$)
`Purpose: Creates a Net_Server Object Instance
`Parameters:
` NED_NetServerTypeID - Server Object Type
` NED_NetServerName$ - Server Name
`Return: NED_NetServer Object ID
this = NED_NetServerIndex()
remove from stack NED_NetServerIndex()
NED_NetServer(this).ID = this
NED_NetServer(this).typeID = NED_NetServerTypeID
NED_NetServer(this).name$ = NED_NetServerName$
endfunction this
function NED_NetServerDelete(this)
`Purpose: Removes NED_NetServer Instance
`Parameters: this NED_Server Object ID
`Return: None
NED_NetServer(this).ID = 0
NED_NetServer(this).typeID = 0
NED_NetServer(this).name$ = ""
add to stack NED_NetServerIndex()
NED_NetServerIndex()=this
endfunction
function NED_NetServerUpdate()
`Purpose: Updates all server objects
`Parameters: None
`Return: None
for each = 1 to NED_NETSERVER_MAX
select NED_NetServer(each).state
case NED_NETSERVER_STATE_INACTIVE
endcase
case NED_NETSERVER_STATE_START
` Get the list of available connection types from the OS
perform checklist for net connections
NED_NetServer(each).state = NED_NETSERVER_STATE_IDLE
endcase
case NED_NETSERVER_STATE_STARTING1
set net connection NED_NetServer(each).connection, NED_NetServer(each).host$
NED_NetServer(each).state = NED_NETSERVER_STATE_IDLE
endcase
case NED_NETSERVER_STATE_STARTING2
empty checklist
perform checklist for net sessions
NED_NetServer(each).state = NED_NETSERVER_STATE_IDLE
endcase
case NED_NETSERVER_STATE_STARTING3
join net game NED_NetServer(each).netsession, NED_NetServer(each).name$
NED_NetServer(each).state = NED_NETSERVER_STATE_STARTING
endcase
case NED_NETSERVER_STATE_STARTING4
create net game NED_NetServer(each).netsession$, NED_NetServer(each).name$, NED_NETCLIENT_MAX, 1
NED_NetServer(each).state = NED_NETSERVER_STATE_STARTING
endcase
case NED_NETSERVER_STATE_STARTING
NED_NetServerClientList(each)
NED_NetServer(each).state = NED_NETSERVER_STATE_IDLE
endcase
case NED_NETSERVER_STATE_ACTIVE
` get net message tells DB what the next message is.
get net message
` Now we ask DB if there is a message waiting for us or not.
while net message exists() > 0
` We have a message. This is a chat program so it better be a string (message type 3).
select net message type()
case 3
` it's a string so find out who it's from and add this data to the chat area.
NED_NetChat(1).message$ = NED_NetServerClient$(each,net message player from()) + ": " + net message string$()
`gosub _add_current_message_to_chat
NED_NetChatAdd(1)
` Update the counter for posterity.
NED_NetChat(1).msgincount = NED_NetChat(1).msgincount+1
endcase
endselect
` now that we've sorted that message out, let's see if there's another one.
get net message
endwhile
endcase
case NED_NETSERVER_STATE_STOPPING
free net game
exit
endcase
case NED_NETSERVER_STATE_STOP
endcase
case NED_NETSERVER_STATE_IDLE
endcase
endselect
next each
endfunction
function NED_NetServerClientList(this)
`Purpose: Performs a check for net players
`Parameters: this NED_NetServer Object ID
`Return: None
empty checklist
perform checklist for net players
` Clear out the old data
for NED_NetServerPlayerChecklist = 1 to NED_NETCLIENT_MAX
NED_NetServerClient$(this,NED_NetServerPlayerChecklist) = "<None>"
next NED_NetServerPlayerChecklist
` Bring in the new data
for NED_NetServerPlayerChecklist = 1 to checklist quantity()
NED_NetServerClient$(this,checklist value a(NED_NetServerPlayerChecklist)) = checklist string$(NED_NetServerPlayerChecklist)
next NED_NetServerPlayerChecklist
endfunction
function NED_NetServerClientDisplay(this)
`Purpose: Displays a List of Clients on the Server
`Parameters:
` this - Current Server ID
`Return: None
` If a player joins or leaves then re-make our list of players as there's no
` multiplayer command that asks them for their name.
if net player created() > 0 or net player destroyed() > 0
NED_NetServerClientList(this)
endif
text 0, 15, "Using " + NED_NetServer(this).connection$ + " on " + NED_NetServer(this).host$ + " in " + NED_NetServer(this).netsession$ + " as " + NED_NetServer(this).name$
text 0, 30, "Clients Found: "
` loop through the list of players, printing them to the screen along with their player number.
for NED_NetServerClientEach = 1 to NED_NETCLIENT_MAX
NED_NetServerClientOutput$ = str$(NED_NetServerClientEach) + ": " + NED_NetServerClient$(this,NED_NetServerClientEach)
text 0, (NED_NetServerClientEach*15)+30, NED_NetServerClientOutput$
NED_NetChat(1).endofplayerlist = (NED_NetServerClientEach*15)+30
next NED_NetServerClientEach
endfunction
`============================
`NED_NetClient FUNCTIONS
`============================
function NED_NetClientStart()
`Purpose: Initialize NED_NetClient Objects
`Parameters: None
`Return: None
for NED_NetClientIndices = NED_NETCLIENT_MAX to 1 step -1
add to stack NED_NetClientIndex()
NED_NetClientIndex()=NED_NetClientIndices
next NED_NetClientIndices
endfunction
function NED_NetClientStop()
`Purpose: Shutdown Class, free mem
`Parameters: None
`Return: None
endfunction
function NED_NetClientNew(NED_NetClientTypeID,NED_NetClientName$)
`Purpose: Creates a Net_Client Object Instance
`Parameters:
` NED_NetClientTypeID
` NED_NetClientName
`Return: ID of NED_NetClient Object
this = NED_NetClientIndex()
remove from stack NED_NetClientIndex()
NED_NetClient(this).ID = this
NED_NetClient(this).typeID = NED_NetClientTypeID
NED_NetClient(this).name$ = NED_NetClientName$
endfunction this
function NED_NetClientDelete(this)
`Purpose: Removes NED_NetClient Instance
`Parameters: this NED_NetClient Object ID
`Return: None
NED_NetClient(this).ID = 0
NED_NetClient(this).typeID = 0
NED_NetClient(this).name$ = ""
NED_NetClient(this).state = 0
add to stack NED_NetClientIndex()
NED_NetClientIndex()=this
endfunction
function NED_NetClientUpdate()
`Purpose: Updates all NED_NetClient Objects
`Parameters: None
`Return: None
for each = 1 to NED_NETSERVER_MAX
select NED_NetClient(each).state
case NED_NETCLIENT_STATE_INACTIVE
endcase
case NED_NETCLIENT_STATE_START
endcase
case NED_NETCLIENT_STATE_STARTING
endcase
case NED_NETCLIENT_STATE_ACTIVE
endcase
case NED_NETCLIENT_STATE_STOPPING
endcase
case NED_NETCLIENT_STATE_STOP
endcase
case NED_NETCLIENT_STATE_IDLE
endcase
endselect
next each
endfunction
`============================
`NED_NetClhat FUNCTIONS
`============================
function NED_NetChatStart()
`Purpose: Initialize NED_NetChat Object, Setup Object ID Management Stack
`Parameters: None
`Return: None
for NED_NetChatIndices = NED_NETCHAT_MAX to 1 step -1
add to stack NED_NetChatIndex()
NED_NetChatIndex()=NED_NetChatIndices
next NED_NetChatIndices
NED_NetChat(1).state = NED_NETCHAT_STATE_START
endfunction
function NED_NetChatNew(NED_NetChatTypeID)
`Purpose: Creates a new instance of NED_NetChat Object the loads default values
`Parameters:
` NED_NetChatTypeID - chat object type
`Return: this Object ID
this = NED_NetChatIndex()
remove from stack NED_NetChatIndex()
NED_NetChat(this).ID = this
NED_NetChat(this).typeID = NED_NetChatTypeID
endfunction this
function NED_NetChatDelete(this)
`Purpose: Delete NED_NetChat Object, resets Object varialbes
`Parameters: this Object ID
`Return: None
NED_NetChat(this).ID = 0
NED_NetChat(this).typeID = 0
add to stack NED_NetChatIndex()
NED_NetChatIndex()=this
endfunction
function NED_NetChatUpdate()
`Purpose: Updates all NED_NetChat Objects
`Parameters: None
`Return: None
if escapekey()=1 then end
for each = 1 to NED_NETCHAT_MAX
select NED_NetChat(each).state
case NED_NETCHAT_STATE_INACTIVE
endcase
case NED_NETCHAT_STATE_START
cls
NED_NetChatKeyUpdate(each)
text 0, 15, "[1]Start Session [2]Join Session"
` Check for key-ups. See the comments in the update_keystate() function.
select NED_NetChatKey$(each,1)
case "1"
text 0, 30, "Checking for connections..."
NED_NetChat(each).action = NED_NETCHAT_ACTION_START
NED_NetServer(1).state = NED_NETSERVER_STATE_START
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING
endcase
case "2"
text 0, 30, "Checking for connections..."
NED_NetChat(each).action = NED_NETCHAT_ACTION_FIND
NED_NetServer(1).state = NED_NETSERVER_STATE_START
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING
endcase
endselect
endcase
case NED_NETCHAT_STATE_STARTING
` The connection selection screen. Usually would need TCP/IP but might get
` used for other things.
cls
NED_NetChatKeyUpdate(each)
text 0, 15, "Please select a connection to use: "
` Get DB to print out the list of connection types.
for NED_NetChatNetConnectionChecklist = 1 to checklist quantity()
NED_NetChatNetConnectionChecklistOutput$ = str$(NED_NetChatNetConnectionChecklist) + ": "
NED_NetChatNetConnectionChecklistOutput$ = NED_NetChatNetConnectionChecklistOutput$ + checklist string$(NED_NetChatNetConnectionChecklist)
text 0, (NED_NetChatNetConnectionChecklist*15)+15, NED_NetChatNetConnectionChecklistOutput$
next NED_NetChatNetConnectionChecklist
` Check for the user pressing a NED_NetChatKey.
if val(NED_NetChatKey$(each,1)) > 0 and checklist quantity() > 0 and val(NED_NetChatKey$(each,1)) <= checklist quantity()
NED_NetServer(1).connection = val(NED_NetChatKey$(each,1))
NED_NetServer(1).connection$ = checklist string$(NED_NetServer(1).connection)
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING2
endif
endcase
case NED_NETCHAT_STATE_STARTING2
cls
NED_NetChatKeyUpdate(each)
text 0, 15, "Using " + NED_NetServer(1).connection$
NED_NetChatKeyHandle(each)
text 0, 30, "Please enter your host name or IP address: " + NED_NetChat(each).chatline$
` take the user-entered chatline$ and store it in a variable called host$
if NED_NetChat(each).chatflag$ = "DONE"
NED_NetServer(1).host$ = NED_NetChat(each).chatline$
text 0, 45, "Attempting to open session on " + NED_NetServer(1).host$ + " - please wait a moment..."
NED_NetServer(1).state = NED_NETSERVER_STATE_STARTING1
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING3
endif
endcase
case NED_NETCHAT_STATE_STARTING3
cls
NED_NetChatKeyUpdate(each)
text 0, 15, "Using " + NED_NetServer(1).connection$ + " on " + NED_NetServer(1).host$
NED_NetChatKeyHandle(each)
text 0, 30, "Please enter the name you wish to use: " + NED_NetChat(each).chatline$
` take the user-entered chatline$ and store it in a variable called session$
if NED_NetChat(each).chatflag$ = "DONE"
NED_NetServer(1).name$ = NED_NetChat(each).chatline$
select NED_NetChat(each).action
case NED_NETCHAT_ACTION_START
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING7
endcase
case NED_NETCHAT_ACTION_FIND
Rem Look for sessions on the host and make a list.
NED_NetServer(1).state = NED_NETSERVER_STATE_STARTING2
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING5
endcase
endselect
endif
endcase
case NED_NETCHAT_STATE_STARTING4
NED_NetChat(each).state = NED_NETCHAT_STATE_ACTIVATING
endcase
case NED_NETCHAT_STATE_STARTING5
if checklist quantity()=0
cls
text 0, 15, "Using " + NED_NetServer(1).connection$ + " on " + NED_NetServer(1).host$ + " as " + NED_NetServer(1).name$
text 0, 45, "NO SESSIONS FOUND. Press any key to exit..."
NED_EditorRun = 0
endif
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING6
endcase
case NED_NETCHAT_STATE_STARTING6
cls
NED_NetChatKeyUpdate(each)
text 0, 15, "Using " + connection$ + " on " + host$ + " as " + playername$
text 0, 30, "Please select a session to join: "
` Print the list of sessions out
for NED_NetChatNetSessionChecklist = 1 to checklist quantity()
NED_NetChatNetSessionChecklistOutput$ = str$(NED_NetChatNetSessionChecklist) + ": " + checklist string$(NED_NetChatNetSessionChecklist)
text 0, (NED_NetChatNetSessionChecklist*15)+30, NED_NetChatNetSessionChecklistOutput$
next NED_NetChatNetSessionChecklist
` Check for key presses that match up to a checklist item
if val(NED_NetChatKey$(each,1)) > 0 and checklist quantity() > 0 and val(NED_NetChatKey$(each,1)) <= checklist quantity()
NED_NetServer(1).netsession = val( NED_NetChatKey$(each,1) )
NED_NetServer(1).netsession$ = checklist string$(NED_NetServer(1).netsession)
NED_NetChatNetSession$ = str$(NED_NetServer(1).netsession) + ": " + checklist string$(NED_NetServer(1).netsession)
text text width(NED_NetChatNetSession$),30+NED_NetServer(1).netsession*15," - CONNECTING..."
NED_NetServer(1).state = NED_NETSERVER_STATE_STARTING3
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING4
endif
endcase
case NED_NETCHAT_STATE_STARTING7
Rem The net game needs a name
cls
NED_NetChatKeyUpdate(each)
text 0, 15, "Using " + NED_NetServer(1).connection$ + " on " + NED_NetServer(1).host$ + " as " + NED_NetServer(1).name$
NED_NetChatKeyHandle(each)
text 0, 30, "Please enter a name for your session: " + NED_NetChat(each).chatline$
` take the user-entered chatline$ and store it in a variable called session$
if NED_NetChat(each).chatflag$ = "DONE"
NED_NetServer(1).netsession$ = NED_NetChat(each).chatline$
text 0, 45, "Attempting to start session on " + NED_NetServer(1).netsession$ + " - please wait a moment..."
`server state change
NED_NetServer(1).state = NED_NETSERVER_STATE_STARTING4
NED_NetChat(each).state = NED_NETCHAT_STATE_STARTING4
endif
endcase
case NED_NETCHAT_STATE_ACTIVATING
if checklist quantity()=0
cls
`If there are no players then we didn't make/join successfully.
text 0, 15, "Using " + NED_NetServer(1).connection$ + " on " + NED_NetServer(1).host$ + " as " + NED_NetServer(1).name$
text 0, 45, "FAILED TO START or FIND SESSION. Press any key to exit..."
NED_EditorRun = 0
NED_NetServer(1).timeout = NED_NetServer(1).timeout + 1
endif
NED_NetServer(1).state = NED_NETSERVER_STATE_ACTIVE
NED_NetChat(each).state = NED_NETCHAT_STATE_ACTIVE
endcase
case NED_NETCHAT_STATE_ACTIVE
cls
NED_NetChatKeyUpdate(each)
`Report continuously on other players connected to the game.
NED_NetServerClientDisplay(1)
` Read the keybaord input and send it out as a chat line where necessary
NED_NetChatKeyHandle(each)
NED_NetChatSend(each)
` Show chat line as user types it (chatline$ is use in _handle_chat_key_input)
NED_NetChat(each).chatlinebase = NED_NetChat(each).endofplayerlist + 15
` Draw some lines around the chat area to make it a bit more obvious
NED_NetChatBoxDraw(each)
text 0, NED_NetChat(each).chatlinebase, " SEND:" + NED_NetChat(each).chatline$
`gosub _handle_chat_net_input
`NED_NetChatRecv(each)
NED_NetChat(each).chatbase = NED_NetChat(each).chatlinebase + 15
NED_NetChatDisplay(each)
` Print out the total count of messages sent and received in the bottom right
` corner of the screen.
text screen width() - 1 - text width("Sent: " + str$(NED_NetChat(each).msgoutcount)), screen height() - 30, "Sent: " + str$(NED_NetChat(each).msgoutcount)
text screen width() - 1 - text width("Received: " + str$(NED_NetChat(each).msgincount)), screen height() - 15, "Recieved: " + str$(NED_NetChat(each).msgincount)
if escapekey()=1
NED_NetServer(1).state = NED_NETSERVER_STATE_STOPPING
endif
endcase
case NED_NETCHAT_STATE_STOPPING
endcase
case NED_NETCHAT_STATE_STOP
endcase
case NED_NETCHAT_STATE_IDLE
cls
text 0,0,"START or FIND SESSION ...OK"
endcase
endselect
next each
endfunction
function NED_NetChatKeyUpdate(this)
`Purpose:
remstart
A very simple way of detecting when a key is pressed and when it's released.
key$(0) represents a "key down" i.e. when a key is pressed.
key$(1) represents a "key up" i.e. when a key is released.
If key$(1) isn't empty then it's equal to a key that's just been released.
We use this to determine what the user is typing so that we don't pause the
program with an INPUT command.
If we used the letter that was currently being pressed then we would get one
letter for every frame per second.
remend
`Parameters: None
`Return: None
NED_NetChatKey$(this,1)=""
if NED_NetChatKey$(this,0) <> inkey$()
NED_NetChatKey$(this,1) = NED_NetChatKey$(this,0)
endif
NED_NetChatKey$(this,0)=inkey$()
endfunction
function NED_NetChatKeyHandle(this)
`Purpose: Handles Chat Key Input
`Parameters: this NED_NetChat ID
`Return: None
` Reset the flag and clear the input line.
if NED_NetChat(this).chatflag$="DONE"
NED_NetChat(this).chatflag$=""
NED_NetChat(this).chatline$=""
endif
` If a key is pressed
if NED_NetChatKey$(this,1)<>""
` Did the user press backspace? (ascii 8)
if asc( NED_NetChatKey$(this,1) ) = 8
` backspace - chop off the character at the end of the line
NED_NetChat(this).chatline$ = left$( NED_NetChat(this).chatline$, len(NED_NetChat(this).chatline$)-1)
else
` did the user hit return? (ascii 13)
if asc( NED_NetChatKey$(this,1) ) = 13
` Yep - they hit return.
` Mark the chat line as being DONE and ready for sending.
NED_NetChat(this).chatflag$="DONE"
else
` add anything else the user types to the chat line
NED_NetChat(this).chatline$ = NED_NetChat(this).chatline$ + NED_NetChatKey$(this,1)
endif
endif
endif
endfunction
function NED_NetChatAdd(this)
`Purpose: Adds a Line of text in the Chat Queue
`Parameters: This NED_NetChat Object ID
`Return: None
` Move along to the next slot in our message array
NED_NetChat(this).prevline = NED_NetChat(this).prevline+1
` Make sure we wrap around to the start if we count past the end of the array.
` if NED_NetChat(this).prevline > array count(NED_NetChatLines$(this,0)) then NED_NetChat(this).prevline = 1
if NED_NetChat(this).prevline > NED_NETCHAT_LINES_MAX then NED_NetChat(this).prevline = 1
` Overwrite whatever is here with the current message.
NED_NetChatLines$(this,NED_NetChat(this).prevline) = NED_NetChat(this).message$
endfunction
function NED_NetChatSend(this)
`Purpose: Sends network chat message
`Parameters: This NED_NetChat Object ID
`Return: None
if NED_NetChat(this).chatflag$ = "DONE"
` send out our chat line
send net message string 0, NED_NetChat(this).chatline$
` Update the currentmessage$ variable for use with the subroutine.
` Add our own name to the line for our own benefit.
NED_NetChat(this).message$ = NED_NetServer(1).name$ + ": " + NED_NetChat(this).chatline$
` we won't receive our chat message over te network so we have to "cheat" and add
` it to our chat array manually.
`gosub _add_current_message_to_chat
NED_NetChatAdd(this)
` update our counter
NED_NetChat(this).msgoutcount = NED_NetChat(this).msgoutcount+1
endif
endfunction
function NED_NetChatRecv(this)
`Purpose: Recieves Net Chat Message, moving this functionality to the NED_NetServer
`Parameters: This NED_NetChat Object ID
`Return:
` get net message tells DB what the next message is.
get net message
` Now we ask DB if there is a message waiting for us or not.
while net message exists() > 0
` We have a message. This is a chat program so it better be a string (message type 3).
if net message type() = 3
` it's a string so find out who it's from and add this data to the chat area.
NED_NetChat(this).message$ = NED_NetServerClient$(this,net message player from()) + ": " + net message string$()
`gosub _add_current_message_to_chat
NED_NetChatAdd(this)
endif
` Update the counter for posterity.
NED_NetChat(this).msgincount = NED_NetChat(this).msgincount+1
` now that we've sorted that message out, let's see if there's another one.
get net message
endwhile
endfunction
function NED_NetChatBoxDraw(this)
`Purpose: Draws Rectangle Chat Box
`Parameters: This NED_NetChat Object ID
`Return: None
` Top of box
line 0, NED_NetChat(this).chatlinebase, screen width()-1, NED_NetChat(this).chatlinebase
` Left side of box
line 0, NED_NetChat(this).chatlinebase, 0, NED_NetChat(this).chatlinebase+15
` Right side of box
line screen width()-1, NED_NetChat(this).chatlinebase, screen width()-1, NED_NetChat(this).chatlinebase+15
` Bottom of box
line 0, NED_NetChat(this).chatlinebase+15, screen width()-1, NED_NetChat(this).chatlinebase+15
endfunction
function NED_NetChatDisplay(this)
`Purpose: Displays Chat of Lines of Text
`Parameters: This NED_NetChat Object ID
`Return: None
` Go through all the chat lines we've recorded and print them out to the screen.
` Have to do it backwards, though, so the newest one appears at the bottom of the screen.
NED_NetChatLinesCount = NED_NETCHAT_LINES_MAX - NED_NETCLIENT_MAX
for NED_NetChatLineEach = 0 to NED_NetChatLinesCount-1
NED_NetChat(this).nextline = NED_NetChat(this).prevline-NED_NetChatLineEach
` check to make sure we wrap around to the end of the array if we count backwards
` past the beginning.
if NED_NetChat(this).nextline < 1 then NED_NetChat(this).nextline = NED_NetChatLinesCount + NED_NetChat(this).nextline
text 0, NED_NetChat(this).chatbase+15*NED_NetChatLinesCount-((NED_NetChatLineEach+1)*15), NED_NetChatLines$(this,NED_NetChat(this).nextline)
next NED_NetChatLineEach
endfunction