Public repository for MUR pre alpha
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.

43 lines
1.4 KiB

  1. extends Node
  2. signal connection_failed()
  3. signal connection_succeeded()
  4. signal server_disconnected()
  5. func join_game(ip, port:int):
  6. get_tree().connect("connected_to_server", self, "_connected_ok")
  7. get_tree().connect("connection_failed", self, "_connected_fail")
  8. get_tree().connect("server_disconnected", self, "_server_disconnected")
  9. gamestate.connect("game_ended",self,"_game_ended")
  10. var host = NetworkedMultiplayerENet.new()
  11. host.create_client(ip, port)
  12. get_tree().set_network_peer(host)
  13. func _connected_ok():
  14. gamestate.rpc("set_player", get_tree().get_network_unique_id())
  15. emit_signal("connection_succeeded")
  16. func _connected_fail():
  17. get_tree().disconnect("connected_to_server", self, "_connected_ok")
  18. get_tree().disconnect("connection_failed", self, "_connected_fail")
  19. get_tree().disconnect("server_disconnected", self, "_server_disconnected")
  20. get_tree().set_network_peer(null)
  21. emit_signal("connection_failed")
  22. func _server_disconnected():
  23. gamestate.quit_game()
  24. emit_signal("server_disconnected")
  25. func _game_ended():
  26. get_tree().disconnect("connected_to_server", self, "_connected_ok")
  27. get_tree().disconnect("connection_failed", self, "_connected_fail")
  28. get_tree().disconnect("server_disconnected", self, "_server_disconnected")
  29. gamestate.disconnect("game_ended",self,"_game_ended")
  30. get_tree().set_refuse_new_network_connections(false)
  31. get_tree().set_network_peer(null)