mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 13:45:42 +12:00
Add %BAN
This commit is contained in:
parent
9f44620fd7
commit
49522e9fef
8 changed files with 165 additions and 6 deletions
|
@ -108,7 +108,7 @@
|
|||
}
|
||||
},
|
||||
"login":{
|
||||
"banned":"Your account has been banned. This occurs when too many rules have been broken",
|
||||
"banned":"Your account has been banned. This occurs when too many rules have been broken. ",
|
||||
"ip_banned":"Your IP address has been blocked (%IP%)"
|
||||
},
|
||||
"abuse_report":{
|
||||
|
|
|
@ -64,6 +64,8 @@ namespace HISP.Game.Chat
|
|||
return Command.Kick(message, args, user);
|
||||
if (message.StartsWith("%NOCLIP"))
|
||||
return Command.NoClip(message, args, user);
|
||||
if (message.StartsWith("%BAN"))
|
||||
return Command.Ban(message, args, user);
|
||||
return false;
|
||||
}
|
||||
if (message[0] == '!')
|
||||
|
|
|
@ -62,6 +62,34 @@ namespace HISP.Game.Chat
|
|||
user.LoggedinClient.SendPacket(chatPacket);
|
||||
return true;
|
||||
}
|
||||
public static bool Ban(string message, string[] args, User user)
|
||||
{
|
||||
if (args.Length <= 0)
|
||||
return false;
|
||||
if(!user.Administrator || !user.Moderator)
|
||||
return false;
|
||||
try{
|
||||
string userName = args[0];
|
||||
int id = Database.GetUserid(userName);
|
||||
string ip = Database.GetIpAddress(id);
|
||||
string reason = "NONE SPECIFIED";
|
||||
if (args.Length >= 2)
|
||||
{
|
||||
reason = string.Join(" ", args, 1, args.Length - 1);
|
||||
}
|
||||
|
||||
Database.BanUser(id, ip, reason);
|
||||
User bannedUser = GameServer.GetUserByName(args[0]);
|
||||
bannedUser.LoggedinClient.Kick(Messages.KickReasonBanned);
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Stickbug(string message, string[] args, User user)
|
||||
{
|
||||
if (args.Length <= 0)
|
||||
|
|
|
@ -523,6 +523,10 @@ namespace HISP.Game
|
|||
public static string FountainDrankYourFull;
|
||||
public static string FountainDroppedMoneyFormat;
|
||||
|
||||
// Login Fail messages
|
||||
public static string LoginFailedReasonBanned;
|
||||
public static string LoginFailedReasonBannedIpFormat;
|
||||
|
||||
// Disconnect Messages
|
||||
public static string KickReasonBanned;
|
||||
public static string KickReasonKicked;
|
||||
|
@ -537,7 +541,10 @@ namespace HISP.Game
|
|||
|
||||
// Click
|
||||
public static string NothingInterestingHere;
|
||||
|
||||
public static string FormatIpBannedMessage(string Ip)
|
||||
{
|
||||
return LoginFailedReasonBannedIpFormat.Replace("%IP%", Ip);
|
||||
}
|
||||
public static string FormatAwardEntry(int iconId, string awardName, int bonusMoney, string description)
|
||||
{
|
||||
return AwardEntryFormat.Replace("%ICONID%", iconId.ToString()).Replace("%AWARDNAME%", awardName).Replace("%BONUSMONEY%",bonusMoney.ToString("N0")).Replace("%DESCRIPTION%",description);
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace HISP.Server
|
|||
{
|
||||
db.Open();
|
||||
string UserTable = "CREATE TABLE Users(Id INT, Username TEXT(16),Email TEXT(128),Country TEXT(128),SecurityQuestion Text(128),SecurityAnswerHash TEXT(128),Age INT,PassHash TEXT(128), Salt TEXT(128),Gender TEXT(16), Admin TEXT(3), Moderator TEXT(3))";
|
||||
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, LastLogin INT, Money INT, QuestPoints INT, BankBalance DOUBLE, BankInterest DOUBLE, ProfilePage Text(1028),PrivateNotes Text(1028), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT)";
|
||||
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, LastLogin INT, Money INT, QuestPoints INT, BankBalance DOUBLE, BankInterest DOUBLE, ProfilePage Text(1028),IpAddress TEXT(1028),PrivateNotes Text(1028), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT)";
|
||||
string MailTable = "CREATE TABLE Mailbox(IdTo INT, PlayerFrom TEXT(16),Subject TEXT(128), Message Text(1028), TimeSent INT)";
|
||||
string BuddyTable = "CREATE TABLE BuddyList(Id INT, IdFriend INT, Pending BOOL)";
|
||||
string WorldTable = "CREATE TABLE World(Time INT,Day INT, Year INT, Weather TEXT(64))";
|
||||
|
@ -40,6 +40,7 @@ namespace HISP.Server
|
|||
string WildHorse = "CREATE TABLE WildHorse(randomId INT, originalOwner INT, breed INT, x INT, y INT, name TEXT(128), description TEXT(1028), sex TEXT(128), color TEXT(128), health INT, shoes INT, hunger INT, thirst INT, mood INT, groom INT, tiredness INT, experience INT, speed INT, strength INT, conformation INT, agility INT, endurance INT, inteligence INT, personality INT, height INT, saddle INT, saddlepad INT, bridle INT, companion INT, timeout INT, autoSell INT, trainTimer INT, category TEXT(128), spoiled INT, magicUsed INT)";
|
||||
string LastPlayer = "CREATE TABLE LastPlayer(roomId TEXT(1028), playerId INT)";
|
||||
string TrackingStats = "CREATE TABLE Tracking(playerId INT, what TEXT(128), count INT)";
|
||||
string BannedPlayers = "CREATE TABLE BannedPlayers(playerId INT, ipAddress TEXT(1028), reason TEXT(1028))";
|
||||
string DeleteOnlineUsers = "DELETE FROM OnlineUsers";
|
||||
|
||||
try
|
||||
|
@ -52,6 +53,7 @@ namespace HISP.Server
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.DebugPrint(e.GetType().ToString());
|
||||
Logger.WarnPrint(e.Message);
|
||||
};
|
||||
|
||||
|
@ -224,7 +226,19 @@ namespace HISP.Server
|
|||
Logger.WarnPrint(e.Message);
|
||||
};
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = BannedPlayers;
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WarnPrint(e.Message);
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
@ -637,6 +651,51 @@ namespace HISP.Server
|
|||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void BanUser(int userId, string ip, string reason)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "INSERT INTO BannedPlayers VALUES(@playerId,@ipAddress,@reason)";
|
||||
sqlCommand.Parameters.AddWithValue("@playerId", userId);
|
||||
sqlCommand.Parameters.AddWithValue("@ipAddress", ip);
|
||||
sqlCommand.Parameters.AddWithValue("@reason", reason);
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool IsIpBanned(string ip)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "SELECT COUNT(1) FROM BannedPlayers WHERE ipAddress=@ipAddr";
|
||||
sqlCommand.Parameters.AddWithValue("@ipAddr", ip);
|
||||
int count = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
sqlCommand.Dispose();
|
||||
return count >= 1;
|
||||
}
|
||||
}
|
||||
public static bool IsUserBanned(int userId)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "SELECT COUNT(1) FROM BannedPlayers WHERE playerId=@playerId";
|
||||
sqlCommand.Parameters.AddWithValue("@playerId", userId);
|
||||
int count = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
sqlCommand.Dispose();
|
||||
return count >= 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void AddWildHorse(WildHorse horse)
|
||||
{
|
||||
|
||||
|
@ -2597,6 +2656,42 @@ namespace HISP.Server
|
|||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
public static string GetIpAddress(int id)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
if (!CheckUserExtExists(id)) // user allready exists!
|
||||
throw new Exception("Userid " + id + " Does not exist in UserExt.");
|
||||
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "SELECT IpAddress FROM UserExt WHERE Id=@playerId";
|
||||
sqlCommand.Parameters.AddWithValue("@playerId", id);
|
||||
sqlCommand.Prepare();
|
||||
string IpAddress = sqlCommand.ExecuteScalar().ToString();
|
||||
sqlCommand.Dispose();
|
||||
return IpAddress;
|
||||
}
|
||||
}
|
||||
public static void SetIpAddress(int id, string ipAddress)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
if (!CheckUserExtExists(id)) // user allready exists!
|
||||
throw new Exception("Userid " + id + " Does not exist in UserExt.");
|
||||
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "UPDATE UserExt SET IpAddress=@ipAddr WHERE Id=@playerId";
|
||||
sqlCommand.Parameters.AddWithValue("@ipAddr", ipAddress);
|
||||
sqlCommand.Parameters.AddWithValue("@playerId", id);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateUserExt(int id)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
|
@ -2606,7 +2701,7 @@ namespace HISP.Server
|
|||
throw new Exception("Userid " + id + " Allready in UserExt.");
|
||||
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "INSERT INTO UserExt VALUES(@id,@x,@y,@timestamp,0,0,0,0,'','',0,0,'NO',0,0,1000,1000,1000, 180)";
|
||||
sqlCommand.CommandText = "INSERT INTO UserExt VALUES(@id,@x,@y,@timestamp,0,0,0,0,'','','',0,0,'NO',0,0,1000,1000,1000, 180)";
|
||||
sqlCommand.Parameters.AddWithValue("@id", id);
|
||||
sqlCommand.Parameters.AddWithValue("@timestamp", Convert.ToInt32(new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds()));
|
||||
sqlCommand.Parameters.AddWithValue("@x", Map.NewUserStartX);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using HISP.Player;
|
||||
|
@ -125,10 +126,11 @@ namespace HISP.Server
|
|||
Client.Kick(Messages.KickReasonDuplicateLogin);
|
||||
}
|
||||
}
|
||||
|
||||
LoggedinUser = new User(this,id);
|
||||
LoggedIn = true;
|
||||
|
||||
Database.SetIpAddress(id, RemoteIp);
|
||||
|
||||
updateTimer = new Timer(new TimerCallback(updateTimerTick), null, updateInterval, updateInterval);
|
||||
inactivityTimer = new Timer(new TimerCallback(keepAliveTimerTick), null, keepAliveInterval, keepAliveInterval);
|
||||
}
|
||||
|
@ -332,6 +334,9 @@ namespace HISP.Server
|
|||
{
|
||||
ClientSocket = clientSocket;
|
||||
RemoteIp = clientSocket.RemoteEndPoint.ToString();
|
||||
|
||||
if(RemoteIp.Contains(":"))
|
||||
RemoteIp = RemoteIp.Substring(0, RemoteIp.IndexOf(":"));
|
||||
|
||||
Logger.DebugPrint("Client connected @ " + RemoteIp);
|
||||
|
||||
|
|
|
@ -1054,6 +1054,10 @@ namespace HISP.Server
|
|||
Messages.NpcInformationButton = gameData.messages.meta.npc.npc_information_button;
|
||||
Messages.NpcInformationFormat = gameData.messages.meta.npc.npc_information_format;
|
||||
|
||||
// Login Failed Reasons
|
||||
Messages.LoginFailedReasonBanned = gameData.messages.login.banned;
|
||||
Messages.LoginFailedReasonBannedIpFormat = gameData.messages.login.ip_banned;
|
||||
|
||||
// Disconnect Reasons
|
||||
|
||||
Messages.KickReasonKicked = gameData.messages.disconnect.kicked;
|
||||
|
|
|
@ -3506,6 +3506,24 @@ namespace HISP.Server
|
|||
{
|
||||
// Obtain user information
|
||||
int userId = Database.GetUserid(username);
|
||||
|
||||
if(Database.IsUserBanned(userId))
|
||||
{
|
||||
Logger.DebugPrint(sender.RemoteIp + " Tried to login to : " + username + " but, the account was banned.");
|
||||
byte[] userBannedPacket = PacketBuilder.CreateLoginPacket(false, Messages.LoginFailedReasonBanned);
|
||||
sender.SendPacket(userBannedPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
if(Database.IsIpBanned(sender.RemoteIp))
|
||||
{
|
||||
Logger.DebugPrint(sender.RemoteIp + " Tried to login to : " + username + " but, the IP was banned.");
|
||||
byte[] ipBannedPacket = PacketBuilder.CreateLoginPacket(false, Messages.FormatIpBannedMessage(sender.RemoteIp));
|
||||
sender.SendPacket(ipBannedPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sender.Login(userId);
|
||||
sender.LoggedinUser.Password = password;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue