summaryrefslogtreecommitdiff
path: root/Network/Network.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Network/Network.gd')
-rw-r--r--Network/Network.gd53
1 files changed, 28 insertions, 25 deletions
diff --git a/Network/Network.gd b/Network/Network.gd
index d58de75..0b3e379 100644
--- a/Network/Network.gd
+++ b/Network/Network.gd
@@ -30,51 +30,54 @@ var players_ready = []
func _ready():
- get_tree().connect("network_peer_connected", self, '_player_connected')
- get_tree().connect("network_peer_disconnected", self,"_player_disconnected")
- get_tree().connect("connected_to_server", self, "_connection_succeeded")
- get_tree().connect("connection_failed", self, "_connection_failed")
- get_tree().connect("server_disconnected", self, "_server_disconnected")
- Global.connect("game_started", self, "_on_Global_game_started")
- Global.connect("game_ended", self, "_on_Global_game_ended")
- Global.connect("game_won", self, "_on_Global_game_won")
-
-
-remote func register_player(name):
- var id = get_tree().get_rpc_sender_id()
+ multiplayer.connect("peer_connected", Callable(self, '_player_connected'))
+ multiplayer.connect("peer_disconnected", Callable(self, "_player_disconnected"))
+ multiplayer.connect("connected_to_server", Callable(self, "_connection_succeeded"))
+ multiplayer.connect("connection_failed", Callable(self, "_connection_failed"))
+ multiplayer.connect("server_disconnected", Callable(self, "_server_disconnected"))
+ Global.connect("game_started", Callable(self, "_on_Global_game_started"))
+ Global.connect("game_ended", Callable(self, "_on_Global_game_ended"))
+ Global.connect("game_won", Callable(self, "_on_Global_game_won"))
+
+
+@rpc("any_peer") func register_player(player_name):
+ var id = get_tree().get_remote_sender_id()
self.players[id] = {
- name = name,
+ name = player_name,
ip = self.peer.get_peer_address(id),
}
emit_signal("player_list_changed")
-remote func unregister_player(id):
+@rpc("any_peer") func unregister_player(id):
self.players.erase(id)
emit_signal("player_list_changed")
func host_game(player_name):
self.player.name = player_name
- self.peer = NetworkedMultiplayerENet.new()
+ self.peer = ENetMultiplayerPeer.new()
self.peer.create_server(self.PORT, self.MAX_PEERS)
- get_tree().set_network_peer(self.peer)
+ multiplayer.multiplayer_peer = self.peer
+ #get_tree().set_multiplayer_peer(self.peer)
func join_game(ip, player_name):
self.player.name = player_name
- self.peer = NetworkedMultiplayerENet.new()
+ self.peer = ENetMultiplayerPeer.new()
self.peer.create_client(ip, self.PORT)
- get_tree().set_network_peer(self.peer)
+ multiplayer.multiplayer_peer = self.peer
+ #get_tree().set_multiplayer_peer(self.peer)
func leave_game():
rpc("_leave_game")
- get_tree().set_network_peer(null)
+ multiplayer.multiplayer_peer = null
+ #get_tree().set_multiplayer_peer(null)
-remote func _leave_game():
- var id = get_tree().get_rpc_sender_id()
+@rpc("any_peer") func _leave_game():
+ var id = get_tree().get_remote_sender_id()
self.peer.disconnect_peer(id)
@@ -94,11 +97,11 @@ func _on_Global_game_started():
rpc("_start_game")
-remote func _preconfigure_game(idx):
+@rpc("any_peer") func _preconfigure_game(idx):
self.player.idx = idx
-sync func _start_game():
+@rpc("any_peer", "call_local") func _start_game():
emit_signal("game_started")
@@ -111,7 +114,7 @@ func _on_Global_game_won(winning_player):
rpc("_end_game", winning_player)
-sync func _end_game(winning_player):
+@rpc("any_peer", "call_local") func _end_game(winning_player):
self.winning_player = winning_player
emit_signal("game_ended")
@@ -133,7 +136,7 @@ func _connection_succeeded():
func _connection_failed():
- get_tree().set_network_peer(null) # remove peer
+ get_tree().set_multiplayer_peer(null) # remove peer
emit_signal("connection_failed")