From c8448b7848c023659857325d34ad8362436fd7c7 Mon Sep 17 00:00:00 2001 From: shmyga Date: Wed, 28 Mar 2018 17:30:42 +0300 Subject: [PATCH] [client] hostname from environ --- ansible/roles/deploy/tasks/main.yml | 7 ++++- src/client/haxe/ru/m/tankz/Init.hx | 27 +++++++++++++++++-- .../haxe/ru/m/connect/js/JsConnection.hx | 2 +- src/server/haxe/ru/m/tankz/server/Server.hx | 2 +- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ansible/roles/deploy/tasks/main.yml b/ansible/roles/deploy/tasks/main.yml index cb97045..f0e59e1 100644 --- a/ansible/roles/deploy/tasks/main.yml +++ b/ansible/roles/deploy/tasks/main.yml @@ -16,4 +16,9 @@ file: src: "{{ release_dir }}" dest: "{{ project_dir }}/current" - state: link \ No newline at end of file + state: link + +- name: "restart {{ project_name }} service" + systemd: + state: restarted + name: "{{ project_name }}" diff --git a/src/client/haxe/ru/m/tankz/Init.hx b/src/client/haxe/ru/m/tankz/Init.hx index 9d40f4d..cb1728e 100644 --- a/src/client/haxe/ru/m/tankz/Init.hx +++ b/src/client/haxe/ru/m/tankz/Init.hx @@ -19,10 +19,31 @@ import ru.m.tankz.proto.pack.Response; import ru.m.tankz.sound.SoundManager; import ru.m.tankz.storage.SaveStorage; import ru.m.tankz.storage.UserStorage; +#if flash +import flash.Lib; +#elseif html5 +import js.Browser; +#end class Init { + private static function getHost():String { + #if flash + var url = Lib.current.loaderInfo.url; + var r:EReg = ~/((app|https?):\/\/?[-_\w\d\.]+(:\d+)?)\/?/; + if (r.match(url) && !(r.matched(2) == "app")) { + return r.matched(1); + } else { + return "localhost"; + } + #elseif html5 + return Browser.location.hostname; + #else + return "localhost"; + #end + } + public static function init():Void { Provider.setFactory(IResources, Resources); Provider.setFactory(ILevelBundle, LevelBundle); @@ -35,10 +56,12 @@ class Init { Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE); Provider.setFactory(Game, DotaGame, DotaGame.TYPE); + var host:String = getHost(); + L.d('Init', 'host: ${host}'); #if flash - Provider.set(IConnection, new ru.m.connect.flash.FlashConnection('localhost', 5001, Response)); + Provider.set(IConnection, new ru.m.connect.flash.FlashConnection(host, 5000, Response)); #elseif html5 - Provider.set(IConnection, new ru.m.connect.js.JsConnection('localhost', 5001, Response)); + Provider.set(IConnection, new ru.m.connect.js.JsConnection(host, 5000, Response)); #else Provider.set(IConnection, new ru.m.connect.fake.FakeConnection(Response)); #end diff --git a/src/common/haxe/ru/m/connect/js/JsConnection.hx b/src/common/haxe/ru/m/connect/js/JsConnection.hx index 63012a6..db3edab 100644 --- a/src/common/haxe/ru/m/connect/js/JsConnection.hx +++ b/src/common/haxe/ru/m/connect/js/JsConnection.hx @@ -30,7 +30,7 @@ class JsConnection extends BaseConnection { } private function buildSocket(host:String, port:Int):WebSocket { - return untyped __js__('new WebSocket("ws://${host}:${port}");'); + return untyped __js__("new WebSocket('ws://'+host+':'+port);"); } override public function connect():Promise> { diff --git a/src/server/haxe/ru/m/tankz/server/Server.hx b/src/server/haxe/ru/m/tankz/server/Server.hx index 2c6151c..1f62cd8 100755 --- a/src/server/haxe/ru/m/tankz/server/Server.hx +++ b/src/server/haxe/ru/m/tankz/server/Server.hx @@ -58,6 +58,6 @@ class Server extends ThreadServer { Provider.setFactory(ILevelBundle, ServerLevelBundle); Provider.setFactory(IControlFactory, NoneControlFactory); var wserver = new Server(); - wserver.run("localhost", 5001); + wserver.run("localhost", 5000); } } \ No newline at end of file