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
|
|
@ -41,7 +41,7 @@ namespace Server.Items
|
|||
|
||||
public override void OnItemAdded(Item item)
|
||||
{
|
||||
if (!(item is VirtualCheck))
|
||||
if (item is not VirtualCheck)
|
||||
{
|
||||
ClearChecks();
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ namespace Server.Items
|
|||
|
||||
public override void OnItemRemoved(Item item)
|
||||
{
|
||||
if (!(item is VirtualCheck))
|
||||
if (item is not VirtualCheck)
|
||||
{
|
||||
ClearChecks();
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ namespace Server.Items
|
|||
|
||||
public override void OnSubItemAdded(Item item)
|
||||
{
|
||||
if (!(item is VirtualCheck))
|
||||
if (item is not VirtualCheck)
|
||||
{
|
||||
ClearChecks();
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ namespace Server.Items
|
|||
|
||||
public override void OnSubItemRemoved(Item item)
|
||||
{
|
||||
if (!(item is VirtualCheck))
|
||||
if (item is not VirtualCheck)
|
||||
{
|
||||
ClearChecks();
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ namespace Server.Items
|
|||
|
||||
public override bool IsChildVisibleTo(Mobile m, Item child) =>
|
||||
child is VirtualCheck
|
||||
? AccountGold.Enabled && m.NetState?.NewSecureTrading != true
|
||||
? !AccountGold.Enabled || m.NetState?.NewSecureTrading != true
|
||||
: base.IsChildVisibleTo(m, child);
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
|
|
|
|||
|
|
@ -303,6 +303,8 @@ namespace Server.Network
|
|||
ns.Send(writer.Span);
|
||||
}
|
||||
|
||||
public static void SendStopMusic(this NetState ns) => ns?.Send(stackalloc byte[] { 0x6D, 0x1F, 0xFF });
|
||||
|
||||
public static void SendScrollMessage(this NetState ns, int type, int tip, string text)
|
||||
{
|
||||
if (ns == null)
|
||||
|
|
|
|||
|
|
@ -76,7 +76,8 @@ namespace Server
|
|||
Paws,
|
||||
SelimsBar,
|
||||
SerpentIsleCombat_U7,
|
||||
ValoriaShips
|
||||
ValoriaShips,
|
||||
NoMusic = 0x1FFF
|
||||
}
|
||||
|
||||
public class Region : IComparable<Region>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using Server.Engines.Chat;
|
||||
using Server.Tests;
|
||||
using Server.Tests.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace UOContent.Tests
|
||||
{
|
||||
public class ChatPacketTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(null, 100, "some param", "some other param")]
|
||||
[InlineData("ENU", 200, "a third param", "another param")]
|
||||
public void TestSendChatMessage(string lang, int number, string param1, string param2)
|
||||
{
|
||||
var expected = new ChatMessagePacket(lang, number, param1, param2).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendChatMessage(lang, number, param1, param2);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ namespace Server.Engines.Chat
|
|||
{
|
||||
public sealed class ChatMessagePacket : Packet
|
||||
{
|
||||
public ChatMessagePacket(Mobile who, int number, string param1, string param2) : base(0xB2)
|
||||
public ChatMessagePacket(string lang, int number, string param1, string param2) : base(0xB2)
|
||||
{
|
||||
param1 ??= string.Empty;
|
||||
param2 ??= string.Empty;
|
||||
|
|
@ -13,9 +13,9 @@ namespace Server.Engines.Chat
|
|||
|
||||
Stream.Write((ushort)(number - 20));
|
||||
|
||||
if (who != null)
|
||||
if (lang != null)
|
||||
{
|
||||
Stream.WriteAsciiFixed(who.Language, 4);
|
||||
Stream.WriteAsciiFixed(lang, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using Server;
|
||||
using Server.Engines.VeteranRewards;
|
||||
using Server.Network;
|
||||
using Server.Tests;
|
||||
using Server.Tests.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace UOContent.Tests
|
||||
{
|
||||
public class CharacterStatuePacketTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0x1024u, 1, 100, 200)]
|
||||
public void TestSendStatueAnimation(uint s, int status, int anim, int frame)
|
||||
{
|
||||
Serial serial = s;
|
||||
var expected = new UpdateStatueAnimation(serial, status, anim, frame).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendStatueAnimation(serial, status, anim, frame);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,12 +2,12 @@ namespace Server.Network
|
|||
{
|
||||
public class UpdateStatueAnimation : Packet
|
||||
{
|
||||
public UpdateStatueAnimation(Mobile m, int status, int animation, int frame) : base(0xBF, 17)
|
||||
public UpdateStatueAnimation(Serial serial, 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(serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0xFF);
|
||||
Stream.Write((byte)status);
|
||||
|
|
@ -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,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,9 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
public static class BulletinBoardSystem
|
||||
{
|
||||
// Threads will be removed six hours after the last post was made
|
||||
public static TimeSpan ThreadDeletionTime { get; private set; }
|
||||
|
||||
// A player may only create a thread once every two minutes
|
||||
public static TimeSpan ThreadCreateTime { get; private set; }
|
||||
|
||||
// A player may only reply once every thirty seconds
|
||||
public static TimeSpan ThreadReplyTime { get; private set; }
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
ThreadCreateTime = ServerConfiguration.GetOrUpdateSetting("bulletinboards.creationTimeDelay", TimeSpan.FromMinutes(2.0));
|
||||
ThreadDeletionTime = ServerConfiguration.GetOrUpdateSetting("bulletinboards.expireDuration", TimeSpan.FromHours(6.0));
|
||||
ThreadReplyTime = ServerConfiguration.GetOrUpdateSetting("bulletinboards.replyDelay", TimeSpan.FromSeconds(30.0));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool CheckCreateTime(DateTime time) => time + ThreadCreateTime < DateTime.UtcNow;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
public static bool CheckDeletionTime(DateTime time) => time + ThreadDeletionTime < DateTime.UtcNow;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool CheckReplyTime(DateTime time) => time + ThreadReplyTime < DateTime.UtcNow;
|
||||
}
|
||||
|
||||
[Flippable(0x1E5E, 0x1E5F)]
|
||||
public class BulletinBoard : BaseBulletinBoard
|
||||
{
|
||||
|
|
@ -33,15 +62,6 @@ namespace Server.Items
|
|||
|
||||
public abstract class BaseBulletinBoard : Item
|
||||
{
|
||||
// Threads will be removed six hours after the last post was made
|
||||
private static readonly TimeSpan ThreadDeletionTime = TimeSpan.FromHours(6.0);
|
||||
|
||||
// A player may only create a thread once every two minutes
|
||||
private static readonly TimeSpan ThreadCreateTime = TimeSpan.FromMinutes(2.0);
|
||||
|
||||
// A player may only reply once every thirty seconds
|
||||
private static readonly TimeSpan ThreadReplyTime = TimeSpan.FromSeconds(30.0);
|
||||
|
||||
public BaseBulletinBoard(int itemID) : base(itemID)
|
||||
{
|
||||
BoardName = "bulletin board";
|
||||
|
|
@ -55,27 +75,6 @@ namespace Server.Items
|
|||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public string BoardName { get; set; }
|
||||
|
||||
public static bool CheckTime(DateTime time, TimeSpan range) => time + range < DateTime.UtcNow;
|
||||
|
||||
public static string FormatTS(TimeSpan ts)
|
||||
{
|
||||
var totalSeconds = (int)ts.TotalSeconds;
|
||||
var seconds = totalSeconds % 60;
|
||||
var minutes = totalSeconds / 60;
|
||||
|
||||
if (minutes != 0 && seconds != 0)
|
||||
{
|
||||
return $"{minutes} minute{(minutes == 1 ? "" : "s")} and {seconds} second{(seconds == 1 ? "" : "s")}";
|
||||
}
|
||||
|
||||
if (minutes != 0)
|
||||
{
|
||||
return $"{minutes} minute{(minutes == 1 ? "" : "s")}";
|
||||
}
|
||||
|
||||
return $"{seconds} second{(seconds == 1 ? "" : "s")}";
|
||||
}
|
||||
|
||||
public virtual void Cleanup()
|
||||
{
|
||||
var items = Items;
|
||||
|
|
@ -92,7 +91,7 @@ namespace Server.Items
|
|||
continue;
|
||||
}
|
||||
|
||||
if (msg.Thread == null && CheckTime(msg.LastPostTime, ThreadDeletionTime))
|
||||
if (msg.Thread == null && BulletinBoardSystem.CheckDeletionTime(msg.LastPostTime))
|
||||
{
|
||||
msg.Delete();
|
||||
RecurseDelete(msg); // A root-level thread has expired
|
||||
|
|
@ -211,128 +210,5 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
IncomingPackets.Register(0x71, 0, true, BBClientRequest);
|
||||
}
|
||||
|
||||
public static void BBClientRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
int packetID = reader.ReadByte();
|
||||
|
||||
if (World.FindItem(reader.ReadUInt32()) is not BaseBulletinBoard board || !board.CheckRange(from))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (packetID)
|
||||
{
|
||||
case 3:
|
||||
BBRequestContent(from, board, reader);
|
||||
break;
|
||||
case 4:
|
||||
BBRequestHeader(from, board, reader);
|
||||
break;
|
||||
case 5:
|
||||
BBPostMessage(from, board, reader);
|
||||
break;
|
||||
case 6:
|
||||
BBRemoveMessage(from, board, reader);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void BBRequestContent(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
|
||||
{
|
||||
if (World.FindItem(reader.ReadUInt32()) is not BulletinMessage msg || msg.Parent != board)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
from.NetState.SendBBMessage(board, msg, true);
|
||||
}
|
||||
|
||||
public static void BBRequestHeader(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
|
||||
{
|
||||
if (World.FindItem(reader.ReadUInt32()) is not BulletinMessage msg || msg.Parent != board)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
from.NetState.SendBBMessage(board, msg);
|
||||
}
|
||||
|
||||
public static void BBPostMessage(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
|
||||
{
|
||||
var thread = World.FindItem(reader.ReadUInt32()) as BulletinMessage;
|
||||
|
||||
if (thread != null && thread.Parent != board)
|
||||
{
|
||||
thread = null;
|
||||
}
|
||||
|
||||
var breakout = 0;
|
||||
|
||||
while (thread?.Thread != null && breakout++ < 10)
|
||||
{
|
||||
thread = thread.Thread;
|
||||
}
|
||||
|
||||
var lastPostTime = DateTime.MinValue;
|
||||
|
||||
if (board.GetLastPostTime(from, thread == null, ref lastPostTime) &&
|
||||
!CheckTime(lastPostTime, thread == null ? ThreadCreateTime : ThreadReplyTime))
|
||||
{
|
||||
if (thread == null)
|
||||
{
|
||||
from.SendMessage("You must wait {0} before creating a new thread.", FormatTS(ThreadCreateTime));
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendMessage("You must wait {0} before replying to another thread.", FormatTS(ThreadReplyTime));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var subject = reader.ReadUTF8Safe(reader.ReadByte());
|
||||
|
||||
if (subject.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = new string[reader.ReadByte()];
|
||||
|
||||
if (lines.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < lines.Length; ++i)
|
||||
{
|
||||
lines[i] = reader.ReadUTF8Safe(reader.ReadByte());
|
||||
}
|
||||
|
||||
board.PostMessage(from, thread, subject, lines);
|
||||
}
|
||||
|
||||
public static void BBRemoveMessage(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
|
||||
{
|
||||
if (World.FindItem(reader.ReadUInt32()) is not BulletinMessage msg || msg.Parent != board)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (from.AccessLevel < AccessLevel.GameMaster && msg.Poster != from)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
msg.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,150 @@ namespace Server.Network
|
|||
{
|
||||
public static class BulletinBoardPackets
|
||||
{
|
||||
public static void Configure()
|
||||
{
|
||||
IncomingPackets.Register(0x71, 0, true, BBClientRequest);
|
||||
}
|
||||
|
||||
public static string FormatTS(TimeSpan ts)
|
||||
{
|
||||
var totalSeconds = (int)ts.TotalSeconds;
|
||||
var seconds = totalSeconds % 60;
|
||||
var minutes = totalSeconds / 60;
|
||||
|
||||
if (minutes != 0 && seconds != 0)
|
||||
{
|
||||
return $"{minutes} minute{(minutes == 1 ? "" : "s")} and {seconds} second{(seconds == 1 ? "" : "s")}";
|
||||
}
|
||||
|
||||
if (minutes != 0)
|
||||
{
|
||||
return $"{minutes} minute{(minutes == 1 ? "" : "s")}";
|
||||
}
|
||||
|
||||
return $"{seconds} second{(seconds == 1 ? "" : "s")}";
|
||||
}
|
||||
|
||||
public static void BBClientRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
int packetID = reader.ReadByte();
|
||||
|
||||
if (World.FindItem(reader.ReadUInt32()) is not BaseBulletinBoard board || !board.CheckRange(from))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (packetID)
|
||||
{
|
||||
case 3:
|
||||
BBRequestContent(from, board, reader);
|
||||
break;
|
||||
case 4:
|
||||
BBRequestHeader(from, board, reader);
|
||||
break;
|
||||
case 5:
|
||||
BBPostMessage(from, board, reader);
|
||||
break;
|
||||
case 6:
|
||||
BBRemoveMessage(from, board, reader);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void BBRequestContent(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
|
||||
{
|
||||
if (World.FindItem(reader.ReadUInt32()) is not BulletinMessage msg || msg.Parent != board)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
from.NetState.SendBBMessage(board, msg, true);
|
||||
}
|
||||
|
||||
public static void BBRequestHeader(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
|
||||
{
|
||||
if (World.FindItem(reader.ReadUInt32()) is not BulletinMessage msg || msg.Parent != board)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
from.NetState.SendBBMessage(board, msg);
|
||||
}
|
||||
|
||||
public static void BBPostMessage(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
|
||||
{
|
||||
var thread = World.FindItem(reader.ReadUInt32()) as BulletinMessage;
|
||||
|
||||
if (thread != null && thread.Parent != board)
|
||||
{
|
||||
thread = null;
|
||||
}
|
||||
|
||||
var breakout = 0;
|
||||
|
||||
while (thread?.Thread != null && breakout++ < 10)
|
||||
{
|
||||
thread = thread.Thread;
|
||||
}
|
||||
|
||||
var lastPostTime = DateTime.MinValue;
|
||||
|
||||
if (board.GetLastPostTime(from, thread == null, ref lastPostTime))
|
||||
{
|
||||
if (thread == null)
|
||||
{
|
||||
if (!BulletinBoardSystem.CheckCreateTime(lastPostTime))
|
||||
{
|
||||
from.SendMessage($"You must wait {FormatTS(BulletinBoardSystem.ThreadCreateTime)} before creating a new thread.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!BulletinBoardSystem.CheckReplyTime(lastPostTime))
|
||||
{
|
||||
from.SendMessage($"You must wait {FormatTS(BulletinBoardSystem.ThreadReplyTime)} before replying to another thread.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var subject = reader.ReadUTF8Safe(reader.ReadByte());
|
||||
|
||||
if (subject.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = new string[reader.ReadByte()];
|
||||
|
||||
if (lines.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < lines.Length; ++i)
|
||||
{
|
||||
lines[i] = reader.ReadUTF8Safe(reader.ReadByte());
|
||||
}
|
||||
|
||||
board.PostMessage(from, thread, subject, lines);
|
||||
}
|
||||
|
||||
public static void BBRemoveMessage(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
|
||||
{
|
||||
if (World.FindItem(reader.ReadUInt32()) is not BulletinMessage msg || msg.Parent != board)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (from.AccessLevel < AccessLevel.GameMaster && msg.Poster != from)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
msg.Delete();
|
||||
}
|
||||
|
||||
public static void SendBBDisplayBoard(this NetState ns, BaseBulletinBoard board)
|
||||
{
|
||||
if (ns == null)
|
||||
|
|
|
|||
|
|
@ -1,268 +0,0 @@
|
|||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public delegate void OnMahjongPacketReceive(MahjongGame game, NetState state, CircularBufferReader reader);
|
||||
|
||||
public sealed class MahjongPacketHandlers
|
||||
{
|
||||
private static readonly OnMahjongPacketReceive[] m_SubCommandDelegates = new OnMahjongPacketReceive[0x100];
|
||||
|
||||
public static void RegisterSubCommand(int subCmd, OnMahjongPacketReceive onReceive)
|
||||
{
|
||||
m_SubCommandDelegates[subCmd] = onReceive;
|
||||
}
|
||||
|
||||
public static OnMahjongPacketReceive GetSubCommandDelegate(int cmd)
|
||||
{
|
||||
if (cmd >= 0 && cmd < 0x100)
|
||||
{
|
||||
return m_SubCommandDelegates[cmd];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
IncomingPackets.Register(0xDA, 0, true, OnPacket);
|
||||
|
||||
RegisterSubCommand(0x6, ExitGame);
|
||||
RegisterSubCommand(0xA, GivePoints);
|
||||
RegisterSubCommand(0xB, RollDice);
|
||||
RegisterSubCommand(0xC, BuildWalls);
|
||||
RegisterSubCommand(0xD, ResetScores);
|
||||
RegisterSubCommand(0xF, AssignDealer);
|
||||
RegisterSubCommand(0x10, OpenSeat);
|
||||
RegisterSubCommand(0x11, ChangeOption);
|
||||
RegisterSubCommand(0x15, MoveWallBreakIndicator);
|
||||
RegisterSubCommand(0x16, TogglePublicHand);
|
||||
RegisterSubCommand(0x17, MoveTile);
|
||||
RegisterSubCommand(0x18, MoveDealerIndicator);
|
||||
}
|
||||
|
||||
public static void OnPacket(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var game = World.FindItem(reader.ReadUInt32()) as MahjongGame;
|
||||
|
||||
game?.Players.CheckPlayers();
|
||||
|
||||
reader.ReadByte();
|
||||
|
||||
int cmd = reader.ReadByte();
|
||||
|
||||
var onReceive = GetSubCommandDelegate(cmd);
|
||||
|
||||
if (onReceive != null)
|
||||
{
|
||||
onReceive(game, state, reader);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Trace(state);
|
||||
}
|
||||
}
|
||||
|
||||
private static MahjongPieceDirection GetDirection(int value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
0 => MahjongPieceDirection.Up,
|
||||
1 => MahjongPieceDirection.Left,
|
||||
2 => MahjongPieceDirection.Down,
|
||||
_ => MahjongPieceDirection.Right
|
||||
};
|
||||
}
|
||||
|
||||
private static MahjongWind GetWind(int value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
0 => MahjongWind.North,
|
||||
1 => MahjongWind.East,
|
||||
2 => MahjongWind.South,
|
||||
_ => MahjongWind.West
|
||||
};
|
||||
}
|
||||
|
||||
public static void ExitGame(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var from = state.Mobile;
|
||||
|
||||
game.Players.LeaveGame(from);
|
||||
}
|
||||
|
||||
public static void GivePoints(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGamePlayer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int to = reader.ReadByte();
|
||||
var amount = reader.ReadInt32();
|
||||
|
||||
game.Players.TransferScore(state.Mobile, to, amount);
|
||||
}
|
||||
|
||||
public static void RollDice(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGamePlayer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game.Dices.RollDices(state.Mobile);
|
||||
}
|
||||
|
||||
public static void BuildWalls(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game.ResetWalls(state.Mobile);
|
||||
}
|
||||
|
||||
public static void ResetScores(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game.Players.ResetScores(MahjongGame.BaseScore);
|
||||
}
|
||||
|
||||
public static void AssignDealer(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int position = reader.ReadByte();
|
||||
|
||||
game.Players.AssignDealer(position);
|
||||
}
|
||||
|
||||
public static void OpenSeat(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int position = reader.ReadByte();
|
||||
|
||||
if (game.Players.GetPlayer(position) == state.Mobile)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game.Players.OpenSeat(position);
|
||||
}
|
||||
|
||||
public static void ChangeOption(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
reader.ReadInt16();
|
||||
reader.ReadByte();
|
||||
|
||||
int options = reader.ReadByte();
|
||||
|
||||
game.ShowScores = (options & 0x1) != 0;
|
||||
game.SpectatorVision = (options & 0x2) != 0;
|
||||
}
|
||||
|
||||
public static void MoveWallBreakIndicator(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int y = reader.ReadInt16();
|
||||
int x = reader.ReadInt16();
|
||||
|
||||
game.WallBreakIndicator.Move(new Point2D(x, y));
|
||||
}
|
||||
|
||||
public static void TogglePublicHand(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGamePlayer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
reader.ReadInt16();
|
||||
reader.ReadByte();
|
||||
|
||||
var publicHand = reader.ReadBoolean();
|
||||
|
||||
game.Players.SetPublic(game.Players.GetPlayerIndex(state.Mobile), publicHand);
|
||||
}
|
||||
|
||||
public static void MoveTile(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGamePlayer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int number = reader.ReadByte();
|
||||
|
||||
if (number < 0 || number >= game.Tiles.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
reader.ReadByte(); // Current direction
|
||||
|
||||
var direction = GetDirection(reader.ReadByte());
|
||||
|
||||
reader.ReadByte();
|
||||
|
||||
var flip = reader.ReadBoolean();
|
||||
|
||||
reader.ReadInt16(); // Current Y
|
||||
reader.ReadInt16(); // Current X
|
||||
|
||||
reader.ReadByte();
|
||||
|
||||
int y = reader.ReadInt16();
|
||||
int x = reader.ReadInt16();
|
||||
|
||||
reader.ReadByte();
|
||||
|
||||
game.Tiles[number].Move(new Point2D(x, y), direction, flip, game.Players.GetPlayerIndex(state.Mobile));
|
||||
}
|
||||
|
||||
public static void MoveDealerIndicator(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var direction = GetDirection(reader.ReadByte());
|
||||
|
||||
var wind = GetWind(reader.ReadByte());
|
||||
|
||||
int y = reader.ReadInt16();
|
||||
int x = reader.ReadInt16();
|
||||
|
||||
game.DealerIndicator.Move(new Point2D(x, y), direction, wind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,10 +20,270 @@ using Server.Network;
|
|||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public delegate void OnMahjongPacketReceive(MahjongGame game, NetState state, CircularBufferReader reader);
|
||||
|
||||
public static class MahjongPackets
|
||||
{
|
||||
public const int MahjongGeneralInfoPacketLength = 25;
|
||||
public const int MahjongRelievePacketLength = 9;
|
||||
private static readonly OnMahjongPacketReceive[] m_SubCommandDelegates = new OnMahjongPacketReceive[0x100];
|
||||
|
||||
public static void RegisterSubCommand(int subCmd, OnMahjongPacketReceive onReceive)
|
||||
{
|
||||
m_SubCommandDelegates[subCmd] = onReceive;
|
||||
}
|
||||
|
||||
public static OnMahjongPacketReceive GetSubCommandDelegate(int cmd)
|
||||
{
|
||||
if (cmd >= 0 && cmd < 0x100)
|
||||
{
|
||||
return m_SubCommandDelegates[cmd];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
IncomingPackets.Register(0xDA, 0, true, OnPacket);
|
||||
|
||||
RegisterSubCommand(0x6, ExitGame);
|
||||
RegisterSubCommand(0xA, GivePoints);
|
||||
RegisterSubCommand(0xB, RollDice);
|
||||
RegisterSubCommand(0xC, BuildWalls);
|
||||
RegisterSubCommand(0xD, ResetScores);
|
||||
RegisterSubCommand(0xF, AssignDealer);
|
||||
RegisterSubCommand(0x10, OpenSeat);
|
||||
RegisterSubCommand(0x11, ChangeOption);
|
||||
RegisterSubCommand(0x15, MoveWallBreakIndicator);
|
||||
RegisterSubCommand(0x16, TogglePublicHand);
|
||||
RegisterSubCommand(0x17, MoveTile);
|
||||
RegisterSubCommand(0x18, MoveDealerIndicator);
|
||||
}
|
||||
|
||||
public static void OnPacket(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var game = World.FindItem(reader.ReadUInt32()) as MahjongGame;
|
||||
|
||||
game?.Players.CheckPlayers();
|
||||
|
||||
reader.ReadByte();
|
||||
|
||||
int cmd = reader.ReadByte();
|
||||
|
||||
var onReceive = GetSubCommandDelegate(cmd);
|
||||
|
||||
if (onReceive != null)
|
||||
{
|
||||
onReceive(game, state, reader);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Trace(state);
|
||||
}
|
||||
}
|
||||
|
||||
private static MahjongPieceDirection GetDirection(int value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
0 => MahjongPieceDirection.Up,
|
||||
1 => MahjongPieceDirection.Left,
|
||||
2 => MahjongPieceDirection.Down,
|
||||
_ => MahjongPieceDirection.Right
|
||||
};
|
||||
}
|
||||
|
||||
private static MahjongWind GetWind(int value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
0 => MahjongWind.North,
|
||||
1 => MahjongWind.East,
|
||||
2 => MahjongWind.South,
|
||||
_ => MahjongWind.West
|
||||
};
|
||||
}
|
||||
|
||||
public static void ExitGame(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var from = state.Mobile;
|
||||
|
||||
game.Players.LeaveGame(from);
|
||||
}
|
||||
|
||||
public static void GivePoints(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGamePlayer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int to = reader.ReadByte();
|
||||
var amount = reader.ReadInt32();
|
||||
|
||||
game.Players.TransferScore(state.Mobile, to, amount);
|
||||
}
|
||||
|
||||
public static void RollDice(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGamePlayer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game.Dices.RollDices(state.Mobile);
|
||||
}
|
||||
|
||||
public static void BuildWalls(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game.ResetWalls(state.Mobile);
|
||||
}
|
||||
|
||||
public static void ResetScores(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game.Players.ResetScores(MahjongGame.BaseScore);
|
||||
}
|
||||
|
||||
public static void AssignDealer(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int position = reader.ReadByte();
|
||||
|
||||
game.Players.AssignDealer(position);
|
||||
}
|
||||
|
||||
public static void OpenSeat(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int position = reader.ReadByte();
|
||||
|
||||
if (game.Players.GetPlayer(position) == state.Mobile)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game.Players.OpenSeat(position);
|
||||
}
|
||||
|
||||
public static void ChangeOption(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
reader.ReadInt16();
|
||||
reader.ReadByte();
|
||||
|
||||
int options = reader.ReadByte();
|
||||
|
||||
game.ShowScores = (options & 0x1) != 0;
|
||||
game.SpectatorVision = (options & 0x2) != 0;
|
||||
}
|
||||
|
||||
public static void MoveWallBreakIndicator(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int y = reader.ReadInt16();
|
||||
int x = reader.ReadInt16();
|
||||
|
||||
game.WallBreakIndicator.Move(new Point2D(x, y));
|
||||
}
|
||||
|
||||
public static void TogglePublicHand(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGamePlayer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
reader.ReadInt16();
|
||||
reader.ReadByte();
|
||||
|
||||
var publicHand = reader.ReadBoolean();
|
||||
|
||||
game.Players.SetPublic(game.Players.GetPlayerIndex(state.Mobile), publicHand);
|
||||
}
|
||||
|
||||
public static void MoveTile(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGamePlayer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int number = reader.ReadByte();
|
||||
|
||||
if (number < 0 || number >= game.Tiles.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
reader.ReadByte(); // Current direction
|
||||
|
||||
var direction = GetDirection(reader.ReadByte());
|
||||
|
||||
reader.ReadByte();
|
||||
|
||||
var flip = reader.ReadBoolean();
|
||||
|
||||
reader.ReadInt16(); // Current Y
|
||||
reader.ReadInt16(); // Current X
|
||||
|
||||
reader.ReadByte();
|
||||
|
||||
int y = reader.ReadInt16();
|
||||
int x = reader.ReadInt16();
|
||||
|
||||
reader.ReadByte();
|
||||
|
||||
game.Tiles[number].Move(new Point2D(x, y), direction, flip, game.Players.GetPlayerIndex(state.Mobile));
|
||||
}
|
||||
|
||||
public static void MoveDealerIndicator(MahjongGame game, NetState state, CircularBufferReader reader)
|
||||
{
|
||||
if (game?.Players.IsInGameDealer(state.Mobile) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var direction = GetDirection(reader.ReadByte());
|
||||
|
||||
var wind = GetWind(reader.ReadByte());
|
||||
|
||||
int y = reader.ReadInt16();
|
||||
int x = reader.ReadInt16();
|
||||
|
||||
game.DealerIndicator.Move(new Point2D(x, y), direction, wind);
|
||||
}
|
||||
|
||||
public static void SendMahjongJoinGame(this NetState ns, Serial game)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -320,48 +320,5 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
IncomingPackets.Register(0x56, 11, true, OnMapCommand);
|
||||
}
|
||||
|
||||
private static void OnMapCommand(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (!(World.FindItem(reader.ReadUInt32()) is MapItem map))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int command = reader.ReadByte();
|
||||
int number = reader.ReadByte();
|
||||
|
||||
int x = reader.ReadInt16();
|
||||
int y = reader.ReadInt16();
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case 1:
|
||||
map.OnAddPin(from, x, y);
|
||||
break;
|
||||
case 2:
|
||||
map.OnInsertPin(from, number, x, y);
|
||||
break;
|
||||
case 3:
|
||||
map.OnChangePin(from, number, x, y);
|
||||
break;
|
||||
case 4:
|
||||
map.OnRemovePin(from, number);
|
||||
break;
|
||||
case 5:
|
||||
map.OnClearPins(from);
|
||||
break;
|
||||
case 6:
|
||||
map.OnToggleEditable(from);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,49 @@ namespace Server.Network
|
|||
{
|
||||
public static class MapItemPackets
|
||||
{
|
||||
public static void Configure()
|
||||
{
|
||||
IncomingPackets.Register(0x56, 11, true, OnMapCommand);
|
||||
}
|
||||
|
||||
private static void OnMapCommand(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (!(World.FindItem(reader.ReadUInt32()) is MapItem map))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int command = reader.ReadByte();
|
||||
int number = reader.ReadByte();
|
||||
|
||||
int x = reader.ReadInt16();
|
||||
int y = reader.ReadInt16();
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case 1:
|
||||
map.OnAddPin(from, x, y);
|
||||
break;
|
||||
case 2:
|
||||
map.OnInsertPin(from, number, x, y);
|
||||
break;
|
||||
case 3:
|
||||
map.OnChangePin(from, number, x, y);
|
||||
break;
|
||||
case 4:
|
||||
map.OnRemovePin(from, number);
|
||||
break;
|
||||
case 5:
|
||||
map.OnClearPins(from);
|
||||
break;
|
||||
case 6:
|
||||
map.OnToggleEditable(from);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendMapDetails(this NetState ns, MapItem map)
|
||||
{
|
||||
if (ns == null)
|
||||
|
|
|
|||
|
|
@ -7,16 +7,6 @@ using Server.Network;
|
|||
|
||||
namespace Server.Items
|
||||
{
|
||||
public sealed class StopMusic : Packet
|
||||
{
|
||||
public static readonly Packet Instance = SetStatic(new StopMusic());
|
||||
|
||||
public StopMusic() : base(0x6D, 3)
|
||||
{
|
||||
Stream.Write((short)0x1FFF);
|
||||
}
|
||||
}
|
||||
|
||||
[Flippable(0x2AF9, 0x2AFD)]
|
||||
public class DawnsMusicBox : Item, ISecurable
|
||||
{
|
||||
|
|
@ -244,7 +234,7 @@ namespace Server.Items
|
|||
m_Timer.Stop();
|
||||
}
|
||||
|
||||
m.Send(StopMusic.Instance);
|
||||
m.NetState.SendStopMusic();
|
||||
|
||||
if (m_Count > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ namespace Server
|
|||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime TimeReceived { get; private set; }
|
||||
|
||||
public static void Initialize()
|
||||
public static void Configure()
|
||||
{
|
||||
IncomingPackets.Register(0xD9, 0x10C, false, OnReceive);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue