diff --git a/Team123it.Arcaea.MarveCube.Standalone/Team123it.Arcaea.MarveCube.Standalone.csproj b/Team123it.Arcaea.MarveCube.Standalone/Team123it.Arcaea.MarveCube.Standalone.csproj index db91ef9..33a97de 100644 --- a/Team123it.Arcaea.MarveCube.Standalone/Team123it.Arcaea.MarveCube.Standalone.csproj +++ b/Team123it.Arcaea.MarveCube.Standalone/Team123it.Arcaea.MarveCube.Standalone.csproj @@ -6,7 +6,7 @@ 0.2.0 123 Open-Source Organization Arcaea Server 2(123 Marvelous Cube) Standalone Version - 0.2.0 + 0.2.1 0.2.0 (C)Copyright 2015-2022 123 Open-Source Organization. All rights reserved. 123 Marvelous Cube Standalone Version diff --git a/Team123it.Arcaea.MarveCube/FirstStart/FirstStart.cs b/Team123it.Arcaea.MarveCube/FirstStart/FirstStart.cs index a8eacc1..cbda04d 100644 --- a/Team123it.Arcaea.MarveCube/FirstStart/FirstStart.cs +++ b/Team123it.Arcaea.MarveCube/FirstStart/FirstStart.cs @@ -11,6 +11,7 @@ using System.Text; using System.Reflection; using Newtonsoft.Json; +using System.Enhance.MySql.Data; namespace Team123it.Arcaea.MarveCube.FirstStart { @@ -37,15 +38,10 @@ public static void FastInitialize() cmd.CommandText = $"CREATE DATABASE {dbName};"; cmd.ExecuteNonQuery(); conn.Close(); - conn = new MySqlConnection(DatabaseConnectURL); - conn.Open(); - cmd = conn.CreateCommand(); - cmd.CommandText = initSQLCodes; - cmd.ExecuteNonQuery(); - conn.Close(); + MysqlExecutor.ExecuteSqlFileData(DatabaseConnectURL, initSQLCodes); c.WriteLine("数据库初始化成功完成"); } - catch (MySqlException) + catch (MySqlException ex) { c.WriteLine("无法连接到数据库, 请检查配置信息是否填写有误后单击任意键继续"); goto DoInitialize; diff --git a/Team123it.Arcaea.MarveCube/FirstStartData/Initialization.sql b/Team123it.Arcaea.MarveCube/FirstStartData/Initialization.sql index 069daec..f362503 100644 --- a/Team123it.Arcaea.MarveCube/FirstStartData/Initialization.sql +++ b/Team123it.Arcaea.MarveCube/FirstStartData/Initialization.sql @@ -1,6 +1,3 @@ --- ---------------------------- --- Table structure for bests --- ---------------------------- DROP TABLE IF EXISTS `bests`; CREATE TABLE `bests` ( `user_id` int(11) NOT NULL, @@ -19,10 +16,6 @@ CREATE TABLE `bests` ( `rating` decimal(10,3) DEFAULT NULL, PRIMARY KEY (`user_id`,`song_id`,`difficulty`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for bests_special --- ---------------------------- DROP TABLE IF EXISTS `bests_special`; CREATE TABLE `bests_special` ( `user_id` int(11) NOT NULL, @@ -41,9 +34,6 @@ CREATE TABLE `bests_special` ( `rating` decimal(10,3) DEFAULT NULL, PRIMARY KEY (`user_id`,`song_id`,`difficulty`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; --- ---------------------------- --- Table structure for fixed_characters --- ---------------------------- DROP TABLE IF EXISTS `fixed_characters`; CREATE TABLE `fixed_characters` ( `character_id` int(11) NOT NULL, @@ -67,10 +57,6 @@ CREATE TABLE `fixed_characters` ( `version` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`character_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for fixed_packs --- ---------------------------- DROP TABLE IF EXISTS `fixed_packs`; CREATE TABLE `fixed_packs` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -97,10 +83,6 @@ CREATE TABLE `fixed_packs` ( `version` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`,`pid`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for fixed_presents --- ---------------------------- DROP TABLE IF EXISTS `fixed_presents`; CREATE TABLE `fixed_presents` ( `present_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, @@ -113,20 +95,12 @@ CREATE TABLE `fixed_presents` ( `items` text COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`present_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for fixed_properties --- ---------------------------- DROP TABLE IF EXISTS `fixed_properties`; CREATE TABLE `fixed_properties` ( `key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `value` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`key`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for fixed_purchases --- ---------------------------- DROP TABLE IF EXISTS `fixed_purchases`; CREATE TABLE `fixed_purchases` ( `item_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, @@ -138,10 +112,6 @@ CREATE TABLE `fixed_purchases` ( `discount_to` datetime DEFAULT NULL, PRIMARY KEY (`item_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for fixed_songs --- ---------------------------- DROP TABLE IF EXISTS `fixed_songs`; CREATE TABLE `fixed_songs` ( `sid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, @@ -186,30 +156,18 @@ CREATE TABLE `fixed_songs` ( `version` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`sid`,`date`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for fixed_songs_checksum --- ---------------------------- DROP TABLE IF EXISTS `fixed_songs_checksum`; CREATE TABLE `fixed_songs_checksum` ( `sid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `filename` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `checksum` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for friend --- ---------------------------- DROP TABLE IF EXISTS `friend`; CREATE TABLE `friend` ( `user_id_me` int(11) NOT NULL, `user_id_other` int(11) NOT NULL, PRIMARY KEY (`user_id_me`,`user_id_other`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for logins --- ---------------------------- DROP TABLE IF EXISTS `logins`; CREATE TABLE `logins` ( `access_token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, @@ -220,20 +178,12 @@ CREATE TABLE `logins` ( `last_login_deviceId` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`access_token`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for user_bydunlocks --- ---------------------------- DROP TABLE IF EXISTS `user_bydunlocks`; CREATE TABLE `user_bydunlocks` ( `user_id` int(11) NOT NULL, `sid` varchar(255) NOT NULL, PRIMARY KEY (`user_id`,`sid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - --- ---------------------------- --- Table structure for user_chars --- ---------------------------- DROP TABLE IF EXISTS `user_chars`; CREATE TABLE `user_chars` ( `user_id` int(11) NOT NULL, @@ -253,10 +203,6 @@ CREATE TABLE `user_chars` ( `is_uncapped_override` int(11) DEFAULT 0, PRIMARY KEY (`user_id`,`character_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for user_saves --- ---------------------------- DROP TABLE IF EXISTS `user_saves`; CREATE TABLE `user_saves` ( `user_id` int(10) unsigned NOT NULL, @@ -270,10 +216,6 @@ CREATE TABLE `user_saves` ( `create_time` datetime DEFAULT NULL, PRIMARY KEY (`user_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for user_world --- ---------------------------- DROP TABLE IF EXISTS `user_world`; CREATE TABLE `user_world` ( `user_id` int(11) NOT NULL, @@ -283,10 +225,6 @@ CREATE TABLE `user_world` ( `is_locked` int(11) DEFAULT 0, PRIMARY KEY (`user_id`,`map_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for users --- ---------------------------- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, @@ -331,10 +269,6 @@ CREATE TABLE `users` ( PRIMARY KEY (`user_id`) USING BTREE, UNIQUE KEY `name` (`name`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=10000024 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; - --- ---------------------------- --- Table structure for world_songplay --- ---------------------------- DROP TABLE IF EXISTS `world_songplay`; CREATE TABLE `world_songplay` ( `user_id` int(11) NOT NULL, diff --git a/Team123it.Arcaea.MarveCube/System.Enhance (Part)/System.Enhance.MySql.Data.cs b/Team123it.Arcaea.MarveCube/System.Enhance (Part)/System.Enhance.MySql.Data.cs new file mode 100644 index 0000000..cf7dd65 --- /dev/null +++ b/Team123it.Arcaea.MarveCube/System.Enhance (Part)/System.Enhance.MySql.Data.cs @@ -0,0 +1,73 @@ +using MySql.Data.MySqlClient; +using System.Collections; +using System.IO; +using System.Text; + +namespace System.Enhance.MySql.Data +{ + public class MysqlExecutor + { + public static bool ExecuteSqlFileData(string sqlConnString, string varData) + { + var stream = new MemoryStream(); + var ws = new StreamWriter(stream, Encoding.UTF8); + ws.Write(varData); + ws.Flush(); + stream.Seek(0, SeekOrigin.Begin); + var rs = new StreamReader(stream, Encoding.UTF8); + var alSql = new ArrayList(); + string commandText = ""; + string varLine = ""; + while (rs.Peek() > -1) + { + varLine = rs.ReadLine(); + if (varLine == "") + { + continue; + } + if (varLine != "GO") + { + commandText += varLine; + commandText += "\r\n"; + } + else + { + commandText += ""; + } + } + alSql.Add(commandText); + rs.Close(); + try + { + ExecuteCommand(sqlConnString, alSql); + return true; + } + catch (Exception ex) + { + throw; + } + } + private static void ExecuteCommand(string sqlConnString, ArrayList varSqlList) + { + using var conn = new MySqlConnection(sqlConnString); + conn.Open(); + var cmd = conn.CreateCommand(); + try + { + foreach (string varcommandText in varSqlList) + { + cmd.CommandText = varcommandText; + cmd.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + throw; + } + finally + { + conn.Close(); + } + } + } +} diff --git a/Team123it.Arcaea.MarveCube/Team123it.Arcaea.MarveCube.csproj b/Team123it.Arcaea.MarveCube/Team123it.Arcaea.MarveCube.csproj index a082722..28e7f72 100644 --- a/Team123it.Arcaea.MarveCube/Team123it.Arcaea.MarveCube.csproj +++ b/Team123it.Arcaea.MarveCube/Team123it.Arcaea.MarveCube.csproj @@ -3,11 +3,11 @@ net6.0 MarveCube - 0.2.0 + 0.2.1 123 Open-Source Organization Arcaea Server 2(123 Marvelous Cube Open-Source Version) - 0.2.0 - 0.2.0 + 0.2.1 + 0.2.1 (C)Copyright 2015-2022 123 Open-Source Organization. All rights reserved. Arcaea Server 2 - High-Speed Protable Arcaea API Server x64;ARM64