Browse Source

server api addr fixes

Lurkars 6 years ago
parent
commit
84edfb71b3
  1. 22
      ext/server.py
  2. 8
      scenes/menus/ServerCreateGameMenu.tscn
  3. 43
      scenes/menus/SettingsMenu.tscn
  4. 4
      scripts/game/local_storage.gd
  5. 8
      scripts/menus/settings.gd
  6. 16
      scripts/networking/game_server.gd
  7. 1
      scripts/networking/game_server_requests.gd
  8. 8
      scripts/networking/server.gd

22
ext/server.py

@ -5,13 +5,17 @@ import secrets
from flask import Flask, abort, request, jsonify from flask import Flask, abort, request, jsonify
START_PORT = 8128 START_PORT = 8128
GAME_EXEC = '/opt/godot/Godot_v3.1.1-stable_linux_server.64'
GAME_EXEC = 'godot_server'
GAME_EXEC_ARG_PACK = '--main-pack' GAME_EXEC_ARG_PACK = '--main-pack'
GAME_EXEC_ARG_PACK_PATH = '/opt/godot/Muffrace Pre Alpha.pck'
GAME_EXEC_ARG_PACK_PATH = '/opt/godot/MUR.pck'
GAME_EXEC_ARG_PORT = '--port={0}' GAME_EXEC_ARG_PORT = '--port={0}'
GAME_EXEC_ARG_ID = '--server-id={0}' GAME_EXEC_ARG_ID = '--server-id={0}'
GAME_EXEC_ARG_SECRET = '--secret={0}' GAME_EXEC_ARG_SECRET = '--secret={0}'
GAME_EXEC_ARG_BOTS = '--bots={0}' GAME_EXEC_ARG_BOTS = '--bots={0}'
GAME_EXEC_ARG_SERVER_ADDR = '--server-addr={0}'
GAME_EXEC_ARG_API_ADDR = '--api-addr={0}'
games = {} games = {}
try: try:
@ -66,15 +70,21 @@ def create_game():
# gen secret # gen secret
secret = secrets.token_hex(32) secret = secrets.token_hex(32)
cur.execute("INSERT INTO games (name,secret,ip,port,bots,running) VALUES (?,?,?,?,?,0)",
cur.execute("INSERT INTO games (name,secret,ip,port,bots,player_count,running) VALUES (?,?,?,?,?,0,0)",
(name, secret, request.remote_addr, port, bots)) (name, secret, request.remote_addr, port, bots))
con.commit() con.commit()
cur.execute("SELECT id FROM games WHERE secret=?", cur.execute("SELECT id FROM games WHERE secret=?",
(secret,)) (secret,))
result = cur.fetchone() result = cur.fetchone()
if result[0]: if result[0]:
games[result[0]] = subprocess.Popen([GAME_EXEC, GAME_EXEC_ARG_PACK, GAME_EXEC_ARG_PACK_PATH, GAME_EXEC_ARG_ID.format(int(result[0])), GAME_EXEC_ARG_PORT.format(
port), GAME_EXEC_ARG_SECRET.format(secret), GAME_EXEC_ARG_BOTS.format(int(bots))])
games[result[0]] = subprocess.Popen([GAME_EXEC,
GAME_EXEC_ARG_PACK,GAME_EXEC_ARG_PACK_PATH,
GAME_EXEC_ARG_ID.format(int(result[0])),
GAME_EXEC_ARG_PORT.format(port),
GAME_EXEC_ARG_SECRET.format(secret),
GAME_EXEC_ARG_BOTS.format(int(bots)),
GAME_EXEC_ARG_SERVER_ADDR.format('127.0.0.1'), # localhost
GAME_EXEC_ARG_API_ADDR.format('http://127.0.0.1:5000/')])
except: except:
con.rollback() con.rollback()
abort(500) abort(500)
@ -168,4 +178,4 @@ def close_game():
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True)
app.run(debug=True,host='0.0.0.0',port=5000)

8
scenes/menus/ServerCreateGameMenu.tscn

@ -23,9 +23,9 @@ anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
margin_left = -217.5
margin_left = -296.5
margin_top = -68.5 margin_top = -68.5
margin_right = 217.5
margin_right = 296.5
margin_bottom = 68.5 margin_bottom = 68.5
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
@ -33,7 +33,7 @@ grow_vertical = 2
[node name="GridContainer" type="GridContainer" parent="menu"] [node name="GridContainer" type="GridContainer" parent="menu"]
margin_left = 12.0 margin_left = 12.0
margin_top = 11.0 margin_top = 11.0
margin_right = 427.0
margin_right = 584.0
margin_bottom = 92.0 margin_bottom = 92.0
columns = 2 columns = 2
@ -45,7 +45,7 @@ text = "GAME_NAME"
[node name="name" type="LineEdit" parent="menu/GridContainer"] [node name="name" type="LineEdit" parent="menu/GridContainer"]
margin_left = 166.0 margin_left = 166.0
margin_right = 415.0
margin_right = 572.0
margin_bottom = 37.0 margin_bottom = 37.0
focus_neighbour_left = NodePath("../../back") focus_neighbour_left = NodePath("../../back")
focus_neighbour_right = NodePath("../../create") focus_neighbour_right = NodePath("../../create")

43
scenes/menus/SettingsMenu.tscn

@ -35,6 +35,7 @@ size_flags_vertical = 3
tab_align = 0 tab_align = 0
[node name="game" type="Tabs" parent="menu/tabs"] [node name="game" type="Tabs" parent="menu/tabs"]
visible = false
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_left = 4.0 margin_left = 4.0
@ -43,6 +44,7 @@ margin_right = -4.0
margin_bottom = -4.0 margin_bottom = -4.0
[node name="GridContainer" type="GridContainer" parent="menu/tabs/game"] [node name="GridContainer" type="GridContainer" parent="menu/tabs/game"]
editor/display_folded = true
margin_left = 9.0 margin_left = 9.0
margin_top = 10.0 margin_top = 10.0
margin_right = 416.0 margin_right = 416.0
@ -91,6 +93,16 @@ margin_right = -4.0
margin_bottom = -4.0 margin_bottom = -4.0
[node name="settings_controls" parent="menu/tabs/controls" instance=ExtResource( 5 )] [node name="settings_controls" parent="menu/tabs/controls" instance=ExtResource( 5 )]
editor/display_folded = true
[node name="empty" parent="menu/tabs/controls/settings_controls/ScrollContainer/grid" index="0"]
margin_bottom = 27.0
[node name="keyboard_label" parent="menu/tabs/controls/settings_controls/ScrollContainer/grid" index="1"]
margin_bottom = 27.0
[node name="joypad_label" parent="menu/tabs/controls/settings_controls/ScrollContainer/grid" index="2"]
margin_bottom = 27.0
[node name="graphics" type="Tabs" parent="menu/tabs"] [node name="graphics" type="Tabs" parent="menu/tabs"]
visible = false visible = false
@ -102,7 +114,6 @@ margin_right = -4.0
margin_bottom = -4.0 margin_bottom = -4.0
[node name="system" type="Tabs" parent="menu/tabs"] [node name="system" type="Tabs" parent="menu/tabs"]
visible = false
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_left = 4.0 margin_left = 4.0
@ -118,18 +129,44 @@ margin_bottom = 124.0
columns = 2 columns = 2
[node name="locale_label" type="Label" parent="menu/tabs/system/GridContainer"] [node name="locale_label" type="Label" parent="menu/tabs/system/GridContainer"]
margin_right = 102.0
margin_right = 190.0
margin_bottom = 27.0 margin_bottom = 27.0
text = "LOCALE" text = "LOCALE"
valign = 1 valign = 1
[node name="locales" type="ItemList" parent="menu/tabs/system/GridContainer"] [node name="locales" type="ItemList" parent="menu/tabs/system/GridContainer"]
margin_left = 106.0
margin_left = 194.0
margin_right = 464.0 margin_right = 464.0
margin_bottom = 27.0 margin_bottom = 27.0
size_flags_horizontal = 3 size_flags_horizontal = 3
auto_height = true auto_height = true
[node name="server_addr_label" type="Label" parent="menu/tabs/system/GridContainer"]
margin_top = 36.0
margin_right = 190.0
margin_bottom = 63.0
text = "SERVER_ADDR"
valign = 1
[node name="server_addr" type="LineEdit" parent="menu/tabs/system/GridContainer"]
margin_left = 194.0
margin_top = 31.0
margin_right = 464.0
margin_bottom = 68.0
[node name="api_addr_label" type="Label" parent="menu/tabs/system/GridContainer"]
margin_top = 77.0
margin_right = 190.0
margin_bottom = 104.0
text = "API_ADDR"
valign = 1
[node name="api_addr" type="LineEdit" parent="menu/tabs/system/GridContainer"]
margin_left = 194.0
margin_top = 72.0
margin_right = 464.0
margin_bottom = 109.0
[node name="save" type="Button" parent="menu"] [node name="save" type="Button" parent="menu"]
anchor_left = 1.0 anchor_left = 1.0
anchor_top = 1.0 anchor_top = 1.0

4
scripts/game/local_storage.gd

@ -5,6 +5,10 @@ const FILE_PATH = "user://local_storage"
func _ready(): func _ready():
TranslationServer.set_locale(read_value("locale","en")) TranslationServer.set_locale(read_value("locale","en"))
if read_value("server_addr") != null:
game_server.set_server_addr(read_value("server_addr"))
if read_value("api_addr") != null:
game_server.set_api_addr(read_value("api_addr"))
func read_content(): func read_content():

8
scripts/menus/settings.gd

@ -12,6 +12,8 @@ var locale
func _ready(): func _ready():
get_node("menu/back").connect("pressed",self,"_on_back_pressed") get_node("menu/back").connect("pressed",self,"_on_back_pressed")
find_node("bots").set_pressed(local_storage.read_value("bots", true)) find_node("bots").set_pressed(local_storage.read_value("bots", true))
find_node("server_addr").set_text(local_storage.read_value("server_addr", game_server.SERVER_ADDR))
find_node("api_addr").set_text(local_storage.read_value("api_addr", game_server.API_ADDR))
game_tab.set_name(tr("GAME")) game_tab.set_name(tr("GAME"))
controls_tab.set_name(tr("CONTROLS")) controls_tab.set_name(tr("CONTROLS"))
graphics_tab.set_name(tr("GRAPHICS")) graphics_tab.set_name(tr("GRAPHICS"))
@ -63,5 +65,11 @@ func _on_save_pressed():
values['player_color'] = player_settings.get_color_node().color.to_html() values['player_color'] = player_settings.get_color_node().color.to_html()
values['bots'] = find_node("bots").is_pressed() values['bots'] = find_node("bots").is_pressed()
values['locale'] = locale values['locale'] = locale
values['server_addr'] = find_node("server_addr").text
values['api_addr'] = find_node("api_addr").text
local_storage.write_values(values) local_storage.write_values(values)
game_server.set_server_addr(local_storage.read_value("server_addr",game_server.SERVER_ADDR))
game_server.set_api_addr(local_storage.read_value("api_addr",game_server.API_ADDR))
_on_back_pressed() _on_back_pressed()

16
scripts/networking/game_server.gd

@ -13,14 +13,6 @@ var headers:Array = HEADERS
var ssl:bool = SSL var ssl:bool = SSL
func _ready():
for argument in OS.get_cmdline_args():
if argument.split("=")[0] == "--server-addr":
server_addr = str(argument.split("=")[1])
if argument.split("=")[0] == "--api-addr":
api_addr = str(argument.split("=")[1])
func http(): func http():
var game_server_requests = GameServerRequests.new() var game_server_requests = GameServerRequests.new()
add_child(game_server_requests) add_child(game_server_requests)
@ -31,10 +23,18 @@ func get_server_addr():
return server_addr return server_addr
func set_server_addr(new_server_addr:String):
server_addr = new_server_addr
func get_api_addr(): func get_api_addr():
return api_addr return api_addr
func set_api_addr(new_api_addr:String):
api_addr = new_api_addr
func get_headers(): func get_headers():
return headers return headers

1
scripts/networking/game_server_requests.gd

@ -9,6 +9,7 @@ func _ready():
http = HTTPRequest.new() http = HTTPRequest.new()
add_child(http) add_child(http)
http.connect("request_completed",self, "_self_destroy") http.connect("request_completed",self, "_self_destroy")
print(game_server.get_api_addr())
func connect_http(node,function): func connect_http(node,function):

8
scripts/networking/server.gd

@ -25,13 +25,17 @@ func _ready():
server_secret=argument.split("=")[1] server_secret=argument.split("=")[1]
if argument.split("=")[0] == "--bots": if argument.split("=")[0] == "--bots":
gamestate.set_bots(bool(int(argument.split("=")[1]))) gamestate.set_bots(bool(int(argument.split("=")[1])))
if argument.split("=")[0] == "--server-addr":
game_server.set_server_addr(str(argument.split("=")[1]))
if argument.split("=")[0] == "--api-addr":
game_server.set_api_addr(str(argument.split("=")[1]))
if dedicated_server: if dedicated_server:
var err = host_game(port) var err = host_game(port)
if err == OK: if err == OK:
print(server_id + "New game hosted: port=" + str(port) + " secret=" + str(server_secret) + " bots=" + str(gamestate.bots))
print(server_id + "New game hosted: port=" + str(port) + " secret=" + str(server_secret) + " bots=" + str(gamestate.bots) + " server-addr=" + game_server.get_server_addr() + " api-addr=" + game_server.get_api_addr())
else: else:
print(server_id + "Could not create Server! (port=" + str(port) + " secret=" + str(server_secret) + ")")
print(server_id + "Could not create Server! (port=" + str(port) + " secret=" + str(server_secret) + " server-addr=" + game_server.get_server_addr() + " api-addr=" + game_server.get_api_addr() + ")")
quit_server() quit_server()

Loading…
Cancel
Save