mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-20 20:33:11 +01:00
Preparations for async commands
This commit is contained in:
parent
fc562f2a2f
commit
c6bd66559a
7 changed files with 42 additions and 13 deletions
4
main.gd
4
main.gd
|
@ -2,8 +2,8 @@ extends Control
|
|||
|
||||
var dragged = null
|
||||
|
||||
var level_set = "top-down"
|
||||
#var level_set = "bottom-up"
|
||||
#var level_set = "top-down"
|
||||
var level_set = "bottom-up"
|
||||
var current_level = 0
|
||||
|
||||
export(NodePath) var terminal_path
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
[ext_resource path="res://main.gd" type="Script" id=2]
|
||||
[ext_resource path="res://repository.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://styles/alert_button.tres" type="StyleBox" id=4]
|
||||
[ext_resource path="res://tcp_server.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://styles/theme.tres" type="Theme" id=6]
|
||||
[ext_resource path="res://fonts/big.tres" type="DynamicFont" id=7]
|
||||
[ext_resource path="res://tcp_server.gd" type="Script" id=8]
|
||||
[ext_resource path="res://test.gd" type="Script" id=9]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
|
@ -196,9 +196,7 @@ repository_path = NodePath("../../Repositories/ActiveRepository")
|
|||
visible = false
|
||||
script = ExtResource( 9 )
|
||||
|
||||
[node name="TCPServer" type="Node" parent="Test"]
|
||||
script = ExtResource( 8 )
|
||||
port = 6666
|
||||
[node name="TCPServer" parent="Test" instance=ExtResource( 5 )]
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Test"]
|
||||
margin_left = 720.526
|
||||
|
@ -212,5 +210,4 @@ __meta__ = {
|
|||
[connection signal="button_down" from="HBoxContainer/RightSide/TopStuff/Menu/LevelSelect" to="." method="repopulate_levels"]
|
||||
[connection signal="pressed" from="HBoxContainer/RightSide/TopStuff/Menu/ReloadButton" to="." method="reload_level"]
|
||||
[connection signal="pressed" from="HBoxContainer/RightSide/TopStuff/Menu/NextLevelButton" to="." method="load_next_level"]
|
||||
[connection signal="data_received" from="Test/TCPServer" to="Test" method="data"]
|
||||
[connection signal="text_entered" from="Test/LineEdit" to="Test" method="send"]
|
||||
|
|
15
scripts/better-reverse-shell
Normal file
15
scripts/better-reverse-shell
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/env/perl
|
||||
|
||||
use Socket;
|
||||
|
||||
$ip="127.0.0.1";
|
||||
$port=6666;
|
||||
|
||||
socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));
|
||||
|
||||
if(connect(S,sockaddr_in($port,inet_aton($ip)))){
|
||||
open(STDIN,">&S");
|
||||
open(STDOUT,">&S");
|
||||
open(STDERR,">&S");
|
||||
exec("python -c 'import pty; pty.spawn([\"/bin/bash\", \"--noprofile\", \"--norc\"])'")
|
||||
};
|
|
@ -13,7 +13,7 @@ func _ready():
|
|||
|
||||
func start():
|
||||
_s.listen(port)
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
if _s.is_connection_available():
|
||||
if _connected:
|
||||
|
@ -29,12 +29,13 @@ func _process(_delta):
|
|||
print("disconnected")
|
||||
var available = _c.get_available_bytes()
|
||||
while available > 0:
|
||||
var data = _c.get_utf8_string(-1)
|
||||
var data = _c.get_utf8_string(available)
|
||||
emit_signal("data_received", data)
|
||||
available = _c.get_available_bytes()
|
||||
|
||||
func send(text):
|
||||
if _connected:
|
||||
_c.put_utf8_string(text)
|
||||
text += "\n"
|
||||
_c.put_data(text.to_utf8())
|
||||
else:
|
||||
push_error("Trying to send data on closed connection")
|
||||
|
|
7
tcp_server.tscn
Normal file
7
tcp_server.tscn
Normal file
|
@ -0,0 +1,7 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://tcp_server.gd" type="Script" id=1]
|
||||
|
||||
[node name="TCPServer" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
port = 6666
|
|
@ -60,9 +60,10 @@ func send_command(command):
|
|||
thread.start(self, "run_command_in_a_thread", command)
|
||||
|
||||
func send_command_async(command):
|
||||
output.text += "$ "+command+"\n"
|
||||
#output.text += "$ "+command+"\n"
|
||||
input.text = ""
|
||||
repository.shell.run_async(command)
|
||||
#repository.shell.run_async(command)
|
||||
$TCPServer.send(command+"\n")
|
||||
|
||||
func run_command_in_a_thread(command):
|
||||
var o = repository.shell.run(command)
|
||||
|
@ -75,6 +76,7 @@ func run_command_in_a_thread(command):
|
|||
|
||||
func receive_output(text):
|
||||
output.text += text
|
||||
repository.update_everything()
|
||||
|
||||
func clear():
|
||||
output.text = ""
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
|
||||
[ext_resource path="res://terminal.gd" type="Script" id=2]
|
||||
[ext_resource path="res://tcp_server.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://fonts/monospace.tres" type="DynamicFont" id=4]
|
||||
[ext_resource path="res://text_editor.tscn" type="PackedScene" id=5]
|
||||
|
||||
|
@ -22,6 +23,9 @@ anchor_right = 1.0
|
|||
anchor_bottom = 1.0
|
||||
mouse_filter = 1
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Control" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
|
@ -80,5 +84,8 @@ __meta__ = {
|
|||
visible = false
|
||||
mouse_filter = 1
|
||||
syntax_highlighting = false
|
||||
|
||||
[node name="TCPServer" parent="." instance=ExtResource( 3 )]
|
||||
[connection signal="text_entered" from="Control/InputLine/Input" to="." method="send_command"]
|
||||
[connection signal="pressed" from="ClearButton" to="." method="clear"]
|
||||
[connection signal="data_received" from="TCPServer" to="." method="receive_output"]
|
||||
|
|
Loading…
Reference in a new issue