Skip to content

Commit ad7a68c

Browse files
committed
part 10
1 parent 1b8fb0d commit ad7a68c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Server.gd

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ extends Node
22

33
const SERVER_PORT: int = 5466
44

5+
const ERROR_INEXISTENT_ROOM: String = "There is no room with such id"
6+
const ERROR_GAME_ALREADY_STARTED: String = "Game already started"
7+
58
var rooms: Dictionary = {}
69
var players_room: Dictionary = {}
710

@@ -50,7 +53,14 @@ remote func create_room(info: Dictionary) -> void:
5053
remote func join_room(room_id: int, info: Dictionary) -> void:
5154
var sender_id: int = get_tree().get_rpc_sender_id()
5255

53-
_add_player_to_room(room_id, sender_id, info)
56+
if not rooms.keys().has(room_id):
57+
rpc_id(sender_id, "show_error", ERROR_INEXISTENT_ROOM)
58+
get_tree().network_peer.disconnect_peer(sender_id)
59+
elif rooms[room_id].state == STARTED:
60+
rpc_id(sender_id, "show_error", ERROR_GAME_ALREADY_STARTED)
61+
get_tree().network_peer.disconnect_peer(sender_id)
62+
else:
63+
_add_player_to_room(room_id, sender_id, info)
5464

5565

5666
func _add_player_to_room(room_id: int, id: int, info: Dictionary) -> void:

0 commit comments

Comments
 (0)