本文整理汇总了C#中Lidgren.Network.NetPeer.Recycle方法的典型用法代码示例。如果您正苦于以下问题:C# NetPeer.Recycle方法的具体用法?C# NetPeer.Recycle怎么用?C# NetPeer.Recycle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetPeer
的用法示例。
在下文中一共展示了NetPeer.Recycle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PeerListener
public void PeerListener(NetPeer peer)
{
while (true)
{
NetIncomingMessage msg;
while ((msg=peer.ReadMessage())!=null)
{
NetConnection connection = msg.SenderConnection;
switch (msg.MessageType)
{
case NetIncomingMessageType.StatusChanged:
switch (msg.SenderConnection.Status)
{
case NetConnectionStatus.Connected:
logger.Info("{0}: connected",connection.RemoteEndPoint.Address.ToString());
ExecuteCommand(new CmdInitOk(connection));
break;
case NetConnectionStatus.Disconnected:
logger.Info("{0}: disconnected", connection.RemoteEndPoint.Address.ToString());
break;
case NetConnectionStatus.Disconnecting:
logger.Info("{0}: disconnecting", connection.RemoteEndPoint.Address.ToString());
break;
}
break;
case NetIncomingMessageType.Data:
msg.Decrypt(new NetRC2Encryption(peer, connection.CryptoKey));
string[] OpData = msg.ReadString().Split('&');
var OpCode = (LoginOperation)Enum.Parse(typeof(LoginOperation), OpData[0]);
switch (OpCode)
{
case LoginOperation.AuthLog:
string[] authData = OpData[1].Split('#');
string login = authData[0];
string pass = authData[1];
ExecuteCommand(new CmdLoginOkFail(connection, login,pass));
break;
}
break;
}
peer.Recycle(msg);
}
}
}
示例2: Listen
private static void Listen(NetPeer peer)
{
//TODO FIXME!
if (peer == null)
return;
NetIncomingMessage msg;
while ((msg = peer.ReadMessage()) != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.Data:
//JapeLog.WriteLine("Message received: Data");
IncomingData(msg);
break;
case NetIncomingMessageType.ConnectionApproval:
// Read the first byte of the packet
// ( Enums can be casted to bytes, so it be used to make bytes human readable )
int type = msg.ReadInt32();
if (type == (int)DataType.Login)
{
JapeLog.WriteLine("Incoming LOGIN");
msg.SenderConnection.Approve();
string hailMessage = msg.ReadString();
JapeLog.WriteLine("Approved new connection: " + hailMessage);
}
break;
case NetIncomingMessageType.StatusChanged:
if (msg.SenderConnection.Status == NetConnectionStatus.Connected)
{
if (!IsHost)
{
SendMessageParams(NetDeliveryMethod.ReliableOrdered,
(int)DataType.NewPlayer,
DataStorage.GetLocalPlayerConfig().UserName,
(IsHost) ? 0 : -1,
RemoteUID
);
JapeLog.WriteLine("SEND NEWPLAYER");
}
else
JapeLog.WriteLine("This server is Dedicated (Not sending a new player message)");
}
if (msg.SenderConnection.Status == NetConnectionStatus.Disconnected)
{
JapeLog.WriteLine("Player Disconnected");
//if player is in connected => remove from play
}
if (msg.SenderConnection.Status == NetConnectionStatus.Disconnecting)
{
JapeLog.WriteLine("Player Disconnecting");
//if player is in connected => remove from play
}
break;
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
//JapeLog.WriteLine(msg.ReadString());
break;
}
peer.Recycle(msg);
}
}