I've made the changes you mentioned and also went through the demo projects fairly in depth, and the good news is the server is now sending the packets! The bad, is now (even after sorting out my client code for use with the updated server) I am now getting a client side error (screenie attached) unfortunately, the error doesn't tell me much about what's really going wrong with my code. Here's the code for handling darknet at the client end:
_SEND_PACKET = mn create packet()
_RECV_PACKET = mn create packet()
mn set memory size _SEND_PACKET,1024
mn start 2, 0
sync : input "Server IP: ", _SERVER_IP$
mn connect 1, _SERVER_IP$, 1105, _SERVER_IP$, 1105, 10, 1
sync : print "UDP Port:" + str$(mn get connect port udp(1))
sync : print "TCP Port:" + str$(mn get connect port tcp(1))
sync : wait key
_LAST_SENT = timer()
_LAST_RECV = timer()
create bitmap 1, text width("PACK RECIEVED..."), text height("PACK RECIEVED...")
ink rgb(0,0,0), rgb(255,255,255)
set text opaque
set cursor 0,0
print "PACK RECIEVED..."
get image 1, 0, 0, text width("PACK RECIEVED..."), text height("PACK RECIEVED...")
delete bitmap 1
DO
gosub NetPlay
sync
LOOP
NetPlay:
//Sends Position data to other clients
mn add float _SEND_PACKET, _PLAYER_X#
mn add float _SEND_PACKET, _PLAYER_Y#
mn add float _SEND_PACKET, _PLAYER_Z#
mn send udp 1, _SEND_PACKET, 0, 0, 1
_LAST_SENT=timer()
_TCP_RECVD = mn recv tcp(1, _RECV_PACKET, NULL)
if _TCP_RECVD>0
_TYPE = mn get int(_RECV_PACKET)
_PLAYER = mn get int(_RECV_PACKET)
if _TYPE=0
if object exist(_PLAYER) = 0 then make object cube _PLAYER, 50
endif
if _TYPE=1
if object exist(_PLAYER) = 1 then delete object _PLAYER
endif
endif
//Checks packets from connected players
for _PLAYER=1 to 50
if _PLAYER <> mn get client id(1)
_RECVD = mn recv udp (1, _RECV_PACKET, _PLAYER, 0)
if object exist(_PLAYER)
if _RECVD = 1
_LAST_RECV=timer()
posX# = mn get float(_RECV_PACKET)
posY# = mn get float(_RECV_PACKET)
posZ# = mn get float(_RECV_PACKET)
position object _PLAYER, posX#, posY#, posZ#
endif
endif
endif
next _PLAYER
text 0, 0, "X: " + str$(_PLAYER_X#) + " Y: " + str$(_PLAYER_Y#) + " Z: " + str$(_PLAYER_Z#)
if (timer() - _LAST_RECV) < 3000 then paste image 1, 0, 50
return
And the updated server source:
type PLAYER
X# as float
Y# as float
Z# as float
HP as integer
MANA as integer
endtype
remstart
Every sent packet contains a integer first, this integer is to inform the client of what
data the packet contains.
1 - Server Text
2 - Player information
3 - Player attack information
remend
dim PLAYERS(51) as PLAYER
_SEND_PACKET = mn create packet()
_RECV_PACKET = mn create packet()
mn set memory size _SEND_PACKET,1024
mn start 2, 0
mn set local 1, "", 1105, "", 1105
result = mn start server(1, 50, 0, 1)
_LOCAL_IP$ = mn get local ip udp (1)
sync : print "Server started on " + _LOCAL_IP$
sync : print "At " + GET TIME$() + " on " + GET DATE$()
sync : print "UDP IP: " + str$(mn Get Local Port UDP(1))
sync : print "TCP IP: " + str$(mn Get Local Port TCP(1))
sync : print "System Time: " + str$(timer())
do
_NEW_CLIENT = mn client joined(1)
if _NEW_CLIENT > 0
for _CLIENT=1 to 50
if mn client connected ( 1, _CLIENT) and _CLIENT <> _NEW_CLIENT
mn add int _SEND_PACKET, 0
mn add int _SEND_PACKET, _CLIENT
mn send tcp 1, _SEND_PACKET, _NEW_CLIENT, 0, 0
endif
next _CLIENT
print "|---------------------------------------------------|"
print "New player has joined!" + " t:" + str$(timer())
print "player ID: " + str$(_NEW_CLIENT)
print "player TCP IP address: " + mn get client ip tcp(1, _NEW_CLIENT)
print "player UDP IP address: " + mn get client ip udp(1, _NEW_CLIENT)
mn add int _SEND_PACKET, 0
mn add int _SEND_PACKET, _NEW_CLIENT
mn send tcp all 1, _SEND_PACKET, 0, 0, _NEW_CLIENT
endif
_CLIENT_LEFT = mn client left(1)
if _CLIENT_LEFT > 0
mn add int _SEND_PACKET, 1
mn add int _SEND_PACKET, _CLIENT_LEFT
mn send tcp all 1, _SEND_PACKET, 0, 0, _CLIENT_LEFT
print "|---------------------------------------------------|"
print "Player has disconnected." + " t:" + str$(timer())
print "player ID: " + str$(_CLIENT_LEFT)
print "player TCP IP address: " + mn get client ip tcp(1, _CLIENT_LEFT)
print "player UDP IP address: " + mn get client ip udp(1, _CLIENT_LEFT)
endif
for _CLIENT = 1 to 50
if mn client connected (1, _CLIENT) = 1
_RECVD = mn recv udp (1, _RECV_PACKET, _CLIENT, 0)
if _RECVD = 1
PLAYERS(_CLIENT).X# = mn get float (_RECV_PACKET)
PLAYERS(_CLIENT).Y# = mn get float (_RECV_PACKET)
PLAYERS(_CLIENT).Z# = mn get float (_RECV_PACKET)
mn add float _SEND_PACKET, PLAYERS(_CLIENT).X#
mn add float _SEND_PACKET, PLAYERS(_CLIENT).Y#
mn add float _SEND_PACKET, PLAYERS(_CLIENT).Z#
mn send udp all 1, _SEND_PACKET, 0, 1, _CLIENT
// print "Client: " + str$(_CLIENT) + " X: " + str$(PLAYERS(_CLIENT).X#) + " Y: " + str$(PLAYERS(_CLIENT).Y#) + " Z: " + str$(PLAYERS(_CLIENT).Z#) + " HP: " + str$(PLAYERS(_CLIENT).HP) + " MANA: " + str$(PLAYERS(_CLIENT).MANA) + " " + str$(timer())
endif
endif
next _CLIENT
loop
mn finish -1