Revert "Updates Packets & Randomizer (#43)" (#61)

This reverts commit 179cb50557.
This commit is contained in:
Kamron Batman 2019-11-11 08:46:11 -08:00 • committed by GitHub
parent 179cb50557
commit c2ecc76457
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
588 changed files with 16260 additions and 10926 deletions

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
namespace Server.Engines.Chat
{
@ -402,7 +401,18 @@ namespace Server.Engines.Chat
}
}
public static Channel FindChannelByName(string name) => Channels.FirstOrDefault(channel => channel.m_Name == name);
public static Channel FindChannelByName(string name)
{
for (int i = 0; i < Channels.Count; ++i)
{
Channel channel = Channels[i];
if (channel.m_Name == name)
return channel;
}
return null;
}
public static void Initialize()
{

View file

@ -1,13 +1,12 @@
using System;
using System.IO;
using System.Linq;
using Server.Accounting;
using Server.Misc;
using Server.Network;
namespace Server.Engines.Chat
{
public static class ChatSystem
public class ChatSystem
{
public static bool Enabled{ get; set; } = true;
@ -19,7 +18,7 @@ namespace Server.Engines.Chat
public static void SendCommandTo(Mobile to, ChatCommand type, string param1 = null, string param2 = null)
{
ChatPackets.SendChatMessage(to?.NetState, null, (int)type + 20, param1, param2);
to?.Send(new ChatMessagePacket(null, (int)type + 20, param1, param2));
}
public static void OpenChatWindowRequest(NetState state, PacketReader pvSrc)
@ -62,11 +61,21 @@ namespace Server.Engines.Chat
{
// TODO: Optimize this search
if (Accounts.GetAccounts().Cast<Account>().Any(checkAccount => Insensitive.Equals(checkAccount.GetTag("ChatName")?.Trim(), chatName)))
foreach (Account checkAccount in Accounts.GetAccounts())
{
from.SendMessage("Nickname already in use.");
SendCommandTo(from, ChatCommand.AskNewNickname);
return;
string existingName = checkAccount.GetTag("ChatName");
if (existingName != null)
{
existingName = existingName.Trim();
if (Insensitive.Equals(existingName, chatName))
{
from.SendMessage("Nickname already in use.");
SendCommandTo(from, ChatCommand.AskNewNickname);
return;
}
}
}
accountChatName = chatName;
@ -120,15 +129,17 @@ namespace Server.Engines.Chat
if (handler.RequireConference && channel == null)
user.SendMessage(31); /* You must be in a conference to do this.
* To join a conference, select one from the Conference menu.
*/
* To join a conference, select one from the Conference menu.
*/
else if (handler.RequireModerator && !user.IsModerator)
user.SendMessage(29); // You must have operator status to do this.
else
handler.Callback(user, channel, param);
}
else
{
Console.WriteLine("Client: {0}: Unknown chat action 0x{1:X}: {2}", state, actionID, param);
}
}
catch (Exception e)
{
@ -136,4 +147,4 @@ namespace Server.Engines.Chat
}
}
}
}
}

View file

@ -1,6 +1,6 @@
namespace Server.Engines.Chat
{
public static class ChatActionHandlers
public class ChatActionHandlers
{
private static ChatActionHandler[] m_Handlers;
@ -112,8 +112,8 @@ namespace Server.Engines.Chat
{
from.IgnorePrivateMessage = true;
from.SendMessage(38); /* You will no longer receive private messages.
* Those who send you a message will be notified that you are blocking incoming messages.
*/
* Those who send you a message will be notified that you are blocking incoming messages.
*/
}
public static void TogglePrivateMessages(ChatUser from, Channel channel, string param)

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Server.Accounting;
namespace Server.Engines.Chat
@ -65,14 +64,16 @@ namespace Server.Engines.Chat
return false;
}
public void SendMessage(int number, string param1 = "", string param2 = "")
public void SendMessage(int number, string param1 = null, string param2 = null)
{
ChatPackets.SendChatMessage(Mobile.NetState, Mobile, number, param1, param2);
if (Mobile.NetState != null)
Mobile.Send(new ChatMessagePacket(Mobile, number, param1, param2));
}
public void SendMessage(int number, Mobile from, string param1 = "", string param2 = "")
public void SendMessage(int number, Mobile from, string param1, string param2)
{
ChatPackets.SendChatMessage(Mobile.NetState, from, number, param1, param2);
if (Mobile.NetState != null)
Mobile.Send(new ChatMessagePacket(from, number, param1, param2));
}
public bool IsIgnored(ChatUser check) => Ignored.Contains(check);
@ -80,7 +81,9 @@ namespace Server.Engines.Chat
public void AddIgnored(ChatUser user)
{
if (IsIgnored(user))
{
SendMessage(22, user.Username); // You are already ignoring %1.
}
else
{
Ignored.Add(user);
@ -103,7 +106,9 @@ namespace Server.Engines.Chat
SendMessage(26); // You are no longer ignoring anyone.
}
else
{
SendMessage(25, user.Username); // You are not ignoring %1.
}
}
public static ChatUser AddChatUser(Mobile from)
@ -167,7 +172,18 @@ namespace Server.Engines.Chat
return c;
}
public static ChatUser GetChatUser(string username) => m_Users.FirstOrDefault(user => user.Username == username);
public static ChatUser GetChatUser(string username)
{
for (int i = 0; i < m_Users.Count; ++i)
{
ChatUser user = m_Users[i];
if (user.Username == username)
return user;
}
return null;
}
public static void GlobalSendCommand(ChatCommand command, string param1, string param2 = null)
{

View file

@ -1,6 +1,6 @@
namespace Server.Chat
{
public static class ChatSystem
public class ChatSystem
{
public static void Initialize()
{
@ -12,4 +12,4 @@ namespace Server.Chat
e.Mobile.SendMessage("Chat is not currently supported.");
}
}
}
}

View file

@ -1,36 +1,28 @@
using Server.Buffers;
using Server.Network;
namespace Server.Engines.Chat
{
public static class ChatPackets
public sealed class ChatMessagePacket : Packet
{
public static void SendChatMessage(NetState ns, Mobile who, int number, string param1, string param2)
public ChatMessagePacket(Mobile who, int number, string param1, string param2) : base(0xB2)
{
if (ns == null)
return;
if (param1 == null)
param1 = string.Empty;
param1 ??= "";
param2 ??= "";
if (param2 == null)
param2 = string.Empty;
int length = 13 + (param1.Length + param2.Length) * 2;
//base(0xB2)
EnsureCapacity(13 + (param1.Length + param2.Length) * 2);
SpanWriter writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0xB2); // Packet ID
writer.Write((ushort)length); // Dynamic Length
writer.Write((ushort)(number - 20));
m_Stream.Write((ushort)(number - 20));
if (who != null)
writer.WriteAsciiFixed(who.Language, 4);
m_Stream.WriteAsciiFixed(who.Language, 4);
else
writer.Position += 4;
m_Stream.Write(0);
writer.WriteBigUniNull(param1);
writer.WriteBigUniNull(param2);
ns.Send(writer.Span);
m_Stream.WriteBigUniNull(param1);
m_Stream.WriteBigUniNull(param2);
}
}
}
}