Advertisement
Guest User

Untitled

a guest
Jul 10th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. using System.Text;
  2. using System.Net.Sockets;
  3. using UnityEngine;
  4. using System.Threading;
  5. using MySql.Data.MySqlClient;
  6. using System.Data;
  7.  
  8.  
  9. namespace Server
  10. {
  11. public class SocketHelper : MonoBehaviour
  12. {
  13. TcpClient mscClient;
  14. string mstrMessage;
  15. string mstrResponse;
  16. byte[] bytesSent;
  17. public string incomingData = null;
  18. byte[] data = new byte[256];
  19. public string MyConncetionString = "Server=localhost;Database=server;Uid=root;Pwd=;";
  20. public string idString = "";
  21. public string pwString = "";
  22. private string passwordData;
  23.  
  24. public void processData(TcpClient client, NetworkStream stream, byte[] bytesReceived)
  25. {
  26.  
  27. Debug.Log(Thread.CurrentThread.Name);
  28.  
  29. while (true)
  30. {
  31. int bytes = stream.Read(data, 0, data.Length);
  32. incomingData = Encoding.ASCII.GetString(data, 0, bytes);
  33. Debug.Log(incomingData);
  34. string[] words = incomingData.Split(' ');
  35. foreach (string word in words)
  36. {
  37. idString = words[0];
  38. Debug.Log(idString);
  39. pwString = words[1];
  40. Debug.Log(pwString);
  41. }
  42. Thread AuthServer = new Thread(authServer);
  43. AuthServer.Name = "AuthorisationThread";
  44. AuthServer.Start();
  45. }
  46.  
  47. }
  48.  
  49. public void authServer()
  50. {
  51. MySqlConnection connection = null;
  52. string hostname = "localhost";
  53. string database = "server";
  54. string username = "root";
  55. string password = "";
  56. connection = new MySqlConnection("host=" + hostname +
  57. ";database=" + database +
  58. ";username=" + username +
  59. ";password=" + password + ";");
  60. MySqlCommand cmd;
  61. connection.Open();
  62. Debug.Log("MySQL Connection established");
  63. DataSet ds = new DataSet();
  64.  
  65. cmd = connection.CreateCommand();
  66. cmd.CommandText = "select * from account " +
  67. "where login like '" + idString + "'";
  68.  
  69. MySqlDataReader reader = cmd.ExecuteReader();
  70. reader.Read();
  71. passwordData = reader.GetString("password");
  72. if (passwordData == pwString)
  73. {
  74. Debug.Log("logged in");
  75. WorldServer worldServer = new WorldServer();
  76. Thread account = new Thread(() => worldServer.Account(idString));
  77. account.Name = idString;
  78. Debug.Log(account.Name.ToString());
  79. account.Start();
  80. Server server = new Server();
  81. }
  82. }
  83.  
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement