172 lines
8.5 KiB
GDScript
172 lines
8.5 KiB
GDScript
extends Control
|
|
|
|
signal login_button_pressed
|
|
signal register_button_pressed
|
|
|
|
var _username
|
|
var _password
|
|
|
|
func _on_login_button_pressed():
|
|
emit_signal( "login_button_pressed" )
|
|
|
|
|
|
func _on_play_button_pressed():
|
|
var username = $h_box_container/v_box_container/margin_container/login_box/email_box/email_edit.get_text();
|
|
var password = $h_box_container/v_box_container/margin_container/login_box/password_box/password_edit.get_text();
|
|
if username != null and username != "" and password != null and password != "":
|
|
do_request_salt(username, password)
|
|
|
|
|
|
func _on_play_without_connexion_pressed():
|
|
emit_signal( "login_button_pressed" )
|
|
|
|
# Step get salt
|
|
|
|
func do_request_salt(username, password):
|
|
#var message = load("res://assets/Scripts/Models/nel_login_message.gd")
|
|
var connexion = preload("res://assets/Scripts/Config/connexion.gd").connexion.new()
|
|
#if message:
|
|
_username = username
|
|
_password = password
|
|
var message = preload("res://assets/Scripts/Models/nel_login_message.gd").nel_login_message.new("https-login", _username, _password, "Lirria", "2", "en")
|
|
#message = message.nel_login_message.new("https-login", _username, _password, "Lirria", "2", "en")
|
|
var url_login = connexion.get_url_login();
|
|
$HTTPSalt.request(url_login + "?" + message.get_request_salt());
|
|
#$HTTPRequest.request(url_login + "?" + message.get_request_salt());
|
|
print("[login_menu] URL:" + url_login + "?" + message.get_request_salt());
|
|
|
|
|
|
func _on_HTTPSalt_request_completed(result, response_code, headers, body):
|
|
print("[login_menu:_on_HTTPSalt_request_completed] response_code:" + str(response_code))
|
|
if response_code != 200: # || ProjectSettings.get_setting("khaganat/debug_mode"):
|
|
print("[login_menu:_on_HTTPSalt_request_completed] Impossible to connect")
|
|
#emit_signal( "login_button_pressed" )
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect"
|
|
$error_dialog.popup_centered()
|
|
else:
|
|
var text = str2var(body.get_string_from_utf8())
|
|
var s = body.get_string_from_utf8().split(":")
|
|
print("[login_menu:_on_HTTPSalt_request_completed] return:'" + str(text) + "'")
|
|
if(s[0] == "1"):
|
|
print("[login_menu] salt:'" + str(s[1]) + "'")
|
|
var message = preload("res://assets/Scripts/Models/nel_login_message.gd").nel_login_message.new("https-login", _username, _password, "Lirria", "2", "en")
|
|
var connexion = preload("res://assets/Scripts/Config/connexion.gd").connexion.new()
|
|
var url_login = connexion.get_url_login();
|
|
print("[login_menu] URL:" + url_login + "?" + message.get_request_string(str(s[1])));
|
|
$HTTPRequest.request(url_login + "?" + message.get_request_string(str(s[1])));
|
|
else:
|
|
print("[login_menu:_on_HTTPSalt_request_completed] error to connect")
|
|
var regex = RegEx.new()
|
|
regex.compile("^(\\d+)[:](?<comment>.+)$")
|
|
var search = regex.search(s[0])
|
|
if search:
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect\n" + search.get_string("comment")
|
|
$error_dialog.popup_centered()
|
|
else:
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect\n" + str(s[0])
|
|
$error_dialog.popup_centered()
|
|
return
|
|
|
|
# Step Login
|
|
|
|
func do_request(username, password):
|
|
var message = preload("res://assets/Scripts/Models/nel_login_message.gd")
|
|
var connexion = preload("res://assets/Scripts/Config/connexion.gd").connexion.new()
|
|
if message:
|
|
var url_login
|
|
message = message.nel_login_message.new("https-login", username, password, "Lirria", "2", "en")
|
|
url_login = connexion.get_url_login();
|
|
$HTTPRequest.request(url_login + "?" + message.get_request_string());
|
|
print("Login to URL:" + url_login + "?" + message.get_request_string());
|
|
|
|
|
|
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
|
|
print("[login_menu:_on_HTTPRequest_request_completed] response_code:" + str(response_code))
|
|
if response_code != 200: # || ProjectSettings.get_setting("khaganat/debug_mode"):
|
|
# emit_signal( "login_button_pressed" )
|
|
print("[login_menu:_on_HTTPRequest_request_completed] Impossible to connect")
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect"
|
|
$error_dialog.popup_centered()
|
|
else:
|
|
var text = str2var(body.get_string_from_utf8())
|
|
var lines = body.get_string_from_utf8().split("\n")
|
|
if lines.size() != 2:
|
|
print("[login_menu] Impossible to connect (bad return)")
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect (bad return)"
|
|
$error_dialog.popup_centered()
|
|
return
|
|
var line1 = lines[0].split("#")
|
|
var line2 = lines[1].split("#")
|
|
#print("[login_menu:_on_HTTPRequest_request_completed] return:'" + str(text) + "'" + str(lines.size()) + "'" + str(line1.size()) + "'" + str(line2.size()))
|
|
if line1[0] != "1":
|
|
print("[login_menu] Impossible to connect (return" + line1[0] + ")")
|
|
var regex = RegEx.new()
|
|
regex.compile("^(\\d+)[:](?<comment>.+)$")
|
|
var search = regex.search(line1[0])
|
|
if search:
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect\n" + search.get_string("comment")
|
|
$error_dialog.popup_centered()
|
|
else:
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect\n" + str(line1[0])
|
|
$error_dialog.popup_centered()
|
|
return
|
|
if line1.size() < 5:
|
|
print("[login_menu] Impossible to connect (bad return 1st line, size:" + str(line1.size()) + ")")
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect (bad return 1st line, size:" + str(line1.size()) + ")"
|
|
$error_dialog.popup_centered()
|
|
return
|
|
if line2.size() != 3:
|
|
print("[login_menu] Impossible to connect (bad return 2nd line, size:" + str(line2.size()) + ")")
|
|
$error_dialog/v_box_container/label.text = "Impossible to connect (bad return 2nd line, size:" + str(line2.size()) + ")"
|
|
$error_dialog.popup_centered()
|
|
return
|
|
var server_info_script = preload("res://assets/Scripts/Models/nel_server_info.gd");
|
|
print("[login_menu] " + str(body.get_string_from_utf8()))
|
|
var state = line1[0]
|
|
var cookie = line1[1]
|
|
var fsaddr = line1[2]
|
|
var khaganat = fsaddr.split(":")
|
|
var khaganat_host = khaganat[0]
|
|
var khaganat_port = int(khaganat[1])
|
|
var ringmainurl = line1[3]
|
|
var fartp = line1[4]
|
|
var stat = "0"
|
|
if line1.size() >= 6:
|
|
stat = line1[5]
|
|
var r2serverversion = line2[0]
|
|
var r2backuppatchurl = line2[1]
|
|
var r2patchurl = line2[2]
|
|
|
|
var cookieSplit = cookie.split("|")
|
|
if cookieSplit.size() != 3:
|
|
$error_dialog/v_box_container/label.text = "Impossible de se connecter (bad cookies size:" + str(cookieSplit.size()) + ")"
|
|
$error_dialog.popup_centered()
|
|
return
|
|
var UserAddr = cookieSplit[0]
|
|
var UserKey = cookieSplit[1]
|
|
var UserId = cookieSplit[2]
|
|
|
|
print("[login_menu:_on_HTTPRequest_request_completed] state:" + state + ", cookie:" + cookie + ", fsaddr:" + fsaddr + ", ringmainurl:" + ringmainurl + ", fartp:" + fartp + ", stat:" + stat + ", r2serverversion:" + r2serverversion + ", r2backuppatchurl:" + r2backuppatchurl + ", r2patchurl:" + r2patchurl)
|
|
var server_info = server_info_script.nel_server_info.new(body.get_string_from_utf8());
|
|
var connexion = load("res://assets/Scripts/Config/connexion.gd").connexion.new()
|
|
var lang = connexion.get_language()
|
|
print("[login_menu:_on_HTTPRequest_request_completed] khaganat_host:" + khaganat_host + ", khaganat_port:" + str(khaganat_port))
|
|
net_low_level.connect_to_server(khaganat_host, khaganat_port, UserAddr, UserKey, UserId, lang)
|
|
|
|
emit_signal( "login_button_pressed" )
|
|
|
|
|
|
func _make_post_request(url, data_to_send, use_ssl):
|
|
# Convert data to json string:
|
|
var query = JSON.print(data_to_send)
|
|
# Add 'Content-Type' header:
|
|
var headers = ["Content-Type: application/json"]
|
|
$HTTPRequest.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)
|
|
|
|
|
|
func _on_register_button_pressed():
|
|
emit_signal( "register_button_pressed" )
|
|
|
|
|
|
func _on_error_dialog_button_pressed():
|
|
get_node("error_dialog").hide()
|