From 107e6aa68b5084e726fd79e345cf9e5a4bba8d4a Mon Sep 17 00:00:00 2001 From: issork Date: Mon, 24 Apr 2023 19:04:29 +0200 Subject: [PATCH] fixed some browsers not showing the reply, attempted to fix another error --- Gift.gd | 2 +- Node.tscn | 1 - addons/gift/gift_node.gd | 23 ++++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Gift.gd b/Gift.gd index add7f17..977792c 100644 --- a/Gift.gd +++ b/Gift.gd @@ -75,7 +75,7 @@ func _ready() -> void: # Send a chat message to channel # chat("TEST", initial_channel) - # Send a whisper to target user + # Send a whisper to target user (requires user:manage:whispers scope) # whisper("TEST", initial_channel) func on_event(type : String, data : Dictionary) -> void: diff --git a/Node.tscn b/Node.tscn index 7078594..e9abc8c 100644 --- a/Node.tscn +++ b/Node.tscn @@ -15,7 +15,6 @@ grow_vertical = 2 [node name="Gift" type="Node" parent="."] script = ExtResource("1") -scopes = Array[String](["chat:edit", "chat:read", "moderator:read:followers"]) [node name="ChatContainer" type="VBoxContainer" parent="."] unique_name_in_owner = true diff --git a/addons/gift/gift_node.gd b/addons/gift/gift_node.gd index 6030778..4d14af1 100644 --- a/addons/gift/gift_node.gd +++ b/addons/gift/gift_node.gd @@ -205,24 +205,16 @@ func get_token() -> void: var data : Dictionary = {} for entry in response.split("&"): var pair = entry.split("=") - data[pair[0]] = pair[1] + data[pair[0]] = pair[1] if pair.size() > 0 else "" if (data.has("error")): var msg = "Error %s: %s" % [data["error"], data["error_description"]] print(msg) - var response_code = 400 - var body := msg.to_utf8_buffer() - peer.put_utf8_string("HTTP/1.1 %d\r\n" % response_code) - peer.put_utf8_string("Content-Length: %d\r\n\r\n" % body.size()) - peer.put_data(body) + send_response(peer, "400 BAD REQUEST", msg.to_utf8_buffer()) peer.disconnect_from_host() break else: print("Success.") - var response_code = 200 - var body := "Success!".to_utf8_buffer() - peer.put_utf8_string("HTTP/1.1 %d\r\n" % response_code) - peer.put_utf8_string("Content-Length: %d\r\n\r\n" % body.size()) - peer.put_data(body) + send_response(peer, "200 OK", "Success!".to_utf8_buffer()) peer.disconnect_from_host() var request : HTTPRequest = HTTPRequest.new() add_child(request) @@ -238,6 +230,15 @@ func get_token() -> void: break OS.delay_msec(100) +func send_response(peer : StreamPeer, response : String, body : PackedByteArray) -> void: + peer.put_data(("HTTP/1.1 %s\r\n" % response).to_utf8_buffer()) + peer.put_data("Server: GIFT (Godot Engine)\r\n".to_utf8_buffer()) + peer.put_data(("Content-Length: %d\r\n"% body.size()).to_utf8_buffer()) + peer.put_data("Connection: close\r\n".to_utf8_buffer()) + peer.put_data("Content-Type: text/plain; charset=UTF-8\r\n".to_utf8_buffer()) + peer.put_data("\r\n".to_utf8_buffer()) + peer.put_data(body) + # If the token is valid, returns the username of the token bearer. func is_token_valid(token : String) -> String: var request : HTTPRequest = HTTPRequest.new()