本文整理汇总了C#中NetGore.IO.BitStream类的典型用法代码示例。如果您正苦于以下问题:C# BitStream类的具体用法?C# BitStream怎么用?C# BitStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitStream类属于NetGore.IO命名空间,在下文中一共展示了BitStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecvMoveStopHorizontal
void RecvMoveStopHorizontal(IIPSocket conn, BitStream r)
{
User user;
if ((user = TryGetUser(conn)) != null && (user.IsMovingLeft || user.IsMovingRight))
{
if (user.IsPeerTrading)
return;
user.StopMovingHorizontal();
}
}
示例2: AssertRestOfStreamIsZero
static void AssertRestOfStreamIsZero(BitStream data)
{
if (!RestOfStreamIsZero(data))
{
const string errmsg = "Encountered msgID = 0, but there was set bits remaining in the stream.";
if (log.IsWarnEnabled)
log.WarnFormat(errmsg);
Debug.Fail(errmsg);
}
}
示例3: RecvMoveStopVertical
void RecvMoveStopVertical(IIPSocket conn, BitStream r)
{
User user;
if ((user = TryGetUser(conn)) != null && (user.IsMovingUp || user.IsMovingDown))
{
if (user.IsPeerTrading)
return;
user.StopMovingVertical();
}
}
示例4: RecvMoveUp
void RecvMoveUp(IIPSocket conn, BitStream r)
{
User user;
if ((user = TryGetUser(conn)) != null && !user.IsMovingUp)
{
if (user.IsPeerTrading)
return;
user.MoveUp();
}
}
示例5: RecvJump
void RecvJump(IIPSocket conn, BitStream r)
{
User user;
if (((user = TryGetUser(conn)) != null) && user.CanJump)
{
if (user.IsPeerTrading)
return;
user.Jump();
}
}
示例6: InvokeProcessor
/// <summary>
/// Invokes the <see cref="IMessageProcessor"/> for handle processing a message block.
/// </summary>
/// <param name="socket">The <see cref="IIPSocket"/> that the data came from.</param>
/// <param name="processor">The <see cref="IMessageProcessor"/> to invoke.</param>
/// <param name="reader">The <see cref="BitStream"/> containing the data to process.</param>
protected override void InvokeProcessor(IIPSocket socket, IMessageProcessor processor, BitStream reader)
{
// Invoke the processor as normal, but keeping track of the bit position before and after invoking
var startBits = reader.PositionBits;
base.InvokeProcessor(socket, processor, reader);
var endBits = reader.PositionBits;
// Update the stats
_stats.HandleProcessorInvoked(processor.MsgID, endBits - startBits);
}
示例7: AcceptConnect
/// <summary>
/// Determines whether or not a connection request should be accepted.
/// </summary>
/// <param name="ip">The IPv4 address the remote connection is coming from.</param>
/// <param name="port">The port that the remote connection is coming from.</param>
/// <param name="data">The data sent along with the connection request.</param>
/// <returns>
/// If null or empty, the connection will be accepted. Otherwise, return a non-empty string containing the reason
/// as to why the connection is to be rejected to reject the connection.
/// </returns>
protected override string AcceptConnect(uint ip, ushort port, BitStream data)
{
// Check for too many connections from the IP
var maxConnsPerIP = ServerSettings.Default.MaxConnectionsPerIP;
if (maxConnsPerIP > 0)
{
var connsFromIP = Connections.Count(x => x.IP == ip);
if (connsFromIP >= maxConnsPerIP)
return GameMessageHelper.AsString(GameMessage.DisconnectTooManyConnectionsFromIP);
}
return base.AcceptConnect(ip, port, data);
}
示例8: ReadWriteFromHelperUsingPropertyTest
public void ReadWriteFromHelperUsingPropertyTest()
{
var bs = new BitStream(512);
var a = new ClassB { A = "asdf", B = 512 };
var b = new ClassB();
a.WriteState(bs);
bs.PositionBits = 0;
b.ReadState(bs);
Assert.AreEqual(a.A, b.A);
Assert.AreEqual(a.B, b.B);
}
示例9: CopyValuesTo
/// <summary>
/// Copies the values of this NPCChatConditionalCollectionBase to another NPCChatConditionalCollectionBase.
/// </summary>
/// <param name="dest">The NPCChatConditionalCollectionBase to copy the values into.</param>
public void CopyValuesTo(NPCChatConditionalCollectionBase dest)
{
var stream = new BitStream(256);
using (var writer = BinaryValueWriter.Create(stream))
{
Write(writer);
}
stream.PositionBits = 0;
var reader = BinaryValueReader.Create(stream);
dest.Read(reader);
}
示例10: ReadWriteFromInterfaceTest
public void ReadWriteFromInterfaceTest()
{
var bs = new BitStream(512);
var a = new ClassA { A = "asdf", B = 512 };
var b = new ClassA();
a.WriteState(bs);
bs.PositionBits = 0;
b.ReadState(bs);
Assert.AreEqual(a.A, b.A);
Assert.AreEqual(a.B, b.B);
}
示例11: Send
/// <summary>
/// Sends data to the <see cref="INetworkSender"/>. This method is thread-safe.
/// </summary>
/// <param name="sender">The <see cref="INetworkSender"/> to use to send the data.</param>
/// <param name="data">BitStream containing the data to send to the User.</param>
/// <param name="messageType">The <see cref="ServerMessageType"/> to use for sending the <paramref name="data"/>.</param>
public static void Send(this INetworkSender sender, BitStream data, ServerMessageType messageType)
{
if (!sender.IsConnected)
{
const string errmsg = "Send to `{0}` failed - not connected.";
if (log.IsErrorEnabled)
log.ErrorFormat(errmsg, sender);
return;
}
NetDeliveryMethod method;
int seqChannel;
messageType.GetDeliveryMethod(out method, out seqChannel);
sender.Send(data, method, seqChannel);
}
示例12: OnReceiveData
/// <summary>
/// When overridden in the derived class, allows for handling received data from an <see cref="IIPSocket"/>.
/// </summary>
/// <param name="sender">The <see cref="IIPSocket"/> that the data came from.</param>
/// <param name="data">The data that was received.</param>
protected override void OnReceiveData(IIPSocket sender, BitStream data)
{
base.OnReceiveData(sender, data);
try
{
// Process the data
_messageProcessorManager.Process(sender, data);
}
catch (Exception ex)
{
const string errmsg = "Failed to process received data from `{0}`. Exception: {1}";
if (log.IsWarnEnabled)
log.WarnFormat(errmsg, sender, ex);
Debug.Fail(string.Format(errmsg, sender, ex));
}
}
示例13: EditorNPCChatConditionalCollection
/// <summary>
/// Initializes a new instance of the <see cref="EditorNPCChatConditionalCollection"/> class.
/// </summary>
/// <param name="source">The source <see cref="NPCChatConditionalCollectionBase"/> to copy the values from. If null,
/// no values are copied.</param>
public EditorNPCChatConditionalCollection(NPCChatConditionalCollectionBase source)
{
if (source == null)
return;
var stream = new BitStream(256);
using (var writer = BinaryValueWriter.Create(stream))
{
source.Write(writer);
}
stream.PositionBits = 0;
IValueReader reader = BinaryValueReader.Create(stream);
Read(reader);
}
示例14: DeepCopy
public ParticleModifier DeepCopy()
{
// Create the deep copy by serializing to/from an IValueWriter
using (var bs = new BitStream())
{
// Write
using (var writer = BinaryValueWriter.Create(bs, false))
{
Write(writer);
}
bs.Position = 0;
// Read
var reader = BinaryValueReader.Create(bs, false);
return Read(reader);
}
}
示例15: TestSyncNullable
static void TestSyncNullable(string propertyName, object value)
{
// Get the property
var property = typeof(NullableTestClass).GetProperty(propertyName);
// Set the value and ensure it was set correctly
var cSrc = new NullableTestClass();
property.SetValue(cSrc, value, null);
Assert.AreEqual(value, property.GetValue(cSrc, null));
// Serialize
var bs = new BitStream();
cSrc.Serialize(bs);
// Deserialize
var cDest = new NullableTestClass();
bs.PositionBits = 0;
cDest.Deserialize(bs);
// Check
Assert.AreEqual(value, property.GetValue(cDest, null));
}