Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "header.bas"
- print "Server started..."
- hBind(ServerSocket,ServerPort)
- hListen(ServerSocket)
- dim shared as ClientInfo cl_info(MaxClients)
- dim shared as ClientData cl(MaxClients)
- dim shared as ServerData sv
- do
- screenlock
- if hSelect(ServerSocket) then
- for i as integer = 1 to MaxClients
- with Cl_Info(i)
- if .sock = 0 then
- .sock = haccept(ServerSocket,.IP,.Port)
- cl(i).slot = i
- cl(i).x = scrnx*rnd
- cl(i).y = scrny*rnd
- hsend(.Sock,cast(any ptr,@cl(i)), sizeof(cl(i)))
- sv.ConnectedClients+=1
- exit for
- end if
- end with
- next i
- end if
- for i as integer = 1 to MaxClients
- with Cl_Info(i)
- if .Sock andalso hSelect(.Sock) then
- var iResult = hReceive(.Sock,cast(any ptr,@cl(i)), sizeof(cl(i)))
- if iResult <= 0 then
- hClose(.Sock)
- .Sock = 0
- sv.ConnectedClients-=1
- else
- hSend(.Sock,cast(any ptr,@cl(i)), sizeof(cl(i)))
- hSend(.Sock,cast(any ptr,@sv), sizeof(sv))
- for j as integer = 1 to MaxClients
- if j <> i andalso .sock <> 0 then
- hSend(.Sock,cast(any ptr,@cl(i)), sizeof(cl(i)))
- end if
- next j
- end if
- end if
- end with
- next i
- cls
- print sv.ConnectedClients
- for i as integer = 1 to sv.ConnectedClients
- with cl(i)
- locate(2,10*i-10):print "x: " & .x
- locate(3,10*i-10):print "y: " & .y
- end with
- next i
- screenunlock
- sleep 10
- loop until multikey(sc_escape)
- hClose(ServerSocket)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement