本文整理汇总了C#中Packet类的典型用法代码示例。如果您正苦于以下问题:C# Packet类的具体用法?C# Packet怎么用?C# Packet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Packet类属于命名空间,在下文中一共展示了Packet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _handleAdminShow
private void _handleAdminShow(Packet pkt)
{
if (OnAdminHiddenChange == null) return;
short id = pkt.GetShort();
OnAdminHiddenChange(id, false);
}
示例2: OnCreatingResponse
public bool OnCreatingResponse(PacketSession session, Packet requestPacket, Packet responsePacket)
{
var idTypes = session.Server.IdTypes;
if (ValidateRequest(requestPacket))
{
var idType = idTypes.FirstOrDefault(x => x.Code == requestPacket.Words[1]);
var idValue = requestPacket.Words[2];
var banListItem = session.Server.BanList.FirstOrDefault(x => x.IdType.Code == idType.Code && x.IdValue == idValue);
if (banListItem != null)
{
session.Server.BanList.Remove(banListItem);
responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_SUCCESS);
}
else
{
responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_NOT_FOUND);
}
}
else
{
responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_INVALID_ARGUMENTS);
}
return true;
}
示例3: SendJob
public Guid SendJob(Base activity)
{
if (_ConnectionToManager == null || !_ConnectionToManager.IsConnected()) throw new Exception("Not connected to the manager");
while (true)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
MemoryStream datastream = new MemoryStream();
binaryFormatter.Serialize(datastream, activity);
Packet p = new Packet(1000);
Byte[] data= datastream.ToArray();
p.Add(data,true);
_ConnectionToManager.SendPacket(p);
Stopwatch sendTime = new Stopwatch();
sendTime.Start();
while (sendTime.ElapsedMilliseconds < _CommsTimeout)
{
if (_ConnectionToManager.GetPacketsToProcessCount() > 0)
{
foreach (Guid jobGuid in from packet in _ConnectionToManager.GetPacketsToProcess() where packet.Type == 1001 select new Guid((Byte[]) packet.GetObjects()[0]))
{
return jobGuid;
}
}
Thread.Sleep(1);
}
if (_ConnectionToManager.IsConnected()) _ConnectionToManager.Disconnect();
_ConnectionToManager.Connect(_IpAddress, _Port, 20480 * 1024);
}
throw new Exception("Mananger unavailable or busy");
}
示例4: AccountCreate
public bool AccountCreate(string uName, string pass, string realName, string location, string email, string HDDSerial, out AccountReply result)
{
result = AccountReply.THIS_IS_WRONG;
if (!m_client.ConnectedAndInitialized || !Initialized)
return false;
Packet builder = new Packet(PacketFamily.Account, PacketAction.Create);
//eoserv doesn't care...
builder.AddShort(1337);
builder.AddByte(42);
builder.AddBreakString(uName);
builder.AddBreakString(pass);
builder.AddBreakString(realName);
builder.AddBreakString(location);
builder.AddBreakString(email);
builder.AddBreakString(System.Net.Dns.GetHostName());
builder.AddBreakString(HDDSerial);
if (!m_client.SendPacket(builder) || !m_account_responseEvent.WaitOne(Constants.ResponseTimeout))
return false;
result = m_account_reply;
return true;
}
示例5: ReadPacket
public Packet ReadPacket()
{
if (_reader.PeekChar() < 0)
return null;
if (Version != 0x0300)
{
var direction = _reader.ReadByte();
var unixtime = _reader.ReadUInt32();
var tickcount = _reader.ReadUInt32();
var packet = new Packet();
packet.Size = _reader.ReadInt32() - (direction == 0xFF ? 2 : 4);
packet.OpcodeNumber = (uint)(direction == 0xFF ? _reader.ReadInt16() : _reader.ReadInt32());
packet.Data = _reader.ReadBytes(packet.Size);
return packet;
}
else
{
var direction = _reader.ReadUInt32();
var unixtime = _reader.ReadUInt32();
var tickcount = _reader.ReadUInt32();
var packet = new Packet();
var optSize = _reader.ReadInt32();
packet.Size = _reader.ReadInt32() - 4;
_reader.ReadBytes(optSize);
packet.OpcodeNumber = (uint)_reader.ReadInt32();
packet.Data = _reader.ReadBytes(packet.Size);
return packet;
}
}
示例6: AsciiSpeech
public static void AsciiSpeech( Packet p, PacketHandlerEventArgs args )
{
// 0, 1, 2
Serial serial = p.ReadUInt32(); // 3, 4, 5, 6
ushort body = p.ReadUInt16(); // 7, 8
MessageType type = (MessageType)p.ReadByte(); // 9
ushort hue = p.ReadUInt16(); // 10, 11
ushort font = p.ReadUInt16();
string name = p.ReadStringSafe( 30 );
string text = p.ReadStringSafe();
if ( World.Player != null && serial == Serial.Zero && body == 0 && type == MessageType.Regular && hue == 0xFFFF && font == 0xFFFF && name == "SYSTEM" )
{
args.Block = true;
p.Seek( 3, SeekOrigin.Begin );
p.WriteAsciiFixed( "", (int)p.Length-3 );
ClientCommunication.DoFeatures( World.Player.Features ) ;
}
else
{
HandleSpeech( p, args, serial, body, type, hue, font, "A", name, text );
if ( !serial.IsValid )
BandageTimer.OnAsciiMessage( text );
}
}
示例7: addPacketToQueue
public void addPacketToQueue(Packet p)
{
lock (queuedPackets)
{
queuedPackets.Enqueue(p);
}
}
示例8: OnGetValue
protected override bool OnGetValue(PacketSession session, Packet responsePacket)
{
bool isRanked = session.Server.ServerInfo.IsRanked;
responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_SUCCESS);
responsePacket.Words.Add(Convert.ToString(isRanked));
return true;
}
示例9: CreateParser
public static Parser CreateParser(Packet packet)
{
Type type;
if (Parsers.TryGetValue(packet.Code, out type))
{
var parser = (Parser) Activator.CreateInstance(type);
parser.Initialize(packet);
parser.Parse();
parser.CheckPacket();
return parser;
}
MethodInfo mi;
if (MethodParsers.TryGetValue(packet.Code, out mi))
{
Type createdType = mi.IsStatic ? typeof (Parser) : mi.DeclaringType;
var parserObj = (Parser) Activator.CreateInstance(createdType);
parserObj.Initialize(packet);
var args = new object[mi.GetParameters().Length];
if (args.Length > 0)
args[0] = parserObj; // pass the Parser object as a parameter for compatibility
try
{
mi.Invoke(parserObj, args);
}
catch (Exception e)
{
if (e.InnerException != null)
e = e.InnerException;
parserObj.WriteLine("ERROR: Parsing failed with exception " + e);
}
parserObj.CheckPacket();
return parserObj;
}
return UnknownParser;
}
示例10: IncomingDataTask
private static void IncomingDataTask(object tuple)
{
Socket cSocket = ((Tuple<Socket, Input>)tuple).Item1;
Input input = ((Tuple<Socket, Input>)tuple).Item2;
byte[] buffer;
int readBytes;
try
{
while (true)
{
buffer = new byte[cSocket.SendBufferSize];
readBytes = cSocket.Receive(buffer);
if (readBytes > 0)
{
Packet packet = new Packet(buffer);
DataManager(packet, input);
}
}
}
catch (SocketException)
{
lock (Server.clientsLock)
{
Server.clients.Remove(Server.clients.Last((c) => { return c.clientSocket == cSocket; }));
}
Server.Informer.AddEventInformation("A client disconnected");
}
}
示例11: ReadPacket
public Packet ReadPacket()
{
if (_readPackets >= _packets.Count)
{
return null;
}
var element = _packets[_readPackets];
var data = element.InnerText;
var len = data.Length / 2;
var bytes = new byte[len];
for (var i = 0; i < len; ++i)
{
var pos = i * 2;
var str = data[pos].ToString();
str += data[pos + 1];
bytes[i] = byte.Parse(str, System.Globalization.NumberStyles.HexNumber);
}
var packet = new Packet();
packet.Size = len;
packet.Code = (OpCodes)Convert.ToInt32(element.Attributes["opcode"].Value);
packet.Data = bytes;
_readPackets++;
return packet;
}
示例12: DeserializeServerOriginatedPacketTest
public void DeserializeServerOriginatedPacketTest()
{
var expectedPacket = new Packet(PacketOrigin.Server, false, 458, new List<string>() {"listPlayers", "all"});
var packetBytes = Convert.FromBase64String("ygEAgCQAAAACAAAACwAAAGxpc3RQbGF5ZXJzAAMAAABhbGwA");
var deserializedPackets = this.serializer.Deserialize(packetBytes).ToArray();
Assert.AreEqual(expectedPacket, deserializedPackets[0], "Deserializing Server Packet not successful");
}
示例13: DeserializeServerOriginatedPacketResponseTest
public void DeserializeServerOriginatedPacketResponseTest()
{
var expectedPacket = new Packet(PacketOrigin.Server, true, 458, new List<string>() { "OK", "21", "test" });
var packetBytes = Convert.FromBase64String("ygEAwCMAAAADAAAAAgAAAE9LAAIAAAAyMQAEAAAAdGVzdAA=");
var deserializedPackets = this.serializer.Deserialize(packetBytes).ToArray();
Assert.AreEqual(expectedPacket, deserializedPackets[0], "Deserializing Server Packet Response not successful");
}
示例14: GetPackage
//**CONFIRMED
public static Packet GetPackage(int shipNumber)
{
SetShipSubPacket ssp = new SetShipSubPacket(shipNumber);
ShipActionPacket sap = new ShipActionPacket(ssp);
Packet p = new Packet(sap);
return p;
}
示例15: FPSAim
public FPSAim(String vcd)
{
InitializeComponent();
VideoCaptureDevice videoSource = new VideoCaptureDevice(vcd, new Size(320, 240), false);
OpenVideoSource(videoSource);
redDot.Location = new Point(gridBox.Width / 2 + gridBox.Left, gridBox.Height / 2 + gridBox.Top);
servos = new Servos();
redDot.Location = servos.GetPorportionalMathPosition(gridBox.Bounds);
redDot.Location = new Point(redDot.Location.X - REDDOT_OFFSET_X, redDot.Location.Y - REDDOT_OFFSET_Y);
label1.Text = "(-" + servos.CenterServosPosition.X + "," + servos.CenterServosPosition.Y + ")";
textBoxXServo.Text = servos.ShootingRange.Width.ToString();
textBoxYServo.Text = servos.ShootingRange.Height.ToString();
textBoxXCoord.Text = servos.ServosPosition.X.ToString();
textBoxYCoord.Text = servos.ServosPosition.Y.ToString();
Packet packet = new Packet(servos.CenterServosPosition);
packet.setFireOff();
this.sendData(packet);
Cursor.Hide();
cursorhidden = true;
CoordinateTimer.Start();
//Point camwindowcenter = new Point(gridBox.PointToScreen(new Point(0, 0)).X , gridBox.PointToScreen(new Point(0, 0)).Y );
//Cursor.Position = camwindowcenter;
currentX = Cursor.Position.X;
currentY = Cursor.Position.Y;
lastX = 0;
lastY = 0;
}