Advertisement
Guest User

Server.bas

a guest
Sep 15th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include "header.bas"
  2.  
  3. print "Server started..."
  4.  
  5. hBind(ServerSocket,ServerPort)
  6. hListen(ServerSocket)
  7.  
  8. dim shared as ClientInfo cl_info(MaxClients)
  9. dim shared as ClientData cl(MaxClients)
  10. dim shared as ServerData sv
  11.  
  12. do
  13. screenlock
  14. if hSelect(ServerSocket) then
  15. for i as integer = 1 to MaxClients
  16. with Cl_Info(i)
  17. if .sock = 0 then
  18. .sock = haccept(ServerSocket,.IP,.Port)
  19.  
  20. cl(i).slot = i
  21. cl(i).x = scrnx*rnd
  22. cl(i).y = scrny*rnd
  23.  
  24. hsend(.Sock,cast(any ptr,@cl(i)), sizeof(cl(i)))
  25.  
  26. sv.ConnectedClients+=1
  27. exit for
  28. end if
  29. end with
  30. next i
  31. end if
  32.  
  33. for i as integer = 1 to MaxClients
  34. with Cl_Info(i)
  35. if .Sock andalso hSelect(.Sock) then
  36. var iResult = hReceive(.Sock,cast(any ptr,@cl(i)), sizeof(cl(i)))
  37.  
  38. if iResult <= 0 then
  39. hClose(.Sock)
  40. .Sock = 0
  41. sv.ConnectedClients-=1
  42. else
  43. hSend(.Sock,cast(any ptr,@cl(i)), sizeof(cl(i)))
  44. hSend(.Sock,cast(any ptr,@sv), sizeof(sv))
  45.  
  46. for j as integer = 1 to MaxClients
  47. if j <> i andalso .sock <> 0 then
  48. hSend(.Sock,cast(any ptr,@cl(i)), sizeof(cl(i)))
  49. end if
  50. next j
  51. end if
  52. end if
  53. end with
  54. next i
  55.  
  56. cls
  57. print sv.ConnectedClients
  58. for i as integer = 1 to sv.ConnectedClients
  59. with cl(i)
  60. locate(2,10*i-10):print "x: " & .x
  61. locate(3,10*i-10):print "y: " & .y
  62. end with
  63. next i
  64. screenunlock
  65.  
  66. sleep 10
  67. loop until multikey(sc_escape)
  68.  
  69. hClose(ServerSocket)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement