1 // Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
16 using System.Collections.Concurrent;
\r
17 using System.Collections.Generic;
\r
18 using System.Collections.Specialized;
\r
20 using System.Text.RegularExpressions;
\r
21 using System.Threading.Tasks;
\r
23 namespace KancolleSniffer
\r
25 public class KancolleDb
\r
27 private readonly BlockingCollection<Tuple<string, string, string>> _queue =
\r
28 new BlockingCollection<Tuple<string, string, string>>(10);
\r
30 private bool _started;
\r
31 private string _token;
\r
33 public void Start(string token)
\r
45 var e = _queue.Take();
\r
48 using (var wc = new WebClient())
\r
50 var values = new NameValueCollection
\r
53 {"agent", "KdpR5STmwYTaFpNCbD4N"},
\r
55 {"requestbody", e.Item2},
\r
56 {"responsebody", e.Item3}
\r
58 wc.UploadValues("http://api.kancolle-db.net/2/", values);
\r
61 catch (WebException)
\r
66 catch (InvalidOperationException)
\r
72 private readonly HashSet<string> _urlSet = new HashSet<string>()
\r
74 "/kcsapi/api_port/port",
\r
75 "/kcsapi/api_get_member/ship2",
\r
76 "/kcsapi/api_get_member/ship3",
\r
77 "/kcsapi/api_get_member/slot_item",
\r
78 "/kcsapi/api_get_member/kdock",
\r
79 "/kcsapi/api_get_member/mapinfo",
\r
80 "/kcsapi/api_req_hensei/change",
\r
81 "/kcsapi/api_req_kousyou/createship",
\r
82 "/kcsapi/api_req_kousyou/getship",
\r
83 "/kcsapi/api_req_kousyou/createitem",
\r
84 "/kcsapi/api_req_map/start",
\r
85 "/kcsapi/api_req_map/next",
\r
86 "/kcsapi/api_req_map/select_eventmap_rank",
\r
87 "/kcsapi/api_req_sortie/battle",
\r
88 "/kcsapi/api_req_battle_midnight/battle",
\r
89 "/kcsapi/api_req_battle_midnight/sp_midnight",
\r
90 "/kcsapi/api_req_sortie/night_to_day",
\r
91 "/kcsapi/api_req_sortie/battleresult",
\r
92 "/kcsapi/api_req_combined_battle/battle",
\r
93 "/kcsapi/api_req_combined_battle/airbattle",
\r
94 "/kcsapi/api_req_combined_battle/midnight_battle",
\r
95 "/kcsapi/api_req_combined_battle/battleresult",
\r
96 "/kcsapi/api_req_sortie/airbattle",
\r
97 "/kcsapi/api_req_combined_battle/battle_water",
\r
98 "/kcsapi/api_req_combined_battle/sp_midnight"
\r
101 public void Send(string url, string request, string response)
\r
103 if (!_urlSet.Contains(url))
\r
105 request = Regex.Replace(request, @"&api%5Ftoken=[^&]+|api%5Ftoken=[^&]+&?", "");
\r
106 response = response.Replace("svdata=", "");
\r
107 _queue.TryAdd(new Tuple<string, string, string>(url, request, response));
\r
112 _queue.CompleteAdding();
\r