diff --git a/.gitignore b/.gitignore
index ffec2b7..c60db89 100755
--- a/.gitignore
+++ b/.gitignore
@@ -9,4 +9,5 @@ out/
.idea/
config.json
package-lock.json
-/node_modules
\ No newline at end of file
+/node_modules
+/log
\ No newline at end of file
diff --git a/build/client.js b/build/client.js
index 23b8871..ced3822 100755
--- a/build/client.js
+++ b/build/client.js
@@ -5,33 +5,19 @@ const tail = require('../tasks/tail');
const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer');
const version = require('./version');
-const dateformat = require('dateformat');
const prepare = require('./prepare');
const debug = require('../tasks/debug');
-const build = (params) => function build() {
- params = params || {};
+const build = () => function build() {
const argv = yargs.argv;
- const values = {
- build: dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
- };
- let outputFile = 'tankz.swf';
- if (params.outputFile) {
- outputFile = params.outputFile;
- }
- if (argv.dev) {
- values.dev = true;
- if (!values['dev.address']) values['dev.address'] = argv['dev-address'] || 'localhost';
- if (!values['dev.port']) values['dev.port'] = argv['dev-port'] || 5000;
- }
return gulp.src('.')
.pipe(new Haxe().openfl({
command: 'build',
platform: 'flash',
version: version,
- values: values,
- outputFile: outputFile,
+ outputFile: 'tankz.swf',
+ debug: argv.dev,
}))
.pipe(gulp.dest('target'));
};
@@ -40,7 +26,8 @@ const test = (build) => function test() {
const argv = yargs.argv;
return build()
.pipe(new FlashPlayer().run(argv.dev))
- .pipe(tail(debug.log));
+ //.pipe(tail(debug.log));
+ .pipe(debug());
};
diff --git a/build/server.js b/build/server.js
index c51f163..a70957e 100755
--- a/build/server.js
+++ b/build/server.js
@@ -6,47 +6,29 @@ const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer');
const Neko = require('../tasks/neko');
const version = require('./version');
-const dateformat = require('dateformat');
const prepare = require('./prepare');
const debug = require('../tasks/debug');
-const build = (params) => function build() {
- params = params || {};
+const build = () => function build() {
const argv = yargs.argv;
- const values = {
- build: dateformat(new Date(), 'yyyy-mm-dd h:MM:ss'),
- };
- let outputFile = 'tankz.n';
- if (params.outputFile) {
- outputFile = params.outputFile;
- }
- if (argv.dev) {
- values.dev = true;
- if (!values['dev.address']) values['dev.address'] = argv['dev-address'] || 'localhost';
- if (!values['dev.port']) values['dev.port'] = argv['dev-port'] || 5000;
- }
return gulp.src('.')
.pipe(new Haxe().build({
platform: 'neko',
version: version,
- values: values,
lib: [
'protohx',
'orm',
- 'haxework',
+ 'haxework:git',
],
cp: [
'src/common/haxe',
'src/server/haxe',
'src-gen/haxe',
],
- macro: [
- `CompilationOption.set('debug.address','${values['dev.address']}')`,
- `CompilationOption.set('debug.port','${values['dev.port']}')`,
- ],
main: 'ru.m.tankz.server.Server',
- outputFile: outputFile,
+ outputFile: 'tankz.n',
+ debug: argv.dev,
}))
.pipe(gulp.dest('target'));
};
diff --git a/capfile b/capfile
new file mode 100644
index 0000000..08b04d7
--- /dev/null
+++ b/capfile
@@ -0,0 +1,5 @@
+require 'capistrano/setup'
+require 'capistrano/deploy'
+require 'airbrussh/capistrano'
+
+Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
diff --git a/config/deploy.rb b/config/deploy.rb
new file mode 100644
index 0000000..b3b9cd8
--- /dev/null
+++ b/config/deploy.rb
@@ -0,0 +1,44 @@
+require_relative 'service'
+
+app = 'tankz'
+user = 'adman'
+
+set :scm, :git
+set :application, app
+set :repo_url, "git@bitbucket.org:shmyga/#{app}.git"
+set :user, user
+set :deploy_to, "/home/#{user}/repo/#{app}"
+
+
+namespace :build do
+ task :lib do
+ on roles(:app) do
+ execute "mkdir ~/haxelib 2>/dev/null || :"
+ execute "haxelib setup ~/haxelib"
+ execute "haxelib install lime"
+ execute "haxelib install openfl"
+ execute "haxelib install protohx"
+ execute "haxelib install orm"
+ execute "haxelib git haxework git@bitbucket.org:shmyga/haxework.git"
+ end
+ end
+
+ task :gen do
+ on roles(:app) do
+ execute "cd #{release_path} && haxelib run protohx generate protohx.json"
+ execute "cd #{release_path} && haxelib run orm mysql://shmyga:xkbp8jh9z2@localhost:3306/armageddon -s src-gen/haxe -c ru.m.tankz.db -a ru.m.tankz.db"
+ end
+ end
+
+ task :run do
+ on roles(:app) do
+ execute "cd #{release_path} && openfl build html5"
+ execute "cd #{release_path} && openfl build flash"
+ execute "cd #{release_path} && haxe server.hxml"
+ end
+ end
+end
+
+before 'build:run', 'build:lib'
+before 'build:run', 'build:gen'
+before 'deploy:updated', 'build:run'
diff --git a/config/deploy/develop.rb b/config/deploy/develop.rb
new file mode 100644
index 0000000..cb4797b
--- /dev/null
+++ b/config/deploy/develop.rb
@@ -0,0 +1,10 @@
+role :app, %w{localhost}
+role :web, %w{localhost}
+role :db, %w{localhost}
+
+user = fetch(:user)
+
+server 'localhost', ssh_options: { port: 22, user: user, forward_agent: true }
+
+set :tmp_dir, "/home/#{user}/tmp"
+set :branch, 'master'
diff --git a/config/deploy/production.rb b/config/deploy/production.rb
new file mode 100644
index 0000000..98a2014
--- /dev/null
+++ b/config/deploy/production.rb
@@ -0,0 +1,10 @@
+role :app, %w{test.instreamatic.com}
+role :web, %w{test.instreamatic.com}
+role :db, %w{test.instreamatic.com}
+
+user = fetch(:user)
+
+server 'test.instreamatic.com', ssh_options: { port: 3607, user: user, forward_agent: true }
+
+set :tmp_dir, "/home/#{user}/tmp"
+set :branch, 'master'
diff --git a/config/service.rb b/config/service.rb
new file mode 100644
index 0000000..7b30f95
--- /dev/null
+++ b/config/service.rb
@@ -0,0 +1,52 @@
+module Service
+ class Manager
+ def initialize(env)
+ @env = env
+ end
+
+ def execute(action, command)
+ Airbrussh.configure do |config|
+ config.command_output = true
+ end
+ service_role = "service_role_#{action}".to_sym
+ role = fetch(service_role)
+ on roles(role) do
+ execute :sudo, "/bin/systemctl #{command} #{action}"
+ end
+ end
+ end
+end
+
+services = %w{tankz}
+
+namespace :service do
+ task :restart, :param do |task, args|
+ services = args[:param] ? [args[:param]] : services
+ services.each { |service|
+ Service::Manager.new(self).execute(service, 'restart')
+ }
+ end
+
+ task :stop, :param do |task, args|
+ services = args[:param] ? [args[:param]] : services
+ services.each { |service|
+ Service::Manager.new(self).execute(service, 'stop')
+ }
+ end
+
+ task :start, :param do |task, args|
+ services = args[:param] ? [args[:param]] : services
+ services.each { |service|
+ Service::Manager.new(self).execute(service, 'start')
+ }
+ end
+
+ task :status, :param do |task, args|
+ services = args[:param] ? [args[:param]] : services
+ services.each { |service|
+ Service::Manager.new(self).execute(service, 'status')
+ }
+ end
+end
+
+set :service_role_tankz, :app
diff --git a/project.xml b/project.xml
index 52717d7..ef388b1 100755
--- a/project.xml
+++ b/project.xml
@@ -2,14 +2,13 @@
-
-
+
@@ -17,11 +16,4 @@
-
-
\ No newline at end of file
diff --git a/server.hxml b/server.hxml
deleted file mode 100755
index d5c59b2..0000000
--- a/server.hxml
+++ /dev/null
@@ -1,11 +0,0 @@
--main ru.m.tankz.server.Server
--lib protohx
--lib orm
--lib haxework
--cp src/common/haxe
--cp src/server/haxe
--cp src-gen/haxe
---macro CompilationOption.set('debug.address','localhost')
---macro CompilationOption.set('debug.port','5000')
--neko target/server.n
-# -D proto_debug
\ No newline at end of file
diff --git a/server.sh b/server.sh
deleted file mode 100755
index 54b7688..0000000
--- a/server.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-haxe server.hxml && neko target/server.n
diff --git a/src/client/haxe/ru/m/tankz/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx
index 5554846..fc64afc 100755
--- a/src/client/haxe/ru/m/tankz/Client.hx
+++ b/src/client/haxe/ru/m/tankz/Client.hx
@@ -1,5 +1,6 @@
package ru.m.tankz;
+import haxework.log.SocketLogger;
import haxework.resources.Resources;
import haxework.resources.IResources;
import haxework.gui.VGroupView;
@@ -31,6 +32,9 @@ class Client implements IConnectionHandler {
#if flash
L.push(new JSLogger());
#end
+ #if debug
+ L.push(new SocketLogger());
+ #end
Const.init();
L.d(TAG, "Debug: " + Const.DEBUG);
L.i(TAG, "Version: " + Const.VERSION);
diff --git a/src/server/haxe/ru/m/tankz/server/Server.hx b/src/server/haxe/ru/m/tankz/server/Server.hx
index 68031c8..d73aa76 100755
--- a/src/server/haxe/ru/m/tankz/server/Server.hx
+++ b/src/server/haxe/ru/m/tankz/server/Server.hx
@@ -38,8 +38,11 @@ class Server extends ThreadServer {
public static function main() {
L.push(new TraceLogger());
+ #if debug
L.push(new SocketLogger());
+ #end
L.d(TAG, "Running");
+ L.i(TAG, "Build: " + CompilationOption.get("build"));
Provider.set(IPacketBuilder, new PacketBuilder());
var wserver = new Server();
wserver.run("localhost", 5001);
diff --git a/tankz.service b/tankz.service
new file mode 100644
index 0000000..3a0c626
--- /dev/null
+++ b/tankz.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Tankz server
+
+[Service]
+WorkingDirectory=/home/adman/repo/tankz/current/target
+ExecStart=/usr/bin/neko tankz.n
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
+Alias=tankz.service
\ No newline at end of file
diff --git a/tasks/debug.js b/tasks/debug.js
index 37f3efb..fc1daca 100755
--- a/tasks/debug.js
+++ b/tasks/debug.js
@@ -20,11 +20,17 @@ const log = (line) => {
module.exports = () => {
return through.obj(function (file, enc, callback) {
+ const debug = file.debug;
+ if (!file.debug) {
+ this.emit('end');
+ callback();
+ return;
+ }
const server = net.createServer((socket) => {
socket.on("data", (data) => {
const lines = data.toString().split('\n');
for (let line of lines) if (line.length > 2) {
- log(line.substr(2));
+ log(line);
}
});
socket.on("close", () => {
@@ -34,7 +40,8 @@ module.exports = () => {
callback();
});
});
- server.listen(5000);
+ gutil.log(col.green('[debug]'), col.cyan('listen on'), col.magenta(`${debug.host}:${debug.port}`));
+ server.listen(debug.port, debug.host);
})
};
diff --git a/tasks/flashplayer.js b/tasks/flashplayer.js
index fdbaa97..39919a0 100755
--- a/tasks/flashplayer.js
+++ b/tasks/flashplayer.js
@@ -125,18 +125,18 @@ class FlashPlayer extends Sdk {
FlashPlayer.enableLog();
exec('.', [this.flashPlayerBin(debug), file.path].join(' ')).then(() => {
stream.emit('end');
- //callback();
+ callback();
}).catch((error) => {
- stream.emit('end');
- //callback();
- stream.emit('error', error);
+ stream.emit('error', new gutil.PluginError({plugin: this.tag, message: error}));
+ callback();
});
//stream.push(file);
// ToDo: watch when file is exists
// or create log file in FlashPlayer.enableLog()?
- stream.push(new gutil.File({
+ /*stream.push(new gutil.File({
path: FlashPlayer.log
- }));
+ }));*/
+ stream.push(file);
};
return stream = through.obj(bufferContents);
diff --git a/tasks/haxe.js b/tasks/haxe.js
index e9b38bd..88fcd23 100755
--- a/tasks/haxe.js
+++ b/tasks/haxe.js
@@ -10,6 +10,7 @@ const gulp = require('gulp');
const through = require('through2');
const col = gutil.colors;
const Sdk = require('./sdk');
+const dateformat = require('dateformat');
class Haxe extends Sdk {
@@ -130,6 +131,12 @@ class Haxe extends Sdk {
* }
*/
openfl(params) {
+ params = Object.assign({
+ build: dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
+ macro: [],
+ debug: false,
+ }, params);
+
const files = [];
let stream = null;
@@ -156,12 +163,26 @@ class Haxe extends Sdk {
args.push(`--app-path=${dir}`);
args.push(`--app-file=${name}`);
if (params.version) args.push(`--meta-version=${params.version}`);
- if (params.build) args.push(`--haxedef=BUILD="${params.build}"`);
+ //if (params.build) args.push(`--haxedef=BUILD="${params.build}"`);
+ args.push(`--haxeflag="--macro=CompilationOption.set('build','${params.build}')"`);
+ let debug = null;
+ if (params.debug) {
+ debug = {
+ host: 'localhost',
+ port: 6000 + Math.floor(Math.random() * 1000),
+ };
+ args.push(`--haxeflag="--macro=CompilationOption.set('debug.address','${debug.host}')"`);
+ args.push(`--haxeflag="--macro=CompilationOption.set('debug.port','${debug.port}')"`);
+ args.push('-debug');
+ }
+ //console.log('haxelib', args.join(' '));
this.haxelib(args).then(() => {
- stream.push(new gutil.File({
+ const out = new gutil.File({
path: params.outputFile,
contents: fs.createReadStream(`${dir}/flash/bin/${name}.swf`)
- }));
+ });
+ out.debug = debug;
+ stream.push(out);
callback();
}).catch((error) => {
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
@@ -185,9 +206,16 @@ class Haxe extends Sdk {
* src: [],
* main: 'Main.hx',
* outputFile: 'out.n',
+ * debug: true,
* }
*/
build(params) {
+ params = Object.assign({
+ build: dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
+ macro: [],
+ debug: false,
+ }, params);
+
const files = [];
let stream = null;
@@ -222,13 +250,25 @@ class Haxe extends Sdk {
const dir = path.dirname(tmpFile.path);
const name = path.basename(tmpFile.path);
args.push(`-${params.platform}`, tmpFile.path);
- if (params.build) args.push(`--haxedef=BUILD="${params.build}"`);
+ args.push(`--macro "CompilationOption.set('build','${params.build}')"`);
+ let debug = null;
+ if (params.debug) {
+ debug = {
+ host: 'localhost',
+ port: 6000 + Math.floor(Math.random() * 1000),
+ };
+ args.push(`--macro "CompilationOption.set('debug.address','${debug.host}')"`);
+ args.push(`--macro "CompilationOption.set('debug.port','${debug.port}')"`);
+ args.push('-debug');
+ }
//console.log('haxe', args.join(' '));
this.haxe(args).then(() => {
- stream.push(new gutil.File({
+ const out = new gutil.File({
path: params.outputFile,
contents: fs.createReadStream(tmpFile.path)
- }));
+ });
+ out.debug = debug;
+ stream.push(out);
callback();
}).catch((error) => {
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));