fix(core): Converts some packets & misc fixes/cleanup (#414)
- [X] Adds a stop music packet - [X] Converts chat packets - [X] Breaks out chat code a little bit more - [X] Converts character statue animation packet - [X] Renames some folders to have spaces - [X] Organizes and consolidates incoming/outgoing packets for other content - [X] Fixes virtual checks
This commit is contained in:
parent
a146955f6c
commit
fbafd7210d
49 changed files with 814 additions and 662 deletions
|
|
@ -1,6 +1,3 @@
|
|||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Chat
|
||||
{
|
||||
public static class ChatSystem
|
||||
|
|
@ -12,36 +9,9 @@ namespace Server.Engines.Chat
|
|||
Enabled = ServerConfiguration.GetOrUpdateSetting("chat.enabled", false);
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
IncomingPackets.Register(0xB5, 0x40, true, OpenChatWindowRequest);
|
||||
IncomingPackets.Register(0xB3, 0, true, ChatAction);
|
||||
}
|
||||
|
||||
public static void SendCommandTo(Mobile to, ChatCommand type, string param1 = null, string param2 = null)
|
||||
{
|
||||
to?.Send(new ChatMessagePacket(null, (int)type + 20, param1, param2));
|
||||
}
|
||||
|
||||
public static void OpenChatWindowRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (!Enabled)
|
||||
{
|
||||
from.SendMessage("The chat system has been disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Newer clients don't send chat username anymore so we are ignoring the rest of this packet.
|
||||
|
||||
// TODO: How does OSI handle incognito/disguise kits?
|
||||
// TODO: Does OSI still allow duplicate names?
|
||||
// For now we assume they should use their raw name.
|
||||
var chatName = from.RawName ?? $"Unknown User {Utility.RandomMinMax(1000000, 9999999)}";
|
||||
|
||||
SendCommandTo(from, ChatCommand.OpenChatWindow, chatName);
|
||||
ChatUser.AddChatUser(from, chatName);
|
||||
to?.NetState.SendChatMessage(null, (int)type + 20, param1, param2);
|
||||
}
|
||||
|
||||
public static ChatUser SearchForUser(ChatUser from, string name)
|
||||
|
|
@ -55,58 +25,5 @@ namespace Server.Engines.Chat
|
|||
|
||||
return user;
|
||||
}
|
||||
|
||||
public static void ChatAction(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
if (!Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var user = ChatUser.GetChatUser(from);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lang = reader.ReadAsciiSafe(4);
|
||||
int actionID = reader.ReadInt16();
|
||||
var param = reader.ReadBigUniSafe();
|
||||
|
||||
var handler = ChatActionHandlers.GetHandler(actionID);
|
||||
|
||||
if (handler == null)
|
||||
{
|
||||
state.WriteConsole("Unknown chat action 0x{0:X}: {1}", actionID, param);
|
||||
return;
|
||||
}
|
||||
|
||||
var channel = user.CurrentChannel;
|
||||
|
||||
if (handler.RequireConference && channel == null)
|
||||
{
|
||||
// You must be in a conference to do this.
|
||||
// To join a conference, select one from the Conference menu.
|
||||
user.SendMessage(31);
|
||||
return;
|
||||
}
|
||||
|
||||
if (handler.RequireModerator && !user.IsModerator)
|
||||
{
|
||||
user.SendMessage(29); // You must have operator status to do this.
|
||||
return;
|
||||
}
|
||||
|
||||
handler.Callback(user, channel, param);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
127
Projects/UOContent/Engines/Chat/ChatPackets.cs
Normal file
127
Projects/UOContent/Engines/Chat/ChatPackets.cs
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ChatPackets.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Chat
|
||||
{
|
||||
public static class ChatPackets
|
||||
{
|
||||
public static void Configure()
|
||||
{
|
||||
IncomingPackets.Register(0xB5, 0x40, true, OpenChatWindowRequest);
|
||||
IncomingPackets.Register(0xB3, 0, true, ChatAction);
|
||||
}
|
||||
|
||||
public static void OpenChatWindowRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (!ChatSystem.Enabled)
|
||||
{
|
||||
from.SendMessage("The chat system has been disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Newer clients don't send chat username anymore so we are ignoring the rest of this packet.
|
||||
|
||||
// TODO: How does OSI handle incognito/disguise kits?
|
||||
// TODO: Does OSI still allow duplicate names?
|
||||
// For now we assume they should use their raw name.
|
||||
var chatName = from.RawName ?? $"Unknown User {Utility.RandomMinMax(1000000, 9999999)}";
|
||||
|
||||
ChatSystem.SendCommandTo(from, ChatCommand.OpenChatWindow, chatName);
|
||||
ChatUser.AddChatUser(from, chatName);
|
||||
}
|
||||
|
||||
public static void ChatAction(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
if (!ChatSystem.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var user = ChatUser.GetChatUser(from);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lang = reader.ReadAsciiSafe(4);
|
||||
int actionID = reader.ReadInt16();
|
||||
var param = reader.ReadBigUniSafe();
|
||||
|
||||
var handler = ChatActionHandlers.GetHandler(actionID);
|
||||
|
||||
if (handler == null)
|
||||
{
|
||||
state.WriteConsole("Unknown chat action 0x{0:X}: {1}", actionID, param);
|
||||
return;
|
||||
}
|
||||
|
||||
var channel = user.CurrentChannel;
|
||||
|
||||
if (handler.RequireConference && channel == null)
|
||||
{
|
||||
// You must be in a conference to do this.
|
||||
// To join a conference, select one from the Conference menu.
|
||||
user.SendMessage(31);
|
||||
return;
|
||||
}
|
||||
|
||||
if (handler.RequireModerator && !user.IsModerator)
|
||||
{
|
||||
user.SendMessage(29); // You must have operator status to do this.
|
||||
return;
|
||||
}
|
||||
|
||||
handler.Callback(user, channel, param);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendChatMessage(this NetState ns, string lang, int number, string param1, string param2)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
param1 ??= "";
|
||||
param2 ??= "";
|
||||
|
||||
var length = 13 + (param1.Length + param2.Length) * 2;
|
||||
var writer = new SpanWriter(stackalloc byte[length]);
|
||||
writer.Write((byte)0xB2); // Packet ID
|
||||
writer.Write((ushort)length);
|
||||
writer.Write((ushort)(number - 20)); // Command
|
||||
|
||||
writer.WriteAscii(lang ?? "", 4);
|
||||
writer.WriteBigUniNull(param1);
|
||||
writer.WriteBigUniNull(param2);
|
||||
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -52,21 +52,11 @@ namespace Server.Engines.Chat
|
|||
return false;
|
||||
}
|
||||
|
||||
public void SendMessage(int number, string param1 = null, string param2 = null)
|
||||
{
|
||||
if (Mobile.NetState != null)
|
||||
{
|
||||
Mobile.Send(new ChatMessagePacket(Mobile, number, param1, param2));
|
||||
}
|
||||
}
|
||||
public void SendMessage(int number, string param1 = null, string param2 = null) =>
|
||||
SendMessage(number, Mobile, param1, param2);
|
||||
|
||||
public void SendMessage(int number, Mobile from, string param1, string param2)
|
||||
{
|
||||
if (Mobile.NetState != null)
|
||||
{
|
||||
Mobile.Send(new ChatMessagePacket(from, number, param1, param2));
|
||||
}
|
||||
}
|
||||
public void SendMessage(int number, Mobile from, string param1 = null, string param2 = null) =>
|
||||
Mobile.NetState.SendChatMessage(from.Language, number, param1, param2);
|
||||
|
||||
public bool IsIgnored(ChatUser check) => Ignored.Contains(check);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Chat
|
||||
{
|
||||
public sealed class ChatMessagePacket : Packet
|
||||
{
|
||||
public ChatMessagePacket(Mobile who, int number, string param1, string param2) : base(0xB2)
|
||||
{
|
||||
param1 ??= string.Empty;
|
||||
param2 ??= string.Empty;
|
||||
|
||||
EnsureCapacity(13 + (param1.Length + param2.Length) * 2);
|
||||
|
||||
Stream.Write((ushort)(number - 20));
|
||||
|
||||
if (who != null)
|
||||
{
|
||||
Stream.WriteAsciiFixed(who.Language, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write(0);
|
||||
}
|
||||
|
||||
Stream.WriteBigUniNull(param1);
|
||||
Stream.WriteBigUniNull(param2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Accounting;
|
||||
using Server.ContextMenus;
|
||||
using Server.Engines.VeteranRewards;
|
||||
|
|
@ -197,9 +198,10 @@ namespace Server.Mobiles
|
|||
|
||||
public override bool CanBeDamaged() => false;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void OnRequestedAnimation(Mobile from)
|
||||
{
|
||||
from.Send(new UpdateStatueAnimation(this, 1, m_Animation, m_Frames));
|
||||
from.NetState.SendStatueAnimation(Serial, 1, m_Animation, m_Frames);
|
||||
}
|
||||
|
||||
public override void OnAosSingleClick(Mobile from)
|
||||
|
|
@ -384,27 +386,24 @@ namespace Server.Mobiles
|
|||
break;
|
||||
}
|
||||
|
||||
if (Map != null)
|
||||
if (Map == null)
|
||||
{
|
||||
ProcessDelta();
|
||||
|
||||
Packet p = null;
|
||||
|
||||
var eable = Map.GetClientsInRange(Location);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
p ??= Packet.Acquire(new UpdateStatueAnimation(this, 1, m_Animation, m_Frames));
|
||||
|
||||
state.Send(p);
|
||||
}
|
||||
|
||||
Packet.Release(p);
|
||||
|
||||
eable.Free();
|
||||
return;
|
||||
}
|
||||
|
||||
ProcessDelta();
|
||||
|
||||
var eable = Map.GetClientsInRange(Location);
|
||||
Span<byte> animPacket = stackalloc byte[CharacterStatuePackets.StatueAnimationPacketLength].InitializePacket();
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
CharacterStatuePackets.CreateStatueAnimation(animPacket, Serial, 1, m_Animation, m_Frames);
|
||||
state.Send(animPacket);
|
||||
}
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
|
||||
private class DemolishEntry : ContextMenuEntry
|
||||
|
|
@ -415,12 +414,10 @@ namespace Server.Mobiles
|
|||
|
||||
public override void OnClick()
|
||||
{
|
||||
if (m_Statue.Deleted)
|
||||
if (!m_Statue.Deleted)
|
||||
{
|
||||
return;
|
||||
m_Statue.Demolish(Owner.From);
|
||||
}
|
||||
|
||||
m_Statue.Demolish(Owner.From);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -607,71 +604,75 @@ namespace Server.Mobiles
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_Maker.IsChildOf(from.Backpack))
|
||||
if (!m_Maker.IsChildOf(from.Backpack))
|
||||
{
|
||||
SpellHelper.GetSurfaceTop(ref p);
|
||||
BaseHouse house = null;
|
||||
var loc = new Point3D(p);
|
||||
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
|
||||
return;
|
||||
}
|
||||
|
||||
if (targeted is Item item && !item.IsLockedDown && !item.IsSecure && !(item is AddonComponent))
|
||||
SpellHelper.GetSurfaceTop(ref p);
|
||||
BaseHouse house = null;
|
||||
var loc = new Point3D(p);
|
||||
|
||||
if (targeted is Item item && !item.IsLockedDown && !item.IsSecure && !(item is AddonComponent))
|
||||
{
|
||||
from.SendLocalizedMessage(1076191); // Statues can only be placed in houses.
|
||||
return;
|
||||
}
|
||||
|
||||
if (from.IsBodyMod)
|
||||
{
|
||||
from.SendLocalizedMessage(1073648); // You may only proceed while in your original state...
|
||||
return;
|
||||
}
|
||||
|
||||
var result = CouldFit(loc, map, from, ref house);
|
||||
|
||||
if (result == AddonFitResult.Valid)
|
||||
{
|
||||
var statue = new CharacterStatue(from, m_Type);
|
||||
var plinth = new CharacterStatuePlinth(statue);
|
||||
|
||||
house.Addons.Add(plinth);
|
||||
|
||||
if (m_Maker is IRewardItem rewardItem)
|
||||
{
|
||||
from.SendLocalizedMessage(1076191); // Statues can only be placed in houses.
|
||||
return;
|
||||
statue.IsRewardItem = rewardItem.IsRewardItem;
|
||||
}
|
||||
|
||||
if (from.IsBodyMod)
|
||||
{
|
||||
from.SendLocalizedMessage(1073648); // You may only proceed while in your original state...
|
||||
return;
|
||||
}
|
||||
statue.Plinth = plinth;
|
||||
plinth.MoveToWorld(loc, map);
|
||||
statue.InvalidatePose();
|
||||
|
||||
var result = CouldFit(loc, map, from, ref house);
|
||||
|
||||
if (result == AddonFitResult.Valid)
|
||||
{
|
||||
var statue = new CharacterStatue(from, m_Type);
|
||||
var plinth = new CharacterStatuePlinth(statue);
|
||||
|
||||
house.Addons.Add(plinth);
|
||||
|
||||
if (m_Maker is IRewardItem rewardItem)
|
||||
{
|
||||
statue.IsRewardItem = rewardItem.IsRewardItem;
|
||||
}
|
||||
|
||||
statue.Plinth = plinth;
|
||||
plinth.MoveToWorld(loc, map);
|
||||
statue.InvalidatePose();
|
||||
|
||||
/*
|
||||
/*
|
||||
* TODO: Previously the maker wasn't deleted until after statue
|
||||
* customization, leading to redeeding issues. Exact OSI behavior
|
||||
* needs looking into.
|
||||
*/
|
||||
m_Maker.Delete();
|
||||
statue.Sculpt(from);
|
||||
m_Maker.Delete();
|
||||
statue.Sculpt(from);
|
||||
|
||||
from.CloseGump<CharacterStatueGump>();
|
||||
from.SendGump(new CharacterStatueGump(m_Maker, statue, from));
|
||||
}
|
||||
else if (result == AddonFitResult.Blocked)
|
||||
{
|
||||
from.SendLocalizedMessage(500269); // You cannot build that there.
|
||||
}
|
||||
else if (result == AddonFitResult.NotInHouse)
|
||||
{
|
||||
from.SendLocalizedMessage(
|
||||
1076192
|
||||
); // Statues can only be placed in houses where you are the owner or co-owner.
|
||||
}
|
||||
else if (result == AddonFitResult.DoorTooClose)
|
||||
{
|
||||
from.SendLocalizedMessage(500271); // You cannot build near the door.
|
||||
}
|
||||
from.CloseGump<CharacterStatueGump>();
|
||||
from.SendGump(new CharacterStatueGump(m_Maker, statue, from));
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
if (result == AddonFitResult.Blocked)
|
||||
{
|
||||
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
|
||||
from.SendLocalizedMessage(500269); // You cannot build that there.
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == AddonFitResult.NotInHouse)
|
||||
{
|
||||
// Statues can only be placed in houses where you are the owner or co-owner.
|
||||
from.SendLocalizedMessage(1076192);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == AddonFitResult.DoorTooClose)
|
||||
{
|
||||
from.SendLocalizedMessage(500271); // You cannot build near the door.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: CharacterStatuePackets.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.VeteranRewards
|
||||
{
|
||||
public static class CharacterStatuePackets
|
||||
{
|
||||
public const int StatueAnimationPacketLength = 17;
|
||||
|
||||
public static void CreateStatueAnimation(Span<byte> buffer, Serial serial, int status, int anim, int frame)
|
||||
{
|
||||
if (buffer[0] != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)17);
|
||||
writer.Write((short)0x19);
|
||||
writer.Write((byte)0x5);
|
||||
writer.Write(serial);
|
||||
writer.Write((byte)0);
|
||||
writer.Write((byte)0xFF);
|
||||
writer.Write((byte)status);
|
||||
writer.Write((byte)0);
|
||||
writer.Write((byte)anim);
|
||||
writer.Write((byte)0);
|
||||
writer.Write((byte)frame);
|
||||
}
|
||||
|
||||
public static void SendStatueAnimation(this NetState ns, Serial serial, int status, int anim, int frame)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[StatueAnimationPacketLength].InitializePacket();
|
||||
CreateStatueAnimation(buffer, serial, status, anim, frame);
|
||||
ns.Send(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
namespace Server.Network
|
||||
{
|
||||
public class UpdateStatueAnimation : Packet
|
||||
{
|
||||
public UpdateStatueAnimation(Mobile m, int status, int animation, int frame) : base(0xBF, 17)
|
||||
{
|
||||
Stream.Write((short)0x11);
|
||||
Stream.Write((short)0x19);
|
||||
Stream.Write((byte)0x5);
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0xFF);
|
||||
Stream.Write((byte)status);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)animation);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue