diff --git a/Client/autoloads/Network.gd b/Client/autoloads/Network.gd index 26739d9..3239aea 100644 --- a/Client/autoloads/Network.gd +++ b/Client/autoloads/Network.gd @@ -35,8 +35,11 @@ remote func _requestClientServerpassword(): print("sending password: ",serverPassword) rpc_id(1,'_returnClientServerPassword',serverPassword) +signal successful_connection + remote func _passwordReturn(correct): if correct: print("correct server password") + emit_signal("successful_connection") else: print("wrong server password") diff --git a/Client/autoloads/PlayerManager.gd b/Client/autoloads/PlayerManager.gd index 3113d23..baede33 100644 --- a/Client/autoloads/PlayerManager.gd +++ b/Client/autoloads/PlayerManager.gd @@ -1,110 +1,8 @@ extends Node -var authcache : Dictionary = {'playername':'', 'factionname':'', 'password':'', 'units':'', -'campaigndifficulty':'', 'campaignlength':'', 'response':{"found":false}} -var myFactionData = {} - -var pathToPlayer = "user://players.sav" -var factions = {} - -var diplomacyStates = {'neutral': 1, 'own' : 2, 'enemies':3, "allies":4} - -#client helper data -var subMenuOpen = false - - -func checkdiplo(factionA, factionB): - var response = 'neutral' - if factionA == factionB: - response = 'own' - else: - if factions.has(factionA): - var factionData = factions[factionA] - if factionData.has('diplomacy'): - var diplo = factionData['diplomacy'] - for key in diplo: - if diplo[key].has(factionB): - response = key - return response - return response - -#returns neutral for neutral, allies for allies, own for own and enemies for enemies -func checkDiplo(faction): - var data = authcache['response'] - var authed = data['found'] - var response = 'neutral' - if faction==data['faction']: - response = 'own' - return response - elif authed: - if data.has('factiondata'): - var factiondata = data['factiondata'] - if factiondata.has('diplomacy'): - var diplo = factiondata['diplomacy'] - for key in diplo: - if diplo[key].has(faction): - response = key - return response -# print("checking diplo") -# print(data, faction) -# print("considered ", response) -# print(" ") -# print("illegal move attempt") - return response - #var diplo = factiondata['diplomacy'] - pass - - -func player_disconnected(id): - pass - - -func getPlayerFactionData(): - return myFactionData - - -# Register Player Data - -func setAuthcache(data: Dictionary): - print("> RegisterPlayerData arrived in PlayerManager") - var keys : Array = authcache.keys() # saving the keys into the array to cycle through them in the loop -# print("Keys: ", keys[i]) -# print("Data: ", data[i], "\n") - #print(">> Authcache with RegisterPlayerData: ", authcache) - saveAuthInServer(data) - -func getAuthcache() -> Dictionary: - return authcache - -func getAuthcachePlayerName() -> String: - #print("Auth PlayerName ",authcache["playername"]) - return authcache["playername"] - -func getAuthcacheFactionName() -> String: - #print("Auth FactionName ",authcache["factionname"]) - return authcache["factionname"] - -func requestAuth(): - rpc_id(1, 'identifyPlayer', authcache['playername'], authcache['password']) - -# Register Player Data END - -func saveAuthInServer(data): - var authcacheJSON = JSON.print(data) - rpc('registerPlayer', authcacheJSON) # Network -> PlayerManager - print(authcacheJSON) - -remote func receiveAuth(response): - print('Client receiveAuth response ' + response) - if not response.found: - return - authcache.response = response - print(response) - if response.has('faction'): - myFactionData = response['faction'] - print("faction name is ", myFactionData) - #to do: remove accesses to redundant data and then erase redundant data -# if authcache.response.has('faction'): -# myFactionData = response.faction -# #to do: remove accesses to redundant data and then erase redundant data +func logInUser(username, password): + rpc_id(1,'_logInUser',username, password) +func registerUser(username, password, factionName, race): + rpc_id(1,'_registerUser',username, password, factionName, race) + rpc_id(1,'_logInUser',username, password) diff --git a/Client/font/anton.tres b/Client/font/anton.tres index 3f29579..46cd0e2 100644 --- a/Client/font/anton.tres +++ b/Client/font/anton.tres @@ -3,4 +3,5 @@ [ext_resource path="res://font/Anton-Regular.ttf" type="DynamicFontData" id=1] [resource] +size = 25 font_data = ExtResource( 1 ) diff --git a/Client/menues/LoginPlayerMenu.gd b/Client/menues/LoginPlayerMenu.gd new file mode 100644 index 0000000..28f495f --- /dev/null +++ b/Client/menues/LoginPlayerMenu.gd @@ -0,0 +1,15 @@ +extends Control +var username +var password + +func _on_btnBack_button_down(): + print("back") + +func _on_btnRegister_button_down(): + PlayerManager.logInUser(username, password) + +func _on_iptPlayerName_text_changed(new_text): + username = new_text + +func _on_iptPassword_text_changed(new_text): + password = new_text diff --git a/Client/menues/LoginPlayerMenu.tscn b/Client/menues/LoginPlayerMenu.tscn new file mode 100644 index 0000000..5bd2a16 --- /dev/null +++ b/Client/menues/LoginPlayerMenu.tscn @@ -0,0 +1,84 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://menues/LoginPlayerMenu.gd" type="Script" id=1] +[ext_resource path="res://font/anton.tres" type="DynamicFont" id=2] + +[node name="RegisterPlayerMenu" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="VBoxMainContainer" type="VBoxContainer" parent="."] +margin_left = -1.22778 +margin_top = -2.45551 +margin_right = 1914.77 +margin_bottom = 1014.54 + +[node name="HBoxPlayerName" type="HBoxContainer" parent="VBoxMainContainer"] +margin_right = 1915.0 +margin_bottom = 38.0 +alignment = 1 + +[node name="lblPlayerName" type="Label" parent="VBoxMainContainer/HBoxPlayerName"] +margin_left = 640.0 +margin_right = 771.0 +margin_bottom = 38.0 +custom_fonts/font = ExtResource( 2 ) +text = "Spielername:" + +[node name="iptPlayerName" type="LineEdit" parent="VBoxMainContainer/HBoxPlayerName"] +margin_left = 775.0 +margin_right = 1275.0 +margin_bottom = 38.0 +rect_min_size = Vector2( 500, 0 ) + +[node name="HBoxPassword" type="HBoxContainer" parent="VBoxMainContainer"] +margin_top = 42.0 +margin_right = 1915.0 +margin_bottom = 80.0 +alignment = 1 + +[node name="lblPassword" type="Label" parent="VBoxMainContainer/HBoxPassword"] +margin_left = 655.0 +margin_right = 755.0 +margin_bottom = 38.0 +custom_fonts/font = ExtResource( 2 ) +text = "Passwort:" + +[node name="iptPassword" type="LineEdit" parent="VBoxMainContainer/HBoxPassword"] +margin_left = 759.0 +margin_right = 1259.0 +margin_bottom = 38.0 +rect_min_size = Vector2( 500, 0 ) + +[node name="HBoxRegisterButton" type="HBoxContainer" parent="VBoxMainContainer"] +margin_top = 84.0 +margin_right = 1915.0 +margin_bottom = 104.0 +alignment = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="btnRegister" type="Button" parent="VBoxMainContainer/HBoxRegisterButton"] +margin_left = 921.0 +margin_right = 994.0 +margin_bottom = 20.0 +text = "Einloggen" + +[node name="HBoxBackButton" type="HBoxContainer" parent="VBoxMainContainer"] +margin_top = 108.0 +margin_right = 1915.0 +margin_bottom = 128.0 +alignment = 1 + +[node name="btnBack" type="Button" parent="VBoxMainContainer/HBoxBackButton"] +margin_left = 917.0 +margin_right = 997.0 +margin_bottom = 20.0 +text = "Schliessen" + +[connection signal="text_changed" from="VBoxMainContainer/HBoxPlayerName/iptPlayerName" to="." method="_on_iptPlayerName_text_changed"] +[connection signal="text_changed" from="VBoxMainContainer/HBoxPassword/iptPassword" to="." method="_on_iptPassword_text_changed"] +[connection signal="button_down" from="VBoxMainContainer/HBoxRegisterButton/btnRegister" to="." method="_on_btnRegister_button_down"] +[connection signal="button_down" from="VBoxMainContainer/HBoxBackButton/btnBack" to="." method="_on_btnBack_button_down"] diff --git a/Client/menues/Main Menue.gd b/Client/menues/Main Menue.gd index d45ab03..08283bd 100644 --- a/Client/menues/Main Menue.gd +++ b/Client/menues/Main Menue.gd @@ -2,13 +2,24 @@ extends Control var serverPassword = "" +func _ready(): + Network.connect("successful_connection", self, "_on_successful_connection") + func _on_Input_PW_text_changed(new_text): serverPassword = new_text - func _on_Input_IP_text_changed(new_text): Network.ip = new_text func _on_Join_pressed():# change this to check on the server user data login information Network.connect_to_server(serverPassword) #if server exists -> load seperate menu to create name select faction etc etc + +func _on_btnLogIn_button_down(): + get_tree().change_scene("res://menues/LoginPlayerMenu.tscn") + +func _on_btnRegister_button_down(): + get_tree().change_scene("res://menues/RegisterPlayerMenu.tscn") + +func _on_successful_connection(): + $PopupDialog.popup() diff --git a/Client/menues/Main Menue.tscn b/Client/menues/Main Menue.tscn index 0fadcf7..f2470b1 100644 --- a/Client/menues/Main Menue.tscn +++ b/Client/menues/Main Menue.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://menues/Main Menue.gd" type="Script" id=1] [ext_resource path="res://font/Anton-Regular.ttf" type="DynamicFontData" id=2] +[ext_resource path="res://font/anton.tres" type="DynamicFont" id=3] [sub_resource type="GDScript" id=1] script/source = "extends VBoxContainer @@ -37,9 +38,6 @@ margin_left = 1.0 margin_top = -3.0 margin_right = 1.0 script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} [node name="VBoxContainer" type="VBoxContainer" parent="."] margin_left = -0.000244141 @@ -76,9 +74,8 @@ margin_left = 975.0 margin_right = 1475.0 margin_bottom = 119.0 rect_min_size = Vector2( 500, 0 ) -align = 2 +custom_fonts/font = ExtResource( 3 ) max_length = 16 -secret = true [node name="HBoxIP" type="HBoxContainer" parent="VBoxContainer"] margin_top = 511.0 @@ -99,7 +96,7 @@ margin_left = 856.0 margin_right = 1356.0 margin_bottom = 119.0 rect_min_size = Vector2( 500, 0 ) -align = 2 +custom_fonts/font = ExtResource( 3 ) max_length = 16 [node name="HBoxButtons" type="HBoxContainer" parent="VBoxContainer"] @@ -115,6 +112,40 @@ margin_bottom = 125.0 custom_fonts/font = SubResource( 3 ) text = " Beitreten " +[node name="PopupDialog" type="PopupDialog" parent="."] +visible = true +margin_left = 659.0 +margin_top = 339.0 +margin_right = 1298.0 +margin_bottom = 734.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="Panel" type="Panel" parent="PopupDialog"] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="PopupDialog/Panel"] +anchor_right = 1.0 +anchor_bottom = 1.0 +alignment = 1 + +[node name="btnLogIn" type="Button" parent="PopupDialog/Panel/VBoxContainer"] +margin_top = 70.0 +margin_right = 639.0 +margin_bottom = 195.0 +custom_fonts/font = SubResource( 3 ) +text = "Einloggen" + +[node name="btnRegister" type="Button" parent="PopupDialog/Panel/VBoxContainer"] +margin_top = 199.0 +margin_right = 639.0 +margin_bottom = 324.0 +custom_fonts/font = SubResource( 3 ) +text = "Registrieren " + [connection signal="text_changed" from="VBoxContainer/HBoxPassword/iptPassword" to="." method="_on_Input_PW_text_changed"] [connection signal="text_changed" from="VBoxContainer/HBoxIP/iptIP" to="." method="_on_Input_IP_text_changed"] [connection signal="pressed" from="VBoxContainer/HBoxButtons/btnJoin" to="." method="_on_Join_pressed"] +[connection signal="button_down" from="PopupDialog/Panel/VBoxContainer/btnLogIn" to="." method="_on_btnLogIn_button_down"] +[connection signal="button_down" from="PopupDialog/Panel/VBoxContainer/btnRegister" to="." method="_on_btnRegister_button_down"] diff --git a/Client/menues/RegisterPlayerMenu.gd b/Client/menues/RegisterPlayerMenu.gd index 5e7183c..a927c00 100644 --- a/Client/menues/RegisterPlayerMenu.gd +++ b/Client/menues/RegisterPlayerMenu.gd @@ -1,120 +1,37 @@ extends Control -var playerName: String = "Bob" -var factionName: String = "Bobarier" -var password: String = "password" -var passwordRepeated: String = "password" -var volk: Array = ["Zwerge"] -var campaignDifficulties: Array = ["Einfach", "Normal", "Schwer", "Hardcore"] -var campaignLengths: Array = ["Kurz", "Mittel", "Lang"] +var username +var password1 +var password2 +var factionName +var race -var registerPlayerData: Dictionary = {} -var passwordCheck: bool +func _on_btnBack_button_down(): + print("back") -func _ready(): - $"VBoxMainContainer/HBoxPlayerName/iptPlayerName".set_text(playerName) - $"VBoxMainContainer/HBoxFactionName/iptFactionName".set_text(factionName) - $"VBoxMainContainer/HBoxPassword/iptPassword".set_text(password) - $"VBoxMainContainer/HBoxPasswordRepeated/iptPasswordRepeated".set_text(passwordRepeated) +func _on_btnRegister_button_down(): + if password1 == password2: + PlayerManager.registerUser(username, password1, factionName, race) - # The items get added to the dropdown button; The units get first added to an array before being added to the drowdown - for v in volk: - $"VBoxMainContainer/HBoxUnits/obtnUnits".add_item(v) - for difficulty in campaignDifficulties: - $"VBoxMainContainer/HBoxDifficulty/obtnDifficulty".add_item(difficulty) - for length in campaignLengths: - $"VBoxMainContainer/HBoxCampaignLength/obtnCampaignLength".add_item(length) - - # Sets default values for the RegisterPlayerData Array so it isnt empty - # ToDo (?) add randomizer for Playername and Factionname - setRegisterPlayerData("playername", playerName) - setRegisterPlayerData("factionname", factionName) - setRegisterPlayerData("volk", volk[0]) - setRegisterPlayerData("difficulty", campaignDifficulties[0]) - setRegisterPlayerData("length", campaignLengths[0]) -# _ready END ################################################################################### - -# Menu Nodes ###################### -func _on_ipt_PlayerName_text_changed(new_text): - setRegisterPlayerData("playername", new_text) - playerName = new_text +func _on_iptPlayerName_text_changed(new_text): + username = new_text func _on_iptFactionName_text_changed(new_text): - setRegisterPlayerData("factionname", new_text) factionName = new_text - func _on_iptPassword_text_changed(new_text): - setRegisterPlayerData("password", new_text) - password = new_text - passwordCheck = (passwordRepeated == password) - -# TODO: check password continuously instead of saving it as a var or in an array -func _on_iptPasswordRepeated_text_changed(new_text): - passwordRepeated = new_text - passwordCheck = (passwordRepeated == password) - -func _on_obtnUnits_item_selected(index): - setRegisterPlayerData("volk", volk[index]) - print("Volk ", volk[index]) - - -func _on_obtnDifficulty_item_selected(index): - setRegisterPlayerData("difficulty", campaignDifficulties[index]) - print("Difficulty " ,campaignDifficulties[index]) - - -func _on_obtnCampaignLength_item_selected(index): - setRegisterPlayerData("length", campaignLengths[index]) - print("Kampagnen Länge " ,campaignLengths[index]) - -func _on_btnRegister_pressed(): # overhaul this so it checks server side maybe and delete useless methods - if(!registerPlayerData.empty()): - if passwordCheck: - print("Check Player Name" , checkPlayerName()) - if checkPlayerName(): - if checkFactionName(): - sendRegisterPlayerDataToPlayerManager() - get_tree().change_scene("res://menues/Main Menue.tscn") - else: - print("Your FactionName is already being used") - else: - print("Your PlayerName is already being used") - else: - print("Passwords dont match") + password1 = new_text + if password1 == password2: + $VBoxMainContainer/HBoxPasswordRepeated/PasswordConfirm.color = Color(0,1,0,1) else: - print("Data missing") + $VBoxMainContainer/HBoxPasswordRepeated/PasswordConfirm.color = Color(1,0,0,1) -# Menu Nodes END ################################# +func _on_iptPasswordRepeated_text_changed(new_text): + password2 = new_text + if password1 == password2: + $VBoxMainContainer/HBoxPasswordRepeated/PasswordConfirm.color = Color(0,1,0,1) + else: + $VBoxMainContainer/HBoxPasswordRepeated/PasswordConfirm.color = Color(1,0,0,1) -# Functions ################################# -# Saving the register data in an Array -func setRegisterPlayerData(key:String, value:String): - registerPlayerData[key] = value - print("Setting Register Player Data KEY-", key, " VALUE-", value ) - # DEBUGGING -# print(registerPlayerData) -# print(registerPlayerData.size()) -# print(registerPlayerData.has(null)) -# print(registerPlayerData.has("")) - # DEBUGGING END - -# Checking if Playername or Factionname is used -func checkPlayerName() -> bool: # checks if the written playername is not equal the one in playermanager - print(PlayerManager.getAuthcachePlayerName()) - return (registerPlayerData["playername"] != PlayerManager.getAuthcachePlayerName()) - -func checkFactionName() -> bool: # checks if the written factionname is not equal to the one in playermanager - return (registerPlayerData["factionname"] != PlayerManager.getAuthcacheFactionName()) - -# Sending register data to PlayerManager in autoload -func sendRegisterPlayerDataToPlayerManager(): - #registerPlayerData.erase() # removes the repeated password variable because its not needed anymore - print("Sent RegisterPlayerData: ", registerPlayerData) - PlayerManager.setAuthcache(registerPlayerData) - print("> RegisterPlayerData has been sent to PlayerManager") - -# Functions END ############################## - -func _on_btnBack_pressed(): - get_tree().change_scene("res://menues/Main Menue.tscn") +func _on_obtnRace_item_selected(index): + race = $VBoxMainContainer/HBoxRace/obtnRace.get_item_text(index) diff --git a/Client/menues/RegisterPlayerMenu.tscn b/Client/menues/RegisterPlayerMenu.tscn index 415f579..2f11bf7 100644 --- a/Client/menues/RegisterPlayerMenu.tscn +++ b/Client/menues/RegisterPlayerMenu.tscn @@ -7,41 +7,35 @@ anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} [node name="VBoxMainContainer" type="VBoxContainer" parent="."] margin_left = -1.22778 margin_top = -2.45551 margin_right = 1914.77 margin_bottom = 1014.54 -__meta__ = { -"_edit_use_anchors_": false -} [node name="HBoxPlayerName" type="HBoxContainer" parent="VBoxMainContainer"] margin_right = 1915.0 -margin_bottom = 25.0 +margin_bottom = 38.0 alignment = 1 [node name="lblPlayerName" type="Label" parent="VBoxMainContainer/HBoxPlayerName"] -margin_left = 663.0 -margin_right = 748.0 -margin_bottom = 25.0 +margin_left = 640.0 +margin_right = 771.0 +margin_bottom = 38.0 custom_fonts/font = ExtResource( 2 ) text = "Spielername:" [node name="iptPlayerName" type="LineEdit" parent="VBoxMainContainer/HBoxPlayerName"] -margin_left = 752.0 -margin_right = 1252.0 -margin_bottom = 25.0 +margin_left = 775.0 +margin_right = 1275.0 +margin_bottom = 38.0 rect_min_size = Vector2( 500, 0 ) [node name="HBoxFactionName" type="HBoxContainer" parent="VBoxMainContainer"] -margin_top = 29.0 +margin_top = 42.0 margin_right = 1915.0 -margin_bottom = 54.0 +margin_bottom = 80.0 rect_pivot_offset = Vector2( 897.744, 221.958 ) alignment = 1 __meta__ = { @@ -49,138 +43,120 @@ __meta__ = { } [node name="lblFactionName" type="Label" parent="VBoxMainContainer/HBoxFactionName"] -margin_left = 655.0 -margin_right = 756.0 -margin_bottom = 25.0 +margin_left = 628.0 +margin_right = 782.0 +margin_bottom = 38.0 custom_fonts/font = ExtResource( 2 ) text = "Fraktionsname:" [node name="iptFactionName" type="LineEdit" parent="VBoxMainContainer/HBoxFactionName"] -margin_left = 760.0 -margin_right = 1260.0 -margin_bottom = 25.0 +margin_left = 786.0 +margin_right = 1286.0 +margin_bottom = 38.0 rect_min_size = Vector2( 500, 0 ) [node name="HBoxPassword" type="HBoxContainer" parent="VBoxMainContainer"] -margin_top = 58.0 +margin_top = 84.0 margin_right = 1915.0 -margin_bottom = 83.0 +margin_bottom = 122.0 alignment = 1 [node name="lblPassword" type="Label" parent="VBoxMainContainer/HBoxPassword"] -margin_left = 672.0 -margin_right = 738.0 -margin_bottom = 25.0 +margin_left = 655.0 +margin_right = 755.0 +margin_bottom = 38.0 custom_fonts/font = ExtResource( 2 ) text = "Passwort:" [node name="iptPassword" type="LineEdit" parent="VBoxMainContainer/HBoxPassword"] -margin_left = 742.0 -margin_right = 1242.0 -margin_bottom = 25.0 +margin_left = 759.0 +margin_right = 1259.0 +margin_bottom = 38.0 rect_min_size = Vector2( 500, 0 ) +secret = true [node name="HBoxPasswordRepeated" type="HBoxContainer" parent="VBoxMainContainer"] -margin_top = 87.0 +margin_top = 126.0 margin_right = 1915.0 -margin_bottom = 112.0 +margin_bottom = 164.0 alignment = 1 [node name="lblPasswordRepeated" type="Label" parent="VBoxMainContainer/HBoxPasswordRepeated"] -margin_left = 630.0 -margin_right = 781.0 -margin_bottom = 25.0 +margin_left = 569.0 +margin_right = 798.0 +margin_bottom = 38.0 custom_fonts/font = ExtResource( 2 ) text = "Passwort wiederholen:" [node name="iptPasswordRepeated" type="LineEdit" parent="VBoxMainContainer/HBoxPasswordRepeated"] -margin_left = 785.0 -margin_right = 1285.0 -margin_bottom = 25.0 +margin_left = 802.0 +margin_right = 1302.0 +margin_bottom = 38.0 rect_min_size = Vector2( 500, 0 ) +secret = true -[node name="HBoxUnits" type="HBoxContainer" parent="VBoxMainContainer"] -margin_top = 116.0 +[node name="PasswordConfirm" type="ColorRect" parent="VBoxMainContainer/HBoxPasswordRepeated"] +margin_left = 1306.0 +margin_right = 1346.0 +margin_bottom = 38.0 +rect_min_size = Vector2( 40, 0 ) +color = Color( 0.501961, 0.501961, 0.501961, 0 ) + +[node name="HBoxRace" type="HBoxContainer" parent="VBoxMainContainer"] +margin_top = 168.0 margin_right = 1915.0 -margin_bottom = 141.0 +margin_bottom = 206.0 alignment = 1 __meta__ = { "_edit_use_anchors_": false } -[node name="lblUnits" type="Label" parent="VBoxMainContainer/HBoxUnits"] -margin_left = 925.0 -margin_right = 957.0 -margin_bottom = 25.0 +[node name="lblRace" type="Label" parent="VBoxMainContainer/HBoxRace"] +margin_left = 887.0 +margin_right = 935.0 +margin_bottom = 38.0 custom_fonts/font = ExtResource( 2 ) text = "Volk:" -[node name="obtnUnits" type="OptionButton" parent="VBoxMainContainer/HBoxUnits"] -margin_left = 961.0 -margin_right = 990.0 -margin_bottom = 25.0 - -[node name="HBoxDifficulty" type="HBoxContainer" parent="VBoxMainContainer"] -margin_top = 145.0 -margin_right = 1915.0 -margin_bottom = 170.0 - -[node name="lblDifficulty" type="Label" parent="VBoxMainContainer/HBoxDifficulty"] -margin_right = 134.0 -margin_bottom = 25.0 -custom_fonts/font = ExtResource( 2 ) -text = "Schwierigkeitsstufe:" - -[node name="obtnDifficulty" type="OptionButton" parent="VBoxMainContainer/HBoxDifficulty"] -margin_left = 138.0 -margin_right = 167.0 -margin_bottom = 25.0 - -[node name="HBoxCampaignLength" type="HBoxContainer" parent="VBoxMainContainer"] -margin_top = 174.0 -margin_right = 1915.0 -margin_bottom = 199.0 - -[node name="lblCampaignLength" type="Label" parent="VBoxMainContainer/HBoxCampaignLength"] -margin_right = 108.0 -margin_bottom = 25.0 -custom_fonts/font = ExtResource( 2 ) -text = "Kampagnelänge:" - -[node name="obtnCampaignLength" type="OptionButton" parent="VBoxMainContainer/HBoxCampaignLength"] -margin_left = 112.0 -margin_right = 141.0 -margin_bottom = 25.0 +[node name="obtnRace" type="OptionButton" parent="VBoxMainContainer/HBoxRace"] +margin_left = 939.0 +margin_right = 1028.0 +margin_bottom = 38.0 +text = "Optionen" +items = [ "Race1", null, false, 0, null, "Race2", null, false, 1, null ] +selected = 0 [node name="HBoxRegisterButton" type="HBoxContainer" parent="VBoxMainContainer"] -margin_top = 203.0 +margin_top = 210.0 margin_right = 1915.0 -margin_bottom = 223.0 +margin_bottom = 230.0 +alignment = 1 __meta__ = { "_edit_use_anchors_": false } [node name="btnRegister" type="Button" parent="VBoxMainContainer/HBoxRegisterButton"] -margin_right = 89.0 +margin_left = 913.0 +margin_right = 1002.0 margin_bottom = 20.0 text = "Registrieren" [node name="HBoxBackButton" type="HBoxContainer" parent="VBoxMainContainer"] -margin_top = 227.0 +margin_top = 234.0 margin_right = 1915.0 -margin_bottom = 247.0 +margin_bottom = 254.0 +alignment = 1 [node name="btnBack" type="Button" parent="VBoxMainContainer/HBoxBackButton"] -margin_right = 42.0 +margin_left = 917.0 +margin_right = 997.0 margin_bottom = 20.0 -text = "Back" +text = "Schliessen" -[connection signal="text_changed" from="VBoxMainContainer/HBoxPlayerName/iptPlayerName" to="." method="_on_ipt_PlayerName_text_changed"] +[connection signal="text_changed" from="VBoxMainContainer/HBoxPlayerName/iptPlayerName" to="." method="_on_iptPlayerName_text_changed"] [connection signal="text_changed" from="VBoxMainContainer/HBoxFactionName/iptFactionName" to="." method="_on_iptFactionName_text_changed"] [connection signal="text_changed" from="VBoxMainContainer/HBoxPassword/iptPassword" to="." method="_on_iptPassword_text_changed"] [connection signal="text_changed" from="VBoxMainContainer/HBoxPasswordRepeated/iptPasswordRepeated" to="." method="_on_iptPasswordRepeated_text_changed"] -[connection signal="item_selected" from="VBoxMainContainer/HBoxUnits/obtnUnits" to="." method="_on_obtnUnits_item_selected"] -[connection signal="item_selected" from="VBoxMainContainer/HBoxDifficulty/obtnDifficulty" to="." method="_on_obtnDifficulty_item_selected"] -[connection signal="item_selected" from="VBoxMainContainer/HBoxCampaignLength/obtnCampaignLength" to="." method="_on_obtnCampaignLength_item_selected"] -[connection signal="pressed" from="VBoxMainContainer/HBoxRegisterButton/btnRegister" to="." method="_on_btnRegister_pressed"] -[connection signal="pressed" from="VBoxMainContainer/HBoxBackButton/btnBack" to="." method="_on_btnBack_pressed"] +[connection signal="item_selected" from="VBoxMainContainer/HBoxRace/obtnRace" to="." method="_on_obtnRace_item_selected"] +[connection signal="button_down" from="VBoxMainContainer/HBoxRegisterButton/btnRegister" to="." method="_on_btnRegister_button_down"] +[connection signal="button_down" from="VBoxMainContainer/HBoxBackButton/btnBack" to="." method="_on_btnBack_button_down"] diff --git a/Server/Network.gd b/Server/Network.gd deleted file mode 100644 index 3499179..0000000 --- a/Server/Network.gd +++ /dev/null @@ -1,126 +0,0 @@ -extends Node - -const DEFAULT_IP = '127.0.0.1' -const DEFAULT_PORT = 31400 -const MAX_PLAYERS = 50 - -var ip = '' -var players = { } -var self_data = { name = '', faction = '' } -var pw = '' -var ongoingQry = false -var lastRequest = '' - -signal player_disconnected -signal server_disconnected - -func _ready(): - get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected') - get_tree().connect('network_peer_connected', self, '_on_player_connected') - - -func create_server(response): - self_data.name = response['name'] - self_data.faction = response['faction'] - PlayerManager.authcache['name'] = response['name'] - PlayerManager.authcache['response']= response - players[1] = self_data - var peer = NetworkedMultiplayerENet.new() - peer.create_server(DEFAULT_PORT, MAX_PLAYERS) - get_tree().set_network_peer(peer) - set_network_master(1) - -func connect_to_server(player_nickname,pw): - self_data.name = player_nickname - get_tree().connect('connected_to_server', self, '_connected_to_server') - var peer = NetworkedMultiplayerENet.new() - if ip == '': - ip = DEFAULT_IP - peer.create_client(ip, DEFAULT_PORT) - get_tree().set_network_peer(peer) - PlayerManager.authcache['password']=pw - PlayerManager.authcache['name']=player_nickname - - -func _connected_to_server(): - var local_player_id = get_tree().get_network_unique_id() - players[local_player_id] = self_data - rpc('_send_player_info', local_player_id, self_data) - var name = PlayerManager.authcache['name'] - var pw = PlayerManager.authcache['password'] - rpc_id(1, '_request_auth', local_player_id, name, pw) - -#function that creates needed files and directories in user -#To do: copy preset folder to user, handling should be uniform -func firstStart(): - var dir = Directory.new() - dir.open("user://") - dir.make_dir("armies") - dir.make_dir("factions") - var file = File.new() - file.open("user://armies/known.txt", File.WRITE) - file.store_line("{}") - file.close() - file.open("user://server.txt", File.WRITE) - file.store_line("server was started before") - file.close() - file.open("user://players.sav", File.WRITE) - file.store_line('{"name":"teas","password":"1","faction":"barb"}') - file.close() - - -func _on_player_disconnected(id): - players.erase(id) - PlayerManager.player_disconnected(id) - -func _on_player_connected(connected_player_id): - var local_player_id = get_tree().get_network_unique_id() - if not(get_tree().is_network_server()): - rpc_id(1, '_request_player_info', local_player_id, connected_player_id) - - -#never to be called from server -func request(request): - if not ongoingQry: - lastRequest = request - ongoingQry = true - rpc_id(1, 'respond', request) - return true - return false - -remote func _request_auth(id, name, pw): - var response = PlayerManager.identify_player(id, name, pw) - rpc_id(id, '_receive_auth', response) - - -remote func respond(request): - var response = 'nothing found' - - - rpc_id(get_tree().get_rpc_sender_id(), 'receive', response) - pass - - -func receive(request): - ongoingQry = false - pass - -remote func _receive_auth(response): - PlayerManager.authcache['response']=response - WorldManager.requestServer() - print(response) - - -remote func _request_player_info(request_from_id, player_id): - if get_tree().is_network_server(): - rpc_id(request_from_id, '_send_player_info', player_id, players[player_id]) - -# A function to be used if needed. The purpose is to request all players in the current session. -remote func _request_players(request_from_id): - if get_tree().is_network_server(): - for peer_id in players: - if( peer_id != request_from_id): - rpc_id(request_from_id, '_send_player_info', peer_id, players[peer_id]) - -remote func _send_player_info(id, info): - players[id] = info diff --git a/Server/autoloads/Network.gd b/Server/autoloads/Network.gd index 2e48cd6..5dea7df 100644 --- a/Server/autoloads/Network.gd +++ b/Server/autoloads/Network.gd @@ -5,10 +5,9 @@ const DEFAULT_PORT = 31400 const MAX_PLAYERS = 50 var ip = '' -var players = { } -var self_data = { name = '', faction = '' } var pw = '' +var verifiedIDs=[] signal player_disconnected signal server_disconnected @@ -26,7 +25,6 @@ remote func checkServerPassword(serverPassword): func createServer(password): pw = password print("server started \nunder password: ",pw) - players[1] = self_data var host = NetworkedMultiplayerENet.new() host.create_server(DEFAULT_PORT, MAX_PLAYERS) get_tree().set_network_peer(host) @@ -61,32 +59,16 @@ remote func _on_player_connected(connected_player_id): print(connected_player_id," has connected") request_player_password(connected_player_id) -func addPlayer(id, name): - print("added player ", id) - pass - -var awaitingConfirmation = [] - func request_player_password(connected_player_id): print("requesting password") - awaitingConfirmation.append(connected_player_id) rpc_id(connected_player_id, '_requestClientServerpassword') remote func _returnClientServerPassword(password): var clientId = get_tree().get_rpc_sender_id() print("client: ",clientId," tried to connect with ", password) - print(awaitingConfirmation) - if awaitingConfirmation.has(clientId): - if password == pw: - rpc_id(clientId, "_passwordReturn", true) - addPlayer(clientId,"replaceMe") - awaitingConfirmation.erase(clientId) - else: - rpc_id(clientId, "_passwordReturn", false) - -# A function to be used if needed. The purpose is to request all players in the current session. -remote func _request_players(request_from_id): - for peer_id in players: - if( peer_id != request_from_id): - rpc_id(request_from_id, '_send_player_info', peer_id, players[peer_id]) - + if password == pw: + rpc_id(clientId, "_passwordReturn", true) + verifiedIDs.append(clientId) + print("id ", clientId," has been verified") + else: + rpc_id(clientId, "_passwordReturn", false) diff --git a/Server/autoloads/PlayerManager.gd b/Server/autoloads/PlayerManager.gd index e06d09b..06d6707 100644 --- a/Server/autoloads/PlayerManager.gd +++ b/Server/autoloads/PlayerManager.gd @@ -1,13 +1,15 @@ extends Node +var knownPlayers = { + "hans":{"name":"hans", "password":"password1", "faction":"faction1", "race":"race1"} +} +var playerToId={ + "hans":123 +} +var idToPlayer={ + 123:"hans" +} - -var authcache = {'response':{"found":"lolno", "faction":"None"}} -var myFactionData = {} -var playerFaction -var player:Array = [] - -var knownPlayers = {} var pathToPlayers = 'user://users/' var clients_factions = {} #used to recognize if networkrequest are allowed to do an action {networkid:factionname} var factions = { @@ -33,11 +35,9 @@ var factions = { var diplomacyStates = {'neutral': 1, 'own' : 2, 'enemies':3, "allies":4} - #client helper data var subMenuOpen = false - func checkdiplo(factionA, factionB): var response = 'neutral' if factionA == factionB: @@ -53,8 +53,6 @@ func checkdiplo(factionA, factionB): return response return response - - func confirmFaction(id, factionname): if factionname==clients_factions[id]: print(id, " is ", factionname) @@ -72,104 +70,30 @@ func _ready(): #register_player("functiontest","yes","barbarian") print("started") +remote func _registerUser(playerName, password, factionName, race): + var clientId = get_tree().get_rpc_sender_id() + if Network.verifiedIDs.has(clientId): + if !knownPlayers.has(playerName): + knownPlayers[playerName] = {"name":playerName, "password":password, "faction":factionName, "race": race} + playerToId[playerName] = clientId + idToPlayer[clientId] = playerName + rpc_id(clientId, "_registerReturn", true) + print("registration successful") + else: + rpc_id(clientId, "_registerReturn", false) + else: + rpc_id(clientId, "_registerReturn", false) - - -func getPlayerFactionData(): - var data = null - if authcache.has('response'): - var response = authcache['response'] - #data = response['factiondata'] - return data - - -func identifyPlayer(playerName, pw = ''): # get the data from the json file - - var response : Dictionary = {'name': playerName, 'found': false, 'auth': false, 'faction': ''} - - if knownPlayers.has(playerName): # checks if player exists in the list - print("Player found: " + playerName) - var playerPW = knownPlayers[playerName]['password'] - print(playerPW) - if not pw.empty() and pw == playerPW: # checks if there is a password - print("Password found") - - - - #var response = {'name':playerName, 'found':false, 'auth':false, 'faction':''} - #takeControl('KG')#for testing purposes - #if knownPlayers.has(authcache[0]): # index 0 = playerName - #response['found'] = true - # player = knownPlayers[authcache] - # if player['password'] == password: - # response['auth'] = true - # var playerFaction = player['faction'] - # response['faction'] = playerFaction - # if factions.has(playerFaction): - # response['factiondata'] = factions[playerFaction] - # clients_factions[id] = player['faction'] -# if loaded: -# clients_factions[1] = player['faction'] -# clients_factions[0] = player['faction'] - # print(playerName, ' logged in as ', player['faction']) - # else: - # print('wrong pw') - #else: - # print('no such name') - #print("identify response is: ",response) - #return response -# register_player(name, password, "barb2") -# print('registering: '+name+' + '+password) - - -func player_disconnected(id): - pass -# if clients_factions[id]: -# clients_factions.erase(id) - - -remote func receiveAuth(response): - print(">>>>> WE RECEIVED DATA <<<<<<<<") - - if not response.found: - return - authcache.response = response - if response.has('factiondata'): - myFactionData = response['factiondata'] - #to do: remove accesses to redundant data and then erase redundant data - if response.has('faction'): - playerFaction = response.faction - #to do: remove accesses to redundant data and then erase redundant data - print("my faction data is:",myFactionData) - - -remote func registerPlayer(userJSON : Dictionary): # create file for user information from client - - var playerName = userJSON['playername'] -# var data = {"name":playerName,"password":password, "faction":faction} - var file = File.new() - #print(pathToPlayers+playerName+".json") - if file.file_exists(pathToPlayers+playerName+".json"): - print(playerName+" exists already") - return - var race = userJSON['volk'] - # controls if the race exists in the game - if !DataManager.units.has(race): - return - - file.open(pathToPlayers+playerName+".json", File.WRITE) - file.store_line(JSON.print(userJSON)) - file.close() - knownPlayers[playerName]=userJSON - print("Known Players: " + knownPlayers) - print("registered player: "+playerName) - - -remote func register_faction(factionname, playername, race): - var faction = { "factionname": factionname, "playername": playername, 'diplomacy' : '', 'race':race} - pass - - -func takeControl(faction): -# clients_factions[1] = faction - clients_factions[0] = faction +remote func _logInUser(playerName, password): + var clientId = get_tree().get_rpc_sender_id() + if Network.verifiedIDs.has(clientId): + if knownPlayers.has(playerName): + if knownPlayers[playerName].password == password: + playerToId[playerName] = clientId + idToPlayer[clientId] = playerName + rpc_id(clientId, "_logInReturn", true) + print("log in succesful") + else: + rpc_id(clientId, "_logInReturn", false) + else: + rpc_id(clientId, "_logInReturn", false)