dango_generator 0.3.6 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,6 @@ package org.rubyforge.dango {
|
|
29
29
|
|
30
30
|
private var default_encode_type:uint = 0; // 送信データのエンコードタイプはJSON
|
31
31
|
|
32
|
-
private var is_debug:Boolean; // Debugモードかどうかのフラグ
|
33
32
|
private var is_connect:Boolean = false; // 接続完了しているかどうか
|
34
33
|
|
35
34
|
private var frame_rate:uint = 24; // デフォルトのフレームレート(想定値)
|
@@ -53,6 +52,8 @@ package org.rubyforge.dango {
|
|
53
52
|
private var recv_do_timer:Timer; // 受信実行用タイマーの追加
|
54
53
|
private var recv_do_last_date:Date = new Date(); // 受信キャッシュ用処理落ちチェック用
|
55
54
|
|
55
|
+
private var send_recv_max_size:uint = 1024*1024; // データ送受信の最大バイト数
|
56
|
+
|
56
57
|
public var server_time:String = ""; // サーバーの時計
|
57
58
|
|
58
59
|
// private var server_host:String = "172.31.1.74";
|
@@ -60,30 +61,34 @@ package org.rubyforge.dango {
|
|
60
61
|
// private var server_port:int = 15000;
|
61
62
|
private var server_host:String;
|
62
63
|
private var server_port:int;
|
64
|
+
private var is_debug:Boolean = false; // Debugモードかどうかのフラグ
|
65
|
+
private var disp_obj:DisplayObject;
|
63
66
|
|
64
67
|
public var sid:int;
|
68
|
+
private var has_sid:Boolean = false; // sidを取得完了しているかどうか
|
65
69
|
|
66
70
|
/**
|
67
71
|
* DangoClientFramework
|
68
72
|
* コンストラクタ
|
69
73
|
*
|
70
74
|
* @param config:*
|
71
|
-
* @param disp_obj:DisplayObject = null
|
72
75
|
* @return void
|
73
76
|
*/
|
74
|
-
public function DangoClientFramework(config
|
75
|
-
|
77
|
+
public function DangoClientFramework(config:*){
|
78
|
+
trace("DangoClientFramework start...");
|
79
|
+
|
80
|
+
// 設定ファイルの読み込み
|
81
|
+
if(config.hasOwnProperty("server_host")){ server_host = config.server_host; }
|
82
|
+
if(config.hasOwnProperty("server_port")){ server_port = config.server_port; }
|
83
|
+
if(config.hasOwnProperty("is_debug" )){ is_debug = config.debug; }
|
84
|
+
if(config.hasOwnProperty("disp_obj" )){ disp_obj = config.disp_obj; }
|
85
|
+
// is_debug = true;
|
76
86
|
|
77
87
|
if(disp_obj){
|
88
|
+
trace("disp_obj: " + disp_obj);
|
78
89
|
frame_rate = disp_obj.stage.frameRate; // フレームレート
|
79
90
|
}
|
80
91
|
|
81
|
-
// 設定ファイルの読み込み
|
82
|
-
server_host = config.server_host;
|
83
|
-
server_port = config.server_port;
|
84
|
-
is_debug = config.debug;
|
85
|
-
// is_debug = true;
|
86
|
-
|
87
92
|
var policy_file_protocol:String = config.policy_file_protocol;
|
88
93
|
// var policy_file_port:uint = config.policy_file_port;
|
89
94
|
var policy_file_path:String = config.policy_file_path;
|
@@ -118,7 +123,7 @@ package org.rubyforge.dango {
|
|
118
123
|
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, true);
|
119
124
|
socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false);
|
120
125
|
socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, true);
|
121
|
-
trace("registered event handling.");
|
126
|
+
if(is_debug){ trace("registered event handling."); }
|
122
127
|
|
123
128
|
// ポリシーファイルの読み込み
|
124
129
|
if(policy_file_protocol){
|
@@ -159,7 +164,8 @@ package org.rubyforge.dango {
|
|
159
164
|
|
160
165
|
// 接続完了のときに接続完了をサーバーに通知するためのハートビート送信
|
161
166
|
var hb_id:String = make_heartbeat();
|
162
|
-
|
167
|
+
// if(is_debug){ trace("DangoClientFramework:send _notice_heart_beat:" + hb_id + ":" + DangoUtil.now2str()); }
|
168
|
+
this.send_action("_notice_heart_beat", { "_hb_id": hb_id}); // ハートビート送信
|
163
169
|
}
|
164
170
|
|
165
171
|
/**
|
@@ -335,10 +341,9 @@ package org.rubyforge.dango {
|
|
335
341
|
if(is_debug){ trace("DangoClientFramework:socket_read_push_cache:receive_encode_type=" + receive_encode_type); }
|
336
342
|
if(is_debug){ trace("DangoClientFramework:socket_read_push_cache:receive_data_size=" + receive_data_size); }
|
337
343
|
|
338
|
-
|
339
|
-
if(is_debug){ trace("DangoClientFramework:socket_read_push_cache:length=" + receive_cache_byta.length); }
|
340
|
-
if(is_debug){ trace("DangoClientFramework:socket_read_push_cache:position=" + receive_cache_byta.position); }
|
344
|
+
if(receive_data_size > send_recv_max_size){ throw new DangoError("recv data size is max size over. maybe data broken."); }
|
341
345
|
|
346
|
+
// receive_cache_bytaの不要な部分を削除
|
342
347
|
if(receive_cache_byta.length - receive_cache_byta.position > 0){
|
343
348
|
receive_cache_byta.readBytes(temp_byta, 0, receive_cache_byta.length - receive_cache_byta.position);
|
344
349
|
receive_cache_byta = temp_byta;
|
@@ -346,14 +351,21 @@ package org.rubyforge.dango {
|
|
346
351
|
} else {
|
347
352
|
receive_cache_byta = new ByteArray;
|
348
353
|
}
|
354
|
+
|
349
355
|
if(is_debug){ trace("DangoClientFramework:socket_read_push_cache:receive_cache_do_phase == 0:end read:length=" + receive_cache_byta.length); }
|
350
356
|
|
357
|
+
receive_cache_do_phase = 1; // データ受信に行く
|
358
|
+
|
351
359
|
} catch(err:Error){
|
352
|
-
this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "failed in DangoClientFramework:socket_read_push_cache:receive_cache_do_phase == 0"));
|
360
|
+
// this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "failed in DangoClientFramework:socket_read_push_cache:receive_cache_do_phase == 0"));
|
361
|
+
|
362
|
+
// キャッシュに残っているデータを消して再度初めから受信できるようにする
|
363
|
+
trace("DangoClientFramework:socket_read_push_cache:receive_cache_do_phase==0:err=" + ObjectUtil.toString(err));
|
364
|
+
receive_cache_do_phase = 0; // 長さから取得する
|
365
|
+
receive_cache_byta = new ByteArray; // キャッシュを空にする
|
353
366
|
break;
|
354
367
|
}
|
355
368
|
|
356
|
-
receive_cache_do_phase = 1;
|
357
369
|
}
|
358
370
|
|
359
371
|
// データ取得処理
|
@@ -371,8 +383,8 @@ package org.rubyforge.dango {
|
|
371
383
|
if(recv_data != "" && recv_data != "\n"){ // データが空じゃないならdecode
|
372
384
|
ret_obj_data = JSON.decode(recv_data) as Array;
|
373
385
|
for(var i:uint = 0; i < ret_obj_data.length; i++){
|
374
|
-
var notice_name:String = ret_obj_data[i]["
|
375
|
-
var recv_server_time:String = ret_obj_data[i]["
|
386
|
+
var notice_name:String = ret_obj_data[i]["_notice_name"];
|
387
|
+
var recv_server_time:String = ret_obj_data[i]["_server_time"];
|
376
388
|
|
377
389
|
if(is_debug){ trace("DangoClientFramework:push recv_wait_do_cache:dango_" + notice_name + " i=" + i + " recv_server_time=" + recv_server_time); }
|
378
390
|
recv_wait_do_cache.push([notice_name, ret_obj_data[i], recv_server_time, recv_do_count_no]);
|
@@ -384,9 +396,6 @@ package org.rubyforge.dango {
|
|
384
396
|
}
|
385
397
|
|
386
398
|
// receive_cache_bytaの不要な部分を削除
|
387
|
-
if(is_debug){ trace("DangoClientFramework:socket_read_push_cache:length=" + receive_cache_byta.length); }
|
388
|
-
if(is_debug){ trace("DangoClientFramework:socket_read_push_cache:position=" + receive_cache_byta.position); }
|
389
|
-
|
390
399
|
if(receive_cache_byta.length - receive_cache_byta.position > 0){
|
391
400
|
receive_cache_byta.readBytes(temp_byta, 0, receive_cache_byta.length - receive_cache_byta.position);
|
392
401
|
receive_cache_byta = temp_byta;
|
@@ -396,11 +405,17 @@ package org.rubyforge.dango {
|
|
396
405
|
}
|
397
406
|
if(is_debug){ trace("DangoClientFramework:socket_read_push_cache:receive_cache_do_phase == 1:end read:length=" + receive_cache_byta.length); }
|
398
407
|
|
408
|
+
receive_cache_do_phase = 0; // データ受信に行く
|
409
|
+
|
399
410
|
} catch(err:Error){
|
400
|
-
this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "failed in DangoClientFramework:socket_read_push_cache:receive_cache_do_phase == 1"));
|
411
|
+
// this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "failed in DangoClientFramework:socket_read_push_cache:receive_cache_do_phase == 1"));
|
412
|
+
|
413
|
+
// キャッシュに残っているデータを消して再度初めから受信できるようにする
|
414
|
+
trace("DangoClientFramework:socket_read_push_cache:receive_cache_do_phase==1:err=" + ObjectUtil.toString(err));
|
415
|
+
receive_cache_do_phase = 0; // 長さから取得する
|
416
|
+
receive_cache_byta = new ByteArray; // キャッシュを空にする
|
401
417
|
break;
|
402
418
|
}
|
403
|
-
receive_cache_do_phase = 0;
|
404
419
|
}
|
405
420
|
}
|
406
421
|
|
@@ -429,6 +444,7 @@ package org.rubyforge.dango {
|
|
429
444
|
|
430
445
|
if(notice_name == "_notice_sid"){ // 接続直後のsid通知なら
|
431
446
|
this.sid = recv_data["_sid"];
|
447
|
+
has_sid = true;
|
432
448
|
if(is_debug){ trace("DangoClientFramework:this.sid=" + this.sid + " server_time=" + server_time); }
|
433
449
|
|
434
450
|
} else { // 通常のデータならイベント発生
|
@@ -454,9 +470,6 @@ package org.rubyforge.dango {
|
|
454
470
|
public function polling_callback(evt:TimerEvent):void {
|
455
471
|
// if(is_debug){ trace("DangoClientFramework:polling_callback:" + DangoUtil.now2str() ); }
|
456
472
|
if(socket.connected){
|
457
|
-
// var send_obj:Object = null;
|
458
|
-
// this.send_data_to_server(send_obj);
|
459
|
-
|
460
473
|
var hb_id:String = make_heartbeat();
|
461
474
|
// if(is_debug){ trace("DangoClientFramework:send _notice_heart_beat:" + hb_id + ":" + DangoUtil.now2str()); }
|
462
475
|
this.send_action("_notice_heart_beat", { "_hb_id": hb_id}); // ハートビート送信
|
@@ -483,17 +496,19 @@ package org.rubyforge.dango {
|
|
483
496
|
public function delay_send_callback(evt:TimerEvent):void {
|
484
497
|
// if(is_debug){ trace("DangoClientFramework:delay_send_callback:evt:" + evt); }
|
485
498
|
if(!is_connect){ return(void); }
|
486
|
-
if(socket.connected){
|
487
|
-
|
488
|
-
|
499
|
+
if(!socket.connected){ return(void); }
|
500
|
+
if(!has_sid){ return(void); }
|
501
|
+
|
502
|
+
var send_obj_dup:Array;
|
503
|
+
var i:uint;
|
504
|
+
|
505
|
+
for (i = 0; i < 5; i++) {
|
506
|
+
if(delay_send_cache.length == 0) { break; }
|
489
507
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
this.send_data_to_server(send_obj_dup);
|
495
|
-
if(is_debug){ trace("DangoClientFramework:delay_send_callback:sent:" + DangoUtil.now2str()); }
|
496
|
-
}
|
508
|
+
// データをすぐ送信
|
509
|
+
send_obj_dup = delay_send_cache.shift();
|
510
|
+
this.send_data_to_server(send_obj_dup);
|
511
|
+
if(is_debug){ trace("DangoClientFramework:delay_send_callback:sent:" + send_obj_dup[0]["_action_name"] + ":" + has_sid + ":" + DangoUtil.now2str()); }
|
497
512
|
}
|
498
513
|
}
|
499
514
|
|
@@ -507,17 +522,17 @@ package org.rubyforge.dango {
|
|
507
522
|
* @return void
|
508
523
|
*/
|
509
524
|
public function send_action(action_name:String, send_obj:Object, delay:Boolean=false):void {
|
510
|
-
if(is_debug){ trace("DangoClientFramework:send_action:start:" + action_name + ":" + DangoUtil.now2str()); }
|
525
|
+
if(is_debug){ trace("DangoClientFramework:send_action:start:action_name=" + action_name + ":delay=" + delay + ":is_connect=" + is_connect + ":has_sid=" + has_sid + ":" + DangoUtil.now2str()); }
|
511
526
|
|
512
|
-
// if(!is_connect){ throw new DangoError("error:not connect"
|
527
|
+
// if(!is_connect){ throw new DangoError("error:not connect"); } // 接続されていない場合はエラー
|
513
528
|
|
514
529
|
// 送信データの作成
|
515
530
|
var send_obj_dup:Object = ObjectUtil.copy(send_obj);
|
516
|
-
send_obj_dup["
|
531
|
+
send_obj_dup["_action_name"] = action_name;
|
517
532
|
send_obj_dup["_return_id"] = (new Date()).time;
|
518
533
|
|
519
534
|
// delayフラグがあったり、接続がまだなら、遅延送信用のキャッシュにデータを入れる
|
520
|
-
if(delay || !is_connect){
|
535
|
+
if(delay || !is_connect || (action_name != "_notice_heart_beat" && !has_sid)){
|
521
536
|
delay_send_cache.push([send_obj_dup]);
|
522
537
|
|
523
538
|
if(is_debug){ trace("DangoClientFramework:send_action:delay_pull:" + action_name + ":" + DangoUtil.now2str()); }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dango_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keisuke Minami
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-05 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|