Guest User

Untitled

a guest
Feb 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1.  
  2. private void HandleClientComm(object client)
  3. {
  4. TcpClient tcpClient = (TcpClient)client;
  5. NetworkStream clientStream = tcpClient.GetStream();
  6. using (BinaryReader reader = new BinaryReader(clientStream))
  7. {
  8.  
  9. string username, pw, email;
  10. while (true)
  11. {
  12. #region stuff....
  13. ////////////////////////////
  14. // MYSQL CONNECTION INFO //
  15. //////////////////////////
  16. string connString = "Server=196.220.60.236;Port=3307;Database=gamedb;Uid=testuser;password=testpass;"; // INTERNET DATABASE
  17. MySqlConnection conn = new MySqlConnection(connString);
  18. MySqlCommand command = conn.CreateCommand();
  19. ////////////////////////////
  20. // MYSQL CONNECTION INFO //
  21. //////////////////////////
  22.  
  23. //////////////////////////////////////
  24. // READ BYTES RECIEVED FROM CLIENT //
  25. ////////////////////////////////////
  26. try
  27. {
  28.  
  29. //blocks until a client sends a message
  30. username = reader.ReadString();//THE ORDER MATTERS!!!
  31. pw = reader.ReadString();
  32. email = reader.ReadString();
  33. }
  34. catch
  35. {
  36. //PROBABLY a socket error has occured
  37. break;
  38. }
  39.  
  40.  
  41. ///////////////////////
  42. // INSERT STATEMENT //
  43. /////////////////////
  44. if (username == null || username.Length == 0)
  45. {
  46. //throw?
  47. }
  48. else if (pw == null || pw.Length == 0)
  49. {
  50. //throw?
  51. }
  52. else if (email == null || email.Length == 0)
  53. {
  54. //throw?
  55. }
  56. else
  57. {
  58. command.CommandText = "Insert into players (id,username,email,password) values('','" + username + "','" + email + "','" + pw + "')";
  59. try
  60. {
  61. conn.Open();
  62. command.ExecuteNonQuery();
  63. }
  64. catch (Exception ex)
  65. {
  66. MessageBox.Show(ex.Message);
  67. }
  68. MessageBox.Show("DONE!");
  69. }
  70. ///////////////////////
  71. // INSERT STATEMENT //
  72. /////////////////////
  73.  
  74. /////////////////////////////
  75. // CLOSE MYSQL CONNECTION //
  76. ///////////////////////////
  77. conn.Close();
  78. /////////////////////////////
  79. // CLOSE MYSQL CONNECTION //
  80. ///////////////////////////
  81. #endregion
  82. }
  83. }
  84. }
Add Comment
Please, Sign In to add comment