@Omen, I've been attempting to remake this in DarkNet V2. I'm having 1 SMALL problem..
It's giving me an error somewhere around mn Start in netClient.dba.
Here's my code:
REM *** Include File: modules\netClient.dba ***
REM Created: 7/4/2010 10:55:22 AM
REM
REM Included in Project: C:\Program Files\The Game Creators\Dark Basic Professional\Projects\worldofomen\worldofomen.dbpro
REM
netClientSetup:
NET_SERVER_NAME = dataSharedGetField("netClient", "netServerName", NET_SERVER_NAME_DEFAULT, DATA_CREATE)
global Timeout
global NoInstances
global NoThreads
global profile
global MaximumClients
global netClientCurrentChannel as string
netClientCurrentChannel = dataSharedGetField("netClient", "netClientCurrentChannel", "BROADCAST", DATA_CREATE)
global netTickerUpdate as integer
netTickerUpdate = systemSharedGetFree(SYSTEM_TYPE_TICKER, SYSTEM_SEARCH_FAST)
MAKE TICKER netTickerUpdate, NET_UDP_UPDATE_INTERVAL
global netTickerHeartbeat as integer
netTickerHeartbeat = systemSharedGetFree(SYSTEM_TYPE_TICKER, SYSTEM_SEARCH_FAST)
MAKE TICKER netTickerHeartbeat, NET_UDP_HEARTBEAT_INTERVAL
global netTickerReconnect as integer
netTickerReconnect = systemSharedGetFree(SYSTEM_TYPE_TICKER, SYSTEM_SEARCH_FAST)
MAKE TICKER netTickerReconnect, NET_TCP_RECONNECT_INTERVAL
global netTickSendNow as boolean
global netTickConnectNow as boolean
global netMaxUDPClients as integer
global netMaxUDPOperations as integer
global netSessionKey$ as string
global netUpdateMode as integer
global netClientUsername$ as string
global netClientPassword$ as string
global netClientAvatarname$ as string
`encryptSetKey(systemGameTitle$)
rem not yet
return
function netClientStart()
` To be filled during connection
MaximumClients as integer
` Setup packets
SendPacket = mn create packet()
RecvPacket = mn create packet()
mn set memory size SendPacket,1024
` Try to connect
Timeout = 4000
profile = mn Create Instance Profile()
` Set the number of threads that will be created
` to deal with incoming data. In most cases this
` should be set to the number of processors on your
` computer. MikeNet can determine this for you
` automatically if you set it to 0
NoThreads = 0
` Set the number of MikeNet instances to create
NoInstances = 1
` Start MikeNet
mn Start NoInstances,NoThreads
if NET_SERVER_NAME = NET_SERVER_NAME_DEFAULT
debugWrite(DEBUGWARN,"Server name not set, attempting search...")
REM NAME WAS NOT SET, SEARCH AND UPDATE
i = intval(dataSharedGetField("netClient", "netSearchMode", "1",1))
select i
case 0:
REM DO NOT SEARCH
debugWrite(DEBUGWARN,"Search mode set to 0, default server name will be used.")
endcase
case 1:
REM SEARCH LAN
debugWrite(DEBUGINFO,"Search mode set to 1, searching on LAN...")
i$ = netSharedGetLANIP()
if i$ = ""
debugWrite(DEBUGERROR,"NO VALID LAN INTERFACES FOUND. FORCING QUIT.")
systemSharedGameModeAdd(SYSTEM_MODE_QUITTING)
else
NET_SERVER_NAME = i$
dataSharedUpdateField("netClient","netServerName",NET_SERVER_NAME)
endif
endcase
case 2:
REM SEARCH WAN
debugWrite(DEBUGINFO,"Search mode set to 2, searching on WAN...")
i$ = netSharedGetWANIP()
if i$ = ""
debugWrite(DEBUGERROR,"NO VALID WAN INTERFACES FOUND. FORCING QUIT.")
systemSharedGameModeAdd(SYSTEM_MODE_QUITTING)
else
NET_SERVER_NAME = i$
dataSharedUpdateField("netClient","netServerName",NET_SERVER_NAME)
endif
endcase
endselect
endif
endfunction
function netClientStop()
mn Finish -1
endfunction
function netClientConnectStart()
`MN CONNECT=MikeNet\mnConnect.html={Instance, TCP connect IP, TCP connect port, UDP connect IP, UDP connect port, Timeout, Block until connected, Instance profile}
Connect = mn Connect(0,NET_SERVER_NAME,NET_SERVER_PORT,NET_SERVER_NAME,NET_SERVER_PORT,NET_TIMEOUT_SECONDS,1,profile)
endfunction
function netClientConnectStop()
mn Stop Connect 0
if (systemMode && SYSTEM_MODE_NET_TCP)
debugWrite(DEBUGERROR,"Net Connect timeout or error connecting to server.")
endif
systemSharedGameModeRemove(SYSTEM_MODE_NET_TCP)
endfunction
function netClientMaintain()
local i as integer
local j as integer
local pollStatus as integer
if (systemMode && SYSTEM_MODE_NET_TCP) = 0
REM WE HAVE NEVER CONNNECTED BEFORE
pollStatus = mn poll connect(0)
select pollStatus
case -1:
REM ERROR
netClientConnectStop()
netClientConnectStart()
debugWrite(DEBUGERROR,"Net Connect Error: " + NET_SERVER_NAME + ":" + str$(NET_SERVER_PORT) + ":" + str$(NET_TIMEOUT_SECONDS))
endcase
case 0:
REM TIMEOUT
netClientConnectStop()
netClientConnectStart()
debugWrite(DEBUGERROR,"Net Connect Timeout.")
endcase
case 1:
REM SUCCESSFUL
systemSharedGameModeAdd(SYSTEM_MODE_NET_TCP)
debugWrite(DEBUGINFO,"Net Connect Successful. Mode TCP Added.")
`guiHideWindow("windowMessageBox")
netMaxUDPClients = mn Get Max Clients(0)
debugWrite(DEBUGINFO,"Net Max UDP Clients set to " + str$(netMaxUDPClients))
netMaxUDPOperations = mn Get Max Operations(0)
debugWrite(DEBUGINFO,"Net Max UDP Operations set to " + str$(netMaxUDPOperations))
endcase
case 2:
REM CONNECT IS STILL IN PROGRESS
REM LET IT KEEP TRYING UNTIL ITS
REM TIMEOUT VALUE
if TICKER(netTickerReconnect,1) = 1 or netTickConnectNow = 1
debugWrite(DEBUGINFO,"Attempting to connect to server...")
endif
endcase
endselect
endif
if (systemMode && SYSTEM_MODE_NET_TCP)
REM WE HAVE CONNECTED AT LEAST ONCE
if TICKER(netTickerReconnect,1) = 1 or netTickConnectNow = 1
netTickConnectNow = 0
if mn Client Connected(0,0) < 1
debugWrite(DEBUGINFO,"Net Disconnected.")
`areaUnload()
`playerUnload(tidPlayer)
systemSharedGameModeRemove(SYSTEM_MODE_NET_TCP)
netClientStop()
netClientStart()
netClientConnectStart()
guiClientSwitchToWindow("windowLogon")
msg$ = "Lost connection to server... attempting to reconnect. Press Cancel to stop and exit."
guiClientMessageBoxShow(msg$,2,"","Cancel","","","/exit","")
endif
endif
endif
REM SEND UPDATES
if (systemMode && SYSTEM_MODE_NET_TCP) <> 0 AND (systemMode && SYSTEM_MODE_LOGON_COMPLETE) <> 0
if ( (TICKER(netTickerUpdate,1)=1 and netUpdateMode>0) or netTickSendNow=1 or TICKER(netTickerHeartbeat,1)=1 )
netTickSendNow = 0
netUpdateMode = 0
netClientMove()
endif
endif
REM RECEIVE UPDATES
if (systemMode && SYSTEM_MODE_NET_TCP)
TcpPackets = mn Recv TCP(0,RecvPacket,0)
if TcpPackets > 0
netClientParseTCP()
endif
REM ONLY PARSE UDP DATA WHEN THE PLAYER IS IN-WORLD
REM HERE WE MUST LOOP THROUGH ALL CLIENT PORTS BECAUSE
REM DATA COULD BE WAITING ON ANY PORT
if (systemMode && SYSTEM_MODE_LOGON_COMPLETE)
for i = 0 to (netMaxUDPOperations - 1)
for j = 0 to netMaxUDPClients
REM A ZERO CLIENT IS THE SERVER
UdpPackets = mn Recv UDP(0,RecvPacket,j,i)
if UdpPackets > 0
netClientParseUDP(j,i)
`debugWrite(DEBUGINFO,"UDP message " + str$(i) + " received on channel " + str$(j))
endif
next j
next i
endif
endif
endfunction
function netClientSendChat(myChannel$,message$)
message$ = keyboardSharedSanitize(message$)
bytes = NET_HEADER_BYTES
inc bytes, len(myChannel$)
inc bytes, len(message$)
REM CHAT WILL NEED TO BE ENCRYPTED ON
REM CHANNELS THAT ARE MARKED PRIVATE
netSharedAddHeader(NETC_CHAT,bytes)
mn Add string SendPacket, myChannel$, 0, 1
mn Add String SendPacket, message$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
endfunction
function netClientSendCommand(cmd$)
cmd$ = keyboardSharedSanitize(cmd$)
bytes = NET_HEADER_BYTES
inc bytes, len(cmd$)
netSharedAddHeader(NETC_COMMAND,bytes)
REM COMMAND MESSAGES WILL ALWAYS
REM BE ENCRYPTED. THIS WILL BE
REM DONE VERY SOON.
mn Add String SendPacket, cmd$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
endfunction
function netClientChangeChannels(operationID as integer, channel$ as string)
channel$ = keyboardSharedSanitize(channel$)
bytes = NET_HEADER_BYTES
inc bytes, len(channel$)
netSharedAddHeader(operationID,bytes)
mn Add String SendPacket, channel$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
endfunction
function netClientSendCreateAccount(accountName$ as string, password$ as string)
bytes = NET_HEADER_BYTES
inc bytes, len(accountName$)
inc bytes, len(password$)
netSharedAddHeader(NETC_CREATE_ACCOUNT,bytes)
mn Add String SendPacket, accountName$, 0, 1 : accountName$ = ""
mn Add String SendPacket, password$, 0, 1 : password$ = ""
mn Send TCP 0,SendPacket,0,0,1
debugWrite(DEBUGINFO, "Sent Create Account Request for " + accountName$)
endfunction
function netClientSendLogonAlpha(accountName$ as string)
bytes = NET_HEADER_BYTES
encryptSetKey(systemGameTitle$)
dat1$ = EncryptString(accountName$) : inc bytes, len(dat1$)
netSharedAddHeader(NETC_LOGON_ALPHA,bytes)
mn Add String SendPacket, dat1$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
`debugWrite(DEBUGINFO,"Sent NETC_LOGON_ALPHA")
endfunction
function netClientSendLogonBeta(testKey$ as string,accountName$ as string)
bytes = NET_HEADER_BYTES
encryptSetKey(testKey$)
dat1$ = EncryptString(accountName$) : inc bytes, len(dat1$)
netSharedAddHeader(NETC_LOGON_BETA, bytes)
mn Add String SendPacket, dat1$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
`debugWrite(DEBUGINFO,"Sent NETC_LOGON_BETA")
endfunction
function netClientSendAvatarList()
REM MUST SEND ENCYPTED ACCOUNTNAME
REM USING UNIQUE SESSION KEY
bytes = NET_HEADER_BYTES
accountName$ = dataSharedGetField( DATA_TABLE_INPUT, "inputLogonAccountName", DATA_KEY_UNDEFINED, DATA_NO_CREATE)
dat1$ = EncryptString(accountName$) : inc bytes, len(dat1$)
netSharedAddHeader(NETC_AVATAR_LIST, bytes)
mn Add String SendPacket, dat1$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
debugWrite(DEBUGINFO,"Sent NETC_AVATAR_LIST")
endfunction
function netClientSendManifestComplete()
REM TELL THE SERVER WE ARE DONE UPDATING MANIFEST
bytes = NET_HEADER_BYTES
netSharedAddHeader(NETC_MANIFEST, bytes)
mn Send TCP 0,SendPacket,0,0,1
debugWrite(DEBUGINFO,"Sent NETC_MANIFEST")
endfunction
function netClientSendAssetIDRequest(path$ as string)
REM REQUEST AN RPGID FROM THE SERVER FOR AN ASSET
bytes = NET_HEADER_BYTES
dat1$ = path$: inc bytes, len(dat1$)
netSharedAddHeader(NETC_ASSETID, bytes)
mn Add String SendPacket, dat1$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
debugWrite(DEBUGINFO,"Sent NETC_ASSETID for " + path$)
endfunction
function netClientParseTCP()
length = mn Get Int(RecvPacket)
time = mn Get Int(RecvPacket)
msgID = mn Get Int(RecvPacket)
REM SKIPPING THE SANITY CHECKS FOR NOW
select msgID
case NETS_CHAT
channel$ = mn Get String(RecvPacket,0,1)
message$ = mn Get String(RecvPacket,0,1)
message$ = "[" + channel$ + "] " + message$
message$ = keyboardSharedSanitize(message$)
REM TURN ON CHAT WHEN WE RECEIVE A MESSAGE
REM ON A CHANNEL WE ARE LISTENING TO
systemSharedGameModeAdd(SYSTEM_MODE_CHAT_ACTIVE)
guiClientUpdateChatRcv(message$)
endcase
case NETS_CREATE_ACCOUNT
REM SERVER IS TELLING US THAT WE SUCCESSFULLY
REM CREATED AN ACCOUNT
guiClientSwitchtoWindow("windowLogon")
guiClientMessageBoxShow("Account creation successful. You can now logon using the accountname and password you just created.",2,"","OK","","","/hidewindow\windowMessageBox","")
endcase
case NETS_LOGON_ALPHA
REM SERVER IS SENDING BACK A TEST PACKET
REM FOR US TO DECRYPT TO SEE IF WE KNOW
REM THE PASSWORD FOR THE ACCOUNT
`debugWrite(DEBUGINFO,"NETS_LOGON_ALPHA received.")
accountName$ = dataSharedGetField( DATA_TABLE_INPUT, "inputLogonAccountName", DATA_KEY_UNDEFINED, DATA_NO_CREATE)
password$ = dataSharedGetField( DATA_TABLE_INPUT, "inputLogonPassword", DATA_KEY_UNDEFINED, DATA_NO_CREATE)
encryptSetKey(password$ + systemGameTitle$)
testKey$ = DecryptString(mn Get String(RecvPacket,0,1))
netClientSendLogonBeta(testKey$, accountName$)
endcase
case NETS_LOGON_BETA
REM SERVER HAS ACCEPTED OUR TEST PACKET
REM AND IS SENDING US OUR UNIQUE KEY FOR
REM THIS GAME SESSION - LOGIN IS COMPLETE
debugWrite(DEBUGINFO,"LOGIN SUCCESS")
keySession$ = DecryptString(mn Get String(RecvPacket,0,1))
encryptSetKey(keySession$)
netClientSendAvatarList()
endcase
case NETS_AVATAR_LIST
REM SERVER IS SENDING AVATAR LIST
REM EXTRACT NAMES AND POPULATE GUI DATA TABLE
REM DYNAMICALLY CONSTRUCT BOTH THE avatarnameX
REM AND switchavatarX RECORDS, AND THEN SWITCH TO
REM THE CHARACTER SELECTION WINDOW
myAvatarList$ = mn Get String(RecvPacket,0,1)
debugWrite(DEBUGINFO,"Avatar list received: " + myAvatarList$)
split string myAvatarList$, DATA_ARGSEP
for i = 1 to split count()
myAvatarName$ = get split word$(i)
guiClientSetGUIDataField("avatarname"+str$(i), myAvatarName$)
guiClientSetGUIDataField("switchavatar"+str$(i), "/switchavatar\"+myAvatarName$)
next i
guiClientSwitchToWindow("windowSelectAvatar")
endcase
case NETS_MANIFEST
REM SERVER IS TELLING US TO UPDATE OUR LIBRARY
debugWrite(DEBUGINFO,"NETS_MANIFEST received")
meshClientRegisterNew()
`soundClientRegisterNew()
`effectClientRegisterNew()
rem not yet
wait 1000
REM TELL THE SERVER WE ARE DONE UPDATING LIBRARY
netClientSendManifestComplete()
endcase
case NETS_ASSETID
REM SERVER IS RESPONDING TO AN RPGID
REM REQUEST FOR A LIBRARY ASSET
assetID = mn Get Int(RecvPacket)
assetPath$ = mn Get String(RecvPacket,0,1)
dataSharedUpdateField(DATA_TABLE_LIBRARY, str$(assetID), assetPath$)
debugWrite(DEBUGINFO,"Asset RPGID for received for " + assetPath$ + " : " + str$(assetID))
endcase
case NETS_SWITCH_WINDOW
REM SERVER IS FORCING A GAME WINDOW CHANGE
windowName$ = mn Get String(RecvPacket,0,1)
guiClientSwitchToWindow(windowName$)
systemSharedGameModeAdd(SYSTEM_MODE_GUI)
debugWrite(DEBUGINFO,"NETS_SWITCH_WINDOW received for " + windowName$)
endcase
case NETS_RPGID
REM SERVER IS SENDING BACK THE UNIQUE
REM RPGID OF THE LOCAL PLAYER
temp = mn Get Int(RecvPacket)
debugWrite(DEBUGINFO,"Local Player RPGID received: " + str$(temp))
REM WE ARE TEMPORARILY CHEATING HERE - THE SERVER
REM WILL NEED TO SEND THE BASE MESH RPGID BY THIS
REM POINT AS WELL - WE'LL USE A WELL-KNOWN VALUE
REM FOR NOW (1 for the player_base.dbo)
tidPlayer = playerClientCreate(temp,1)
REM WE DON'T WANT TO SAVE A TABLE FOR OUR OWN
REM PLAYER - THAT IS HANDLED BY THE SERVER
DATA_NOSAVE_TABLES = systemSharedFieldAdd(DATA_NOSAVE_TABLES,str$(temp),DATA_ARGSEP)
guiClientShowWindow(GUI_WINDOW_MAIN)
systemSharedGameModeAdd(SYSTEM_MODE_LOGON_COMPLETE)
systemSharedGameModeAdd(SYSTEM_MODE_GUI)
endcase
case NETS_CREATE_ACCOUNT_ERROR
guiClientMessageBoxShow("Account creation failed. Account names and passwords must be at least 6 characters long or accountname already in use.",2,"","OK","","","/switchtowindow\windowCreateAccount","")
endcase
case NETS_LOGON_ALPHA_ERROR
guiClientMessageBoxShow("Logon failed. Password is case sensitive. Please try again.",2,"","OK","","","/switchtowindow\windowLogon","")
endcase
case NETS_LOGON_BETA_ERROR
guiClientMessageBoxShow("Logon failed. Password is case sensitive. Please try again.",2,"","OK","","","/switchtowindow\windowLogon","")
endcase
endselect
endfunction
function netClientParseUDP(clientID as integer,OperationID as integer)
REM GET UDP MESSAGES
RPGIDRemotePlayer = mn Get Int(RecvPacket)
tidRemotePlayer = dataSharedTableExist(str$(RPGIDRemotePlayer))
if tidRemotePlayer = DATA_FUNCTION_FAIL and RPGIDRemotePlayer <> 0
REM THIS PLAYER IS NEW TO THIS CLIENT
dataSharedUpdateField(str$(RPGIDRemotePlayer),"rpgid",str$(RPGIDRemotePlayer))
playerClientCreate(RPGIDRemotePlayer,1)
REM WE DON'T WANT TO SAVE TABLES FOR
REM THE TEMPORARY DATA USED FOR
REM REMOTE PLAYERS
DATA_NOSAVE_TABLES = systemSharedFieldAdd(DATA_NOSAVE_TABLES,str$(RPGIDRemotePlayer),DATA_ARGSEP)
endif
if tidRemotePlayer <> DATA_FUNCTION_FAIL
select OperationID
case NETS_MOVE
dataSharedUpdateFieldFast(tidRemotePlayer,"posx",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"posy",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"posz",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"roty",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"attarget","0")
endcase
case NETS_JUMP
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpx",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpy",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpz",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpry",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpready","1")
dataSharedUpdateFieldFast(tidRemotePlayer,"attarget","0")
endcase
endselect
endif
endfunction
function netClientMove()
if tidPlayer < 1 then exitfunction
mydbpid = intval(dataSharedGetFieldFast(tidPlayer, "dbpid"))
if mydbpid = 0 then exitfunction
if object exist(mydbpid) = 0 then exitfunction
mn Clear Packet SendPacket
mn Add Int SendPacket, NETC_MOVE
mn Add Int SendPacket, intval(dataSharedGetFieldFast(tidPlayer,"rpgid"))
mn Add Float SendPacket, object position x(mydbpid)
mn Add Float SendPacket, object position y(mydbpid)
mn Add Float SendPacket, object position z(mydbpid)
mn Add Float SendPacket, object angle y(mydbpid)
mn Send UDP 0, SendPacket, NULL, 0, 1
`debugWrite(DEBUGINFO,"Sent Movement Update")
endfunction
REM *** Include File: modules\netClient.dba ***
REM Created: 7/4/2010 10:55:22 AM
REM
REM Included in Project: C:\Program Files\The Game Creators\Dark Basic Professional\Projects\worldofomen\worldofomen.dbpro
REM
netClientSetup:
NET_SERVER_NAME = dataSharedGetField("netClient", "netServerName", NET_SERVER_NAME_DEFAULT, DATA_CREATE)
global Timeout
global NoInstances
global NoThreads
global profile
global MaximumClients
global netClientCurrentChannel as string
netClientCurrentChannel = dataSharedGetField("netClient", "netClientCurrentChannel", "BROADCAST", DATA_CREATE)
global netTickerUpdate as integer
netTickerUpdate = systemSharedGetFree(SYSTEM_TYPE_TICKER, SYSTEM_SEARCH_FAST)
MAKE TICKER netTickerUpdate, NET_UDP_UPDATE_INTERVAL
global netTickerHeartbeat as integer
netTickerHeartbeat = systemSharedGetFree(SYSTEM_TYPE_TICKER, SYSTEM_SEARCH_FAST)
MAKE TICKER netTickerHeartbeat, NET_UDP_HEARTBEAT_INTERVAL
global netTickerReconnect as integer
netTickerReconnect = systemSharedGetFree(SYSTEM_TYPE_TICKER, SYSTEM_SEARCH_FAST)
MAKE TICKER netTickerReconnect, NET_TCP_RECONNECT_INTERVAL
global netTickSendNow as boolean
global netTickConnectNow as boolean
global netMaxUDPClients as integer
global netMaxUDPOperations as integer
global netSessionKey$ as string
global netUpdateMode as integer
global netClientUsername$ as string
global netClientPassword$ as string
global netClientAvatarname$ as string
`encryptSetKey(systemGameTitle$)
rem not yet
return
function netClientStart()
` To be filled during connection
MaximumClients as integer
` Setup packets
SendPacket = mn create packet()
RecvPacket = mn create packet()
mn set memory size SendPacket,1024
` Try to connect
Timeout = 4000
profile = mn Create Instance Profile()
` Set the number of threads that will be created
` to deal with incoming data. In most cases this
` should be set to the number of processors on your
` computer. MikeNet can determine this for you
` automatically if you set it to 0
NoThreads = 0
` Set the number of MikeNet instances to create
NoInstances = 1
` Start MikeNet
mn Start NoInstances,NoThreads
if NET_SERVER_NAME = NET_SERVER_NAME_DEFAULT
debugWrite(DEBUGWARN,"Server name not set, attempting search...")
REM NAME WAS NOT SET, SEARCH AND UPDATE
i = intval(dataSharedGetField("netClient", "netSearchMode", "1",1))
select i
case 0:
REM DO NOT SEARCH
debugWrite(DEBUGWARN,"Search mode set to 0, default server name will be used.")
endcase
case 1:
REM SEARCH LAN
debugWrite(DEBUGINFO,"Search mode set to 1, searching on LAN...")
i$ = netSharedGetLANIP()
if i$ = ""
debugWrite(DEBUGERROR,"NO VALID LAN INTERFACES FOUND. FORCING QUIT.")
systemSharedGameModeAdd(SYSTEM_MODE_QUITTING)
else
NET_SERVER_NAME = i$
dataSharedUpdateField("netClient","netServerName",NET_SERVER_NAME)
endif
endcase
case 2:
REM SEARCH WAN
debugWrite(DEBUGINFO,"Search mode set to 2, searching on WAN...")
i$ = netSharedGetWANIP()
if i$ = ""
debugWrite(DEBUGERROR,"NO VALID WAN INTERFACES FOUND. FORCING QUIT.")
systemSharedGameModeAdd(SYSTEM_MODE_QUITTING)
else
NET_SERVER_NAME = i$
dataSharedUpdateField("netClient","netServerName",NET_SERVER_NAME)
endif
endcase
endselect
endif
endfunction
function netClientStop()
mn Finish -1
endfunction
function netClientConnectStart()
`MN CONNECT=MikeNet\mnConnect.html={Instance, TCP connect IP, TCP connect port, UDP connect IP, UDP connect port, Timeout, Block until connected, Instance profile}
Connect = mn Connect(0,NET_SERVER_NAME,NET_SERVER_PORT,NET_SERVER_NAME,NET_SERVER_PORT,NET_TIMEOUT_SECONDS,1,profile)
endfunction
function netClientConnectStop()
mn Stop Connect 0
if (systemMode && SYSTEM_MODE_NET_TCP)
debugWrite(DEBUGERROR,"Net Connect timeout or error connecting to server.")
endif
systemSharedGameModeRemove(SYSTEM_MODE_NET_TCP)
endfunction
function netClientMaintain()
local i as integer
local j as integer
local pollStatus as integer
if (systemMode && SYSTEM_MODE_NET_TCP) = 0
REM WE HAVE NEVER CONNNECTED BEFORE
pollStatus = mn poll connect(0)
select pollStatus
case -1:
REM ERROR
netClientConnectStop()
netClientConnectStart()
debugWrite(DEBUGERROR,"Net Connect Error: " + NET_SERVER_NAME + ":" + str$(NET_SERVER_PORT) + ":" + str$(NET_TIMEOUT_SECONDS))
endcase
case 0:
REM TIMEOUT
netClientConnectStop()
netClientConnectStart()
debugWrite(DEBUGERROR,"Net Connect Timeout.")
endcase
case 1:
REM SUCCESSFUL
systemSharedGameModeAdd(SYSTEM_MODE_NET_TCP)
debugWrite(DEBUGINFO,"Net Connect Successful. Mode TCP Added.")
`guiHideWindow("windowMessageBox")
netMaxUDPClients = mn Get Max Clients(0)
debugWrite(DEBUGINFO,"Net Max UDP Clients set to " + str$(netMaxUDPClients))
netMaxUDPOperations = mn Get Max Operations(0)
debugWrite(DEBUGINFO,"Net Max UDP Operations set to " + str$(netMaxUDPOperations))
endcase
case 2:
REM CONNECT IS STILL IN PROGRESS
REM LET IT KEEP TRYING UNTIL ITS
REM TIMEOUT VALUE
if TICKER(netTickerReconnect,1) = 1 or netTickConnectNow = 1
debugWrite(DEBUGINFO,"Attempting to connect to server...")
endif
endcase
endselect
endif
if (systemMode && SYSTEM_MODE_NET_TCP)
REM WE HAVE CONNECTED AT LEAST ONCE
if TICKER(netTickerReconnect,1) = 1 or netTickConnectNow = 1
netTickConnectNow = 0
if mn Client Connected(0,0) < 1
debugWrite(DEBUGINFO,"Net Disconnected.")
`areaUnload()
`playerUnload(tidPlayer)
systemSharedGameModeRemove(SYSTEM_MODE_NET_TCP)
netClientStop()
netClientStart()
netClientConnectStart()
guiClientSwitchToWindow("windowLogon")
msg$ = "Lost connection to server... attempting to reconnect. Press Cancel to stop and exit."
guiClientMessageBoxShow(msg$,2,"","Cancel","","","/exit","")
endif
endif
endif
REM SEND UPDATES
if (systemMode && SYSTEM_MODE_NET_TCP) <> 0 AND (systemMode && SYSTEM_MODE_LOGON_COMPLETE) <> 0
if ( (TICKER(netTickerUpdate,1)=1 and netUpdateMode>0) or netTickSendNow=1 or TICKER(netTickerHeartbeat,1)=1 )
netTickSendNow = 0
netUpdateMode = 0
netClientMove()
endif
endif
REM RECEIVE UPDATES
if (systemMode && SYSTEM_MODE_NET_TCP)
TcpPackets = mn Recv TCP(0,RecvPacket,0)
if TcpPackets > 0
netClientParseTCP()
endif
REM ONLY PARSE UDP DATA WHEN THE PLAYER IS IN-WORLD
REM HERE WE MUST LOOP THROUGH ALL CLIENT PORTS BECAUSE
REM DATA COULD BE WAITING ON ANY PORT
if (systemMode && SYSTEM_MODE_LOGON_COMPLETE)
for i = 0 to (netMaxUDPOperations - 1)
for j = 0 to netMaxUDPClients
REM A ZERO CLIENT IS THE SERVER
UdpPackets = mn Recv UDP(0,RecvPacket,j,i)
if UdpPackets > 0
netClientParseUDP(j,i)
`debugWrite(DEBUGINFO,"UDP message " + str$(i) + " received on channel " + str$(j))
endif
next j
next i
endif
endif
endfunction
function netClientSendChat(myChannel$,message$)
message$ = keyboardSharedSanitize(message$)
bytes = NET_HEADER_BYTES
inc bytes, len(myChannel$)
inc bytes, len(message$)
REM CHAT WILL NEED TO BE ENCRYPTED ON
REM CHANNELS THAT ARE MARKED PRIVATE
netSharedAddHeader(NETC_CHAT,bytes)
mn Add string SendPacket, myChannel$, 0, 1
mn Add String SendPacket, message$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
endfunction
function netClientSendCommand(cmd$)
cmd$ = keyboardSharedSanitize(cmd$)
bytes = NET_HEADER_BYTES
inc bytes, len(cmd$)
netSharedAddHeader(NETC_COMMAND,bytes)
REM COMMAND MESSAGES WILL ALWAYS
REM BE ENCRYPTED. THIS WILL BE
REM DONE VERY SOON.
mn Add String SendPacket, cmd$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
endfunction
function netClientChangeChannels(operationID as integer, channel$ as string)
channel$ = keyboardSharedSanitize(channel$)
bytes = NET_HEADER_BYTES
inc bytes, len(channel$)
netSharedAddHeader(operationID,bytes)
mn Add String SendPacket, channel$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
endfunction
function netClientSendCreateAccount(accountName$ as string, password$ as string)
bytes = NET_HEADER_BYTES
inc bytes, len(accountName$)
inc bytes, len(password$)
netSharedAddHeader(NETC_CREATE_ACCOUNT,bytes)
mn Add String SendPacket, accountName$, 0, 1 : accountName$ = ""
mn Add String SendPacket, password$, 0, 1 : password$ = ""
mn Send TCP 0,SendPacket,0,0,1
debugWrite(DEBUGINFO, "Sent Create Account Request for " + accountName$)
endfunction
function netClientSendLogonAlpha(accountName$ as string)
bytes = NET_HEADER_BYTES
encryptSetKey(systemGameTitle$)
dat1$ = EncryptString(accountName$) : inc bytes, len(dat1$)
netSharedAddHeader(NETC_LOGON_ALPHA,bytes)
mn Add String SendPacket, dat1$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
`debugWrite(DEBUGINFO,"Sent NETC_LOGON_ALPHA")
endfunction
function netClientSendLogonBeta(testKey$ as string,accountName$ as string)
bytes = NET_HEADER_BYTES
encryptSetKey(testKey$)
dat1$ = EncryptString(accountName$) : inc bytes, len(dat1$)
netSharedAddHeader(NETC_LOGON_BETA, bytes)
mn Add String SendPacket, dat1$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
`debugWrite(DEBUGINFO,"Sent NETC_LOGON_BETA")
endfunction
function netClientSendAvatarList()
REM MUST SEND ENCYPTED ACCOUNTNAME
REM USING UNIQUE SESSION KEY
bytes = NET_HEADER_BYTES
accountName$ = dataSharedGetField( DATA_TABLE_INPUT, "inputLogonAccountName", DATA_KEY_UNDEFINED, DATA_NO_CREATE)
dat1$ = EncryptString(accountName$) : inc bytes, len(dat1$)
netSharedAddHeader(NETC_AVATAR_LIST, bytes)
mn Add String SendPacket, dat1$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
debugWrite(DEBUGINFO,"Sent NETC_AVATAR_LIST")
endfunction
function netClientSendManifestComplete()
REM TELL THE SERVER WE ARE DONE UPDATING MANIFEST
bytes = NET_HEADER_BYTES
netSharedAddHeader(NETC_MANIFEST, bytes)
mn Send TCP 0,SendPacket,0,0,1
debugWrite(DEBUGINFO,"Sent NETC_MANIFEST")
endfunction
function netClientSendAssetIDRequest(path$ as string)
REM REQUEST AN RPGID FROM THE SERVER FOR AN ASSET
bytes = NET_HEADER_BYTES
dat1$ = path$: inc bytes, len(dat1$)
netSharedAddHeader(NETC_ASSETID, bytes)
mn Add String SendPacket, dat1$, 0, 1
mn Send TCP 0,SendPacket,0,0,1
debugWrite(DEBUGINFO,"Sent NETC_ASSETID for " + path$)
endfunction
function netClientParseTCP()
length = mn Get Int(RecvPacket)
time = mn Get Int(RecvPacket)
msgID = mn Get Int(RecvPacket)
REM SKIPPING THE SANITY CHECKS FOR NOW
select msgID
case NETS_CHAT
channel$ = mn Get String(RecvPacket,0,1)
message$ = mn Get String(RecvPacket,0,1)
message$ = "[" + channel$ + "] " + message$
message$ = keyboardSharedSanitize(message$)
REM TURN ON CHAT WHEN WE RECEIVE A MESSAGE
REM ON A CHANNEL WE ARE LISTENING TO
systemSharedGameModeAdd(SYSTEM_MODE_CHAT_ACTIVE)
guiClientUpdateChatRcv(message$)
endcase
case NETS_CREATE_ACCOUNT
REM SERVER IS TELLING US THAT WE SUCCESSFULLY
REM CREATED AN ACCOUNT
guiClientSwitchtoWindow("windowLogon")
guiClientMessageBoxShow("Account creation successful. You can now logon using the accountname and password you just created.",2,"","OK","","","/hidewindow\windowMessageBox","")
endcase
case NETS_LOGON_ALPHA
REM SERVER IS SENDING BACK A TEST PACKET
REM FOR US TO DECRYPT TO SEE IF WE KNOW
REM THE PASSWORD FOR THE ACCOUNT
`debugWrite(DEBUGINFO,"NETS_LOGON_ALPHA received.")
accountName$ = dataSharedGetField( DATA_TABLE_INPUT, "inputLogonAccountName", DATA_KEY_UNDEFINED, DATA_NO_CREATE)
password$ = dataSharedGetField( DATA_TABLE_INPUT, "inputLogonPassword", DATA_KEY_UNDEFINED, DATA_NO_CREATE)
encryptSetKey(password$ + systemGameTitle$)
testKey$ = DecryptString(mn Get String(RecvPacket,0,1))
netClientSendLogonBeta(testKey$, accountName$)
endcase
case NETS_LOGON_BETA
REM SERVER HAS ACCEPTED OUR TEST PACKET
REM AND IS SENDING US OUR UNIQUE KEY FOR
REM THIS GAME SESSION - LOGIN IS COMPLETE
debugWrite(DEBUGINFO,"LOGIN SUCCESS")
keySession$ = DecryptString(mn Get String(RecvPacket,0,1))
encryptSetKey(keySession$)
netClientSendAvatarList()
endcase
case NETS_AVATAR_LIST
REM SERVER IS SENDING AVATAR LIST
REM EXTRACT NAMES AND POPULATE GUI DATA TABLE
REM DYNAMICALLY CONSTRUCT BOTH THE avatarnameX
REM AND switchavatarX RECORDS, AND THEN SWITCH TO
REM THE CHARACTER SELECTION WINDOW
myAvatarList$ = mn Get String(RecvPacket,0,1)
debugWrite(DEBUGINFO,"Avatar list received: " + myAvatarList$)
split string myAvatarList$, DATA_ARGSEP
for i = 1 to split count()
myAvatarName$ = get split word$(i)
guiClientSetGUIDataField("avatarname"+str$(i), myAvatarName$)
guiClientSetGUIDataField("switchavatar"+str$(i), "/switchavatar\"+myAvatarName$)
next i
guiClientSwitchToWindow("windowSelectAvatar")
endcase
case NETS_MANIFEST
REM SERVER IS TELLING US TO UPDATE OUR LIBRARY
debugWrite(DEBUGINFO,"NETS_MANIFEST received")
meshClientRegisterNew()
`soundClientRegisterNew()
`effectClientRegisterNew()
rem not yet
wait 1000
REM TELL THE SERVER WE ARE DONE UPDATING LIBRARY
netClientSendManifestComplete()
endcase
case NETS_ASSETID
REM SERVER IS RESPONDING TO AN RPGID
REM REQUEST FOR A LIBRARY ASSET
assetID = mn Get Int(RecvPacket)
assetPath$ = mn Get String(RecvPacket,0,1)
dataSharedUpdateField(DATA_TABLE_LIBRARY, str$(assetID), assetPath$)
debugWrite(DEBUGINFO,"Asset RPGID for received for " + assetPath$ + " : " + str$(assetID))
endcase
case NETS_SWITCH_WINDOW
REM SERVER IS FORCING A GAME WINDOW CHANGE
windowName$ = mn Get String(RecvPacket,0,1)
guiClientSwitchToWindow(windowName$)
systemSharedGameModeAdd(SYSTEM_MODE_GUI)
debugWrite(DEBUGINFO,"NETS_SWITCH_WINDOW received for " + windowName$)
endcase
case NETS_RPGID
REM SERVER IS SENDING BACK THE UNIQUE
REM RPGID OF THE LOCAL PLAYER
temp = mn Get Int(RecvPacket)
debugWrite(DEBUGINFO,"Local Player RPGID received: " + str$(temp))
REM WE ARE TEMPORARILY CHEATING HERE - THE SERVER
REM WILL NEED TO SEND THE BASE MESH RPGID BY THIS
REM POINT AS WELL - WE'LL USE A WELL-KNOWN VALUE
REM FOR NOW (1 for the player_base.dbo)
tidPlayer = playerClientCreate(temp,1)
REM WE DON'T WANT TO SAVE A TABLE FOR OUR OWN
REM PLAYER - THAT IS HANDLED BY THE SERVER
DATA_NOSAVE_TABLES = systemSharedFieldAdd(DATA_NOSAVE_TABLES,str$(temp),DATA_ARGSEP)
guiClientShowWindow(GUI_WINDOW_MAIN)
systemSharedGameModeAdd(SYSTEM_MODE_LOGON_COMPLETE)
systemSharedGameModeAdd(SYSTEM_MODE_GUI)
endcase
case NETS_CREATE_ACCOUNT_ERROR
guiClientMessageBoxShow("Account creation failed. Account names and passwords must be at least 6 characters long or accountname already in use.",2,"","OK","","","/switchtowindow\windowCreateAccount","")
endcase
case NETS_LOGON_ALPHA_ERROR
guiClientMessageBoxShow("Logon failed. Password is case sensitive. Please try again.",2,"","OK","","","/switchtowindow\windowLogon","")
endcase
case NETS_LOGON_BETA_ERROR
guiClientMessageBoxShow("Logon failed. Password is case sensitive. Please try again.",2,"","OK","","","/switchtowindow\windowLogon","")
endcase
endselect
endfunction
function netClientParseUDP(clientID as integer,OperationID as integer)
REM GET UDP MESSAGES
RPGIDRemotePlayer = mn Get Int(RecvPacket)
tidRemotePlayer = dataSharedTableExist(str$(RPGIDRemotePlayer))
if tidRemotePlayer = DATA_FUNCTION_FAIL and RPGIDRemotePlayer <> 0
REM THIS PLAYER IS NEW TO THIS CLIENT
dataSharedUpdateField(str$(RPGIDRemotePlayer),"rpgid",str$(RPGIDRemotePlayer))
playerClientCreate(RPGIDRemotePlayer,1)
REM WE DON'T WANT TO SAVE TABLES FOR
REM THE TEMPORARY DATA USED FOR
REM REMOTE PLAYERS
DATA_NOSAVE_TABLES = systemSharedFieldAdd(DATA_NOSAVE_TABLES,str$(RPGIDRemotePlayer),DATA_ARGSEP)
endif
if tidRemotePlayer <> DATA_FUNCTION_FAIL
select OperationID
case NETS_MOVE
dataSharedUpdateFieldFast(tidRemotePlayer,"posx",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"posy",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"posz",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"roty",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"attarget","0")
endcase
case NETS_JUMP
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpx",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpy",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpz",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpry",str$(mn Get Float(RecvPacket)))
dataSharedUpdateFieldFast(tidRemotePlayer,"jumpready","1")
dataSharedUpdateFieldFast(tidRemotePlayer,"attarget","0")
endcase
endselect
endif
endfunction
function netClientMove()
if tidPlayer < 1 then exitfunction
mydbpid = intval(dataSharedGetFieldFast(tidPlayer, "dbpid"))
if mydbpid = 0 then exitfunction
if object exist(mydbpid) = 0 then exitfunction
mn Clear Packet SendPacket
mn Add Int SendPacket, NETC_MOVE
mn Add Int SendPacket, intval(dataSharedGetFieldFast(tidPlayer,"rpgid"))
mn Add Float SendPacket, object position x(mydbpid)
mn Add Float SendPacket, object position y(mydbpid)
mn Add Float SendPacket, object position z(mydbpid)
mn Add Float SendPacket, object angle y(mydbpid)
mn Send UDP 0, SendPacket, NULL, 0, 1
`debugWrite(DEBUGINFO,"Sent Movement Update")
endfunction
I have attached the error
Thanks!
CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!