PSO2SERVER/Server/Protocol/Handlers/07-ChatHandler/07-00-ChatHandler.cs

69 lines
2.4 KiB
C#
Raw Normal View History

2024-09-21 13:46:28 +08:00
using PSO2SERVER.Models;
using PSO2SERVER.Protocol.Packets;
2024-09-21 13:46:28 +08:00
using System.Collections.Generic;
2024-09-16 15:30:00 +08:00
using System.IO;
2024-09-10 00:31:40 +08:00
using System.Linq;
namespace PSO2SERVER.Protocol.Handlers
2024-09-10 00:31:40 +08:00
{
[PacketHandlerAttr(0x07, 0x00)]
public class ChatHandler : PacketHandler
{
#region implemented abstract members of PacketHandler
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
if (context.Character == null)
return;
2024-09-22 00:08:44 +08:00
//var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
2024-09-21 15:40:13 +08:00
//Logger.WriteHex(info, data);
2024-09-12 03:23:56 +08:00
2024-09-10 00:31:40 +08:00
var reader = new PacketReader(data, position, size);
var obj = reader.ReadObjectHeader();
2024-09-21 13:46:28 +08:00
var channel = reader.ReadByte();
var unk3 = reader.ReadByte();
var unk4 = reader.ReadInt16();
reader.BaseStream.Seek(0x4, SeekOrigin.Current);
var message = reader.ReadUtf16(0x9D3F, 0x44);
2024-09-10 00:31:40 +08:00
2024-09-10 01:13:20 +08:00
if (message.StartsWith(ServerApp.Config.CommandPrefix))
2024-09-10 00:31:40 +08:00
{
var valid = false;
// Iterate commands
2024-09-10 01:13:20 +08:00
foreach (var command in ServerApp.ConsoleSystem.Commands)
2024-09-10 00:31:40 +08:00
{
var full = message.Substring(1); // Strip the command chars
var args = full.Split(' ');
if (command.Names.Any(name => args[0].ToLower() == name.ToLower()))
{
command.Run(args, args.Length, full, context);
valid = true;
2024-09-20 21:58:37 +08:00
Logger.WriteCommand(null, "[CMD] {0} 发送指令 {1}", context._account.Username, full);
2024-09-10 00:31:40 +08:00
}
if (valid)
break;
}
if (!valid)
Logger.WriteClient(context, "[CMD] {0} - 指令不存在", message.Split(' ')[0].Trim('\r'));
}
else
{
2024-09-12 20:53:20 +08:00
Logger.Write("[CHT] <{0}> 频道{1}说 {2}", context.Character.Name, channel, message);
2024-09-10 00:31:40 +08:00
foreach (var c in Server.Instance.Clients)
{
2024-12-10 23:08:39 +08:00
if (c.Character == null || c.CurrentMap != context.CurrentMap)
2024-09-10 00:31:40 +08:00
continue;
2024-09-21 13:46:28 +08:00
c.SendPacket(new ChatPacket((uint)context._account.AccountId, channel, message));
2024-09-10 00:31:40 +08:00
}
}
}
#endregion
}
}