tinboye Posted April 15, 2016 Share Posted April 15, 2016 Does anyone have an example script or instructions on how i can make it so when a user creates a game account/ adds a gameserver to their account, that if the game requires mysql db, that it will auto import the sql file into the created database. I already have these scripts in the game server template. http://help.tcadmin.com/Automatically_Create_a_MySQL_Database thanks for your help Link to comment Share on other sites More sharing options...
tinboye Posted April 23, 2016 Author Share Posted April 23, 2016 So i managed to get this to work by simply taking the http://help.tcadmin.com/Automatically_Create_a_MySQL_Database script of restoring a backup. Operating System: Any Description: Restore MySQL database after move Script Engine: IronPython Event: After move Ignore execution errors Unchecked Script: import clr; import System; clr.AddReference("TCAdmin.DatabaseProviders.MySql"); clr.AddReference("TCAdmin.SDK"); from TCAdmin.DatabaseProviders.MySql import MySqlManager; from System import String; from System.IO import File, Path; mysql_server="localhost"; mysql_root="root"; mysql_password=""; if not ThisService.Variables.HasValue("MySQLUser") : Script.Exit(); backupfile=Path.Combine(ThisService.RootDirectory, "databasename.sql"); with MySqlManager() as mysql: escapeduser=mysql.PrepareSqlValue(ThisService.Variables["MySQLUser"]); escapedpass=mysql.PrepareSqlValue(ThisService.Variables["MySQLPassword"]); mysql.Connect(String.Format("Data Source={0};User Id={1};Password={2};Pooling=False;", mysql_server, mysql_root, mysql_password)); mysql.ExecuteNonQuery(String.Format("DROP DATABASE IF EXISTS {0};", escapeduser)); if mysql.Execute(String.Format("SELECT * FROM mysql.user WHERE user='{0}' AND host='localhost';", escapeduser)).Rows.Count == 1 : mysql.ExecuteNonQuery(String.Format("DROP USER {0}@localhost;", escapeduser)); mysql.ExecuteNonQuery(String.Format("CREATE DATABASE {0};", escapeduser)); mysql.ExecuteNonQuery(String.Format("GRANT ALL PRIVILEGES ON {0}.* TO '{0}'@'localhost' IDENTIFIED BY '{1}';", escapeduser, escapedpass)); if File.Exists(backupfile) : with MySqlManager() as mysql2: mysql2.Connect(String.Format("Data Source={0};Database={1};User Id={1};Password={2};Pooling=False;", mysql_server, ThisService.Variables["MySQLUser"], ThisService.Variables["MySQLPassword"])); mysql2.ImportDatabase(backupfile); File.Delete(backupfile); and made sure that the sql file was in the root directory of the game folder. I have this script execute once the mod for the server is installed. works like a charm Link to comment Share on other sites More sharing options...
barrycarey Posted April 23, 2016 Share Posted April 23, 2016 Glad you got it figured out. I'm assuming that was you that posted on my site earlier. Link to comment Share on other sites More sharing options...
tinboye Posted April 24, 2016 Author Share Posted April 24, 2016 (edited) yes that was me lol, im still figuring things out. mainly how the configuration editor works. I still have not figured out how a user is only able to edit certain fields of a cfg file. Or if thats even possible. Also trying to figure out how I can make it so mysql user/pass can be retrieved as a link in the user control panel. I have seen this done with gtx gaming. Just not sure how to do that. Edited April 24, 2016 by tinboye Link to comment Share on other sites More sharing options...
barrycarey Posted May 7, 2016 Share Posted May 7, 2016 yes that was me lol, im still figuring things out. mainly how the configuration editor works. I still have not figured out how a user is only able to edit certain fields of a cfg file. Or if thats even possible. Also trying to figure out how I can make it so mysql user/pass can be retrieved as a link in the user control panel. I have seen this done with gtx gaming. Just not sure how to do that. Displaying the user/pass is easy. As an example, I have a script that installs mysql and creates the user with a random password. That password is saved to a variable. You can then make a custom button that echos out the password. ThisService.Variables["ExampleUser"] = Random.RandomString(10,True,True) ThisService.Save() Feel free to add me on Skype. I'm not always around but I enjoy teaching people about TCA. Skype is barrycarey66 Link to comment Share on other sites More sharing options...
tinboye Posted May 9, 2016 Author Share Posted May 9, 2016 I was able to just make a batch script that echo'd the variable. echo Mysql Database: %ThisService_MySQLUser% echo Mysql Username: %ThisService_MySQLUser% echo Mysql Password: %ThisService_MySQLPassword% my generate user/pass/mysql scripts were from the http://help.tcadmin.com/Automatically_Create_a_MySQL_Database Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now