diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 0000000..8fea238 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,15 @@ +# pmcenter Authors + +Thanks to all the people that had made contributions to the pmcenter project: + +If you're a new contributor, feel free to add yourself to the list when committing. + +### List of pmcenter Authors + +Elepover / Elepooooover +Genteure +jimchen5209 / Jim Chen +lwl12 +milkice233 / milkice +tasi788 / 踢低吸 +U2FsdGVkX1 diff --git a/README.md b/README.md index 2bf038a..e089dcd 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ A telegram bot helping you process private messages. > - [⛵ Changing File Location](#changing-file-location) > - [🚀 Starting](#starting) > - [🔩 Commands](#commands) +> - [❔ FAQ](#faq) > - [🔺 Disclaimer](#disclaimer) ## Branches @@ -173,6 +174,8 @@ Or, use setup wizard: | `AdvancedLogging` | `Boolean` | ✓ | If enabled, pmcenter will display the code files and line number where the logging was triggered. | | `DisableTimeDisplay` | `Boolean` | ✓ | Don't display time in the logs. | | `UpdateChannel` | `String` | ✓ | Choose which update channel you prefer to. | +| `IgnoreKeyboardInterrupt` | `Boolean` | ✓ | Choose whether pmcenter should ignore Ctrl-C interrupts or not. | +| `DisableNetCore3Check` | `Boolean` | ✓ | Turn this on to hide .NET Core Runtime version warnings. | | `Statistics` | `Stats` | ✕ | Statistics data. | | `Socks5Proxies` | `Array` | ✓ | List of SOCKS5 proxies. | | `BannedKeywords` | `Array` | ✓ | Storage of banned keywords. | @@ -261,9 +264,9 @@ You can write a `systemd service` to keep it running, even after the host machin Please note: `/restart` command only works with a daemon that auto-restarts pmcenter when it exits. pmcenter cannot restart by itself. -# Known Problems +## Known Problems -## OpenSSL Compatibility Problem +### OpenSSL Compatibility Problem This problem only occurs on Linux, and will not occur on Windows. @@ -284,6 +287,34 @@ As is mentioned in issue [#33179](https://github.com/dotnet/corefx/issues/33179) 2. Upgrade to a newer (later than #34443) .NET Core 2.1 runtime. 3. Install OpenSSL 1.0. -# Disclaimer +## FAQ + +### Why are you still targeting to .NET Core 2.1? + +According to [.NET Core Support Policy](https://dotnet.microsoft.com/platform/support/policy/dotnet-core), the .NET Core 2.2 is now EOL, .NET Core 3.0 is also approaching its _End of Support Date_. As for .NET Core 3.1, which has LTS support level, it may not be as widely supported as .NET Core 2.1 (which also has LTS support level). So we finally chose .NET Core 2.1. + +The existing pmcenter code is completely compatible with .NET Core 3.1, but will not take advantage of the new features (like AOT compilation and TLS 1.3 support). + +pmcenter is planning to move to .NET Core 3.1, see [issue #25](https://github.com/Elepover/pmcenter/issues/25). + +### Why cannot I reply to anonymously forwarded messages? + +Please enable the `EnableMsgLink` option in pmcenter's configurations file. Only messages forwarded when `EnableMsgLink` option is turned on can be replied. + +For more information, refer to the [configurations](#pmcenter-settings) part. + +### Why pmcenter.json is too large? + +Maybe your pmcenter instance has saved too many Message Links, try this following command: + +`/clearmessagelinks` + +### Why pmcenter didn't restart when I use the `/restart` command? + +The `/restart` command requires a daemon process or service manager (like `systemd` in some Linux distros), it cannot be restarted by itself. Check your system's configurations. + +We also have a sample `systemd` service for you [here](https://github.com/Elepover/pmcenter/blob/master/pmcenter.service). + +## Disclaimer The program is licensed under Apache License _(Version 2.0. Dependencies are licensed under MIT License)_ and comes with **ABSOLUTELY NO WARRANTY**. By using the program in any way, you acknowledge and confirm that the developer of the program is **NOT RESPONSIBLE** for service outage, data loss or any other rare unlisted incident caused by the program. diff --git a/README_zh.md b/README_zh.md index e6d754a..ce485d5 100644 --- a/README_zh.md +++ b/README_zh.md @@ -25,6 +25,7 @@ > - [⛵ 改变文件位置](#改变文件位置) > - [🚀 启动](#启动) > - [🔩 命令](#命令) +> - [❔ 常见问题](#常见问题) > - [🔺 免责声明](#免责声明) ## 分支 @@ -175,6 +176,8 @@ docker run -d -v $(pwd)/pmcenter.json:/opt/pmcenter/pmcenter.json --restart alwa | `AdvancedLogging` | `Boolean` | ✓ | 如果启用,pmcenter 会在日志消息中附加输出时的代码文件及行号信息 | | `DisableTimeDisplay` | `Boolean` | ✓ | 不在日志中显示时间 | | `UpdateChannel` | `String` | ✓ | 选择更新频道 | +| `IgnoreKeyboardInterrupt` | `Boolean` | ✓ | 是否忽略 Ctrl-C 中断 | +| `DisableNetCore3Check` | `Boolean` | ✓ | 启用以忽略 .NET Core 运行时版本检查 | | `Statistics` | `Stats` | ✕ | 统计数据 | | `Socks5Proxies` | `Array` | ✓ | SOCKS5 代理列表 | | `BannedKeywords` | `Array` | ✓ | 屏蔽的关键字存储 | @@ -264,9 +267,9 @@ pmcenter_lang: pmcenter 语言文件路径。 请注意: `/restart` 命令仅在有有效的守护进程,且其能在 pmcenter 退出后自动将其重启的情况下工作。pmcenter 无法自行重新启动。 -# 已知问题 +## 已知问题 -## OpenSSL 1.1 兼容性问题 +### OpenSSL 1.1 兼容性问题 此问题仅在 Linux 环境下出现,与 Windows 无关。 @@ -287,7 +290,35 @@ System.Net.Http.HttpRequestException: The SSL connection could not be establishe 2. 更新 (新于 #34443) 的 .NET Core 2.1 运行时。 3. 安装 OpenSSL 1.0. -# 免责声明 +## 常见问题 + +### 为什么 pmcenter 的目标框架仍然是 .NET Core 2.1? + +根据 [.NET Core 支持政策](https://dotnet.microsoft.com/platform/support/policy/dotnet-core),.NET Core 2.2 已停止支持,.NET Core 3.0 也即将达到“终止支持日期”,至于有长期支持的 .NET Core 3.1,其支持范围可能不如同样为长期支持的 .NET Core 2.1,所以我们最终选择了 .NET Core 2.1. + +现有的 pmcenter 代码与 .NET Core 3.1 完全兼容,但无法利用其新特性 (如提前编译及 TLS 1.3 支持)。 + +pmcenter 正在准备转向 .NET Core 3.1,请参考 [issue #25](https://github.com/Elepover/pmcenter/issues/25). + +### 为什么我无法回复匿名转发的消息? + +请在 pmcenter 设置文件中启用 `EnableMsgLink` 选项。只有在 `EnableMsgLink` 选项启用后的转发的消息可以被回复。 + +如需更多信息,请参见[配置](#pmcenter-设置)部分。 + +### 为什么 pmcenter.json 这么大? + +可能您的 pmcenter 实例保存了太多的消息链接,请尝试使用以下命令: + +`/clearmessagelinks` + +### 为什么 pmcenter 在我使用 `/restart` 命令时并未重启? + +`/restart` 命令需要一个守护进程或服务管理器 (比如在一些 Linux 发行版中的 `systemd`),其无法自行重启,请检查您的系统设置。 + +我们也[在此](https://github.com/Elepover/pmcenter/blob/master/pmcenter.service)为您提供了一份示例 `systemd` 服务文件。 + +## 免责声明 很抱歉,但鉴于某些事件,我们实在不得不加入这个章节,以至于独立成一个 commit 来提交。 diff --git a/locales/pmcenter_locale_en.json b/locales/pmcenter_locale_en.json index 2d33045..5974282 100644 --- a/locales/pmcenter_locale_en.json +++ b/locales/pmcenter_locale_en.json @@ -1,5 +1,5 @@ { - "TargetVersion": "1.9.1.271", + "TargetVersion": "1.9.280.15", "LangCode": "en.imported", "LanguageNameInEnglish": "English", "LanguageNameInNative": "English", @@ -40,13 +40,13 @@ "Message_SysStatus_UpdateLevel_Unknown": "❓ Unknown", "Message_SysStatus_RestartRequired": "🔄 *Bot restart required to apply changes.*", "Message_SysStatus_Summary": "📝 *Device name*: `$1`\n💿 *Operating System*: `$2`\nℹ *OS description*: `$3`\n⌛ *Server uptime*: `$4`\n🕓 *Bot uptime*: `$5`\n📅 *Server time (UTC)*: `$6`\n📐 *Runtime version*: `$7`\nℹ *Runtime description*: `$8`\n📏 *Application version*: `$9`\n💠 *Processor count*: `$a`\n📖 *Language code*: `$b`\n🛫 *Update channel (current)*: `$f`\n🛬 *Update channel (target)*: `$g`\n🔄 *Update checker*: `$c`\n🔄 *Rate limit processor*: `$d`\n🔄 *Configuration reset verifier*: `$e`", - "Message_Restarting": "🔄 Restarting...\n\n_It only works with systemd daemon._", + "Message_Restarting": "🔄 Restarting...\n\n_It only works with systemd-like daemons._", "Message_NotificationsOff": "📳 Notifications are *OFF*.", "Message_NotificationsOn": "📲 Notifications are *ON*.", "Message_SupportTextMessagesOnly": "📋 Sorry... Only text messages can be forwarded in Anonymous Forward mode.", "Message_ForwarderNotReal": "ℹ The actual sender of this message is $1, whose UID is `$2`.\n\nYou can also ban this user by sending this following command:\n\n`/banid $2`\n\nTo undo this, send this command:\n\n`/pardonid $2`", "Message_GeneralFailure": "✖ Error processing request: $1", - "Message_LangVerMismatch": "⚠ Language file ($1) is not for current version ($2), consider updating language file?", + "Message_LangVerMismatch": "⚠ Language file (`$1`) is not for current version (`$2`), consider updating language file?", "Message_SwitchingLang": "💠 Switching language...", "Message_LangSwitched": "🚀 Language switched!", "Message_ThreadStatus_Unknown": "Unknown", @@ -69,5 +69,6 @@ "Message_Stats": "📝 *Statistics*\n\n💬 Received messages: `$1`\n🔄 Forwarded to owner: `$2`\n🔄 Forwarded from owner: `$3`\n🚀 Commands received: `$4`", "Message_Retracted": "✅ This message has been retracted.", "Message_MsgLinksCleared": "✅ All message links have been cleared.", - "Message_AvailableLang": "ℹ *Available languages*\n\n`$1`" + "Message_AvailableLang": "ℹ *Available languages*\n\n`$1`", + "Message_NetCore31Required": "⚠ You need `.NET Core 3.1` (runtime) installed in order to receive pmcenter v2 and further updates.\n\nLatest .NET Core runtime version detected on your device: `$1`\n\nThis warning will only show once." } \ No newline at end of file diff --git a/locales/pmcenter_locale_zh.json b/locales/pmcenter_locale_zh.json index 53286ca..4c5085c 100644 --- a/locales/pmcenter_locale_zh.json +++ b/locales/pmcenter_locale_zh.json @@ -1,5 +1,5 @@ { - "TargetVersion": "1.9.1.271", + "TargetVersion": "1.9.280.15", "LangCode": "zh.simplified", "LanguageNameInEnglish": "Chinese (Simplified)", "LanguageNameInNative": "简体中文", @@ -46,7 +46,7 @@ "Message_SupportTextMessagesOnly": "📋 抱歉,匿名转发模式下仅能转发纯文本消息。", "Message_ForwarderNotReal": "ℹ 实际消息发送者为: $1, 其 UID 为: `$2`.\n\n您也可以发送以下命令来屏蔽该用户:\n\n`/banid $2`\n\n若要撤销操作,请发送:\n\n`/pardonid $2`", "Message_GeneralFailure": "✖ 处理请求时出错: $1", - "Message_LangVerMismatch": "⚠ 语言文件 ($1) 不适用于当前版本 ($2), 请考虑升级。", + "Message_LangVerMismatch": "⚠ 语言文件 (`$1`) 不适用于当前版本 (`$2`), 请考虑升级。", "Message_SwitchingLang": "💠 正在切换语言...", "Message_LangSwitched": "🚀 语言已切换!", "Message_ThreadStatus_Unknown": "未知", @@ -69,5 +69,6 @@ "Message_Stats": "📝 *统计数据*\n\n💬 接收到的消息: `$1`\n🔄 已转发给所有者: `$2`\n🔄 从所有者处转发: `$3`\n🚀 接收到的命令: `$4`", "Message_Retracted": "✅ 消息已撤回。", "Message_MsgLinksCleared": "✅ 所有消息链接已清空。", - "Message_AvailableLang": "ℹ *可用语言*\n\n`$1`" + "Message_AvailableLang": "ℹ *可用语言*\n\n`$1`", + "Message_NetCore31Required": "⚠ 您的设备上需要安装 `.NET Core 3.1` (运行时) 以获取 pmcenter v2 或未来版本的更新。\n\n在您设备上检测到的最新 .NET Core 运行时版本为: `$1`\n\n此警告只会出现一次。" } \ No newline at end of file diff --git a/locales/pmcenter_locale_zh.meow.json b/locales/pmcenter_locale_zh.meow.json index b16c47c..421f4ae 100644 --- a/locales/pmcenter_locale_zh.meow.json +++ b/locales/pmcenter_locale_zh.meow.json @@ -1,5 +1,5 @@ { - "TargetVersion": "1.9.1.271", + "TargetVersion": "1.9.280.15", "LangCode": "zh.meow", "LanguageNameInEnglish": "Chinese (Meow)", "LanguageNameInNative": "喵体中文", @@ -46,7 +46,7 @@ "Message_SupportTextMessagesOnly": "📋 抱歉qaq, 匿名转发模式下仅能转发纯文本消息。", "Message_ForwarderNotReal": "ℹ 实际消息发送者为: $1, 其 UID 为: `$2`.\n\n主人也可以发送以下命令来拍扁该用户:\n\n`/banid $2`\n\n若要撤销操作,请发送:\n\n`/pardonid $2`", "Message_GeneralFailure": "✖ 处理请求时撞墙了qaq: $1", - "Message_LangVerMismatch": "⚠ 诶,语言文件 ($1) 好像不适用于当前版本 ($2) 呢, 要不要帮本喵升级一下呢w", + "Message_LangVerMismatch": "⚠ 诶,语言文件 (`$1`) 好像不适用于当前版本 (`$2`) 呢, 要不要帮本喵升级一下呢w", "Message_SwitchingLang": "💠 语言包马上就切换好惹w", "Message_LangSwitched": "🚀 语言包切换好啦~", "Message_ThreadStatus_Unknown": "未知", @@ -69,5 +69,6 @@ "Message_Stats": "📝 *统计数据*\n\n💬 小喵接收到的消息: `$1`\n🔄 已转发给主人: `$2`\n🔄 从主人这里转发: `$3`\n🚀 接收到的命令: `$4`", "Message_Retracted": "✅ 消息已经从主人那边撤回啦~", "Message_MsgLinksCleared": "✅ 所有消息链接都清理掉啦~", - "Message_AvailableLang": "ℹ *可用语言*\n\n`$1`" + "Message_AvailableLang": "ℹ *可用语言*\n\n`$1`", + "Message_NetCore31Required": "⚠ 您的设备上需要安装 `.NET Core 3.1` (运行时) 以获取 pmcenter v2 或未来版本的更新。\n\n在您设备上检测到的最新 .NET Core 运行时版本为: `$1`\n\n此警告只会出现一次。" } \ No newline at end of file diff --git a/locales/pmcenter_locale_zh.tw.json b/locales/pmcenter_locale_zh.tw.json index 4a3c474..0f4e478 100644 --- a/locales/pmcenter_locale_zh.tw.json +++ b/locales/pmcenter_locale_zh.tw.json @@ -1,5 +1,5 @@ { - "TargetVersion": "1.9.1.271", + "TargetVersion": "1.9.280.15", "LangCode": "zh.tw", "LanguageNameInEnglish": "Chinese (Traditional, Taiwan)", "LanguageNameInNative": "繁體中文(台灣)", @@ -46,7 +46,7 @@ "Message_SupportTextMessagesOnly": "📋 抱歉,匿名轉傳模式下僅能轉傳純文字訊息。", "Message_ForwarderNotReal": "ℹ 實際訊息發送者為: $1, 其 UID 為: `$2`.\n\n您也可以發送以下指令來封鎖該用戶:\n\n`/banid $2`\n\n若要撤銷操作,請發送:\n\n`/pardonid $2`", "Message_GeneralFailure": "✖ 處理請求時出錯: $1", - "Message_LangVerMismatch": "⚠ 語言文件 ($1) 不適用於目前版本 ($2), 請考慮升級。", + "Message_LangVerMismatch": "⚠ 語言文件 (`$1`) 不適用於目前版本 (`$2`), 請考慮升級。", "Message_SwitchingLang": "💠 正在切換語言...", "Message_LangSwitched": "🚀 語言已切換!", "Message_ThreadStatus_Unknown": "未知", @@ -69,5 +69,6 @@ "Message_Stats": "📝 *統計數據*\n\n💬 接收到的訊息: `$1`\n🔄 已轉傳給所有者: `$2`\n🔄 從所有者處轉傳: `$3`\n🚀 接收到的指令: `$4`", "Message_Retracted": "✅ 訊息已撤銷。", "Message_MsgLinksCleared": "✅ 所有訊息鏈接已清空。", - "Message_AvailableLang": "ℹ *可用語言*\n\n`$1`" + "Message_AvailableLang": "ℹ *可用語言*\n\n`$1`", + "Message_NetCore31Required": "⚠ 您的設備上需要安裝 `.NET Core 3.1` (運行時) 以獲取 pmcenter v2 或更新版本更新。\n\n在您的設備上識別到的最新 .NET Core 運行時版本為: `$1`\n\n此警告僅會出現一次。" } \ No newline at end of file diff --git a/og-banner.psd b/og-banner.psd new file mode 100644 index 0000000..ca6e675 Binary files /dev/null and b/og-banner.psd differ diff --git a/pmcenter/.editorconfig b/pmcenter/.editorconfig index 0587fe0..6f1602b 100644 --- a/pmcenter/.editorconfig +++ b/pmcenter/.editorconfig @@ -30,7 +30,7 @@ dotnet_diagnostic.CA1062.severity = suggestion # CA1707: Identifiers should not contain underscores dotnet_diagnostic.CA1707.severity = suggestion -# IDE0060: 删除未使用的参数 +# IDE0060: Delete unused arguments dotnet_code_quality_unused_parameters = all:suggestion # CA2234: Pass system uri objects instead of strings diff --git a/pmcenter/BotCommands/ResetConfCommand.cs b/pmcenter/BotCommands/ResetConfCommand.cs index 009201b..d8ed91c 100644 --- a/pmcenter/BotCommands/ResetConfCommand.cs +++ b/pmcenter/BotCommands/ResetConfCommand.cs @@ -39,7 +39,7 @@ public async Task ExecuteAsync(TelegramBotClient botClient, Update update) false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId).ConfigureAwait(false); - Environment.Exit(0); + Methods.ExitApp(0); return true; } else @@ -51,8 +51,8 @@ public async Task ExecuteAsync(TelegramBotClient botClient, Update update) false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId).ConfigureAwait(false); - Thread ConfValidator = new Thread(() => Methods.ThrDoResetConfCount()); - ConfValidator.Start(); + Vars.ConfValidator = new Thread(() => Methods.ThrDoResetConfCount()); + Vars.ConfValidator.Start(); return true; } } diff --git a/pmcenter/BotCommands/RestartCommand.cs b/pmcenter/BotCommands/RestartCommand.cs index 4e89749..9ee97a5 100644 --- a/pmcenter/BotCommands/RestartCommand.cs +++ b/pmcenter/BotCommands/RestartCommand.cs @@ -23,7 +23,7 @@ public async Task ExecuteAsync(TelegramBotClient botClient, Update update) Vars.CurrentConf.DisableNotifications, update.Message.MessageId).ConfigureAwait(false); Thread.Sleep(5000); - Environment.Exit(0); + Methods.ExitApp(0); return true; } } diff --git a/pmcenter/BotCommands/UpdateCommand.cs b/pmcenter/BotCommands/UpdateCommand.cs index dab64e9..d9a5f12 100644 --- a/pmcenter/BotCommands/UpdateCommand.cs +++ b/pmcenter/BotCommands/UpdateCommand.cs @@ -78,7 +78,7 @@ await Downloader.DownloadFileTaskAsync( Vars.CurrentConf.DisableNotifications, update.Message.MessageId).ConfigureAwait(false); Log("Exiting program... (Let the daemon do the restart job)", "BOT"); - Environment.Exit(0); + ExitApp(0); return true; // end of difference } diff --git a/pmcenter/BotProcess.cs b/pmcenter/BotProcess.cs index 8df988c..b335840 100644 --- a/pmcenter/BotProcess.cs +++ b/pmcenter/BotProcess.cs @@ -1,7 +1,7 @@ /* // BotProcess.cs / pmcenter project / https://github.com/Elepover/pmcenter // Main processing logic of pmcenter. -// Copyright (C) 2018 Elepover. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using pmcenter.Commands; @@ -16,7 +16,7 @@ namespace pmcenter { public static class BotProcess { - private static readonly CommandManager commandManager = new CommandManager(); + private static readonly CommandRouter commandManager = new CommandRouter(); static BotProcess() { diff --git a/pmcenter/CommandLines.cs b/pmcenter/CommandLineProcess.cs similarity index 85% rename from pmcenter/CommandLines.cs rename to pmcenter/CommandLineProcess.cs index 9df9dde..b9b8d0e 100644 --- a/pmcenter/CommandLines.cs +++ b/pmcenter/CommandLineProcess.cs @@ -1,7 +1,7 @@ /* // CommandLines.cs / pmcenter project / https://github.com/Elepover/pmcenter // Commandlines are processed here. -// Copyright (C) 2018 Elepover. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System.Threading.Tasks; @@ -16,6 +16,7 @@ static CmdLineProcess() { CmdLineRouter.RegisterCommand(new CommandLines.HelpCmdLine()); CmdLineRouter.RegisterCommand(new CommandLines.InfoCmdLine()); + CmdLineRouter.RegisterCommand(new CommandLines.NonServiceModeCmdLine()); CmdLineRouter.RegisterCommand(new CommandLines.SetupWizardCmdLine()); CmdLineRouter.RegisterCommand(new CommandLines.ResetCmdLine()); CmdLineRouter.RegisterCommand(new CommandLines.BackupCmdLine()); diff --git a/pmcenter/CommandLineRouter.cs b/pmcenter/CommandLineRouter.cs index a701276..9e9fd18 100644 --- a/pmcenter/CommandLineRouter.cs +++ b/pmcenter/CommandLineRouter.cs @@ -1,7 +1,7 @@ /* // CommandLineRouter.cs / pmcenter project / https://github.com/Elepover/pmcenter // Command line routing manager. -// Copyright (C) 2018 Elepover. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System; diff --git a/pmcenter/CommandLines/HelpCmdLine.cs b/pmcenter/CommandLines/HelpCmdLine.cs index 01d38a6..8556fec 100644 --- a/pmcenter/CommandLines/HelpCmdLine.cs +++ b/pmcenter/CommandLines/HelpCmdLine.cs @@ -9,7 +9,7 @@ internal class HelpCmdLine : ICmdLine { public string Prefix => "help"; public bool ExitAfterExecution => true; - private static string HelpString => "pmcenter commandline help\n--help: Display this message.\n--info: Get application information.\n--update: Update application manually.\n--backup: Backup configurations.\n--setup: Run setup wizard.\n--reset: Reset everything (use carefully)."; + private static string HelpString => "pmcenter commandline help\n--help: Display this message.\n--info: Get application information.\n--update: Update application manually.\n--backup: Backup configurations.\n--setup: Run setup wizard.\n--reset: Reset everything (use carefully).\n--noservice: Disable service mode, making pmcenter appear as always waiting for user inputs."; public Task Process() { Log("Printing commandline help...", "CMD"); diff --git a/pmcenter/CommandLines/NonServiceModeCmdLine.cs b/pmcenter/CommandLines/NonServiceModeCmdLine.cs new file mode 100644 index 0000000..1da71da --- /dev/null +++ b/pmcenter/CommandLines/NonServiceModeCmdLine.cs @@ -0,0 +1,20 @@ +using System; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +using static pmcenter.Methods; + +namespace pmcenter.CommandLines +{ + internal class NonServiceModeCmdLine : ICmdLine + { + public string Prefix => "noservice"; + public bool ExitAfterExecution => false; + public async Task Process() + { + Vars.ServiceMode = false; + Log("Service mode disabled."); + return true; + } + } +} \ No newline at end of file diff --git a/pmcenter/CommandManager.cs b/pmcenter/CommandRouter.cs similarity index 94% rename from pmcenter/CommandManager.cs rename to pmcenter/CommandRouter.cs index 6c6e1a3..cdcf9dd 100644 --- a/pmcenter/CommandManager.cs +++ b/pmcenter/CommandRouter.cs @@ -1,7 +1,7 @@ /* // CommandManager.cs / pmcenter project / https://github.com/Elepover/pmcenter // Command routing processor. -// Copyright (C) 2018 Genteure. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System; @@ -14,13 +14,13 @@ namespace pmcenter { - internal class CommandManager + internal class CommandRouter { private const char globalPrefix = '/'; private readonly List commands = new List(); - public CommandManager() + public CommandRouter() { } diff --git a/pmcenter/Configurations/Conf.ConfObj.New.cs b/pmcenter/Configurations/Conf.ConfObj.New.cs index 6b5c0fc..78048a2 100644 --- a/pmcenter/Configurations/Conf.ConfObj.New.cs +++ b/pmcenter/Configurations/Conf.ConfObj.New.cs @@ -39,6 +39,8 @@ public ConfObj() AdvancedLogging = false; DisableTimeDisplay = false; UpdateChannel = "master"; + IgnoreKeyboardInterrupt = false; + DisableNetCore3Check = false; Statistics = new Stats(); Socks5Proxies = new List(); BannedKeywords = new List(); diff --git a/pmcenter/Configurations/Conf.ConfObj.cs b/pmcenter/Configurations/Conf.ConfObj.cs index 34a05ae..46578cf 100644 --- a/pmcenter/Configurations/Conf.ConfObj.cs +++ b/pmcenter/Configurations/Conf.ConfObj.cs @@ -37,6 +37,8 @@ public partial class ConfObj public bool AdvancedLogging; public bool DisableTimeDisplay; public string UpdateChannel; + public bool IgnoreKeyboardInterrupt; + public bool DisableNetCore3Check; public Stats Statistics; public List Socks5Proxies; public List BannedKeywords; diff --git a/pmcenter/Configurations/Lang.Language.New.cs b/pmcenter/Configurations/Lang.Language.New.cs index 52c873c..c4616ff 100644 --- a/pmcenter/Configurations/Lang.Language.New.cs +++ b/pmcenter/Configurations/Lang.Language.New.cs @@ -47,13 +47,13 @@ public Language() Message_SysStatus_UpdateLevel_Unknown = "❓ Unknown"; Message_SysStatus_RestartRequired = "🔄 *Bot restart required to apply changes.*"; Message_SysStatus_Summary = "📝 *Device name*: `$1`\n💿 *Operating System*: `$2`\nℹ *OS description*: `$3`\n⌛ *Server uptime*: `$4`\n🕓 *Bot uptime*: `$5`\n📅 *Server time (UTC)*: `$6`\n📐 *Runtime version*: `$7`\nℹ *Runtime description*: `$8`\n📏 *Application version*: `$9`\n💠 *Processor count*: `$a`\n📖 *Language code*: `$b`\n🛫 *Update channel (current)*: `$f`\n🛬 *Update channel (target)*: `$g`\n🔄 *Update checker*: `$c`\n🔄 *Rate limit processor*: `$d`\n🔄 *Configuration reset verifier*: `$e`"; - Message_Restarting = "🔄 Restarting...\n\n_It only works with systemd daemon._"; + Message_Restarting = "🔄 Restarting...\n\n_It only works with systemd-like daemons._"; Message_NotificationsOff = "📳 Notifications are *OFF*."; Message_NotificationsOn = "📲 Notifications are *ON*."; Message_SupportTextMessagesOnly = "📋 Sorry... Only text messages can be forwarded in Anonymous Forward mode."; Message_ForwarderNotReal = "ℹ The actual sender of this message is $1, whose UID is `$2`.\n\nYou can also ban this user by sending this following command:\n\n`/banid $2`\n\nTo undo this, send this command:\n\n`/pardonid $2`"; Message_GeneralFailure = "✖ Error processing request: $1"; - Message_LangVerMismatch = "⚠ Language file ($1) is not for current version ($2), consider updating language file?"; + Message_LangVerMismatch = "⚠ Language file (`$1`) is not for current version (`$2`), consider updating language file?"; Message_SwitchingLang = "💠 Switching language..."; Message_LangSwitched = "🚀 Language switched!"; Message_ThreadStatus_Unknown = "Unknown"; @@ -72,11 +72,12 @@ public Language() Message_Connectivity = "📡 *Connectivity Information*\n\nLatency to GitHub: $1\nLatency to Telegram API: $2\nLatency to CI (updates): $3"; Message_ContinuedChatEnabled = "💬 *Continued Conversation* mode is now `active`! All your messages (except commands and replys) will be forwarded to $1"; Message_ContinuedChatDisabled = "✅ *Continued Conversation* is now `disabled`."; - Message_FeatureNotAvailable = "⚠ This feature is unavailable or disabled."; + Message_FeatureNotAvailable = "⚠ *This feature is unavailable or disabled*."; Message_Stats = "📝 *Statistics*\n\n💬 Received messages: `$1`\n🔄 Forwarded to owner: `$2`\n🔄 Forwarded from owner: `$3`\n🚀 Commands received: `$4`"; Message_Retracted = "✅ This message has been retracted."; Message_MsgLinksCleared = "✅ All message links have been cleared."; Message_AvailableLang = "ℹ *Available languages*\n\n`$1`"; + Message_NetCore31Required = "⚠ You need `.NET Core 3.1` (runtime) installed in order to receive pmcenter v2 and further updates.\n\nLatest .NET Core runtime version detected on your device: `$1`\n\nThis warning will only show once."; } } } diff --git a/pmcenter/Configurations/Lang.Language.cs b/pmcenter/Configurations/Lang.Language.cs index 9c1aba3..20dee04 100644 --- a/pmcenter/Configurations/Lang.Language.cs +++ b/pmcenter/Configurations/Lang.Language.cs @@ -75,6 +75,7 @@ public partial class Language public string Message_Retracted; public string Message_MsgLinksCleared; public string Message_AvailableLang; + public string Message_NetCore31Required; } } } \ No newline at end of file diff --git a/pmcenter/EventHandlers/CtrlCHandler.cs b/pmcenter/EventHandlers/CtrlCHandler.cs new file mode 100644 index 0000000..ecefddd --- /dev/null +++ b/pmcenter/EventHandlers/CtrlCHandler.cs @@ -0,0 +1,29 @@ +using System; +using static pmcenter.Methods; + +namespace pmcenter +{ + public partial class EventHandlers + { + public static void CtrlCHandler(object sender, ConsoleCancelEventArgs e) + { + Vars.CtrlCCounter++; + if (Vars.CtrlCCounter > 3) + { + Log("More than 3 interrupts has received, terminating...", Type: LogLevel.WARN); + Environment.Exit(137); + } + if (Vars.IsCtrlCHandled) return; + if (Vars.CurrentConf.IgnoreKeyboardInterrupt) + { + Log("Keyboard interrupt is currently being ignored. To change this behavior, set \"IgnoreKeyboardInterrupt\" key to \"false\" in pmcenter configurations.", Type: LogLevel.WARN); + e.Cancel = true; + return; + } + Vars.IsCtrlCHandled = true; + Log("Interrupt! pmcenter is exiting..."); + Log("If pmcenter was unresponsive, press Ctrl-C 3 more times."); + ExitApp(130); + } + } +} \ No newline at end of file diff --git a/pmcenter/GlobalErrorHandler.cs b/pmcenter/EventHandlers/GlobalErrorHandler.cs similarity index 94% rename from pmcenter/GlobalErrorHandler.cs rename to pmcenter/EventHandlers/GlobalErrorHandler.cs index 517ab8b..6811a26 100644 --- a/pmcenter/GlobalErrorHandler.cs +++ b/pmcenter/EventHandlers/GlobalErrorHandler.cs @@ -6,9 +6,9 @@ namespace pmcenter { - public partial class Program + public partial class EventHandlers { - private static void GlobalErrorHandler(object sender, UnhandledExceptionEventArgs e) + public static void GlobalErrorHandler(object sender, UnhandledExceptionEventArgs e) { L("[!] Critical error occurred, falling back to basic logging."); L("pmcenter's global error handler has captured a critical error."); diff --git a/pmcenter/Interfaces/ICmdLine.cs b/pmcenter/Interfaces/ICmdLine.cs index 7e5ca24..d283075 100644 --- a/pmcenter/Interfaces/ICmdLine.cs +++ b/pmcenter/Interfaces/ICmdLine.cs @@ -1,7 +1,7 @@ /* // ICmdLine.cs / pmcenter project / https://github.com/Elepover/pmcenter // Commandline interface. -// Copyright (C) 2018 Elepover. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System.Threading.Tasks; diff --git a/pmcenter/Interfaces/ICommand.cs b/pmcenter/Interfaces/ICommand.cs index 55e52a0..8b47096 100644 --- a/pmcenter/Interfaces/ICommand.cs +++ b/pmcenter/Interfaces/ICommand.cs @@ -1,7 +1,7 @@ /* // ICommand.cs / pmcenter project / https://github.com/Elepover/pmcenter // Command interface. -// Copyright (C) 2018 Genteure. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System.Threading.Tasks; diff --git a/pmcenter/Methods/Methods.CheckNetCoreVersion.cs b/pmcenter/Methods/Methods.CheckNetCoreVersion.cs new file mode 100644 index 0000000..b698aab --- /dev/null +++ b/pmcenter/Methods/Methods.CheckNetCoreVersion.cs @@ -0,0 +1,19 @@ +using System; + +namespace pmcenter +{ + public partial class Methods + { + public static bool CheckNetCoreVersion(Version version) + { + if (version.Major != 3 || version.Minor != 1) + { + Log("pmcenter v2 or up wouldn't run on devices without .NET Core 3.1 (runtime) installed.", Type: LogLevel.WARN); + Log($"pmcenter has detected that the latest version installed on your device is .NET Core runtime {version.ToString()}.", Type: LogLevel.WARN); + Log("Consider updating your .NET Core runtime in order to run pmcenter v2 and receive further updates.", Type: LogLevel.WARN); + return false; + } + return true; + } + } +} \ No newline at end of file diff --git a/pmcenter/Methods/Methods.ExitApp.cs b/pmcenter/Methods/Methods.ExitApp.cs new file mode 100644 index 0000000..f8aab50 --- /dev/null +++ b/pmcenter/Methods/Methods.ExitApp.cs @@ -0,0 +1,67 @@ +using System; +using System.Diagnostics; +using System.Threading; + +namespace pmcenter +{ + public partial class Methods + { + public static void ExitApp(int code) + { + Log("Attempting to exit gracefully..."); + Log("Stopping bot message receiving..."); + Vars.Bot.StopReceiving(); + Log("Waiting for background workers to exit (timeout: 10s)..."); + var sw = new Stopwatch(); + sw.Start(); + + Vars.IsShuttingDown = true; + if (Vars.IsPerformanceTestExecuting) + { + while (!Vars.IsPerformanceTestExecuting) + { + if (sw.ElapsedMilliseconds >= 10000) Environment.Exit(16); + Thread.Sleep(50); + } + } + Log("[OK] Shut down performance tester."); + + Thread[] threads = + { + Vars.ConfValidator, + Vars.UpdateChecker, + Vars.RateLimiter, + Vars.BannedSweepper, + Vars.SyncConf + }; + + string[] threadNames = + { + "reset timer", + "update checker", + "rate limiter", + "banned sweeper", + "configurations autosaver" + }; + + for (int i = 0; i < threads.Length; i++) + { + var thread = threads[i]; + if (thread != null && thread.IsAlive) + { + thread.Interrupt(); + while (thread.IsAlive) + { + if (sw.ElapsedMilliseconds >= 10000) Environment.Exit(16); + Thread.Sleep(50); + } + } + Log($"[OK] Shut down {threadNames[i]}."); + } + + sw.Stop(); + Log($"pmcenter has stopped in {Math.Round(sw.Elapsed.TotalSeconds, 2)}s."); + Environment.Exit(code); + } + } +} diff --git a/pmcenter/Methods/Methods.GetNetCoreVersion.cs b/pmcenter/Methods/Methods.GetNetCoreVersion.cs new file mode 100644 index 0000000..160cee1 --- /dev/null +++ b/pmcenter/Methods/Methods.GetNetCoreVersion.cs @@ -0,0 +1,45 @@ +using System; +using System.Diagnostics; +using System.Text; + +namespace pmcenter +{ + public partial class Methods + { + public static Version GetNetCoreVersion() + { + var newVersionInDotnet3 = Environment.Version; + if (newVersionInDotnet3.Major == 3) return newVersionInDotnet3; + try + { + var searchPattern = "Microsoft.NETCore.App "; + var proc = new Process(); + proc.StartInfo.FileName = "dotnet"; + proc.StartInfo.Arguments = "--list-runtimes"; + proc.StartInfo.RedirectStandardOutput = true; + proc.StartInfo.UseShellExecute = false; + proc.Start(); + var output = proc.StandardOutput.ReadToEnd(); + // search pattern: Microsoft.NETCore.App 2.1.7 [/home/user/dotnet/shared/Microsoft.NETCore.App] + int index = output.IndexOf(searchPattern); + Version version; + while (true) + { + int indexOfStartingSpace = index + searchPattern.Length - 1; + int indexOfEndingSpace = output.IndexOf(" ", index + searchPattern.Length); + var versionString = output.Substring(indexOfStartingSpace + 1, indexOfEndingSpace - indexOfStartingSpace - 1); + version = new Version(versionString); + if (version.Major == 3 && version.Minor == 1) return version; + index = output.IndexOf(searchPattern, indexOfEndingSpace); + if (index == -1) break; + } + return version; + } + catch (Exception ex) + { + Log($"pmcenter is unable to detect your .NET Core installation: {ex.Message}, you need to have .NET Core 3.1 (runtime) installed in order to run pmcenter v2 or up.", Type: LogLevel.WARN); + return new Version("0.0.0.0"); + } + } + } +} \ No newline at end of file diff --git a/pmcenter/Methods/Threads/Methods.ThrPerform.cs b/pmcenter/Methods/Threads/Methods.ThrPerform.cs index 3ff7c61..f56a94d 100644 --- a/pmcenter/Methods/Threads/Methods.ThrPerform.cs +++ b/pmcenter/Methods/Threads/Methods.ThrPerform.cs @@ -7,7 +7,7 @@ public static void ThrPerform() if (Vars.IsPerformanceTestExecuting) { return; } Vars.IsPerformanceTestExecuting = true; Vars.PerformanceScore = 0; - while (!Vars.IsPerformanceTestEndRequested) + while (!(Vars.IsPerformanceTestEndRequested || Vars.IsShuttingDown)) { Vars.PerformanceScore += 1; } diff --git a/pmcenter/Methods/Threads/Methods.ThrRateLimiter.cs b/pmcenter/Methods/Threads/Methods.ThrRateLimiter.cs index 414d9e0..6ad14e9 100644 --- a/pmcenter/Methods/Threads/Methods.ThrRateLimiter.cs +++ b/pmcenter/Methods/Threads/Methods.ThrRateLimiter.cs @@ -8,7 +8,7 @@ public partial class Methods public static async void ThrRateLimiter() { Log("Started!", "RATELIMIT"); - while (true) + while (!Vars.IsShuttingDown) { Vars.RateLimiterStatus = ThreadStatus.Working; foreach (RateData Data in Vars.RateLimits) @@ -22,7 +22,7 @@ public static async void ThrRateLimiter() Data.MessageCount = 0; } Vars.RateLimiterStatus = ThreadStatus.Standby; - Thread.Sleep(30000); + try { Thread.Sleep(30000); } catch { } } } } diff --git a/pmcenter/Methods/Threads/Methods.ThrSyncConf.cs b/pmcenter/Methods/Threads/Methods.ThrSyncConf.cs index 1ec9643..1c83150 100644 --- a/pmcenter/Methods/Threads/Methods.ThrSyncConf.cs +++ b/pmcenter/Methods/Threads/Methods.ThrSyncConf.cs @@ -7,7 +7,7 @@ public partial class Methods { public static async void ThrSyncConf() { - while (true) + while (!Vars.IsShuttingDown) { try { @@ -23,7 +23,7 @@ public static async void ThrSyncConf() Log("ConfSync disabled, stopping...", "CONFSYNC", LogLevel.WARN); return; } - Thread.Sleep(Vars.CurrentConf.ConfSyncInterval); + try { Thread.Sleep(Vars.CurrentConf.ConfSyncInterval); } catch { } } } } diff --git a/pmcenter/Methods/Threads/Methods.ThrUpdateChecker.cs b/pmcenter/Methods/Threads/Methods.ThrUpdateChecker.cs index 78cc686..c6ba315 100644 --- a/pmcenter/Methods/Threads/Methods.ThrUpdateChecker.cs +++ b/pmcenter/Methods/Threads/Methods.ThrUpdateChecker.cs @@ -10,7 +10,7 @@ public partial class Methods public static async void ThrUpdateChecker() { Log("Started!", "UPDATER"); - while (true) + while (!Vars.IsShuttingDown) { Vars.UpdateCheckerStatus = ThreadStatus.Working; try @@ -46,7 +46,7 @@ public static async void ThrUpdateChecker() Log($"Error during update check: {ex.ToString()}", "UPDATER", LogLevel.ERROR); } Vars.UpdateCheckerStatus = ThreadStatus.Standby; - Thread.Sleep(60000); + try { Thread.Sleep(60000); } catch { } } } } diff --git a/pmcenter/Program.cs b/pmcenter/Program.cs index 5a0e2ce..78f98dd 100644 --- a/pmcenter/Program.cs +++ b/pmcenter/Program.cs @@ -1,7 +1,7 @@ /* // Program.cs / pmcenter project / https://github.com/Elepover/pmcenter // Main entry to pmcenter. -// Copyright (C) 2018 Elepover. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System; @@ -13,6 +13,7 @@ using Telegram.Bot; using Telegram.Bot.Types.Enums; using static pmcenter.Conf; +using static pmcenter.EventHandlers; using static pmcenter.Lang; using static pmcenter.Methods; @@ -26,7 +27,7 @@ public static void Main(string[] args) Console.WriteLine(Vars.ASCII); Log("Main delegator activated!", "DELEGATOR"); Log($"Starting pmcenter, version {Vars.AppVer.ToString()}. Channel: \"{Vars.CompileChannel}\"", "DELEGATOR"); - Task MainAsyncTask = MainAsync(args); + var MainAsyncTask = MainAsync(args); MainAsyncTask.Wait(); Log("Main worker accidentally exited. Stopping...", "DELEGATOR", LogLevel.ERROR); Environment.Exit(1); @@ -39,6 +40,8 @@ public static async Task MainAsync(string[] args) // hook global errors (final failsafe) AppDomain.CurrentDomain.UnhandledException += GlobalErrorHandler; Log("Global error handler is armed and ready!"); + // hook ctrl-c events + Console.CancelKeyPress += CtrlCHandler; // process commandlines await CmdLineProcess.RunCommand(Environment.CommandLine).ConfigureAwait(false); // everything (exits and/or errors) are handled above, please do not process. @@ -159,6 +162,7 @@ public static async Task MainAsync(string[] args) { Vars.Bot = new TelegramBotClient(Vars.CurrentConf.APIKey); } + Log("Validating API Key..."); _ = await Vars.Bot.TestApiAsync().ConfigureAwait(false); Log("Hooking event processors..."); Vars.Bot.OnUpdate += BotProcess.OnUpdate; @@ -180,7 +184,25 @@ public static async Task MainAsync(string[] args) } catch (Exception ex) { - Log($"Failed to send startup message to owner.\nDid you set the \"OwnerID\" key correctly? Otherwise pmcenter could not work properly.\nYou can try to use setup wizard to update/get your OwnerID automatically, just run \"dotnet pmcenter.dll --setup\".\n\nError details: {ex.ToString()}", "BOT", LogLevel.ERROR); + Log($"Failed to send startup message to owner.\nDid you set the \"OwnerID\" key correctly? Otherwise pmcenter could not work properly.\nYou can try to use setup wizard to update/get your OwnerID automatically, just run \"dotnet pmcenter.dll --setup\".\n\nError details: {ex.ToString()}", "BOT", LogLevel.WARN); + } + try + { + var netCoreVersion = GetNetCoreVersion(); + if (!CheckNetCoreVersion(netCoreVersion) && !Vars.CurrentConf.DisableNetCore3Check) + { + _ = await Vars.Bot.SendTextMessageAsync(Vars.CurrentConf.OwnerUID, + Vars.CurrentLang.Message_NetCore31Required + .Replace("$1", netCoreVersion.ToString()), + ParseMode.Markdown, + false, + false).ConfigureAwait(false); + Vars.CurrentConf.DisableNetCore3Check = true; + } + } + catch (Exception ex) + { + Log($".NET Core runtime version warning wasn't delivered to the owner: {ex.Message}, did you set the \"OwnerID\" key correctly?", "BOT", LogLevel.WARN); } if (Vars.CurrentLang.TargetVersion != Vars.AppVer.ToString()) { @@ -194,10 +216,21 @@ public static async Task MainAsync(string[] args) false).ConfigureAwait(false); } Log("==> All finished!"); - while (true) + if (Vars.ServiceMode) { - Thread.Sleep(60000); + while (true) + { + Thread.Sleep(int.MaxValue); + } + } + else + { + while (true) + { + Console.ReadKey(true); + } } + } catch (Exception ex) { diff --git a/pmcenter/Setup.cs b/pmcenter/Setup.cs index 22f951d..a2252a5 100644 --- a/pmcenter/Setup.cs +++ b/pmcenter/Setup.cs @@ -1,7 +1,7 @@ -/* +/* // Setup.cs / pmcenter project / https://github.com/Elepover/pmcenter // Methods & functions for Setup Wizard. -// Copyright (C) 2018 Elepover. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System; @@ -29,7 +29,7 @@ private static void OnUpdate(object sender, UpdateEventArgs e) { IsUIDReceived = true; ReceivedUID = e.Update.Message.From.Id; - Nickname = $"{e.Update.Message.From.FirstName} {e.Update.Message.From.LastName}"; + Nickname = string.IsNullOrEmpty(e.Update.Message.From.LastName) ? e.Update.Message.From.FirstName : $"{e.Update.Message.From.FirstName} {e.Update.Message.From.LastName}"; TestBot.StopReceiving(); } } @@ -57,7 +57,7 @@ public static async Task SetupWizard() Say(""); await SetAPIKey().ConfigureAwait(false); Say(""); - SetUID(); + await SetUID(); Say(""); SetNotifPrefs(); Say(""); @@ -150,7 +150,7 @@ private static async Task SetAPIKey() NewConf.APIKey = Key; Say(" Done!"); } - private static void SetUID() + private static async Task SetUID() { Say("2> Owner ID"); Say(" Your Telegram UID is your unique and permanent identifier."); @@ -169,7 +169,8 @@ private static void SetUID() { Thread.Sleep(200); } - Say($"Hello, {Nickname}! Your UID has been detected as {ReceivedUID}."); + _ = await TestBot.SendTextMessageAsync(ReceivedUID, $"👋 *Hello my owner!* Your UID `{ReceivedUID}` is now being saved.", ParseMode.Markdown); + Say($"Hello, [{Nickname}]! Your UID has been detected as {ReceivedUID}."); SIn($".. Saving UID: {ReceivedUID}..."); NewConf.OwnerUID = ReceivedUID; Say(" Done!"); diff --git a/pmcenter/Template.cs b/pmcenter/Template.cs index f499883..a8728c6 100644 --- a/pmcenter/Template.cs +++ b/pmcenter/Template.cs @@ -1,7 +1,7 @@ /* // Template.cs / pmcenter project / https://github.com/Elepover/pmcenter // New classes' template. -// Copyright (C) 2018 Elepover. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System; diff --git a/pmcenter/Vars.cs b/pmcenter/Vars.cs index 3e348f6..06706c2 100644 --- a/pmcenter/Vars.cs +++ b/pmcenter/Vars.cs @@ -1,7 +1,7 @@ /* // Vars.cs / pmcenter project / https://github.com/Elepover/pmcenter // Storage of variables for easier calling. -// Copyright (C) 2018 Elepover. Licensed under the Apache License (Version 2.0). +// Copyright (C) The pmcenter authors. Licensed under the Apache License (Version 2.0). */ using System; @@ -17,7 +17,7 @@ namespace pmcenter public static class Vars { public readonly static string ASCII = " __ \n ____ ____ ___ ________ ____ / /____ _____\n / __ \\/ __ `__ \\/ ___/ _ \\/ __ \\/ __/ _ \\/ ___/\n / /_/ / / / / / / /__/ __/ / / / /_/ __/ / \n / .___/_/ /_/ /_/\\___/\\___/_/ /_/\\__/\\___/_/ \n/_/ "; - public readonly static Version AppVer = new Version("1.9.1.271"); + public readonly static Version AppVer = new Version("1.9.280.15"); public readonly static string AppExecutable = Assembly.GetExecutingAssembly().Location; public readonly static string AppDirectory = (new FileInfo(AppExecutable)).DirectoryName; public static string ConfFile = Path.Combine(AppDirectory, "pmcenter.json"); @@ -39,6 +39,10 @@ public static class Vars public static bool NonEmergRestartRequired = false; public static bool UpdatePending = false; public static bool IsResetConfAvailable = false; + public static bool IsCtrlCHandled = false; + public static int CtrlCCounter = 0; + public static bool IsShuttingDown = false; + public static bool ServiceMode = true; public static Conf.UpdateLevel UpdateLevel; public static Version UpdateVersion; public static Stopwatch StartSW = new Stopwatch(); @@ -53,6 +57,7 @@ public static class Vars public static double PerformanceScore = 0; public static Thread BannedSweepper; + public static Thread ConfValidator; public static Methods.ThreadStatus ConfResetTimerStatus = Methods.ThreadStatus.Stopped; public static Thread RateLimiter; public static Methods.ThreadStatus RateLimiterStatus = Methods.ThreadStatus.Stopped; diff --git a/updateinfo2.json b/updateinfo2.json index ee8cb07..3402047 100644 --- a/updateinfo2.json +++ b/updateinfo2.json @@ -1,9 +1,9 @@ { - "Latest": "1.9.1.271", + "Latest": "1.9.280.15", "UpdateLevel": 1, "UpdateCollection": [ { - "Details": "[+] Now pmcenter supports multi-channel updates.\nYou can choose the \"pmcenter-lazer\" channel for faster updates, or stay at \"master\" for a stabler user experience.", + "Details": "[i] This is the final update before pmcenter v2 arrives.\n[+] Added .NET Core Runtime version check.\n[+] Added Ctrl-C event handler.\n[/] Updated Setup Wizard.\n[+] Updated exiting mechanism.", "LangCode": [ "en.imported", "en.integrated" @@ -12,7 +12,7 @@ "UpdateArchiveAddress": "https://see.wtf/pmcenter-update" }, { - "Details": "[+] pmcenter 现已支持多更新频道\n您可以使用 \"pmcenter-lazer\" 频道来更快速地获取更新,或停留在 \"master\" 频道以获得更稳定的使用体验。", + "Details": "[i] 这是 pmcenter v2 更新前的最后一次更新。\n[+] 添加 .NET Core 运行时版本检查。\n[+] 添加 Ctrl-C 事件处理器。\n[/] 更新了设置向导。\n[+] 全新的退出机制。", "LangCode": [ "zh.simplified" ], @@ -20,7 +20,7 @@ "UpdateArchiveAddress": "https://see.wtf/pmcenter-update" }, { - "Details": "[+] pmcenter 现在可以选择不同频道更新啦!\n\"pmcenter-lazer\" 频道更新速度更快,但是可能会翻车(\n\"master\" 频道的 pmcenter 就要更稳定一些(", + "Details": "[i] 这是 pmcenter v2 更新前的最后一次更新。\n[+] 添加 .NET Core 运行时版本检查。\n[+] 添加 Ctrl-C 事件处理器。\n[/] 更新了设置向导。\n[+] 全新的退出机制。", "LangCode": [ "zh.meow" ], @@ -28,7 +28,7 @@ "UpdateArchiveAddress": "https://see.wtf/pmcenter-update" }, { - "Details": "[+] pmcenter 現已支援多更新頻道\n您可透過 \"pmcenter-lazer\" 頻道來快速獲取更新,或留在 \"master\" 頻道以獲得更穩定的使用體驗。", + "Details": "[i] 這是 pmcenter v2 更新前的最後一次更新。\n[+] 新增 .NET Core 運行時版本檢查。\n[+] 新增 Ctrl-C 事件處理器。\n[/] 更新了設置向導。\n[+] 全新的退出機制。", "LangCode": [ "zh.tw" ], @@ -36,7 +36,7 @@ "UpdateArchiveAddress": "https://see.wtf/pmcenter-update" }, { - "Details": "[+] Now pmcenter supports multi-channel updates.\nYou can choose the \"pmcenter-lazer\" channel for faster updates, or stay at \"master\" for a stabler user experience.", + "Details": "[i] This is the final update before pmcenter v2 arrives.\n[+] Added .NET Core Runtime version check.\n[+] Added Ctrl-C event handler.\n[/] Updated Setup Wizard.\n[+] Updated exiting mechanism.", "LangCode": [ "en.imported", "en.integrated" @@ -45,7 +45,7 @@ "UpdateArchiveAddress": "https://see.wtf/pmcenter-lazer-update" }, { - "Details": "[+] pmcenter 现已支持多更新频道\n您可以使用 \"pmcenter-lazer\" 频道来更快速地获取更新,或停留在 \"master\" 频道以获得更稳定的使用体验。", + "Details": "[i] 这是 pmcenter v2 更新前的最后一次更新。\n[+] 添加 .NET Core 运行时版本检查。\n[+] 添加 Ctrl-C 事件处理器。\n[/] 更新了设置向导。\n[+] 全新的退出机制。", "LangCode": [ "zh.simplified" ], @@ -53,7 +53,7 @@ "UpdateArchiveAddress": "https://see.wtf/pmcenter-lazer-update" }, { - "Details": "[+] pmcenter 现在可以选择不同频道更新啦!\n\"pmcenter-lazer\" 频道更新速度更快,但是可能会翻车(\n\"master\" 频道的 pmcenter 就要更稳定一些(", + "Details": "[i] 这是 pmcenter v2 更新前的最后一次更新。\n[+] 添加 .NET Core 运行时版本检查。\n[+] 添加 Ctrl-C 事件处理器。\n[/] 更新了设置向导。\n[+] 全新的退出机制。", "LangCode": [ "zh.meow" ], @@ -61,7 +61,7 @@ "UpdateArchiveAddress": "https://see.wtf/pmcenter-lazer-update" }, { - "Details": "[+] pmcenter 現已支援多更新頻道\n您可透過 \"pmcenter-lazer\" 頻道來快速獲取更新,或留在 \"master\" 頻道以獲得更穩定的使用體驗。", + "Details": "[i] 這是 pmcenter v2 更新前的最後一次更新。\n[+] 新增 .NET Core 運行時版本檢查。\n[+] 新增 Ctrl-C 事件處理器。\n[/] 更新了設置向導。\n[+] 全新的退出機制。", "LangCode": [ "zh.tw" ],