Skip to content

Commit

Permalink
Merge pull request #25 from Giga-Chad-LLC/develop
Browse files Browse the repository at this point in the history
Add inputs for host and ports on client and server
  • Loading branch information
dmitrii-artuhov authored Jun 4, 2022
2 parents 5f8a4fb + f5579b3 commit 728ba1f
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 19 deletions.
6 changes: 4 additions & 2 deletions client/godot/game/global.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
extends Node

var NETWORK_HOST: String = "127.0.0.1"
var TCP_PORT: int = 8000
var HTTP_PORT: int = 8001

var access_token: String = ""
var username: String = ""

Expand All @@ -8,8 +12,6 @@ var STORE_RESPAWN_POINTS_IN_FILE = false

const DataSavingUtils = preload("res://utils/data_saving.gd")



func saveNodesChildrenCollisionShapesInFile(node):
var utils = DataSavingUtils.new()

Expand Down
Binary file added client/godot/game/invasion_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions client/godot/game/models/scene_manager/scene_manager.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://models/scene_manager/scripts/scene_manager.gd" type="Script" id=1]
[ext_resource path="res://screens/start_screen/start_screen.tscn" type="PackedScene" id=2]
[ext_resource path="res://screens/settings_screen/settings_screen.tscn" type="PackedScene" id=2]
[ext_resource path="res://screens/sounds/click_sound.wav" type="AudioStream" id=3]
[ext_resource path="res://screens/sounds/lobby_music.wav" type="AudioStream" id=4]

Expand All @@ -10,7 +10,7 @@ script = ExtResource( 1 )

[node name="UI" type="CanvasLayer" parent="."]

[node name="StartScreen" parent="UI" instance=ExtResource( 2 )]
[node name="SettingsScreen" parent="UI" instance=ExtResource( 2 )]

[node name="LobbyMusic" type="AudioStreamPlayer" parent="UI"]
stream = ExtResource( 4 )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Node2D

onready var current_scene = $UI/StartScreen
var current_scene_name = "start_screen"
onready var current_scene = $UI/SettingsScreen
var current_scene_name = "settings_screen"
onready var lobby_music = $UI/LobbyMusic
onready var click_sound = $ClickSound

Expand All @@ -16,6 +16,10 @@ func _handle_play_click_sound():

func _handle_scene_changed(next_scene_name):
match next_scene_name:
'settings_screen':
var next_scene = load("res://screens/settings_screen/settings_screen.tscn").instance()
$UI.add_child(next_scene)
set_current_scene(next_scene, next_scene_name)
'start_screen':
var next_scene = load("res://screens/start_screen/start_screen.tscn").instance()
$UI.add_child(next_scene)
Expand Down
8 changes: 4 additions & 4 deletions client/godot/game/network/http_request.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class_name HTTPRequester
signal receive(response_code, headers, body)
signal error(message)

const HOST: String = "127.0.0.1" # 127.0.0.1 | 192.168.1.71
const PORT: int = 5555
const PREFIX: String = "http"
const ENDPOINT: String = PREFIX + "://" + HOST + ":" + str(PORT)
var HOST: String = Global.NETWORK_HOST # 127.0.0.1 | 192.168.1.71
var PORT: int = Global.HTTP_PORT
var PREFIX: String = "http"
var ENDPOINT: String = PREFIX + "://" + HOST + ":" + str(PORT)

func method_get(route: String, headers: PoolStringArray, data: String):
request(ENDPOINT + route, headers, false, HTTPClient.METHOD_GET, data)
Expand Down
4 changes: 2 additions & 2 deletions client/godot/game/player/scripts/client_connection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ extends Node


# TCP Networking
const HOST: String = "127.0.0.1" # 127.0.0.1 | 192.168.1.71
const PORT: int = 8000
var HOST: String = Global.NETWORK_HOST # 127.0.0.1 | 192.168.1.71
var PORT: int = Global.TCP_PORT
const RECONNECT_TIMEOUT: float = 3.0

const Network = preload("res://network/network.gd")
Expand Down
4 changes: 3 additions & 1 deletion client/godot/game/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ _global_script_class_icons={

config/name="InVasion"
run/main_scene="res://models/scene_manager/scene_manager.tscn"
config/icon="res://icon.png"
config/icon="res://invasion_icon.png"

[autoload]

Expand All @@ -75,6 +75,8 @@ enabled=PoolStringArray( "res://addons/protobuf/plugin.cfg" )

script=false
window=false
icon=false
full=false

[importer_defaults]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extends Control

signal scene_changed(scene_name)
signal play_click_sound()

onready var Host = $CenterContainer/Form/HostInput
onready var TcpPort = $CenterContainer/Form/TcpPortInput
onready var HttpPort = $CenterContainer/Form/HttpPortInput

func _ready():
Host.text = Global.NETWORK_HOST
TcpPort.text = str(Global.TCP_PORT)
HttpPort.text = str(Global.HTTP_PORT)

func _on_NextButton_pressed():
Global.NETWORK_HOST = Host.text
Global.TCP_PORT = int(TcpPort.text)
Global.HTTP_PORT = int(HttpPort.text)

emit_signal("play_click_sound")
emit_signal("scene_changed", "start_screen")
144 changes: 144 additions & 0 deletions client/godot/game/screens/settings_screen/settings_screen.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://ui/theme/theme.tres" type="Theme" id=1]
[ext_resource path="res://screens/settings_screen/scripts/settings_screen.gd" type="Script" id=2]

[node name="SettingsScreen" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 1 )
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Background" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0, 0, 0, 0.847059 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Title" type="Label" parent="."]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -29.0
margin_top = 8.0
margin_right = 29.0
margin_bottom = 20.0
theme = ExtResource( 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_outline_modulate = Color( 1, 1, 1, 1 )
custom_colors/font_color_shadow = Color( 1, 1, 1, 0 )
text = "InVasion"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="CenterContainer" type="CenterContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -1.0
margin_right = 320.0
margin_bottom = 179.0
rect_scale = Vector2( 0.5, 0.5 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Form" type="Control" parent="CenterContainer"]
margin_left = 320.0
margin_top = 180.0
margin_right = 320.0
margin_bottom = 180.0

[node name="HostInput" type="LineEdit" parent="CenterContainer/Form"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -90.0
margin_top = -62.0
margin_right = 90.0
margin_bottom = -38.0
rect_pivot_offset = Vector2( -360, -58 )
align = 1
max_length = 15
placeholder_text = "127.0.0.1"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="HostLabel" type="Label" parent="CenterContainer/Form"]
margin_left = -90.0
margin_top = -86.0
margin_right = 90.0
margin_bottom = -72.0
rect_pivot_offset = Vector2( -360, -34 )
text = "Enter host ip address: "
__meta__ = {
"_edit_use_anchors_": false
}

[node name="TcpPortInput" type="LineEdit" parent="CenterContainer/Form"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -90.0
margin_top = 2.0
margin_right = -6.0
margin_bottom = 26.0
rect_pivot_offset = Vector2( -360, -58 )
align = 1
max_length = 15
placeholder_text = "TCP port"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="HttpPortInput" type="LineEdit" parent="CenterContainer/Form"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = 6.0
margin_top = 2.0
margin_right = 90.0
margin_bottom = 26.0
rect_pivot_offset = Vector2( -360, -58 )
align = 1
max_length = 15
placeholder_text = "HTTP port"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="PortsLabel" type="Label" parent="CenterContainer/Form"]
margin_left = -90.0
margin_top = -22.0
margin_right = 90.0
margin_bottom = -8.0
rect_pivot_offset = Vector2( -360, -34 )
text = "Servers ports (tcp, http):"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="NextButton" type="Button" parent="CenterContainer/Form"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -90.0
margin_top = 44.0
margin_right = 90.0
margin_bottom = 64.0
text = "Next"
__meta__ = {
"_edit_use_anchors_": false
}

[connection signal="pressed" from="CenterContainer/Form/NextButton" to="." method="_on_NextButton_pressed"]
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ func _on_RegisterButton_pressed():
emit_signal("scene_changed", "register_screen")




func _on_BackButton_pressed():
emit_signal("play_click_sound")
emit_signal("scene_changed", "settings_screen")
13 changes: 12 additions & 1 deletion client/godot/game/screens/start_screen/start_screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ custom_colors/font_outline_modulate = Color( 1, 1, 1, 1 )
custom_colors/font_color_shadow = Color( 1, 1, 1, 0 )
text = "InVasion"
align = 1
percent_visible = -0.125
__meta__ = {
"_edit_use_anchors_": false
}
Expand Down Expand Up @@ -76,5 +75,17 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="BackButton" type="Button" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 74.0
margin_bottom = 28.0
rect_scale = Vector2( 0.5, 0.5 )
text = "Back"
__meta__ = {
"_edit_use_anchors_": false
}

[connection signal="pressed" from="CenterContainer/ButtonGroup/LoginButton" to="." method="_on_LoginButton_pressed"]
[connection signal="pressed" from="CenterContainer/ButtonGroup/RegisterButton" to="." method="_on_RegisterButton_pressed"]
[connection signal="pressed" from="BackButton" to="." method="_on_BackButton_pressed"]
5 changes: 2 additions & 3 deletions include/http-server/HttpServer/http-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ namespace invasion::http_server {

void HttpServer::start(std::string host, short port) {
m_app.bindaddr(host);
m_app.port(port);

StatisticAccessor::clear();
Authenticator::deleteAll();
DatabaseAccessor::deleteAll();

m_thread = std::move(std::thread{[this]() {
m_thread = std::move(std::thread{[this, port]() {
static const std::regex invalidSymbols(R"([a-zA-Z0-9]*)");

AuthService::deleteAllUsers();
Expand Down Expand Up @@ -138,7 +137,7 @@ namespace invasion::http_server {
return crow::response(200, responseJson);
});

m_app.port(5555).multithreaded().run();
m_app.port(port).multithreaded().run();
}});
m_thread.detach();
}
Expand Down
37 changes: 35 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,47 @@
int main() {
try {
bool shouldStop = false;
bool shouldPrompt = true;

std::string host = "127.0.0.1"; // 192.168.1.71
short tcp_port = 8000;
short http_port = 5555;
short http_port = 8001;

if (shouldPrompt) {
std::string in_host;
short in_tcp_port;
short in_http_port;

std::cout << "Enter 0 for default values" << std::endl;

std::cout << "Enter host ip address (default '127.0.0.1'):" << std::endl;
std::cin >> in_host;
if (in_host != "0") {
host = in_host;
}


std::cout << "Enter TCP server port (default: '8000'):" << std::endl;
std::cin >> in_tcp_port;
if (in_tcp_port != 0) {
tcp_port = in_tcp_port;
}


std::cout << "Enter HTTP server port (default: '8001'):" << std::endl;
std::cin >> in_http_port;
if (in_http_port != 0) {
http_port = in_http_port;
}
}

invasion::server::Server server;
invasion::http_server::HttpServer httpServer;


std::cout << "Host: " << host << std::endl;
std::cout << "TCP port: " << tcp_port << std::endl;
std::cout << "HTTP port: " << http_port << std::endl;

if (!shouldStop) {
httpServer.start(host, http_port);
server.start(host, tcp_port); // blocks the current thread of execution!
Expand Down

0 comments on commit 728ba1f

Please sign in to comment.