/// <summary> /// ファイルコンバーター /// </summary> /// <returns></returns> public void Converter() { string[] xmlFileNames = Directory.GetFiles(PATH_FISHDB); foreach (string xmlFileName in xmlFileNames) { List <string> regGroupStr = new List <string>(); if (MiscTool.GetRegexString(xmlFileName, PATH_FISHDB + "\\\\(.*)\\.xml$", out regGroupStr)) { string rodName = regGroupStr[0]; if (!_Rods.Contains(rodName)) { continue; } //最新版までコンバート for (int i = 0; i < Constants.MAX_LOOP_COUNT; i++) { string version = getXmlVersion(xmlFileName); if (string.IsNullOrEmpty(version) || version == VERSION) { break; } if (version == "1.0.0")////1.0.0→1.0.5 { logger.Info("FishDBのコンバート 1.0.0→1.0.5 {0}", xmlFileName); convert1_0_0to1_0_5(xmlFileName, rodName); } } } } }
/// <summary> /// ファイルコンバーター /// </summary> /// <returns></returns> public void Converter() { string[] xmlFileNames = Directory.GetFiles(PATH_FISHHISTORYDB); foreach (string xmlFileName in xmlFileNames) { //string filename = Path.GetFileName(xmlFileName); List <string> regGroupStr = new List <string>(); if (MiscTool.GetRegexString(xmlFileName, PATH_FISHHISTORYDB + "\\\\(.*)_([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])\\.xml$", out regGroupStr)) { string playerName = regGroupStr[0]; DateTime ymd = DateTime.Parse(string.Format("{0}/{1}/{2}", regGroupStr[1], regGroupStr[2], regGroupStr[3])); //最新版までコンバート for (int i = 0; i < Constants.MAX_LOOP_COUNT; i++) { string version = GetXmlVersion(xmlFileName); if (version == VERSION) { break; } else if (version == "1.0.0")////1.0.0→1.0.5 { logger.Info("FishHistoryDBのコンバート 1.0.0→1.0.5 {0}", xmlFileName); convert1_0_0to1_0_5(xmlFileName, playerName, ymd); } else if (version == "1.0.5")////1.0.5→1.1.0 { logger.Info("FishHistoryDBのコンバート 1.0.5→1.1.0 {0}", xmlFileName); convert1_0_5to1_1_0(xmlFileName, playerName, ymd); } } } } }
/// <summary> /// User-Agentの取得 /// </summary> /// <returns></returns> public static string GetUserAgent() { OperatingSystem os = Environment.OSVersion; string ret = MiscTool.GetAppTitle() + "/" + MiscTool.GetAppVersion(); ret += string.Format("(Windows NT {0}.{1};)", os.Version.Major, os.Version.Minor); return(ret); }
/// <summary> /// チャット内容からChatKbnKindを取得する /// </summary> /// <param name="iCl">チャットライン</param> /// <returns>チャット区分</returns> private ChatKbnKind getChatKbnFromChatline(EliteAPI.ChatEntry iCl, out List <string> oArgs) { oArgs = new List <string>(); foreach (KeyValuePair <ChatKbnKind, string> v in dictionaryChat) { string searchStr = v.Value; if (MiscTool.IsRegexString(iCl.Text, searchStr)) { oArgs = MiscTool.GetRegexString(iCl.Text, searchStr); return(v.Key); } } return(ChatKbnKind.Unknown); }
static void Main(string[] args) { // エラーハンドラ Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); Thread.GetDomain().UnhandledException += new UnhandledExceptionEventHandler(Program_UnhandledException); logger.Info("===== {0} {1} =====", MiscTool.GetAppAssemblyName(), MiscTool.GetAppVersion()); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // POL設定 PolTool pol = new PolTool(); if (PolTool.GetPolProcess().Count < 1) { string msg = "FF11を起動してください。"; logger.Warn(msg); MessageBox.Show(msg, MiscTool.GetAppTitle(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); System.Environment.Exit(1); // プログラム終了 } if (!pol.NewPol()) { System.Environment.Exit(1); // プログラム終了 } if (pol.EliteAPI.Player.LoginStatus != (int)LoginStatus.LoggedIn) { string msg = "キャラクター選択後に起動してください。"; logger.Warn(msg); MessageBox.Show(msg, MiscTool.GetAppTitle(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); System.Environment.Exit(1); // プログラム終了 } // シフトキーでテストフォーム表示 if (Control.ModifierKeys == Keys.Shift) { logger.Info("EliteAPIテストモードで起動"); //テストモード EliteAPITestForm testForm = new EliteAPITestForm(pol); testForm.ShowDialog(); System.Environment.Exit(0); // プログラム終了 } // ResourceTool var resource = new ResourceTool(pol.EliteAPI); // メインフォーム表示 MainForm mainForm = new MainForm(pol, resource); mainForm.ShowDialog(); }
public static bool authenticate(NFC.nfc_device pnd, NFC.nfc_target pnt, uint uiBlock, byte[] key, mifare_cmd mc) { mifare_param mp = new mifare_param(); // Set the authentication information (uid) MiscTool.memcpy(mp.mpa.abtAuthUid, 0, pnt.nti.nai.abtUid, pnt.nti.nai.szUidLen - 4, 4); MiscTool.memcpy(mp.mpa.abtKey, 0, key, 0, 6); if (nfc_initiator_mifare_cmd(pnd, mc, (byte)uiBlock, mp)) { return(true); } if (NFC.nfc_initiator_select_passive_target(pnd, nmMfClassic, pnt.nti.nai.abtUid, pnt.nti.nai.szUidLen, null) <= 0) { //ERR("tag was removed"); return(false); } return(true); }
/// <summary> /// エミネンスを取得する /// </summary> /// <param name="iSearchString">エミネンス名</param> /// <returns>装備の一覧</returns> public List <EminenceDBEminenceModel> SelectEminence(string iSearchString) { logger.Trace("SearchString={0}", iSearchString); List <EminenceDBEminenceModel> ret = new List <EminenceDBEminenceModel>(); EminenceDBModel eminenceDB = getEminenceDB(); if (iSearchString == string.Empty) { ret = eminenceDB.Eminences; } else { foreach (EminenceDBEminenceModel eminences in eminenceDB.Eminences) { if (MiscTool.IsRegexString(eminences.EminenceName, iSearchString)) { ret.Add(eminences); } } } return(ret); }
/// <summary> /// 餌を取得する /// </summary> /// <param name="iSearchString">餌名称(正規表現)</param> /// <returns>餌の一覧</returns> public List <BaitDBBaitModel> SelectBait(string iSearchString) { logger.Trace("SearchString={0}", iSearchString); List <BaitDBBaitModel> ret = new List <BaitDBBaitModel>(); BaitDBModel Baitdb = getBaitDB(); if (iSearchString == string.Empty) { ret = Baitdb.Bait; } else { foreach (BaitDBBaitModel Bait in Baitdb.Bait) { if (MiscTool.IsRegexString(Bait.BaitName, iSearchString)) { ret.Add(Bait); } } } ret.Sort(BaitDBModel.SortTypeName); return(ret); }
/// <summary> /// 竿を取得する /// </summary> /// <param name="iSearchString">竿名称(正規表現)</param> /// <returns>竿の一覧</returns> public List <RodDBRodModel> SelectRod(string iSearchString) { logger.Trace("SearchString={0}", iSearchString); List <RodDBRodModel> ret = new List <RodDBRodModel>(); RodDBModel roddb = getRodDB(); if (iSearchString == string.Empty) { ret = roddb.Rod; } else { foreach (RodDBRodModel rod in roddb.Rod) { if (MiscTool.IsRegexString(rod.RodName, iSearchString)) { ret.Add(rod); } } } ret.Sort(RodDBModel.SortTypeName); return(ret); }
public void FillRawData(byte[] dst, int offset) { MiscTool.memcpy(dst, offset, abtValue, 0, abtValue.Length); }
public void FillRawData(byte[] dst, int offset) { MiscTool.memcpy(dst, offset, abtKey, 0, abtKey.Length); offset += abtKey.Length; MiscTool.memcpy(dst, offset, abtAuthUid, 0, abtAuthUid.Length); }
nfc_initiator_mifare_cmd(NFCInternal.nfc_device pnd, mifare_cmd mc, byte ui8Block, mifare_param pmp) { byte[] abtRx = new byte[265]; byte szParamLen; byte[] abtCmd = new byte[265]; //bool bEasyFraming; abtCmd[0] = (byte)mc; // The MIFARE Classic command abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff) switch (mc) { // Read and store command have no parameter case mifare_cmd.MC_READ: case mifare_cmd.MC_STORE: szParamLen = 0; break; // Authenticate command case mifare_cmd.MC_AUTH_A: case mifare_cmd.MC_AUTH_B: szParamLen = (byte)pmp.mpa.Length(); //sizeof( mifare_param_auth); if (szParamLen > 0) { pmp.mpa.FillRawData(abtCmd, 2); } break; // Data command case mifare_cmd.MC_WRITE: szParamLen = (byte)pmp.mpd.Length(); //sizeof( mifare_param_data); if (szParamLen > 0) { pmp.mpd.FillRawData(abtCmd, 2); } break; // Value command case mifare_cmd.MC_DECREMENT: case mifare_cmd.MC_INCREMENT: case mifare_cmd.MC_TRANSFER: szParamLen = (byte)pmp.mpv.Length(); //sizeof( mifare_param_value); if (szParamLen > 0) { pmp.mpv.FillRawData(abtCmd, 2); } break; // Please fix your code, you never should reach this statement default: return(false); break; } // FIXME: Save and restore bEasyFraming // bEasyFraming = nfc_device_get_property_bool (pnd, NP_EASY_FRAMING, &bEasyFraming); if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_EASY_FRAMING, true) < 0) { //nfc_perror(pnd, "nfc_device_set_property_bool"); return(false); } // Fire the mifare command int res; if ((res = NFC.nfc_initiator_transceive_bytes(pnd, abtCmd, 2 + szParamLen, abtRx, abtRx.Length, -1)) < 0) { if (res == NFC.NFC_ERFTRANS) { // "Invalid received frame", usual means we are // authenticated on a sector but the requested MIFARE cmd (read, write) // is not permitted by current acces bytes; // So there is nothing to do here. } else { //nfc_perror(pnd, "nfc_initiator_transceive_bytes"); } // XXX nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming); return(false); } /* XXX * if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming) < 0) { * nfc_perror (pnd, "nfc_device_set_property_bool"); * return false; * } */ // When we have executed a read command, copy the received bytes into the param if (mc == mifare_cmd.MC_READ) { if (res == 16) { MiscTool.memcpy(pmp.mpd.abtData, 0, abtRx, 0, 16); } else { return(false); } } // Command succesfully executed return(true); }
write_card(int write_block_zero) { uint uiBlock; bool bFailure = false; uint uiWriteBlocks = 0; if (write_block_zero != 0) { if (!unlock_card()) { return(false); } } //printf("Writing %d blocks |", uiBlocks + 1); // Write the card from begin to end; for (uiBlock = 0; uiBlock <= uiBlocks; uiBlock++) { // Authenticate everytime we reach the first sector of a new block if (is_first_block(uiBlock)) { if (bFailure) { // When a failure occured we need to redo the anti-collision if (NFC.nfc_initiator_select_passive_target(pnd, nmMifare, null, 0, nt) <= 0) { //printf("!\nError: tag was removed\n"); return(false); } bFailure = false; } //fflush(stdout); // Try to authenticate for the current sector if (0 == write_block_zero && !authenticate(uiBlock)) { //printf("!\nError: authentication failed for block %02x\n", uiBlock); return(false); } } if (is_trailer_block(uiBlock)) { if (bFormatCard) { // Copy the default key and reset the access bits MiscTool.memcpy(mp.mpd.abtData, 0, default_key, 0, 6); MiscTool.memcpy(mp.mpd.abtData, 6, default_acl, 0, 4); MiscTool.memcpy(mp.mpd.abtData, 10, default_key, 0, 6); } else { // Copy the keys over from our key dump and store the retrieved access bits MiscTool.memcpy(mp.mpd.abtData, 0, mtDump.amb[uiBlock].mbt.abtKeyA, 0, 6); MiscTool.memcpy(mp.mpd.abtData, 6, mtDump.amb[uiBlock].mbt.abtAccessBits, 0, 4); MiscTool.memcpy(mp.mpd.abtData, 10, mtDump.amb[uiBlock].mbt.abtKeyB, 0, 6); } // Try to write the trailer if (Mifare.nfc_initiator_mifare_cmd(pnd, Mifare.mifare_cmd.MC_WRITE, (byte)uiBlock, mp) == false) { //printf("failed to write trailer block %d \n", uiBlock); bFailure = true; } } else { // The first block 0x00 is read only, skip this if (uiBlock == 0 && 0 == write_block_zero && !magic2) { continue; } // Make sure a earlier write did not fail if (!bFailure) { // Try to write the data block if (bFormatCard && uiBlock != 0) { MiscTool.memset(mp.mpd.abtData, 0x00, 16); } else { MiscTool.memcpy(mp.mpd.abtData, 0, mtDump.amb[uiBlock].mbd.abtData, 0, 16); } // do not write a block 0 with incorrect BCC - card will be made invalid! if (uiBlock == 0) { if ((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00 && !magic2) { //printf("!\nError: incorrect BCC in MFD file!\n"); //printf("Expecting BCC=%02X\n", mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3]); return(false); } } if (!Mifare.nfc_initiator_mifare_cmd(pnd, Mifare.mifare_cmd.MC_WRITE, (byte)uiBlock, mp)) { bFailure = true; } } } // Show if the write went well for each block print_success_or_failure(bFailure, ref uiWriteBlocks); if ((!bTolerateFailures) && bFailure) { return(false); } } //printf("|\n"); //printf("Done, %d of %d blocks written.\n", uiWriteBlocks, uiBlocks + 1); //fflush(stdout); return(true); }
/// <summary> /// 装備を取得する /// </summary> /// <param name="iSearchString">餌名称(正規表現)</param> /// <returns>装備の一覧</returns> public List <GearDBGearModel> SelectGear(string iSearchString, GearDBPositionKind iPosition) { logger.Trace("SearchString={0}", iSearchString); List <GearDBGearModel> ret = new List <GearDBGearModel>(); GearDBModel gearDB = getGearDB(); if (iSearchString == string.Empty && iPosition == GearDBPositionKind.Unknown) { ret = gearDB.Gear; } else { foreach (GearDBGearModel gear in gearDB.Gear) { if ((iSearchString != string.Empty && iPosition != GearDBPositionKind.Unknown && MiscTool.IsRegexString(gear.GearName, iSearchString) && gear.Position == iPosition) || (iSearchString != string.Empty && iPosition == GearDBPositionKind.Unknown && MiscTool.IsRegexString(gear.GearName, iSearchString)) || (iSearchString == string.Empty && iPosition != GearDBPositionKind.Unknown && gear.Position == iPosition)) { ret.Add(gear); } } } ret.Sort(GearDBModel.SortTypeName); return(ret); }
public void EnumJsonTypes(Action <string, Type> typeFunc) { MiscTool.RegisterAllJsonTypes(typeof(DbShellXmlElementsProvider).Assembly, "DbShell.Xml", typeFunc); }
private object ConvertNode(ParseTreeNode node) { switch (node.Term.Name) { case "CommandList": var batch = new Batch(); ConvertCommandList(batch.Commands, node.ChildNodes); return(batch); case "true": return(true); case "false": return(true); case string s when s.StartsWith("string"): return(node.Token.ValueString); case "Command": if (node.ChildNodes[0].Term.Name == "Assign") { return(ConvertNode(node.ChildNodes[0])); } string typeName = node.ChildNodes[0].Token.Text; var type = _elementFactory.JsonBinder.BindToType(null, typeName); if (type == null) { throw new Exception($"Json type {typeName} not defined"); } var instance = Activator.CreateInstance(type); if (node.ChildNodes[1].Term.Name == "CommandValue") { var singleHolder = instance as ISingleValueDbShellObject; object propValue = ConvertNode(node.ChildNodes[1].ChildNodes[0]); if (singleHolder is null) { throw new Exception($"DBSH-00000 Type {instance.GetType().Name} does not allow parameter without name"); } singleHolder.SingleValue = propValue; } else { foreach (var paramNode in node.ChildNodes[1].ChildNodes) { string propName = MiscTool.ToPascalCase(paramNode.ChildNodes[0].Token.Text); var valueNode = paramNode.ChildNodes[1].ChildNodes[0]; object propValue = ConvertNode(valueNode); var prop = type.GetProperty(propName); if (prop == null) { _logger.LogWarning("Type {type} has not property {property}", typeName, propName); continue; } if (propValue is string propValueString) { if (prop.PropertyType.IsEnum) { propValue = Enum.Parse(prop.PropertyType, propValueString); } if (prop.PropertyType == typeof(char)) { propValue = propValueString.Length > 0 ? propValueString[0] : ' '; } } prop.SetValue(instance, propValue); } } foreach (var subnode in node.ChildNodes[2].ChildNodes) { IList collection = null; if (subnode.ChildNodes.Count == 2) { string propName = MiscTool.ToPascalCase(subnode.ChildNodes[0].Token.Text); var propInfo = type.GetProperty(propName); collection = (IList)propInfo.GetValue(instance); } else { var provider = instance as IDefaultCollectionProvider; if (provider == null) { throw new Exception($"DBSH-00000 Type {typeName} has no default collection provider"); } collection = provider.DefaultCollection; } if (collection == null) { throw new Exception($"DBSH-00000 Type {typeName} has collection not set"); } foreach (var propNode in subnode.ChildNodes.Last().ChildNodes) { var converted = ConvertNode(propNode); collection.Add(converted); } } return(instance); case "Assign": string varName = node.ChildNodes[0].Token.Text; string strExpr = node.ChildNodes[1].Token.ValueString; return(new SetVariable { Name = varName, Value = strExpr, }); } return(new Batch()); }
/// <summary> /// データベース更新処理 /// </summary> public bool UpdateDB() { logger.Debug("DB更新開始"); string response = string.Empty; bool httpRet = false; //アプリケーションバージョンチェック EventReceiveMessage("== クライアントのバージョンチェック ==", 0xFFFFFFFF, true); NameValueCollection postCheckVersion = new NameValueCollection(); postCheckVersion.Add("version", MiscTool.GetAppVersion()); string responseCheckVersion = string.Empty; bool retCheckVersion = HttpPost(serverName + URL_API_CHECK_VERSION, postCheckVersion, out responseCheckVersion); if (!retCheckVersion) { EventReceiveMessage(responseCheckVersion, 0xFFFF0000); return(false); } XmlSerializer seriApiCheckVersion = new XmlSerializer(typeof(UpdateDBApiCheckVersionModel)); MemoryStream msApiCheckVersion = new MemoryStream(Encoding.UTF8.GetBytes(responseCheckVersion)); var resCheckVersion = (UpdateDBApiCheckVersionModel)seriApiCheckVersion.Deserialize(msApiCheckVersion); if (resCheckVersion.Result.Success == "true") { //有効バージョンか? if (resCheckVersion.VersionEnable == "true") { //新しいバージョンがリリースされているか? if (resCheckVersion.NewVersionExists != "true") { //最新バージョンを使用 EventReceiveMessage(resCheckVersion.Message); } else { //新しいバージョンがある EventReceiveMessage(resCheckVersion.Message, 0xFFFF0000); //イベント発生 EventNewerVersion(resCheckVersion.Message, resCheckVersion.NewVersionUrl); } } else { //無効なバージョン EventReceiveMessage(resCheckVersion.Message, 0xFFFF0000); //イベント発生 EventNewerVersion(resCheckVersion.Message, resCheckVersion.NewVersionUrl); return(false); } } else { EventReceiveMessage(resCheckVersion.Result.Message, 0xFFFF0000); return(false); } //有効名称データの取得 EventReceiveMessage("== チェックデータを取得 ==", 0xFFFFFFFF, true); //有効名称データの受信 response = string.Empty; httpRet = Http(serverName + URL_API_ENABLE_NAME, out response); UpdateDBApiEnableNameModel enablename = new UpdateDBApiEnableNameModel(); if (httpRet) { XmlSerializer serializer = new XmlSerializer(typeof(UpdateDBApiEnableNameModel)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response)); enablename = (UpdateDBApiEnableNameModel)serializer.Deserialize(ms); if (enablename.Result.Success != "true") { //イベント発生 EventReceiveMessage(string.Format("{0}", enablename.Result.Message), 0xFFFF0000); return(false); } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", response), 0xFFFF0000); return(false); } //履歴データの送信 EventReceiveMessage("== 履歴データの送信 ==", 0xFFFFFFFF, true); string[] xmlFileNames = Directory.GetFiles(FishHistoryDB.PATH_FISHHISTORYDB); foreach (string xmlFileName in xmlFileNames) { string filename = Path.GetFileName(xmlFileName); List <string> regGroupStr = new List <string>(); if (MiscTool.GetRegexString(xmlFileName, FishHistoryDB.PATH_FISHHISTORYDB + "\\\\(.*)_([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])\\.xml$", out regGroupStr)) { string playerName = regGroupStr[0]; DateTime ymd = DateTime.Parse(string.Format("{0}/{1}/{2}", regGroupStr[1], regGroupStr[2], regGroupStr[3])); //アップロード対象か? FishHistoryDBModel history = historyDB.GetHistoryDB(playerName, ymd); if (!history.Uploaded) { //XMLからプレイヤー情報を消去する history = historyDB.GetHistoryDB(playerName, ymd); history.PlayerName = DUMMY_PLAYER_NAME; //名称チェック 魚 var uploadFishes = new List <FishHistoryDBFishModel>(); foreach (var fish in history.Fishes) { if (fish.Result == FishResultStatusKind.Catch) { if ( enablename.Rods.Contains(new UpdateDBApiEnableNameRodModel(fish.RodName)) && (fish.FishName.Length == 0 | enablename.Fishes.Contains(new UpdateDBApiEnableNameFishModel(fish.FishName))) && enablename.Zones.Contains(new UpdateDBApiEnableNameZoneModel(fish.ZoneName)) && enablename.Baits.Contains(new UpdateDBApiEnableNameBaitModel(fish.BaitName))) { uploadFishes.Add(fish); } } else { uploadFishes.Add(fish); } } history.Fishes = uploadFishes; //名称チェック ハラキリ var uploadHarakiri = new List <FishHistoryDBHarakiriModel>(); foreach (var harakiri in history.Harakiri) { if (enablename.Fishes.Contains(new UpdateDBApiEnableNameFishModel(harakiri.FishName)) && (harakiri.ItemName.Length == 0 | enablename.HarakiriItems.Contains(new UpdateDBApiEnableNameHarakiriItemModel(harakiri.ItemName)))) { uploadHarakiri.Add(harakiri); } } history.Harakiri = uploadHarakiri; //一時ディレクトリにXMLファイルを保存 historyDB.PutHistoryDB(DUMMY_PLAYER_NAME, history, Constants.PATH_TEMP); string uploadFileName = historyDB.GetXmlName(DUMMY_PLAYER_NAME, ymd, Constants.PATH_TEMP); logger.Debug("コピー {0}→{1}", filename, uploadFileName); //ファイルアップロード logger.Debug("{0}を送信中", uploadFileName); EventReceiveMessage(string.Format("{0}をアップロード", filename)); NameValueCollection nvc = new NameValueCollection(); response = string.Empty; httpRet = HttpUploadFile(serverName + URL_API_UPLOAD_HISTORY, uploadFileName, "upfile", "application/xml", nvc, out response); logger.Trace("Response:\r{0}", response); if (httpRet) { //レスポンスを取得 XmlSerializer serializer = new XmlSerializer(typeof(UpdateDBApiUploadHistoryModel)); //byte[] bres = Encoding.UTF8.GetBytes(response); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response)); var res = (UpdateDBApiUploadHistoryModel)serializer.Deserialize(ms); //HistoryDBを送信済みにする FishHistoryDBModel history2 = historyDB.GetHistoryDB(playerName, ymd); history2.Uploaded = true; historyDB.PutHistoryDB(playerName, history2); //エラー発生 if (res.Result.Success != "true") { //イベント発生 EventReceiveMessage(string.Format("{0}", res.Result.Message), 0xFFFF0000); } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", response), 0xFFFF0000); } //テンポラリファイル削除 if (File.Exists(uploadFileName)) { File.Delete(uploadFileName); } } } } //魚情報を取得 EventReceiveMessage("== 魚情報を取得 ==", 0xFFFFFFFF, true); //ステータスの受信 response = string.Empty; httpRet = Http(serverName + URL_API_STATUS, out response); UpdateDBApiStatusModel status = new UpdateDBApiStatusModel(); if (httpRet) { XmlSerializer serializer = new XmlSerializer(typeof(UpdateDBApiStatusModel)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response)); status = (UpdateDBApiStatusModel)serializer.Deserialize(ms); if (status.Result.Success == "true") { foreach (UpdateDBApiStatusStatusModel rod in status.Status) { logger.Info("竿:{0} 更新日:{1}", rod.RodName, rod.LastUpdate); if (!File.Exists(Path.Combine(FishDB.PATH_FISHDB, rod.RodName + ".xml")) || DateTime.Parse(rod.LastUpdate) > DateTime.Parse(settings.Global.UpdateDB.LastUpdate)) { //竿魚情報取得 EventReceiveMessage(string.Format("{0}のダウンロード", rod.RodName)); string url = serverName + URL_API_ROD + "/" + WebUtility.HtmlEncode(rod.RodName); string response2 = string.Empty; bool httpRet2 = Http(url, out response2); //登録処理 if (httpRet2) { XmlSerializer serializer2 = new XmlSerializer(typeof(UpdateDBApiRodModel)); MemoryStream ms2 = new MemoryStream(Encoding.UTF8.GetBytes(response2)); var res2 = (UpdateDBApiRodModel)serializer2.Deserialize(ms2); if (res2.Result.Success == "true") { foreach (FishDBFishModel fish in res2.Rod.Fishes) { //IDの追加 foreach (var id in fish.IDs) { FishDBIdModel idm = new FishDBIdModel(id.ID1, id.ID2, id.ID3, id.ID4, id.Count, id.Critical, id.ItemType); fishDB.AddFish(res2.Rod.RodName, fish.FishName, fish.FishType, idm, fish.ZoneNames[0], fish.BaitNames[0]); } //エリアの追加 foreach (var zone in fish.ZoneNames) { FishDBIdModel idm = new FishDBIdModel(fish.IDs[0].ID1, fish.IDs[0].ID2, fish.IDs[0].ID3, fish.IDs[0].ID4, fish.IDs[0].Count, fish.IDs[0].Critical, fish.IDs[0].ItemType); fishDB.AddFish(res2.Rod.RodName, fish.FishName, fish.FishType, idm, zone, fish.BaitNames[0]); } //エサの追加 foreach (var bait in fish.BaitNames) { FishDBIdModel idm = new FishDBIdModel(fish.IDs[0].ID1, fish.IDs[0].ID2, fish.IDs[0].ID3, fish.IDs[0].ID4, fish.IDs[0].Count, fish.IDs[0].Critical, fish.IDs[0].ItemType); fishDB.AddFish(res2.Rod.RodName, fish.FishName, fish.FishType, idm, fish.ZoneNames[0], bait); } } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", res2.Result.Message), 0xFFFF0000); } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", response2), 0xFFFF0000); } } Thread.Sleep(1); } } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", response), 0xFFFF0000); return(false); } //最終更新日の設定 settings.Global.UpdateDB.LastUpdate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); EventReceiveMessage("データベースの更新が完了しました", 0xFFFFFFFF, true); logger.Debug("DB更新終了"); return(true); }
authenticate(uint uiBlock) { Mifare.mifare_cmd mc; uint uiTrailerBlock; // Set the authentication information (uid) MiscTool.memcpy(mp.mpa.abtAuthUid, 0, nt.nti.nai.abtUid, nt.nti.nai.szUidLen - 4, 4); // Should we use key A or B? mc = (bUseKeyA) ? Mifare.mifare_cmd.MC_AUTH_A : Mifare.mifare_cmd.MC_AUTH_B; // Key file authentication. if (bUseKeyFile) { // Locate the trailer (with the keys) used for this sector uiTrailerBlock = get_trailer_block(uiBlock); // Extract the right key from dump file if (bUseKeyA) { MiscTool.memcpy(mp.mpa.abtKey, 0, mtKeys.amb[uiTrailerBlock].mbt.abtKeyA, 0, 6); } else { MiscTool.memcpy(mp.mpa.abtKey, 0, mtKeys.amb[uiTrailerBlock].mbt.abtKeyB, 0, 6); } // Try to authenticate for the current sector if (Mifare.nfc_initiator_mifare_cmd(pnd, mc, (byte)uiBlock, mp)) { return(true); } } // If formatting or not using key file, try to guess the right key if (bFormatCard || !bUseKeyFile) { for (int key_index = 0; key_index < num_keys; key_index++) { MiscTool.memcpy(mp.mpa.abtKey, 0, keys, (key_index * 6), 6); if (Mifare.nfc_initiator_mifare_cmd(pnd, mc, (byte)uiBlock, mp)) { if (bUseKeyA) { MiscTool.memcpy(mtKeys.amb[uiBlock].mbt.abtKeyA, 0, mp.mpa.abtKey, 0, 6); } else { MiscTool.memcpy(mtKeys.amb[uiBlock].mbt.abtKeyB, 0, mp.mpa.abtKey, 0, 6); } return(true); } if (NFC.nfc_initiator_select_passive_target(pnd, nmMifare, nt.nti.nai.abtUid, nt.nti.nai.szUidLen, null) <= 0) { //ERR("tag was removed"); return(false); } } } return(false); }
read_card(int read_unlocked) { uint iBlock; bool bFailure = false; uint uiReadBlocks = 0; if (read_unlocked != 0) { if (!unlock_card()) { return(false); } } //printf("Reading out %d blocks |", uiBlocks + 1); // Read the card from end to begin for (iBlock = uiBlocks; iBlock >= 0; iBlock--) { // Authenticate everytime we reach a trailer block if (is_trailer_block(iBlock)) { if (bFailure) { // When a failure occured we need to redo the anti-collision if (NFC.nfc_initiator_select_passive_target(pnd, nmMifare, null, 0, nt) <= 0) { //printf("!\nError: tag was removed\n"); return(false); } bFailure = false; } //fflush(stdout); // Try to authenticate for the current sector if (0 == read_unlocked && !authenticate(iBlock)) { //printf("!\nError: authentication failed for block 0x%02x\n", iBlock); return(false); } // Try to read out the trailer if (Mifare.nfc_initiator_mifare_cmd(pnd, Mifare.mifare_cmd.MC_READ, (byte)iBlock, mp)) { if (0 != read_unlocked) { MiscTool.memcpy(mtDump.amb[iBlock].mbd.abtData, 0, mp.mpd.abtData, 0, 16); } else { // Copy the keys over from our key dump and store the retrieved access bits MiscTool.memcpy(mtDump.amb[iBlock].mbt.abtKeyA, 0, mtKeys.amb[iBlock].mbt.abtKeyA, 0, 6); MiscTool.memcpy(mtDump.amb[iBlock].mbt.abtAccessBits, 0, mp.mpd.abtData, 6, 4); MiscTool.memcpy(mtDump.amb[iBlock].mbt.abtKeyB, 0, mtKeys.amb[iBlock].mbt.abtKeyB, 0, 6); } } else { //printf("!\nfailed to read trailer block 0x%02x\n", iBlock); bFailure = true; } } else { // Make sure a earlier readout did not fail if (!bFailure) { // Try to read out the data block if (Mifare.nfc_initiator_mifare_cmd(pnd, Mifare.mifare_cmd.MC_READ, (byte)iBlock, mp)) { MiscTool.memcpy(mtDump.amb[iBlock].mbd.abtData, 0, mp.mpd.abtData, 0, 16); } else { //printf("!\nError: unable to read block 0x%02x\n", iBlock); bFailure = true; } } } // Show if the readout went well for each block print_success_or_failure(bFailure, ref uiReadBlocks); if ((!bTolerateFailures) && bFailure) { return(false); } } //printf("|\n"); //printf("Done, %d of %d blocks read.\n", uiReadBlocks, uiBlocks + 1); //fflush(stdout); return(true); }
public void EnumJsonTypes(Action <string, Type> typeFunc) { MiscTool.RegisterAllJsonTypes(typeof(DbShellCsvElementsProvider).Assembly, "DbShell.Csv", typeFunc); //typeFunc("csvFile", typeof(CsvFile)); }