Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)
This commit is contained in:
parent
e748af4430
commit
513e54f70e
1094 changed files with 15913 additions and 21892 deletions
|
|
@ -116,21 +116,15 @@ namespace Server.Engines.Chat
|
|||
|
||||
public bool ValidateAccess(ChatUser from, ChatUser target)
|
||||
{
|
||||
if (from != null && target != null && from.Mobile.AccessLevel < target.Mobile.AccessLevel)
|
||||
{
|
||||
from.Mobile.SendMessage("Your access level is too low to do this.");
|
||||
return false;
|
||||
}
|
||||
if (from == null || target == null || from.Mobile.AccessLevel >= target.Mobile.AccessLevel)
|
||||
return true;
|
||||
|
||||
from.Mobile.SendMessage("Your access level is too low to do this.");
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddUser(ChatUser user)
|
||||
{
|
||||
return AddUser(user, null);
|
||||
}
|
||||
|
||||
public bool AddUser(ChatUser user, string password)
|
||||
public bool AddUser(ChatUser user, string password = null)
|
||||
{
|
||||
if (Contains(user))
|
||||
{
|
||||
|
|
@ -188,12 +182,7 @@ namespace Server.Engines.Chat
|
|||
}
|
||||
}
|
||||
|
||||
public void AdBan(ChatUser user)
|
||||
{
|
||||
AddBan(user, null);
|
||||
}
|
||||
|
||||
public void AddBan(ChatUser user, ChatUser moderator)
|
||||
public void AddBan(ChatUser user, ChatUser moderator = null)
|
||||
{
|
||||
if (!ValidateModerator(moderator) || !ValidateAccess(moderator, user))
|
||||
return;
|
||||
|
|
@ -210,12 +199,7 @@ namespace Server.Engines.Chat
|
|||
m_Banned.Remove(user);
|
||||
}
|
||||
|
||||
public void Kick(ChatUser user)
|
||||
{
|
||||
Kick(user, null);
|
||||
}
|
||||
|
||||
public void Kick(ChatUser user, ChatUser moderator)
|
||||
public void Kick(ChatUser user, ChatUser moderator = null)
|
||||
{
|
||||
Kick(user, moderator, false);
|
||||
}
|
||||
|
|
@ -248,12 +232,7 @@ namespace Server.Engines.Chat
|
|||
moderator?.SendMessage(62, user.Username); // You are banning %1 from this conference.
|
||||
}
|
||||
|
||||
public void AddVoiced(ChatUser user)
|
||||
{
|
||||
AddVoiced(user, null);
|
||||
}
|
||||
|
||||
public void AddVoiced(ChatUser user, ChatUser moderator)
|
||||
public void AddVoiced(ChatUser user, ChatUser moderator = null)
|
||||
{
|
||||
if (!ValidateModerator(moderator))
|
||||
return;
|
||||
|
|
@ -291,12 +270,7 @@ namespace Server.Engines.Chat
|
|||
}
|
||||
}
|
||||
|
||||
public void AddModerator(ChatUser user)
|
||||
{
|
||||
AddModerator(user, null);
|
||||
}
|
||||
|
||||
public void AddModerator(ChatUser user, ChatUser moderator)
|
||||
public void AddModerator(ChatUser user, ChatUser moderator = null)
|
||||
{
|
||||
if (!ValidateModerator(moderator))
|
||||
return;
|
||||
|
|
@ -316,12 +290,7 @@ namespace Server.Engines.Chat
|
|||
SendCommand(ChatCommand.AddUserToChannel, user.GetColorCharacter() + user.Username);
|
||||
}
|
||||
|
||||
public void RemoveModerator(ChatUser user)
|
||||
{
|
||||
RemoveModerator(user, null);
|
||||
}
|
||||
|
||||
public void RemoveModerator(ChatUser user, ChatUser moderator)
|
||||
public void RemoveModerator(ChatUser user, ChatUser moderator = null)
|
||||
{
|
||||
if (!ValidateModerator(moderator) || !ValidateAccess(moderator, user))
|
||||
return;
|
||||
|
|
@ -338,32 +307,12 @@ namespace Server.Engines.Chat
|
|||
}
|
||||
}
|
||||
|
||||
public void SendMessage(int number)
|
||||
public void SendMessage(int number, string param1 = null)
|
||||
{
|
||||
SendMessage(number, null, null, null);
|
||||
SendMessage(number, null, param1);
|
||||
}
|
||||
|
||||
public void SendMessage(int number, string param1)
|
||||
{
|
||||
SendMessage(number, null, param1, null);
|
||||
}
|
||||
|
||||
public void SendMessage(int number, string param1, string param2)
|
||||
{
|
||||
SendMessage(number, null, param1, param2);
|
||||
}
|
||||
|
||||
public void SendMessage(int number, ChatUser initiator)
|
||||
{
|
||||
SendMessage(number, initiator, null, null);
|
||||
}
|
||||
|
||||
public void SendMessage(int number, ChatUser initiator, string param1)
|
||||
{
|
||||
SendMessage(number, initiator, param1, null);
|
||||
}
|
||||
|
||||
public void SendMessage(int number, ChatUser initiator, string param1, string param2)
|
||||
public void SendMessage(int number, ChatUser initiator, string param1 = null, string param2 = null)
|
||||
{
|
||||
for (int i = 0; i < m_Users.Count; ++i)
|
||||
{
|
||||
|
|
@ -395,32 +344,12 @@ namespace Server.Engines.Chat
|
|||
}
|
||||
}
|
||||
|
||||
public void SendCommand(ChatCommand command)
|
||||
{
|
||||
SendCommand(command, null, null, null);
|
||||
}
|
||||
|
||||
public void SendCommand(ChatCommand command, string param1)
|
||||
{
|
||||
SendCommand(command, null, param1, null);
|
||||
}
|
||||
|
||||
public void SendCommand(ChatCommand command, string param1, string param2)
|
||||
public void SendCommand(ChatCommand command, string param1 = null, string param2 = null)
|
||||
{
|
||||
SendCommand(command, null, param1, param2);
|
||||
}
|
||||
|
||||
public void SendCommand(ChatCommand command, ChatUser initiator)
|
||||
{
|
||||
SendCommand(command, initiator, null, null);
|
||||
}
|
||||
|
||||
public void SendCommand(ChatCommand command, ChatUser initiator, string param1)
|
||||
{
|
||||
SendCommand(command, initiator, param1, null);
|
||||
}
|
||||
|
||||
public void SendCommand(ChatCommand command, ChatUser initiator, string param1, string param2)
|
||||
public void SendCommand(ChatCommand command, ChatUser initiator, string param1 = null, string param2 = null)
|
||||
{
|
||||
for (int i = 0; i < m_Users.Count; ++i)
|
||||
{
|
||||
|
|
@ -457,12 +386,7 @@ namespace Server.Engines.Chat
|
|||
}
|
||||
}
|
||||
|
||||
public static Channel AddChannel(string name)
|
||||
{
|
||||
return AddChannel(name, null);
|
||||
}
|
||||
|
||||
public static Channel AddChannel(string name, string password)
|
||||
public static Channel AddChannel(string name, string password = null)
|
||||
{
|
||||
Channel channel = FindChannelByName(name);
|
||||
|
||||
|
|
@ -521,4 +445,4 @@ namespace Server.Engines.Chat
|
|||
AddChannel(name).AlwaysAvailable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,17 +16,7 @@ namespace Server.Engines.Chat
|
|||
PacketHandlers.Register(0xB3, 0, true, ChatAction);
|
||||
}
|
||||
|
||||
public static void SendCommandTo(Mobile to, ChatCommand type)
|
||||
{
|
||||
SendCommandTo(to, type, null, null);
|
||||
}
|
||||
|
||||
public static void SendCommandTo(Mobile to, ChatCommand type, string param1)
|
||||
{
|
||||
SendCommandTo(to, type, param1, null);
|
||||
}
|
||||
|
||||
public static void SendCommandTo(Mobile to, ChatCommand type, string param1, string param2)
|
||||
public static void SendCommandTo(Mobile to, ChatCommand type, string param1 = null, string param2 = null)
|
||||
{
|
||||
to?.Send(new ChatMessagePacket(null, (int)type + 20, param1, param2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ namespace Server.Engines.Chat
|
|||
|
||||
password = password?.Trim();
|
||||
|
||||
if (password != null && password.Length == 0)
|
||||
if (password?.Length == 0)
|
||||
password = null;
|
||||
|
||||
Channel joined = Channel.FindChannelByName(name);
|
||||
|
|
@ -217,7 +217,7 @@ namespace Server.Engines.Chat
|
|||
|
||||
password = password?.Trim();
|
||||
|
||||
if (password != null && password.Length == 0)
|
||||
if (password?.Length == 0)
|
||||
password = null;
|
||||
|
||||
Channel.AddChannel(name, password).AddUser(from, password);
|
||||
|
|
@ -355,4 +355,4 @@ namespace Server.Engines.Chat
|
|||
channel.VoiceRestricted = !channel.VoiceRestricted;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,17 +49,12 @@ namespace Server.Engines.Chat
|
|||
|
||||
public bool IgnorePrivateMessage{ get; set; }
|
||||
|
||||
public bool IsModerator => CurrentChannel != null && CurrentChannel.IsModerator(this);
|
||||
public bool IsModerator => CurrentChannel?.IsModerator(this) == true;
|
||||
|
||||
public char GetColorCharacter()
|
||||
{
|
||||
if (CurrentChannel != null && CurrentChannel.IsModerator(this))
|
||||
return ModeratorColorCharacter;
|
||||
|
||||
if (CurrentChannel != null && CurrentChannel.IsVoiced(this))
|
||||
return VoicedColorCharacter;
|
||||
|
||||
return NormalColorCharacter;
|
||||
return IsModerator ? ModeratorColorCharacter :
|
||||
CurrentChannel?.IsVoiced(this) == true ? VoicedColorCharacter : NormalColorCharacter;
|
||||
}
|
||||
|
||||
public bool CheckOnline()
|
||||
|
|
@ -71,17 +66,7 @@ namespace Server.Engines.Chat
|
|||
return false;
|
||||
}
|
||||
|
||||
public void SendMessage(int number)
|
||||
{
|
||||
SendMessage(number, null, null);
|
||||
}
|
||||
|
||||
public void SendMessage(int number, string param1)
|
||||
{
|
||||
SendMessage(number, param1, null);
|
||||
}
|
||||
|
||||
public void SendMessage(int number, string param1, string param2)
|
||||
public void SendMessage(int number, string param1 = null, string param2 = null)
|
||||
{
|
||||
if (Mobile.NetState != null)
|
||||
Mobile.Send(new ChatMessagePacket(Mobile, number, param1, param2));
|
||||
|
|
@ -135,28 +120,28 @@ namespace Server.Engines.Chat
|
|||
{
|
||||
ChatUser user = GetChatUser(from);
|
||||
|
||||
if (user == null)
|
||||
if (user != null)
|
||||
return user;
|
||||
|
||||
user = new ChatUser(from);
|
||||
|
||||
m_Users.Add(user);
|
||||
m_Table[from] = user;
|
||||
|
||||
Channel.SendChannelsTo(user);
|
||||
|
||||
List<Channel> list = Channel.Channels;
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
{
|
||||
user = new ChatUser(from);
|
||||
Channel c = list[i];
|
||||
|
||||
m_Users.Add(user);
|
||||
m_Table[from] = user;
|
||||
|
||||
Channel.SendChannelsTo(user);
|
||||
|
||||
List<Channel> list = Channel.Channels;
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
{
|
||||
Channel c = list[i];
|
||||
|
||||
if (c.AddUser(user))
|
||||
break;
|
||||
}
|
||||
|
||||
//ChatSystem.SendCommandTo( user.m_Mobile, ChatCommand.AddUserToChannel, user.GetColorCharacter() + user.Username );
|
||||
if (c.AddUser(user))
|
||||
break;
|
||||
}
|
||||
|
||||
//ChatSystem.SendCommandTo( user.m_Mobile, ChatCommand.AddUserToChannel, user.GetColorCharacter() + user.Username );
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
@ -205,32 +190,12 @@ namespace Server.Engines.Chat
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void GlobalSendCommand(ChatCommand command)
|
||||
{
|
||||
GlobalSendCommand(command, null, null, null);
|
||||
}
|
||||
|
||||
public static void GlobalSendCommand(ChatCommand command, string param1)
|
||||
{
|
||||
GlobalSendCommand(command, null, param1, null);
|
||||
}
|
||||
|
||||
public static void GlobalSendCommand(ChatCommand command, string param1, string param2)
|
||||
public static void GlobalSendCommand(ChatCommand command, string param1, string param2 = null)
|
||||
{
|
||||
GlobalSendCommand(command, null, param1, param2);
|
||||
}
|
||||
|
||||
public static void GlobalSendCommand(ChatCommand command, ChatUser initiator)
|
||||
{
|
||||
GlobalSendCommand(command, initiator, null, null);
|
||||
}
|
||||
|
||||
public static void GlobalSendCommand(ChatCommand command, ChatUser initiator, string param1)
|
||||
{
|
||||
GlobalSendCommand(command, initiator, param1, null);
|
||||
}
|
||||
|
||||
public static void GlobalSendCommand(ChatCommand command, ChatUser initiator, string param1, string param2)
|
||||
public static void GlobalSendCommand(ChatCommand command, ChatUser initiator = null, string param1 = null, string param2 = null)
|
||||
{
|
||||
for (int i = 0; i < m_Users.Count; ++i)
|
||||
{
|
||||
|
|
@ -244,4 +209,4 @@ namespace Server.Engines.Chat
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue