GameOn のゲームプラグインの汎用クラスを追加
AVA を汎用クラスで再定義
Soul of the Ultimate Nation のクラスを追加
@@ -10,46 +10,33 @@ | ||
10 | 10 | { |
11 | 11 | using OGSNET.Plugin; |
12 | 12 | |
13 | - /** \brief AVAの起動プラグイン */ | |
14 | - [Export(typeof(IPlugin))] | |
15 | - [Export(typeof(IGamePlugin))] | |
16 | - [ExportMetadata("PluginId", "GameOn.AVA")] | |
17 | - public class AVA : GamePluginBase | |
13 | + /** brief GameOn の flashvars 汎用プラグイン */ | |
14 | + public class GameOnFlashvars : GamePluginBase | |
18 | 15 | { |
19 | - /** \brief プラグインの情報を初期化する */ | |
20 | - public AVA() | |
16 | + /** \brief プラグインの開始処理 */ | |
17 | + protected override sealed void StartPlugin() | |
21 | 18 | { |
22 | - this.PluginInfo = | |
23 | - new PluginInfo(new Version(1), "Alliance of Valiant Arms (GameOn) プラグイン ", "pine", | |
24 | - "Alliance of Valiant Arms (GameOn) を起動するプラグインです。"); | |
25 | - | |
26 | - this.GameInfo = | |
27 | - new GameInfo("ゲームオン", "GameOn", "Alliance of Valiant Arms", | |
28 | - "http://ava.gamechu.jp/"); | |
19 | + // ログインする | |
20 | + this.CallPlugin("GameOn", this.LoadGameStartPage); | |
29 | 21 | } |
30 | 22 | |
31 | - /** \brief プラグインを開始する */ | |
32 | - protected override void StartPlugin() | |
23 | + /** \brief ゲームを開始するページを読み込む */ | |
24 | + private void LoadGameStartPage() | |
33 | 25 | { |
34 | - this.CallPlugin("GameOn", this.LoadTopPage); | |
26 | + this.Notice("ゲームを開始するページを読み込んでいます。"); | |
27 | + this.Navigate(this.GameStartUrl, this.GameStart); | |
35 | 28 | } |
36 | 29 | |
37 | - /** \brief トップページを読み込む */ | |
38 | - private void LoadTopPage() | |
39 | - { | |
40 | - this.StartCallback(CallbackStatus.Notice, "AVAのトップページを読み込んでいます。"); | |
41 | - this.Navigate("http://ava.gamechu.jp/", this.GameStart); | |
42 | - } | |
43 | - | |
44 | 30 | /** \brief ゲームを開始する */ |
45 | 31 | private void GameStart() |
46 | 32 | { |
47 | - this.StartCallback(CallbackStatus.Notice, "ゲームを起動しています。"); | |
33 | + // Flash の要素を取得 | |
34 | + var flash = this.Document.GetElementById(this.FlashId); | |
48 | 35 | |
49 | - var flash = this.Document.GetElementById("flash_gamestart_loginSWF"); | |
36 | + // Flash の中のすべての param 要素を取得 | |
50 | 37 | var elements = flash.GetElementsByTagName("param").Cast<HtmlElement>(); |
51 | 38 | |
52 | - // flashvars は複数有り | |
39 | + // name 属性が flashvars な param 要素を LINQ で取得 (複数ある場合あり) | |
53 | 40 | var query = |
54 | 41 | from A |
55 | 42 | in elements |
@@ -61,23 +48,109 @@ | ||
61 | 48 | |
62 | 49 | foreach (var value in query) |
63 | 50 | { |
64 | - var regex = new Regex("GAMESTART_LOGIN_URL=(.+)(?:$|&)"); // javascript:~ の形で入ってる | |
51 | + // javascript:~ の形で入ってる | |
52 | + var regex = new Regex(this.FlashvarsName + "=([^&]+)"); | |
53 | + | |
54 | + // マッチ処理 | |
65 | 55 | var match = regex.Match(value); |
66 | 56 | |
67 | - if (match.Success && match.Groups.Count == 2) | |
57 | + // マッチした場合 | |
58 | + if (match.Success) | |
68 | 59 | { |
60 | + // ゲームを開始する | |
69 | 61 | this.Navigate(match.Groups[1].Value); |
62 | + | |
63 | + // 成功フラグを立てる | |
70 | 64 | success = true; |
71 | 65 | break; |
72 | 66 | } |
73 | 67 | } |
74 | 68 | |
69 | + // 成功した場合 | |
75 | 70 | if (success) |
76 | 71 | { |
77 | - this.StartCallback(CallbackStatus.Finish, "ゲームの起動に成功しました。"); | |
78 | - } else { | |
79 | - this.StartCallback(CallbackStatus.Error, "ゲーム開始に必要なパラメーターが見つかりません。"); | |
72 | + this.Notice("ゲームの起動に成功しました。"); | |
80 | 73 | } |
74 | + else | |
75 | + { | |
76 | + this.Notice("ゲーム開始に必要なパラメーターが見つかりません。"); | |
77 | + } | |
81 | 78 | } |
79 | + | |
80 | + /** | |
81 | + * \brief Flash の object 要素の id | |
82 | + * | |
83 | + * ExternalInterface には必ず ID 属性が必要なため、開始する Flash の object 要素には必ず ID 属性がある | |
84 | + */ | |
85 | + protected string FlashId | |
86 | + { | |
87 | + get; | |
88 | + set; | |
89 | + } | |
90 | + | |
91 | + /** | |
92 | + * \brief flashvars で探す名前 | |
93 | + * | |
94 | + * FlashId の中の param 要素で name 属性が flashvars な要素の value 属性の中で検索する | |
95 | + * value 属性が 名前=値&名前=値& ... となってるので、その名前を指定する | |
96 | + */ | |
97 | + protected string FlashvarsName | |
98 | + { | |
99 | + get; | |
100 | + set; | |
101 | + } | |
102 | + | |
103 | + private string GameStartUrl_ = null; | |
104 | + | |
105 | + /** \brief ゲームを開始する URL */ | |
106 | + protected string GameStartUrl | |
107 | + { | |
108 | + get { return this.GameStartUrl_ ?? this.GameInfo.Url.AbsoluteUri; } | |
109 | + set { this.GameStartUrl_ = value; } | |
110 | + } | |
82 | 111 | } |
112 | + | |
113 | + /** \brief AVAの起動プラグイン */ | |
114 | + [Export(typeof(IPlugin))] | |
115 | + [Export(typeof(IGamePlugin))] | |
116 | + [ExportMetadata("PluginId", "GameOn.AVA")] | |
117 | + public class AVA : GameOnFlashvars | |
118 | + { | |
119 | + /** \brief プラグインの情報を初期化する */ | |
120 | + public AVA() | |
121 | + { | |
122 | + this.PluginInfo = | |
123 | + new PluginInfo(new Version(1), "Alliance of Valiant Arms (GameOn) プラグイン ", "pine", | |
124 | + "Alliance of Valiant Arms (GameOn) を起動するプラグインです。"); | |
125 | + | |
126 | + this.GameInfo = | |
127 | + new GameInfo("ゲームオン", "GameOn", "Alliance of Valiant Arms", | |
128 | + "http://ava.gamechu.jp/"); | |
129 | + | |
130 | + this.FlashId = "flash_gamestart_loginSWF"; | |
131 | + this.FlashvarsName = "GAMESTART_LOGIN_URL"; | |
132 | + } | |
133 | + } | |
134 | + | |
135 | + /** \brief Soul of the Ultimate Nation の起動プラグイン */ | |
136 | + [Export(typeof(IPlugin))] | |
137 | + [Export(typeof(IGamePlugin))] | |
138 | + [ExportMetadata("PluginId", "GameOn.SUN")] | |
139 | + public class SUN : GameOnFlashvars | |
140 | + { | |
141 | + /** \brief プラグインの情報を初期化する */ | |
142 | + public SUN() | |
143 | + { | |
144 | + this.PluginInfo = | |
145 | + new PluginInfo(new Version(1), "Soul of the Ultimate Nation (GameOn) プラグイン ", "pine", | |
146 | + "Soul of the Ultimate Nation (GameOn) を起動するプラグインです。"); | |
147 | + | |
148 | + this.GameInfo = | |
149 | + new GameInfo("ゲームオン", "GameOn", "Soul of the Ultimate Nation", | |
150 | + "http://sunonline.gamechu.jp/member/"); | |
151 | + | |
152 | + this.FlashId = "flash_start"; | |
153 | + this.FlashvarsName = "START_URL"; | |
154 | + } | |
155 | + } | |
83 | 156 | } |