Advertisement
XConquer

PlayerTablet to stream

Dec 30th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. using COServer.Client;
  2. using COServer.Database;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace COServer
  10. {
  11. public class PlayersTable
  12. {
  13. public static void UpdateOnlineStatus(GameClient client, bool online, MySql.Data.MySqlClient.MySqlConnection conn)
  14. {
  15. if (online || (!online && client.DoSetOffline))
  16. {
  17. UpdateData(client, "Online", online);
  18. }
  19. }
  20. public static void UpdateOnlineStatus(Client.GameClient client, bool online)
  21. {
  22. if (online || (!online && client.DoSetOffline))
  23. {
  24. UpdateData(client, "Online", online);
  25. }
  26. }
  27. public static void UpdateData(Client.GameClient client, string column, object value)
  28. {
  29. UpdateData(client.Player.UID, column, value);
  30. }
  31. public static void UpdateData(uint UID, string column, object value)
  32. {
  33. if (value is Boolean)
  34. {
  35. using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE))
  36. cmd.Update("entities").Set(column, (Boolean)value).Where("UID", UID)
  37. .Execute();
  38. }
  39. else
  40. {
  41. using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE))
  42. cmd.Update("entities").Set(column, value.ToString()).Where("UID", UID)
  43. .Execute();
  44. }
  45. }
  46. private static bool ExistsMyPlayerUID(uint UID)
  47. {
  48. using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("UID", UID))
  49. using (var reader = new MySqlReader(cmd))
  50. {
  51. while (reader.Read())
  52. {
  53. reader.Close();
  54. reader.Dispose();
  55. return true;
  56. }
  57. return false;
  58. }
  59. }
  60. public static void InserMyPlayerUID(Client.GameClient client)
  61. {
  62. try
  63. {
  64. if (!ExistsMyPlayerUID(client.Player.UID))
  65. {
  66. using (var cmd = new MySqlCommand(MySqlCommandType.INSERT).Insert("entities"))
  67. cmd.Insert("UID", client.Player.UID)
  68. .Execute();
  69. }
  70. }
  71. catch (Exception)
  72. {
  73.  
  74. }
  75. }
  76. public static bool InsertWhenLoggIn(GameClient client)
  77. {
  78. InserMyPlayerUID(client);
  79. WindowsAPI.IniFile ini = new WindowsAPI.IniFile("");
  80. foreach (string fname in System.IO.Directory.GetFiles(Program.ServerConfig.DbLocation + "\\Users\\"))
  81. ini.FileName = fname;
  82. uint UID = ini.ReadUInt32("Character", "UID", 0);
  83. if(UID == 0)
  84. UID = ini.ReadUInt32("Character", "UID", 0);
  85. using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("UID", UID))
  86. using (var reader = new MySqlReader(cmd))
  87. {
  88. if (reader.Read())
  89. {
  90. client.Player.UID = reader.ReadUInt32("UID");
  91. return true;
  92. }
  93. else
  94. return false;
  95. }
  96. }
  97.  
  98. }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement