本文整理汇总了C#中System.IO.PacketWriter类的典型用法代码示例。如果您正苦于以下问题:C# PacketWriter类的具体用法?C# PacketWriter怎么用?C# PacketWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PacketWriter类属于System.IO命名空间,在下文中一共展示了PacketWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnRoomEvent
public static void OnRoomEvent(this GameServer server, StoSMessage msg, RoomInfo info){
using(PacketWriter writer = new PacketWriter(2)){
writer.Write((ushort)msg);
//length
writer.Write((ushort)1);
writer.WriteUnicode(info.Name, 20);
writer.WriteUnicode(info.Pwd, 20);
writer.Write((byte)info.Rule);
writer.Write((byte)info.Mode);
writer.Write(info.IsStart);
writer.WriteUnicode(info.Lflist, 60);
writer.Write(info.Warring);
writer.Write(info.StartLP);
writer.Write((ushort)info.players.Length);
for(int i =0; i<info.players.Length;i++){
writer.WriteUnicode(info.players[i], 20);
}
writer.Write((ushort)info.observers.Count);
for(int i =0; i<info.observers.Count;i++){
writer.WriteUnicode(info.observers[i], 20);
}
//string str = Tool.ToJson(info);
//byte[] bs = Encoding.Unicode.GetBytes(str);
//writer.Write(bs);
writer.Use();
//Send(server.LocalClient, writer.Content);
}
}
示例2: DoShipList
private void DoShipList(Socket socket)
{
var writer = new PacketWriter();
var entries = new List<ShipEntry>();
for (var i = 1; i < 11; i++)
{
var entry = new ShipEntry
{
order = (ushort)i,
number = (uint)i,
status = ShipStatus.Online,
name = String.Format("Ship{0:0#}", i),
ip = PolarisApp.BindAddress.GetAddressBytes()
};
entries.Add(entry);
}
writer.WriteStruct(new PacketHeader(Marshal.SizeOf(typeof(ShipEntry)) * entries.Count + 12, 0x11, 0x3D, 0x4,
0x0));
writer.WriteMagic((uint)entries.Count, 0xE418, 81);
foreach (var entry in entries)
writer.WriteStruct(entry);
writer.Write((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
writer.Write(1);
socket.Send(writer.ToArray());
socket.Close();
}
示例3: OnRoomClose
public static void OnRoomClose(GameRoom room){
using (PacketWriter writer=new PacketWriter(2)){
writer.Write((byte)RoomMessage.RoomClose);
writer.WriteUnicode(room.Config.Name, 20);
Send(writer.Content);
}
}
示例4: OnServerClose
public static void OnServerClose(this RoomServer roomServer, DuelServer server)
{
using (PacketWriter writer = new PacketWriter(2))
{
writer.Write((byte)RoomMessage.ServerClose);
writer.Write(server.Port);
DuelServer srv = roomServer.GetMinServer();
lock (srv.AsyncLock)
{
srv.Count = 0;
}
if (srv != null)
{
//特殊处理
writer.Write(srv.Port);
writer.Write(srv.NeedAuth);
//session.ServerInfo = srv;
lock (roomServer.Clients)
{
foreach (Session client in roomServer.Clients.Values)
{
if (client.ServerInfo != null && client.ServerInfo.Port == server.Port)
{
client.ServerInfo = srv;
client.Send(writer.Content);
}
}
}
}
}
}
示例5: GenerateSpawnBlob
public override byte[] GenerateSpawnBlob()
{
PacketWriter writer = new PacketWriter();
writer.WriteStruct(Header);
writer.WritePosition(Position);
writer.Write((UInt16)0);
writer.WriteFixedLengthASCII(Name, 0x20);
writer.Write(0); // Padding?
writer.Write(new byte[0xC]); // Unknown, usually zero
writer.Write((UInt16)0);
writer.Write((UInt16)0);
writer.Write((UInt32)0);
writer.Write((UInt32)0);
writer.Write((UInt32)1101004800); // Always this
writer.Write((UInt32)0);
writer.Write((UInt32)0);
writer.Write((UInt32)0);
writer.Write((UInt32)1);
writer.WriteMagic(1, 0x9FCD, 0xE7);
writer.Write((UInt32)0);
return writer.ToArray();
}
示例6: HandlePacket
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
var writer = new PacketWriter();
writer.Write((uint) 0);
context.SendPacket(0x11, 0x55, 0x0, writer.ToArray());
}
示例7: OnSendServerInfo
public static void OnSendServerInfo(this RoomServer roomServer, Session session)
{
using (PacketWriter writer = new PacketWriter(2))
{
writer.Write((byte)RoomMessage.Info);
writer.Write(roomServer.GetChatPort());
DuelServer srv = roomServer.GetMinServer();
lock (srv.AsyncLock)
{
srv.Count++;
}
if (srv != null)
{
session.ServerInfo = srv;
writer.Write(srv.Port);
writer.Write(srv.NeedAuth);
}
else
{
writer.Write(0);
writer.Write((byte)0);
}
writer.WriteUnicode(session.Token, 32);
session.Send(writer.Content);
}
}
示例8: RicePacket
public RicePacket(ushort id)
{
Writer = new PacketWriter(new MemoryStream());
ID = id;
Writer.Write(id);
}
示例9: LobbyError
public static void LobbyError(this Session session, string message)
{
using (PacketWriter join = new PacketWriter(2))
{
join.Write((byte)RoomMessage.JoinGame);
join.Write(0U);
join.Write((byte)0);
join.Write((byte)0);
join.Write(0);
join.Write(0);
join.Write(0);
// C++ padding: 5 bytes + 3 bytes = 8 bytes
for (int i = 0; i < 3; i++)
join.Write((byte)0);
join.Write(0);
join.Write((byte)0);
join.Write((byte)0);
join.Write((short)0);
session.Send(join, false);
}
using (PacketWriter enter = new PacketWriter(2))
{
enter.Write((byte)RoomMessage.HsPlayerEnter);
enter.WriteUnicode("[err]" + message, 20);
enter.Write((byte)0);
session.Send(enter);
}
}
示例10: SendRecvPacket
public SendRecvPacket(int id, string name)
{
Id = id;
Name = name;
Stream = PacketWriter.CreateInstance(Length);
Stream.Write(id);
Stream.Write((short) 0);
}
示例11: SendPacket
/// <summary>
/// Creates an instance of a packet
/// </summary>
/// <param name="id">the Id, or Command that identifies the packet</param>
/// <param name="name">The name of the packet</param>
public SendPacket(int id, string name)
{
m_Id = id;
m_Name = name;
Stream = PacketWriter.CreateInstance(m_Length);
Stream.Write((byte)id);
Stream.Write((short)0);
}
示例12: OnPlayerLeave
public static void OnPlayerLeave(GameSession player, GameRoom room){
if (player.Name == null || player.Name.StartsWith("[AI]")) return;
using (PacketWriter writer=new PacketWriter(2)){
writer.Write((byte)RoomMessage.PlayerLeave);
writer.WriteUnicode(player.Name, 20);
writer.WriteUnicode(room.Config.Name, 20);
Send(writer.Content);
}
}
示例13: OnServerInfo
public static void OnServerInfo(GameServer server){
ServerConfig Config = server.Config;
using(PacketWriter writer=new PacketWriter(2)){
writer.Write((byte)RoomMessage.Info);
writer.Write(Config.ServerPort);
writer.Write(Config.isNeedAuth);
Send(writer.Content);
}
}
示例14: HandlePacket
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
if (context.Character == null)
return;
var reader = new PacketReader(data, position, size);
reader.BaseStream.Seek(0xC, SeekOrigin.Begin);
var channel = reader.ReadUInt32();
var message = reader.ReadUtf16(0x9D3F, 0x44);
if (message.StartsWith(PolarisApp.Config.CommandPrefix))
{
var valid = false;
// Iterate commands
foreach (var command in PolarisApp.ConsoleSystem.Commands)
{
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;
Logger.WriteCommand(null, "[CMD] {0} issued command {1}", context.User.Username, full);
}
if (valid)
break;
}
if (!valid)
Logger.WriteClient(context, "[CMD] {0} - Command not found", message.Split(' ')[0].Trim('\r'));
}
else
{
Logger.Write("[CHT] <{0}> <{1}>", context.Character.Name, message);
var writer = new PacketWriter();
writer.WritePlayerHeader((uint) context.User.PlayerId);
writer.Write(channel);
writer.WriteUtf16(message, 0x9D3F, 0x44);
data = writer.ToArray();
foreach (var c in Server.Instance.Clients)
{
if (c.Character == null || c.CurrentZone != context.CurrentZone)
continue;
c.SendPacket(0x07, 0x00, 0x44, data);
}
}
}
示例15: NovacomSocketStream
/// <exception cref="System.IO.IOException" />
internal NovacomSocketStream(TcpClient socket, string cmdUsedForStream)
{
this.socket = socket;
ioStream = this.socket.GetStream();
packetReader = new PacketReader(ioStream);
packetWriter = new PacketWriter(ioStream);
packetMode = true;
outputClosed = false;
inputClosed = false;
this.cmdUsedForStream = cmdUsedForStream;
}