Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andanteyk committed Jun 17, 2015
2 parents 8e65daf + 6eb020a commit c89683a
Show file tree
Hide file tree
Showing 32 changed files with 2,011 additions and 304 deletions.
11 changes: 10 additions & 1 deletion Browser/FormBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ private void ToolMenu_Other_NavigateToLogInPage_Click( object sender, EventArgs
}

private void ToolMenu_Other_Navigate_Click( object sender, EventArgs e ) {
BrowserHost.AsyncRemoteRun( () => BrowserHost.Proxy.RequestNavigation( Browser.Url.ToString() ) );
BrowserHost.AsyncRemoteRun( () => BrowserHost.Proxy.RequestNavigation( Browser.Url == null ? null : Browser.Url.ToString() ) );
}

private void ToolMenu_Other_AppliesStyleSheet_Click( object sender, EventArgs e ) {
Expand Down Expand Up @@ -855,6 +855,14 @@ private void ToolMenu_Other_Alignment_DropDownOpening( object sender, EventArgs
ToolMenu_Other_Alignment_Invisible.Checked = !Configuration.IsToolMenuVisible;
}

protected override void WndProc( ref Message m ) {

if ( m.Msg == WM_ERASEBKGND )
// ignore this message
return;

base.WndProc( ref m );
}


#region 呪文
Expand All @@ -868,6 +876,7 @@ private void ToolMenu_Other_Alignment_DropDownOpening( object sender, EventArgs
private const int GWL_STYLE = ( -16 );
private const uint WS_CHILD = 0x40000000;
private const uint WS_VISIBLE = 0x10000000;
private const int WM_ERASEBKGND = 0x14;


//以下キャッシュ削除用呪文
Expand Down
36 changes: 27 additions & 9 deletions ElectronicObserver/Data/Battle/Phase/PhaseAirBattle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ private void CalculateAttackDamage( int[] damages ) {
}

int totalFirepower = firepower.Sum();
int totalDamage = Damages.Sum();
int totalDamage = Damages.Skip( 6 ).Take( 6 ).Sum();

for ( int i = 0; i < 6; i++ ) {
damages[i] += (int)( (double)totalDamage * firepower[i] / Math.Max( totalFirepower, 1 ) );
damages[i] += (int)Math.Round( (double)totalDamage * firepower[i] / Math.Max( totalFirepower, 1 ) );
}
}

Expand Down Expand Up @@ -220,14 +220,32 @@ public ShipData AACutInShip {
public int[] Damages {
get {
if ( AirBattleData.api_stage3_combined() ) {
return ( (int[])AirBattleData.api_stage3.api_fdam ).Skip( 1 )
.Concat( ( (int[])AirBattleData.api_stage3.api_edam ).Skip( 1 ) )
.Concat( ( (int[])AirBattleData.api_stage3_combined.api_fdam ).Skip( 1 ) )
.ToArray();
int[] ret = new int[18];

int[] friend = (int[])AirBattleData.api_stage3.api_fdam;
int[] enemy = (int[])AirBattleData.api_stage3.api_edam;
int[] escort = (int[])AirBattleData.api_stage3_combined.api_fdam;

for ( int i = 0; i < 6; i++ ) {
ret[i] = Math.Max( friend[i + 1], 0 );
ret[i + 6] = Math.Max( enemy[i + 1], 0 );
ret[i + 12] = Math.Max( escort[i + 1], 0 );
}

return ret;

} else {
return ( (int[])AirBattleData.api_stage3.api_fdam ).Skip( 1 )
.Concat( ( (int[])AirBattleData.api_stage3.api_edam ).Skip( 1 ) )
.ToArray();
int[] ret = new int[12];

int[] friend = (int[])AirBattleData.api_stage3.api_fdam;
int[] enemy = (int[])AirBattleData.api_stage3.api_edam;

for ( int i = 0; i < 6; i++ ) {
ret[i] = Math.Max( friend[i + 1], 0 );
ret[i + 6] = Math.Max( enemy[i + 1], 0 );
}

return ret;
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions ElectronicObserver/Data/Quest/ProgressAGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;

namespace ElectronicObserver.Data.Quest {
using DSPair = KeyValuePair<double, string>;

/// <summary>
/// 任務「あ号作戦」の進捗を管理します。
Expand All @@ -18,13 +19,13 @@ public class ProgressAGo : ProgressData {
/// </summary>
[IgnoreDataMember]
private int sortieMax { get { return 36; } }

/// <summary>
/// 達成に必要なS勝利回数
/// </summary>
[IgnoreDataMember]
private int sWinMax { get { return 6; } }

/// <summary>
/// 達成に必要なボス戦闘回数
/// </summary>
Expand Down Expand Up @@ -209,14 +210,15 @@ public void IncrementBattle( string rank, bool isBoss ) {


public override string ToString() {
return string.Format( "{0:p1} (出撃 {1}/{2}, S勝利 {3}/{4}, ボス {5}/{6}, ボス勝利 {7}/{8})",
ProgressPercentage,
sortieCount, sortieMax,
sWinCount, sWinMax,
bossCount, bossMax,
bossWinCount, bossWinMax );
var list = new List<DSPair>();
list.Add( new DSPair( Math.Min( (double)sortieCount / sortieMax, 1.0 ), string.Format( "出撃 {0}/{1}", sortieCount, sortieMax ) ) );
list.Add( new DSPair( Math.Min( (double)sWinCount / sWinMax, 1.0 ), string.Format( "S勝利 {0}/{1}", sWinCount, sWinMax ) ) );
list.Add( new DSPair( Math.Min( (double)bossCount / bossMax, 1.0 ), string.Format( "ボス {0}/{1}", bossCount, bossMax ) ) );
list.Add( new DSPair( Math.Min( (double)bossWinCount / bossWinMax, 1.0 ), string.Format( "ボス勝利 {0}/{1}", bossWinCount, bossWinMax ) ) );

var slist = list.Where( elem => elem.Key < 1.0 ).OrderBy( elem => elem.Key ).Select( elem => elem.Value );
return string.Format( "{0:p1} ({1})", ProgressPercentage, slist.Count() > 0 ? string.Join( ", ", slist ) : "達成" );
}

}

}
12 changes: 12 additions & 0 deletions ElectronicObserver/Data/QuestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,24 @@ public override void LoadFromResponse( string apiname, dynamic data ) {

//周期任務削除
if ( DateTimeHelper.IsCrossedDay( _prevTime, 5, 0, 0 ) ) {
KCDatabase.Instance.QuestProgress.Progresses.RemoveAll( p => {
var q = Quests[p.QuestID];
return q != null && ( q.Type == 2 || q.Type == 4 || q.Type == 5 );
} );
Quests.RemoveAll( q => q.Type == 2 || q.Type == 4 || q.Type == 5 );
}
if ( DateTimeHelper.IsCrossedWeek( _prevTime, DayOfWeek.Monday, 5, 0, 0 ) ) {
KCDatabase.Instance.QuestProgress.Progresses.RemoveAll( p => {
var q = Quests[p.QuestID];
return q != null && ( q.Type == 3 );
} );
Quests.RemoveAll( q => q.Type == 3 );
}
if ( DateTimeHelper.IsCrossedMonth( _prevTime, 1, 5, 0, 0 ) ) {
KCDatabase.Instance.QuestProgress.Progresses.RemoveAll( p => {
var q = Quests[p.QuestID];
return q != null && ( q.Type == 6 );
} );
Quests.RemoveAll( q => q.Type == 6 );
}

Expand Down
2 changes: 1 addition & 1 deletion ElectronicObserver/Data/ShipGroupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ShipGroupManager : DataStorage {

[DataMember]
private IEnumerable<ShipGroupData> ShipGroupsSerializer {
get { return ShipGroups.Values; }
get { return ShipGroups.Values.OrderBy( g => g.ID ); }
set { ShipGroups = new IDDictionary<ShipGroupData>( value ); }
}

Expand Down
11 changes: 11 additions & 0 deletions ElectronicObserver/ElectronicObserver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms.DataVisualization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -155,6 +156,7 @@
<Compile Include="Notifier\NotifierRepair.cs" />
<Compile Include="Notifier\NotifierExpedition.cs" />
<Compile Include="Notifier\NotifierManager.cs" />
<Compile Include="Observer\APIKancolleDB.cs" />
<Compile Include="Observer\kcsapi\api_get_member\material.cs" />
<Compile Include="Observer\kcsapi\api_get_member\ship_deck.cs" />
<Compile Include="Observer\kcsapi\api_req_kaisou\marriage.cs" />
Expand Down Expand Up @@ -328,6 +330,12 @@
<Compile Include="Window\Dialog\DialogNotifier.Designer.cs">
<DependentUpon>DialogNotifier.cs</DependentUpon>
</Compile>
<Compile Include="Window\Dialog\DialogResourceChart.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Window\Dialog\DialogResourceChart.Designer.cs">
<DependentUpon>DialogResourceChart.cs</DependentUpon>
</Compile>
<Compile Include="Window\Dialog\DialogShipGroupColumnFilter.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -519,6 +527,9 @@
<EmbeddedResource Include="Window\Dialog\DialogNotifier.resx">
<DependentUpon>DialogNotifier.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Window\Dialog\DialogResourceChart.resx">
<DependentUpon>DialogResourceChart.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Window\Dialog\DialogShipGroupColumnFilter.resx">
<DependentUpon>DialogShipGroupColumnFilter.cs</DependentUpon>
</EmbeddedResource>
Expand Down
133 changes: 133 additions & 0 deletions ElectronicObserver/Observer/APIKancolleDB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using ElectronicObserver.Utility;
using Fiddler;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;

namespace ElectronicObserver.Observer {

/// <summary>
/// 艦これ統計データベースへのデータ送信処理を行います。
/// </summary>
/// <remarks>http://kancolle-db.net/</remarks>
public class APIKancolleDB {


private static readonly HashSet<string> apis = new HashSet<string>() {
"/kcsapi/api_port/port" ,
"/kcsapi/api_get_member/ship2" ,
"/kcsapi/api_get_member/ship3" ,
"/kcsapi/api_get_member/kdock" ,
"/kcsapi/api_req_hensei/change" ,
"/kcsapi/api_req_kousyou/createship" ,
"/kcsapi/api_req_kousyou/getship" ,
"/kcsapi/api_req_kousyou/createitem" ,
"/kcsapi/api_req_sortie/battleresult" ,
"/kcsapi/api_req_combined_battle/battleresult",
};


public APIKancolleDB() {

Utility.Configuration.Instance.ConfigurationChanged += ConfigurationChanged;
ConfigurationChanged();

// to avoid http 417 error
ServicePointManager.Expect100Continue = false;

}

private void ConfigurationChanged() {
OAuth = Utility.Configuration.Config.Connection.SendKancolleOAuth;

if ( Utility.Configuration.Config.Connection.UseUpstreamProxy ) {
Proxy = new WebProxy( "127.0.0.1", Utility.Configuration.Config.Connection.Port );
} else {
Proxy = null;
}
}

private string OAuth;
private WebProxy Proxy;


/// <summary>
/// read the after-session, determinate whether it will send to kancolle-db.net
/// </summary>
public void ExecuteSession( Session oSession ) {

if ( string.IsNullOrEmpty( OAuth ) ) {
return;
}

// find the url in dict.
string url = oSession.PathAndQuery;

if ( apis.Contains( url ) ) {
PostToServer( oSession );
}

}

private static Regex RequestRegex = new Regex( @"&api(_|%5F)token=[0-9a-f]+|api(_|%5F)token=[0-9a-f]+&?", RegexOptions.Compiled );

private void PostToServer( Session oSession ) {

string oauth = OAuth;
string url = oSession.fullUrl;
string request = oSession.GetRequestBodyAsString();
string response = oSession.GetResponseBodyAsString();

request = RequestRegex.Replace( request, "" );

try {

//*
using ( System.Net.WebClient wc = new System.Net.WebClient() ) {
wc.Headers["User-Agent"] = "ElectronicObserver/v" + SoftwareInformation.VersionEnglish;

if ( Proxy != null ) {
wc.Proxy = Proxy;
}

System.Collections.Specialized.NameValueCollection post = new System.Collections.Specialized.NameValueCollection();
post.Add( "token", oauth );
// agent key for 'ElectronicObserver'
// https://github.com/about518/kanColleDbPost/issues/3#issuecomment-105534030
post.Add( "agent", "L57Mi4hJeCYinbbBSH5K" );
post.Add( "url", url );
post.Add( "requestbody", request );
post.Add( "responsebody", response );

wc.UploadValuesCompleted += ( sender, e ) => {
if ( e.Error != null ) {

// 結構頻繁に出るのでレポートは残さない方針で 申し訳ないです
//Utility.ErrorReporter.SendErrorReport( e.Error, string.Format( "艦これ統計データベースへの {0} の送信に失敗しました。", url.Substring( url.IndexOf( "/api" ) + 1 ) ) );

Utility.Logger.Add( 3, string.Format( "艦これ統計データベースへの {0} の送信に失敗しました。{1}", url.Substring( url.IndexOf( "/api" ) + 1 ), e.Error.Message ) );

} else {
Utility.Logger.Add( 1, string.Format( "艦これ統計データベースへ {0} を送信しました。", url.Substring( url.IndexOf( "/api" ) + 1 ) ) );
}
};

wc.UploadValuesAsync( new Uri( "http://api.kancolle-db.net/2/" ), post );
}
//*/

} catch ( Exception ex ) {

Utility.ErrorReporter.SendErrorReport( ex, "艦これ統計データベースへの送信中にエラーが発生しました。" );
}

}

}
}
10 changes: 9 additions & 1 deletion ElectronicObserver/Observer/APIObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static APIObserver Instance {
#endregion


public APIDictionary APIList;
public APIDictionary APIList { get; private set; }

public string ServerAddress { get; private set; }
public int ProxyPort { get { return Fiddler.FiddlerApplication.oProxy.ListenPort; } }
Expand All @@ -38,6 +38,7 @@ public static APIObserver Instance {
public event ProxyStartedEventHandler ProxyStarted = delegate { };

private Control UIControl;
private APIKancolleDB DBSender;

private APIObserver() {

Expand Down Expand Up @@ -101,6 +102,8 @@ private APIObserver() {

ServerAddress = null;

DBSender = new APIKancolleDB();

Fiddler.FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest;
Fiddler.FiddlerApplication.BeforeResponse += FiddlerApplication_BeforeResponse;
Fiddler.FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
Expand Down Expand Up @@ -248,6 +251,11 @@ private void FiddlerApplication_AfterSessionComplete( Fiddler.Session oSession )
string body = oSession.GetResponseBodyAsString();
UIControl.BeginInvoke( (Action)( () => { LoadResponse( url, body ); } ) );

// kancolle-db.netに送信する
if ( Utility.Configuration.Config.Connection.SendDataToKancolleDB ) {
Task.Run( (Action)( () => DBSender.ExecuteSession( oSession ) ) );
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
using System.Threading.Tasks;

namespace ElectronicObserver.Observer.kcsapi.api_get_member {

public class picture_book : APIBase {



public class picture_book : APIBase {

public override string APIName {
get { return "api_get_member/picture_book"; }
Expand Down
Loading

0 comments on commit c89683a

Please sign in to comment.