MySQLUserData.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using OpenGrid.Framework.Data;
  5. using libsecondlife;
  6. namespace OpenGrid.Framework.Data.MySQL
  7. {
  8. class MySQLUserData : IUserData
  9. {
  10. public MySQLManager database;
  11. public void Initialise()
  12. {
  13. IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
  14. string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
  15. string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
  16. string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
  17. string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
  18. string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
  19. string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
  20. database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
  21. }
  22. public UserProfileData getUserByName(string name)
  23. {
  24. return getUserByName(name.Split(' ')[0], name.Split(' ')[1]);
  25. }
  26. public UserProfileData getUserByName(string user, string last)
  27. {
  28. try
  29. {
  30. lock (database)
  31. {
  32. Dictionary<string, string> param = new Dictionary<string, string>();
  33. param["?first"] = user;
  34. param["?second"] = last;
  35. System.Data.IDbCommand result = database.Query("SELECT * FROM users WHERE username = ?first AND lastname = ?second", param);
  36. System.Data.IDataReader reader = result.ExecuteReader();
  37. UserProfileData row = database.getUserRow(reader);
  38. reader.Close();
  39. result.Dispose();
  40. return row;
  41. }
  42. }
  43. catch (Exception e)
  44. {
  45. Console.WriteLine(e.ToString());
  46. return null;
  47. }
  48. }
  49. public UserProfileData getUserByUUID(LLUUID uuid)
  50. {
  51. try
  52. {
  53. lock (database)
  54. {
  55. Dictionary<string, string> param = new Dictionary<string, string>();
  56. param["?uuid"] = uuid.ToStringHyphenated();
  57. System.Data.IDbCommand result = database.Query("SELECT * FROM users WHERE UUID = ?uuid", param);
  58. System.Data.IDataReader reader = result.ExecuteReader();
  59. UserProfileData row = database.getUserRow(reader);
  60. reader.Close();
  61. result.Dispose();
  62. return row;
  63. }
  64. }
  65. catch (Exception e)
  66. {
  67. Console.WriteLine(e.ToString());
  68. return null;
  69. }
  70. }
  71. public UserAgentData getAgentByName(string name)
  72. {
  73. return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
  74. }
  75. public UserAgentData getAgentByName(string user, string last)
  76. {
  77. UserProfileData profile = getUserByName(user, last);
  78. return getAgentByUUID(profile.UUID);
  79. }
  80. public UserAgentData getAgentByUUID(LLUUID uuid)
  81. {
  82. try
  83. {
  84. lock (database)
  85. {
  86. Dictionary<string, string> param = new Dictionary<string, string>();
  87. param["?uuid"] = uuid.ToStringHyphenated();
  88. System.Data.IDbCommand result = database.Query("SELECT * FROM agents WHERE UUID = ?uuid", param);
  89. System.Data.IDataReader reader = result.ExecuteReader();
  90. UserAgentData row = database.getAgentRow(reader);
  91. reader.Close();
  92. result.Dispose();
  93. return row;
  94. }
  95. }
  96. catch (Exception e)
  97. {
  98. Console.WriteLine(e.ToString());
  99. return null;
  100. }
  101. }
  102. public void addNewUserProfile(UserProfileData user)
  103. {
  104. }
  105. public void addNewUserAgent(UserAgentData agent)
  106. {
  107. // Do nothing.
  108. }
  109. public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount)
  110. {
  111. return false;
  112. }
  113. public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
  114. {
  115. return false;
  116. }
  117. public string getName()
  118. {
  119. return "MySQL Userdata Interface";
  120. }
  121. public string getVersion()
  122. {
  123. return "0.1";
  124. }
  125. }
  126. }