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,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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue