initial commit

This commit is contained in:
2020-05-09 12:45:05 +02:00
commit a3549d357b
46 changed files with 3051 additions and 0 deletions

View File

@ -0,0 +1,26 @@
extends Node
# {game_id:[_game_id, _game_name, _max_players, _player_list]} # player_list is a dict
# {game_id:[_game_id, _game_name, _max_players, {player_id:[_player_name, _player_id, _game_id, _is_host]}]}
var _open_games = {}
var _players_online = []
remote func get_open_games_from_server(id):
rpc_id(id, "update_open_games", _open_games)
remote func add_game_to_game_list(game_id, game_information, host_player):
_open_games[game_id] = game_information
add_player_to_open_game(game_id, host_player)
get_open_games_from_server(game_id)
remote func join_open_game(game_id, player_information):
add_player_to_open_game(game_id, player_information)
func add_player_to_open_game(game_id, player_information):
_open_games[game_id][3][player_information[1]] = player_information
remote func remove_player_from_open_game(game_id, player_id):
_open_games[game_id][3].erase(player_id)
remote func remove_game_from_game_list(game_id):
_open_games.erase(game_id)

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Networking/Networking_sync.gd" type="Script" id=1]
[node name="Networking" type="Node"]
script = ExtResource( 1 )

View File

@ -0,0 +1,32 @@
extends Node
const SERVER_PORT = 14600
const MAX_PLAYERS = 1000
func _ready():
get_tree().connect("network_peer_connected", self, "_player_connected")
get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
start_server()
func start_server():
print("Try to start the server.")
var peer = NetworkedMultiplayerENet.new()
var result = peer.create_server(SERVER_PORT, MAX_PLAYERS)
if result != OK:
print("Failed creating the server.")
return
else:
print("Created the server.")
get_tree().set_network_peer(peer)
func _player_connected(id):
print(str(id) + " connected to server.")
NetworkingSync._players_online.append(id)
func _player_disconnected(id):
print(str(id) + " left the game.")
NetworkingSync._players_online.erase(id)
if id in NetworkingSync._open_games:
NetworkingSync.remove_game_from_game_list(id)

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Server/Server.gd" type="Script" id=1]
[node name="Server" type="Node"]
script = ExtResource( 1 )