why are you not showing the players who connects to the server? this showing only local player ... and the server displays that was connected + 1 client, most of the clients are not showing each other ...
for those not intendeu, the prints will be esclarencendo below.
Game goal: "to create an online multiplayer game, Server -> Client, Client - -----> server ... as if it were a normal MMORPG ...
source code of Server : >
// Project: Server_Basic1
// Created: 2015-06-07
// set window properties
SetWindowTitle( "Server by Waldemar - Upside Games" )
SetWindowSize( 800, 600, 0 )
// set display properties
SetVirtualResolution( 800, 600 )
SetOrientationAllowed( 1, 1, 1, 1 )
ServerID = HostNetwork("Upside Mobile Server 1","Servidor Mobile 01", 2536)
Global Status As String
Status = "Client "
If Str(ClientID) = 1
Status = "Server "
endif
do
rem IF time# > 60 THEN time# = 1
//time# = time# + 1
if ServerID > 0 and IsNetworkActive(ServerID)
Print("Servidor pronto para receber conexões !")
Print("Jogadores Online : " + Str(GetNetworkNumClients(ServerID)))
ClientID = GetNetworkFirstClient(ServerID)
while ClientID > 0
Print(Status + Str(ClientID))
if GetNetworkClientDisconnected(ServerID, ClientID)
if GetNetworkClientUserData(ServerID, ClientID, 0) = 0
SetNetworkClientUserData(ServerID, ClientID, 0, 1)
DeleteNetworkClient(ServerID, ClientID)
endif
Print(" Client Disconnected")
else
// if the client is connected, print its unique identifying name (chosen in the joinnetwork or hostnetwork commands)
Print(" Client Connected")
Print(" Name: " + GetNetworkClientName(ServerID, ClientID))
endif
// as this machine is the host, we can work out if the current client is the host by checking it against the current machine's id
if ClientID = GetNetworkMyClientId(ServerID)
Print(" Servidor ")
else
Print(" Player ")
endif
// move on to the next client
ClientID = GetNetworkNextClient(ServerID)
endwhile
else
Print("Houve algum erro ao ligar o servidor !")
endif
// If Str(ClientID) = 1
// dim namestatus1 as String = Replace("Client", "Servidor")
// endif
Sync()
loop
Source code of Client
// Project: Client_Basic01
// Created: 2015-06-07
//physics
setphysicsscale(1) //belongs resolution! default 1 unit = 1 meter
SetPhysicsGravity(0 , 50)
//setphysicsdebugon()
#constant groupground 1
#constant groupobject 2
SetWindowSize(deviceWidth#,deviceHeight#,0)
deviceHeight# = GetDeviceHeight()
deviceWidth# = GetDeviceWidth()
// set window properties
SetWindowTitle( "Client_Basic01" )
//SetWindowSize(deviceWidth#,deviceHeight#,0)
time#=timer()
State = 0
// set display properties
SetOrientationAllowed( 1, 1, 1, 1 )
//cria um Id para o player
randomplayername$="player"+str(random(1,10000))
//coneção com o servidor
ServerID = JoinNetwork("127.0.0.1", 2536, randomplayername$)
//joysticks
AddVirtualJoystick( 1, getDeviceHeight()/10,getDeviceHeight()-getDeviceHeight()/10,getDeviceHeight()/4)
//AddVirtualJoystick( 2, GetDeviceHeight()/0.9,GetDeviceHeight()-GetDeviceHeight()/10,GetDeviceHeight()/4)
rem propriedades da tela e etc
//deviceHeight# = GetDeviceHeight()
//deviceWidth# = GetDeviceWidth()
`SetVirtualResolution( 1024, 768 )
`SetVirtualResolution( 1920, 1080 )
SetVirtualResolution( deviceWidth#, deviceHeight# )
SetClearColor(254,235,255)
SetPrintColor(1,1,1, 100)
`SetVirtualJoystickAlpha( 0, 9, 9 )
//Ground
gr = CreateSprite(0)
SetSpriteColor (gr,128,128,128,255)
SetSpriteSize (gr,10,0.1)
SetSpritePosition(gr,0,10-0.05)
SetSpritePhysicsON(gr,1)
SetSpritePhysicsMass(gr,2)
SetSpritePhysicsCanRotate(gr,0)
SetSpritePhysicsFriction(gr,0.75)
SetSpritePhysicsRestitution(gr,0.5)
SetSpritePhysicsDamping(gr,0.5)
SetSpriteGroup( gr, groupground )
// Criar Sprite de teste .
CreateSprite(1,0)
AddSpriteAnimationFrame(1,Loadimage("run1/1.png"))
AddSpriteAnimationFrame(1,Loadimage("run1/2.png"))
AddSpriteAnimationFrame(1,Loadimage("run1/3.png"))
AddSpriteAnimationFrame(1,Loadimage("run1/4.png"))
AddSpriteAnimationFrame(1,Loadimage("run1/5.png"))
AddSpriteAnimationFrame(1,loadimage("run1/6.png"))
//termina atrubuição do personagem 1
SetPhysicsGravity(10,10)
SetSpritePhysicsOn(1,2)
//Começar a executar as animações
PlaySprite(1,10,1,1,6)
//termina a animação
iType = 0
do
if (GetVirtualJoystickExists(1))
SetspritePosition(1,getspritex(1) + (GetVirtualJoystickX(1) * 1) , getspritey(1) + (GetVirtualJoystickY(1) * 1))
endif
//
//
if State = 1 and ServerID = 0 then print ("Network connection failed")
IF (IsNetworkActive ( ServerID ) = 1)
MyID = GetNetworkMyClientID(ServerID)
NewObjectX# = GetObjectX(MyID) + getJoystickX()/10 `get new object position
NewObjectY# = GetObjectY(MyID)
NewObjectZ# = GetObjectZ(MyID) - getJoystickY()/10
DistX# = NewObjectX# - GetObjectX(MyID) `Calculate object rotation
DistZ# = NewObjectZ# - GetObjectZ(MyID)
NewObjAngle# = ATANFULL(DistX#, DistZ#)
SetObjectPosition(MyID, NewObjectX#, NewObjectY#, NewObjectZ#)
IF (getJoystickX() <> 0) or (getJoystickY() <> 0) `rotate player of joystick pressed
SetObjectRotation(MyID, 0, -NewObjAngle#, 0)
ENDIF
ENDIF
Print("")
IF (getJoystickX() <> 0) or (getJoystickY() <> 0) `Send position data if joystick pressed
cmessage = CreateNetworkMessage ( )
AddNetworkMessageFloat ( cmessage, GetNetworkMyClientID(ServerID) )
AddNetworkMessageFloat ( cmessage, NewObjectX# )
AddNetworkMessageFloat ( cmessage, NewObjectZ# )
AddNetworkMessageFloat ( cmessage, NewObjAngle#)
SendNetworkMessage ( ServerID, 0, cmessage )
ENDIF
Print("")
cmessage = GetNetworkMessage ( ServerID ) `Get message ID
IF cmessage <> 0
If iType = 0 `If host, receive locations of individual players, and send to all players
`OtherNum = GetNetworkMessageFromClient( cmessage ) `Get player number that sent this message
`Print ( GetNetworkClientName ( NetworkID, OtherNum ) + " ID: " + STR(OtherNum) )
// cycle through all messages, Position players
// get position
messageFrom = GetNetworkMessageFloat ( cmessage )
otherX# = GetNetworkMessageFloat ( cmessage )
otherZ# = GetNetworkMessageFloat ( cmessage )
OtherNewObjAngle# = GetNetworkMessageFloat ( cmessage )
`Register player positions
`PlayerVar[messageFrom,1] = messageFrom
`PlayerVar[messageFrom,2] = otherX#
`PlayerVar[messageFrom,3] = otherZ#
`Send this player position to all players
Dmessage = CreateNetworkMessage ( )
AddNetworkMessageFloat ( Dmessage, messageFrom )
AddNetworkMessageFloat ( Dmessage, otherX#)
AddNetworkMessageFloat ( Dmessage, otherZ# )
AddNetworkMessageFloat ( Dmessage, NewObjAngle#)
SendNetworkMessage ( ServerID, 0, Dmessage )
// update players position
IF messageFrom = MyID
ELSE
SetObjectPosition ( messageFrom, otherX#, GetObjectY(messageFrom), otherZ# )
SetObjectRotation(messageFrom, 0, -OtherNewObjAngle#, 0)
ENDIF
// delete the current message
DeleteNetworkMessage ( cmessage )
// find the next message
`cmessage = GetNetworkMessage ( NetworkID )
ENDIF `If iType = 0
rem ----------------------------------------------------------------------------------------------
IF iType = 1 `If client, receive locations of all players from host
`For z = 1 to 10
// get position
messageFrom = GetNetworkMessageFloat ( cmessage )
otherX# = GetNetworkMessageFloat ( cmessage )
otherZ# = GetNetworkMessageFloat ( cmessage )
OtherNewObjAngle# = GetNetworkMessageFloat ( cmessage )
`Next z
// update players position
IF messageFrom = MyID
ELSE
SetObjectPosition ( messageFrom, otherX#, GetObjectY(messageFrom), otherZ# )
SetObjectRotation(messageFrom, 0, -OtherNewObjAngle#, 0)
ENDIF
// delete the current message
DeleteNetworkMessage ( cmessage )
// find the next message
`cmessage = GetNetworkMessage ( NetworkID )
ENDIF `IF iType = 1
ENDIF `IF cmessage <> 0
`if IsNetworkActive ( NetworkID ) <> 0
`IF State = 1 and NetworkID > 0
Sync()
loop
Prints of what doing when i compile .
Server works Fine
http://prntscr.com/7es4np
Note = Client 1 = serverHost default
Client conected in server
http://prntscr.com/7es58r
here server receive conection of Client
http://prntscr.com/7es5it
note : Client 2 = Client up ...
but when i open another window dont show nothing ...
how i solve this ?
PrintC(&amp;quot;Hello EveryOne !&amp;quot