Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. using ReBornWarRock_PServer.LoginServer.Docs;
  6. using ReBornWarRock_PServer.LoginServer.Packets.List_Packets;
  7. using System.Data;
  8. using ReBornWarRock_PServer.LoginServer.Virtual.User;
  9.  
  10. namespace ReBornWarRock_PServer.LoginServer.Packets.List_Handle
  11. {
  12. class HANDLE_LOGIN : PacketHandler
  13. {
  14. private enum LoginState { Success = 1, UnknownUser, InvalidPassword, AlreadyLoggedIn, Banned, Unknown };
  15.  
  16. public override void Handle(LoginServer.Virtual.User.User Connection)
  17. {
  18. DateTime current = DateTime.Now;
  19. int StartTime = int.Parse(String.Format("{0:yyMMddHH}", current));
  20. Connection.Username = getBlock(2).ToLower();
  21. int UserID = 0;
  22. string Password = getBlock(3);
  23. try
  24. {
  25. try
  26. {
  27. UserID = int.Parse(MYSQL.runReadOnce("id", "SELECT * FROM users WHERE username='" + Connection.Username + "'").ToString());
  28. }
  29. catch { UserID = 0; }
  30. if (UserID > 0)
  31. {
  32. MYSQL.runQuery("UPDATE users SET lastipaddress='" + Connection.IPAddress + "' WHERE id='" + UserID + "'");
  33. DataTable dt = MYSQL.runRead("SELECT id, username, password, salt, online, nickname, rank, firstlogin, bantime, clanid, clanrank, banned, bantime FROM users WHERE id=" + UserID.ToString());
  34. DataRow row = dt.Rows[0];
  35.  
  36. foreach (string UserLogged in Structure.LogFromLauncher.Keys)
  37. {
  38. if (UserLogged == Connection.IPAddress.ToString())
  39. {
  40. Connection.UserID = int.Parse(row["id"].ToString());
  41. Connection.Username = row["username"].ToString();
  42. Connection.Nickname = row["nickname"].ToString();
  43. Connection.Rank = int.Parse(row["rank"].ToString());
  44. Connection.ClanID = int.Parse(row["clanid"].ToString());
  45. Connection.Banned = int.Parse(row["banned"].ToString());
  46. Connection.ClanRank = int.Parse(row["clanrank"].ToString());
  47. bool Online = (row["online"].ToString() == "1");
  48. Connection.FirstLogin = (row["firstlogin"].ToString() == "0");
  49. bool banned = (Connection.Rank == 0 || row["banned"].ToString() == "1");
  50. string bantime = row["bantime"].ToString();
  51. Connection.send(new PACKET_SERVER_LIST(Connection));
  52. }
  53.  
  54. }
  55.  
  56. string Salt = row["salt"].ToString();
  57. string md5Password = Structure.convertToMD5(Structure.convertToMD5(Password) + Structure.convertToMD5(Salt));
  58.  
  59. if (row["password"].ToString() == md5Password)
  60. {
  61. Connection.UserID = int.Parse(row["id"].ToString());
  62. Connection.Username = row["username"].ToString();
  63. Connection.Nickname = row["nickname"].ToString();
  64. Connection.Rank = int.Parse(row["rank"].ToString());
  65. Connection.ClanID = int.Parse(row["clanid"].ToString());
  66. Connection.Banned = int.Parse(row["banned"].ToString());
  67. Connection.ClanRank = int.Parse(row["clanrank"].ToString());
  68. bool Online = (row["online"].ToString() == "1");
  69. Connection.FirstLogin = (row["firstlogin"].ToString() == "0");
  70. bool banned = (Connection.Rank == 0 || row["banned"].ToString() == "1");
  71. string bantime = row["bantime"].ToString();
  72.  
  73. if (Connection.Rank > 0)
  74. {
  75. if (Online)
  76. {
  77. Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.AlreadyLoggedIn));
  78. Log.AppendText("Player " + Connection.Username + ", logged in with ip: " + Connection.IPAddress + " but the user is already online.");
  79. }
  80. else
  81. {
  82. if (Connection.FirstLogin)
  83. {
  84. Connection.UserID = UserID;
  85. Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.Nickname));
  86. Log.AppendText("Connection from " + Connection.IPAddress + " logged succesfull in as new username ( " + Connection.Username + " )");
  87.  
  88. }
  89. else
  90. {
  91. if (Connection.ClanID != -1)
  92. {
  93. DataTable mydt = MYSQL.runRead("SELECT clanname, iconid FROM clans WHERE id='" + Connection.ClanID + "'");
  94. if (mydt.Rows.Count > 0)
  95. {
  96. DataRow myrow = mydt.Rows[0];
  97. Connection.ClanName = myrow["clanname"].ToString();
  98. Connection.ClanIconID = long.Parse(myrow["iconid"].ToString());
  99. }
  100. }
  101.  
  102. Connection.send(new PACKET_SERVER_LIST(Connection));
  103. Log.AppendText("Player " + Connection.Nickname + ", logged in!");
  104. }
  105. Structure._AcceptedLogins++;
  106. }
  107. }
  108. else
  109. {
  110. if (int.Parse(bantime) > StartTime || Connection.Banned == 1)
  111. {
  112. Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.Banned));
  113. Log.AppendError("Connection from " + Connection.IPAddress + " failed to login because the account " + Connection.Username + " is disabled/banned.");
  114. }
  115. else
  116. {
  117. DB.runQuery("UPDATE users SET rank='1', bantime='-1' WHERE id='" + Connection.UserID + "'");
  118. Connection.send(new PACKET_SERVER_LIST(Connection));
  119. Log.AppendText("Connection from " + Connection.IPAddress + " logged succesfull in as " + Connection.Nickname + ".");
  120. }
  121. }
  122. }
  123. else
  124. {
  125. Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.WrongPW));
  126. Log.AppendError("Connection from " + Connection.IPAddress + " failed to login on the account " + Connection.Username + ".");
  127. }
  128. }
  129. else
  130. {
  131. UserID = -1;
  132. Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.WrongUser));
  133. Log.AppendError("Connection from " + Connection.IPAddress + " logged in with an invalid username: " + Connection.Username + ".");
  134. }
  135. }
  136. catch (Exception ex)
  137. {
  138. Connection.disconnect();
  139. Log.AppendError(ex.Message);
  140. }
  141. }
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement