[client] hostname from environ

This commit is contained in:
2018-03-28 17:30:42 +03:00
parent 6d2a1a002b
commit c8448b7848
4 changed files with 33 additions and 5 deletions

View File

@@ -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<Request, Response>('localhost', 5001, Response));
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection<Request, Response>(host, 5000, Response));
#elseif html5
Provider.set(IConnection, new ru.m.connect.js.JsConnection<Request, Response>('localhost', 5001, Response));
Provider.set(IConnection, new ru.m.connect.js.JsConnection<Request, Response>(host, 5000, Response));
#else
Provider.set(IConnection, new ru.m.connect.fake.FakeConnection<Request, Response>(Response));
#end

View File

@@ -30,7 +30,7 @@ class JsConnection<O:Message, I:Message> extends BaseConnection<O, I> {
}
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<IConnection<O, I>> {

View File

@@ -58,6 +58,6 @@ class Server extends ThreadServer<Session, Bytes> {
Provider.setFactory(ILevelBundle, ServerLevelBundle);
Provider.setFactory(IControlFactory, NoneControlFactory);
var wserver = new Server();
wserver.run("localhost", 5001);
wserver.run("localhost", 5000);
}
}