diff --git a/bootstrap.py b/bootstrap.py deleted file mode 100644 index 5f10cea..0000000 --- a/bootstrap.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python - -import os - -if os.path.exists("project.godot"): - # Update - os.system("git pull") - os.system("godot") -else: - # Initial download - os.system("git clone --depth 1 https://github.com/CosineGaming/nv-moba .") - os.system("godot") diff --git a/project.godot b/project.godot index 8aff89d..e943465 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=3 [application] config/name="mv-moba" -run/main_scene="res://scenes/lobby.tscn" +run/main_scene="res://scenes/update.tscn" config/icon="res://icon.png" [autoload] diff --git a/scenes/update.tscn b/scenes/update.tscn new file mode 100644 index 0000000..ae86eb1 --- /dev/null +++ b/scenes/update.tscn @@ -0,0 +1,101 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://scripts/update.gd" type="Script" id=1] +[ext_resource path="res://assets/DejaVuSansMono.ttf" type="DynamicFontData" id=2] + +[sub_resource type="DynamicFont" id=1] + +size = 0 +use_mipmaps = false +use_filter = false +font_data = ExtResource( 2 ) +_sections_unfolded = [ "Extra Spacing", "Font", "Resource", "Settings" ] + +[node name="Control" type="Control" index="0"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 0 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 + +[node name="HTTPRequest" type="HTTPRequest" parent="." index="0"] + +download_file = "" +use_threads = false +body_size_limit = -1 +max_redirects = 8 +script = ExtResource( 1 ) + +[node name="ProgressBar" type="ProgressBar" parent="." index="1"] + +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -431.0 +margin_top = -30.5 +margin_right = 431.0 +margin_bottom = 30.5 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 0 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 0 +min_value = 0.0 +max_value = 100.0 +step = 1.0 +page = 0.0 +value = 0.0 +exp_edit = false +rounded = false +percent_visible = true + +[node name="Updating" type="Label" parent="." index="2"] + +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -35.0 +margin_top = -63.0 +margin_right = 34.0 +margin_bottom = -49.0 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +text = "Updating..." +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 + +[node name="Title" type="Label" parent="." index="3"] + +anchor_left = 0.5 +anchor_top = 0.0 +anchor_right = 0.5 +anchor_bottom = 0.0 +margin_left = -20.0 +margin_top = 56.0 +margin_right = 20.0 +margin_bottom = 70.0 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +custom_fonts/font = SubResource( 1 ) +text = "VANAGLORIA" +align = 1 +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 +_sections_unfolded = [ "custom_fonts" ] + + diff --git a/scripts/lobby.gd b/scripts/lobby.gd index 33b258b..9e3daf2 100644 --- a/scripts/lobby.gd +++ b/scripts/lobby.gd @@ -38,8 +38,6 @@ func option_sel(button_name, option): func _ready(): - my_info.version = [0,0,0] # Semantic versioning: [0].[1].[2] - randomize() get_node("GameBrowser/Play").connect("pressed", self, "connect_global_server") @@ -136,8 +134,14 @@ func collect_info(): my_info.hero = get_node("PlayerSettings/HeroSelect").get_selected_id() if not "is_right_team" in my_info: my_info.is_right_team = false # Server assigns team, wait for that + my_info.version = util.version remote func register_player(new_peer, info): + var p_version = info.version.split(".") + var version_split = util.version.split(".") + if p_version[0] != version_split[0]: + # TODO: Fail gracefully + return player_info[new_peer] = info render_player_list() if (get_tree().is_network_server()): diff --git a/scripts/update.gd b/scripts/update.gd new file mode 100644 index 0000000..0a1fdb3 --- /dev/null +++ b/scripts/update.gd @@ -0,0 +1,47 @@ +extends HTTPRequest + +var is_update_payload = false +var save_to +var time = 0 + +func _ready(): + connect("request_completed", self, "_request_completed") + # Check if we need an update + request("http://localhost:8080/vanagloria/version") + set_process(true) + +func _request_completed(result, response_code, headers, body): + if result != RESULT_SUCCESS: + print("ERROR: COULD NOT UPDATE. RESULT #" + str(result)) + completed() + return + if not is_update_payload: + # Just checking if we need an update + var server = JSON.parse(body.get_string_from_utf8()).result + if server.version == util.version: + completed() + else: + is_update_payload = true + save_to = server.save_location + request(server.download_path) + else: + var file = File.new() + file.open(save_to, File.WRITE) + file.store_buffer(body) + file.close() + restart() + +func _process(delta): + time += delta + var fake_progress = 1 - (0.8 / time) + get_node("../ProgressBar").value = 100*fake_progress + +func restart(): + # Pass on args to new instance, then quit + var output = [] + OS.execute("./vanagloria", [], false, output) # Mirror just runs godot again + get_tree().quit() + +func completed(): + get_tree().change_scene("res://scenes/lobby.tscn") + diff --git a/scripts/util.gd b/scripts/util.gd index 3f49fa8..bd547fe 100644 --- a/scripts/util.gd +++ b/scripts/util.gd @@ -1,5 +1,15 @@ extends Node +# Semantic versioning, more or less +# Major: Server cannot accept requests (i.e. new hero, or network protocol change) +# Minor: Gameplay was significantly changed, but these can still technically play together (i.e. master-only scope added) + # These are things a server admin might choose to reject if it was decided to be significant +# Patch: Anything else: Bugfixes, UI changes, etc +# Currently 0.0.0 which means API, gameplay, etc can change suddenly and frequently +# Don't rely on it for anything +# 1.0.0 will be the reddit release +var version = "0.0.0" + func get_master_player(): var path = "/root/Level/Players/%d" % get_tree().get_network_unique_id() if has_node(path): @@ -10,7 +20,7 @@ func get_master_player(): func is_friendly(player): var mp = get_master_player() if mp: - return player.player_info.is_right_team == get_master_player().player_info.is_right_team + return player.player_info.is_right_team == mp.player_info.is_right_team else: return true # Doesn't matter, we're headless diff --git a/vanagloria b/vanagloria new file mode 120000 index 0000000..19ef04a --- /dev/null +++ b/vanagloria @@ -0,0 +1 @@ +/opt/godot/godot \ No newline at end of file