Hello everybody.
I tried Multisync example to host a multiplayer session.
But somehow the exe always crash on startup.
What did I do wrong? I even port-forward the port 8888
My local IP: 192.168.1.101
My open port: 8888
My remote IP: 60.49.73.217
It crashes when I used these:
ip$ = "192.168.1.101:8888"
result = net host(MAXIMUM_PLAYERS,ip$)
It doesn't crash when I use this:
result = net host(MAXIMUM_PLAYERS)
But if I wanted to host online multiplayer, I had to use the first method, right?
Any idea on how to fix this?
The codes. It's the same Multisync demo code:
` Constants --------------------------------------
#constant MAXIMUM_PLAYERS 10
#constant MESSAGE_ID_NAME 0
#constant MESSAGE_ID_GENERAL 1 : ` Contains just player data
#constant MESSAGE_ID_GENERALFULL 2 : ` Contains player numbers and player data
#constant MESSAGE_ID_PLAYERJOINED 3
#constant MESSAGE_ID_PLAYERQUIT 4
#constant FLAG_UP 1
#constant FLAG_DOWN 2
#constant FLAG_LEFT 4
#constant FLAG_RIGHT 8
` ------------------------------------------------
` Types ------------------------------------------
type player_data
exist as boolean
active as boolean
name as string
x as float
z as float
realx as float
realz as float
angle as float
key_up as boolean
key_down as boolean
key_left as boolean
key_right as boolean
endtype
` ------------------------------------------------
` Variables --------------------------------------
global dim player(MAXIMUM_PLAYERS) as player_data
global MOUSE_LBM_PRESSED as boolean
` ------------------------------------------------
sync off
autocam off
ip$ = "192.168.1.101:8888"
result = net host(MAXIMUM_PLAYERS,ip$)
`result = net host(MAXIMUM_PLAYERS)
if not result
print "Could not start server: "+chr$(34)+net get error()+chr$(34)+"."
print "Press any key to exit."
wait key
end
endif
make matrix 1, 1000, 1000, 10, 10
position camera 500, 1000, 500
point camera 500, 0, 500
sync on
sync rate 60
do
text 0, 0, str$(screen fps())
text 0, 13, "There are "+str$(net get player amount())+" players connected."
if spacekey() then net kick 1
HandleNetwork()
HandleMouseOvers()
HandleMovement()
TEXT 10,200, "Player IP : " + NET GET PLAYER IP(1)
`port = NET GET PLAYER PORT(0)
sync
loop
function HandleMovement()
for x = 1 to MAXIMUM_PLAYERS
if player(x).exist
if player(x).key_up
player(x).realx = player(x).realx + sin(player(x).angle)
player(x).realz = player(x).realz + cos(player(x).angle)
endif
if player(x).key_down
player(x).realx = player(x).realx - sin(player(x).angle)
player(x).realz = player(x).realz - cos(player(x).angle)
endif
if player(x).key_left then player(x).angle = wrapvalue(player(x).angle-1)
if player(x).key_right then player(x).angle = wrapvalue(player(x).angle+1)
distx# = abs(player(x).realx-player(x).x)
speedx# = distx# / 10.0
distz# = abs(player(x).realz-player(x).z)
speedz# = distz# / 10.0
angle# = atanfull(player(x).realx-player(x).x, player(x).realz-player(x).z)
player(x).x = player(x).x + (sin(angle#)*speedx#)
player(x).z = player(x).z + (cos(angle#)*speedz#)
yrotate object x+10, player(x).angle
position object x+10, player(x).x, 0, player(x).z
endif
next x
endfunction
function HandleMouseOvers()
result = pick object(mousex(), mousey(), 10, 30)
if result = 0 then exitfunction
if result > 9 and result < 20
text mousex(), mousey()-13, player(result-10).name
endif
endfunction
function HandleNetwork()
` Player joining ------------
` ---------------------------
result = net player joined()
while result > 0
make object cube 10+result, 10
player(result).exist = 1
rem send states & positions of players
net put byte MESSAGE_ID_GENERALFULL
for x = 1 to MAXIMUM_PLAYERS
if net player connected(x)
if player(x).active
net put byte x
net put string player(x).name
net put float player(x).realx
net put float player(x).realz
net put byte player(x).angle / 1.411
net put byte GetFlags(x)
endif
endif
next x
net send result
result = net player joined()
endwhile
` Player leaving -------------
` ----------------------------
result = net player left()
while result > 0
ResetPlayer(result)
net put byte MESSAGE_ID_PLAYERQUIT
net put byte result
net send all
result = net player left()
endwhile
` Message processing ---------
` ----------------------------
while net get message()
playerNum = net message from()
select net get byte()
case MESSAGE_ID_NAME
playerNum = net message from()
player(playerNum).name = net get string()
player(playerNum).active = 1
color object playerNum+10, rgb(0, 255, 0)
` Notify other players
net put byte MESSAGE_ID_PLAYERJOINED
net put byte playerNum
net put string player(playerNum).name
for x = 1 to MAXIMUM_PLAYERS
if net player connected(x)
if x <> playerNum
net send x, 1
endif
endif
next x
` Clear message data
net send 0
endcase
case MESSAGE_ID_GENERAL
player(playerNum).realx = net get float()
player(playerNum).realz = net get float()
player(playerNum).angle = net get byte() * 1.411
ApplyFlags(playerNum, net get byte())
ApplyPosition(playerNum)
` Forward message on
net put byte MESSAGE_ID_GENERAL
net put byte playerNum
net put float player(playerNum).realx
net put float player(playerNum).realz
net put byte player(playerNum).angle / 1.411
net put byte GetFlags(playerNum)
SendAllExcept(playerNum)
endcase
endselect
endwhile
endfunction
function ResetPlayer(playerNum as integer)
if object exist(playerNum+10) then delete object playerNum+10
player(playerNum).exist = 0
player(playerNum).active = 0
player(playerNum).name = ""
player(playerNum).x = 0
player(playerNum).z = 0
player(playerNum).realx = 0
player(playerNum).realz = 0
player(playerNum).angle = 0
player(playerNum).key_up = 0
player(playerNum).key_down = 0
player(playerNum).key_left = 0
player(playerNum).key_right = 0
endfunction
function SendAllExcept(except as integer)
for x = 1 to MAXIMUM_PLAYERS
if net player connected(x)
if x <> except
net send x, 1
endif
endif
next x
net send 0
endfunction
function GetFlags(playerNum as integer)
local states as byte
if player(playerNum).key_up then states = states || FLAG_UP
if player(playerNum).key_down then states = states|| FLAG_DOWN
if player(playerNum).key_left then states = states || FLAG_LEFT
if player(playerNum).key_right then states = states || FLAG_RIGHT
endfunction states
function ApplyFlags(playerNum as integer, flags as integer)
if flags && FLAG_UP
player(playerNum).key_up = 1
else
player(playerNum).key_up = 0
endif
if flags && FLAG_DOWN
player(playerNum).key_down = 1
else
player(playerNum).key_down = 0
endif
if flags && FLAG_LEFT
player(playerNum).key_left = 1
else
player(playerNum).key_left = 0
endif
if flags && FLAG_RIGHT
player(playerNum).key_right = 1
else
player(playerNum).key_right = 0
endif
endfunction
function ApplyPosition(playerNum as integer)
position object playerNum+10, player(playerNum).x, 0, player(playerNum).z
yrotate object playerNum+10, player(playerNum).angle
endfunction