Hello everyone,
So I was managed to fix the ingame register. This works for the most databases. ( It is not recommended to use it, because you will be vulnerable for bot attacks... but sometimes you don't have a other choise... I try to get a register limit and add it to it. )
How to install:
Open loginserver source and search for: HANDLE_LOGIN.cs ( At handlers )
Once you've found that, replace the whole code with the code underneath here, and build the project and try it out!
Kind regards,
Onny.
So I was managed to fix the ingame register. This works for the most databases. ( It is not recommended to use it, because you will be vulnerable for bot attacks... but sometimes you don't have a other choise... I try to get a register limit and add it to it. )
How to install:
Open loginserver source and search for: HANDLE_LOGIN.cs ( At handlers )
Once you've found that, replace the whole code with the code underneath here, and build the project and try it out!
Code:
using System;
using System.Collections.Generic;
using System.Text;
using LoginServer.Manager;
using LoginServer.Networking.Packets;
namespace LoginServer.Networking.Handlers
{
class HANDLE_LOGIN : PacketHandler
{
private enum LoginState { Success = 1, UnknownUser, InvalidPassword, AlreadyLoggedIn, Banned, Unknown };
public override void Handle(LoginServer.Virtual_Objects.User.virtualUser Connection)
{
DateTime current = DateTime.Now;
int StartTime = int.Parse(String.Format("{0:yyMMddHH}", current));
Connection.Username = getBlock(2).ToLower();
string Password = getBlock(3).ToLower();
try
{
LoginState ReturnValue = LoginState.Unknown;
int UserID = DB.runRead("SELECT id FROM users WHERE username='" + DB.Stripslash(Connection.Username) + "'", null);
if (UserID > 0)
{
string[] UserData = DB.runReadRow("SELECT id, username, password, salt, online, nickname, rank, firstlogin, bantime FROM users WHERE id=" + UserID.ToString());
if (UserData[2].ToLower() == Password.ToLower())
{
if (BanManager.isBlocked(UserID) == false && RankManager.HasPermision(int.Parse(UserData[6]), "account.authorize"))
{
if (UserData[4].Equals("1"))
{
ReturnValue = LoginState.AlreadyLoggedIn;
Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.AlreadyLoggedIn));
Log.WriteLine("Connection from " + Connection.IPAddress + " logged succesfull in as " + UserData[5] + " but the user is already online.");
}
else
{
ReturnValue = LoginState.Success;
if (UserData[7].Equals("0"))
{
Connection.UserID = UserID;
Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.Nickname));
Log.WriteLine("Connection from " + Connection.IPAddress + " logged succesfull in as " + UserData[5] + ".");
}
else
{
Connection.send(new PACKET_SERVER_LIST(int.Parse(UserData[0]), UserData[1], Password, UserData[5], Connection.SessionID, int.Parse(UserData[6])));
Log.WriteLine("Connection from " + Connection.IPAddress + " logged succesfull in as " + UserData[5] + ".");
}
Program._AcceptedLogins++;
Program._PlayerCount++;
}
}
else
{
if (int.Parse(UserData[8]) > StartTime)
{
ReturnValue = LoginState.Banned;
Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.Banned));
Log.WriteError("Connection from " + Connection.IPAddress + " failed to login because the account " + UserData[1] + " is disabled/banned.");
}
else
{
DB.runQuery("UPDATE users SET rank='1', bantime='-1' WHERE id='" + UserData[0] + "'");
Connection.send(new PACKET_SERVER_LIST(int.Parse(UserData[0]), UserData[1], Password, UserData[5], Connection.SessionID, int.Parse(UserData[6])));
Log.WriteLine("Connection from " + Connection.IPAddress + " logged succesfull in as " + UserData[5] + ".");
}
}
}
else
{
ReturnValue = LoginState.InvalidPassword;
Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.WrongPW));
Log.WriteError("Connection from " + Connection.IPAddress + " failed to login on the account " + UserData[1] + ".");
}
}
else
{
UserID = -1;
ReturnValue = LoginState.UnknownUser;
// Default! >> But this didn't work for me DB.runQuery("INSERT INTO users (username, password, dinar, cash) VALUES ('" + Connection.Username + "', '" + Password + "', '35000', '5000')");
DB.runQuery("INSERT INTO users (username, password, nickname, email, EXP, dinar, cash, kills, deaths, lasthwid) VALUES ('" + Connection.Username + "', '" + Password + "', '" + Connection.Username + "', 'autoregister@gmail.com', '1', '35000', '5000', '0', '0', '0')");
Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.WrongUser));
}
//DB.runQuery("INSERT INTO log_authorize (`time`, `userid`, `username`, `password`, `result`, `ip`, `host`) VALUES ('" + Program.UnixTimestamp + "', '" + UserID + "', '" + DB.Stripslash(Connection.Username) + "', '" + DB.Stripslash(Password) + "', '" + ((int)ReturnValue).ToString() + "', '" + Connection.IPAddress + "', '" + Connection.Hostname + "');");
}
catch (Exception ex)
{
Connection.disconnect();
Log.WriteError(ex.Message);
}
}
private static String hashMD5(String Input)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(Input);
byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}
return sb.ToString();
}
}
}
Kind regards,
Onny.