A team game with an emphasis on movement (with no shooting), inspired by Overwatch and Zineth
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

  1. extends Node
  2. var SERVER_TO_SERVER_PORT = 54671
  3. var MATCHMAKING_PORT = 54672
  4. var SERVER_SIZE = 6
  5. var next_port = 54673
  6. # Filled with queue info which contains
  7. # { "netid" }
  8. var queue = []
  9. var skirmish
  10. # To avoid the confusion of the gameSERVERS being CLIENTS,
  11. # we just call them games whenever possible
  12. var games = []
  13. var game_connections = []
  14. var game_streams = []
  15. # Matchmaker to game servers
  16. var matchmaker_to_games
  17. func _ready():
  18. set_process(false)
  19. func run_matchmaker():
  20. skirmish = spawn_server()
  21. matchmaker_to_games = TCP_Server.new()
  22. if matchmaker_to_games.listen(SERVER_TO_SERVER_PORT):
  23. print("Error, could not listen")
  24. set_process(true)
  25. func _process(delta):
  26. # Manage connection to GAMESERVERS (not clients)
  27. if matchmaker_to_games.is_connection_available(): # check if a gameserver's trying to connect
  28. var game = matchmaker_to_games.take_connection() # accept connection
  29. game_connections.append(game) # store the connection
  30. var stream = PacketPeerStream.new()
  31. stream.set_stream_peer(game) # bind peerstream to new client
  32. game_streams.append(stream) # make new data transfer object for game
  33. print("Server has requested connection")
  34. master func _queue(info):
  35. queue.push(info)
  36. check_queue()
  37. func check_queue():
  38. if queue.size() >= SERVER_SIZE:
  39. var port = spawn_server()
  40. games.push(port)
  41. for p in queue:
  42. rpc_id(p.netid, "join_game", port)
  43. func spawn_server():
  44. OS.execute("util/server.sh", [], false)
  45. next_port += 1
  46. return (next_port - 1) # Return original port