using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Facepunch.Steamworks
{
///
/// If you're manually processing the server queries, you should use this class.
///
public class ServerQuery
{
internal Server server;
internal static byte[] buffer = new byte[64*1024];
internal ServerQuery( Server s )
{
server = s;
}
///
/// A server query packet.
///
public struct Packet
{
///
/// Target IP address
///
public uint Address { get; internal set; }
///
/// Target port
///
public ushort Port { get; internal set; }
///
/// This data is pooled. Make a copy if you don't use it immediately.
/// This buffer is also quite large - so pay attention to Size.
///
public byte[] Data { get; internal set; }
///
/// Size of the data
///
public int Size { get; internal set; }
}
///
/// If true, Steam wants to send a packet. You should respond by sending
/// this packet in an unconnected way to the returned Address and Port.
///
/// Packet to send. The Data passed is pooled - so use it immediately.
/// True if we want to send a packet
public unsafe bool GetOutgoingPacket( out Packet packet )
{
packet = new Packet();
fixed ( byte* ptr = buffer )
{
uint addr = 0;
ushort port = 0;
var size = server.native.gameServer.GetNextOutgoingPacket( (IntPtr)ptr, buffer.Length, out addr, out port );
if ( size == 0 )
return false;
packet.Size = size;
packet.Data = buffer;
packet.Address = addr;
packet.Port = port;
return true;
}
}
///
/// We have received a server query on our game port. Pass it to Steam to handle.
///
public unsafe void Handle( byte[] data, int size, uint address, ushort port )
{
fixed ( byte* ptr = data )
{
server.native.gameServer.HandleIncomingPacket( (IntPtr)ptr, size, address, port );
}
}
}
}