本文整理汇总了C#中Lidgren.Network.NetConnection类的典型用法代码示例。如果您正苦于以下问题:C# NetConnection类的具体用法?C# NetConnection怎么用?C# NetConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetConnection类属于Lidgren.Network命名空间,在下文中一共展示了NetConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecvMCL
public static void RecvMCL()
{
while(true) {
Thread.Sleep(10);
NetIncomingMessage msg;
while((msg = peer.ReadMessage()) != null) {
switch(msg.MessageType) {
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
Console.WriteLine(msg.ReadString());
break;
case NetIncomingMessageType.StatusChanged:
Console.WriteLine(((NetConnectionStatus)msg.ReadByte()).ToString());
break;
case NetIncomingMessageType.DiscoveryResponse:
Console.WriteLine("Found server at " + msg.SenderEndPoint + " name: " + msg.ReadString());
peerConnect = peer.Connect(msg.SenderEndPoint);
break;
case NetIncomingMessageType.Data:
Console.WriteLine(msg.LengthBytes);
break;
default:
Console.WriteLine("Unhandled type: " + msg.MessageType);
break;
}
}
}
}
示例2: Modify
public void Modify(NetConnection conn, uint id)
{
if(ConnectionDictionary.ContainsKey(conn))
{
ConnectionDictionary[conn] = id;
}
}
示例3: getClient
public static KSPClient getClient(NetConnection clientConnection)
{
KSPClient returnVal;
connectionToClient.TryGetValue(clientConnection, out returnVal);
// FUCK IT THIS SHOULDNT EVER BE NULL ANYWAY
return returnVal;
}
示例4: Connection
/// <summary>
/// Constructor
/// </summary>
/// <param name="manager">Local NetPeer</param>
/// <param name="con">NetConnection</param>
/// <param name="key">Encryption key</param>
/// <param name="nodeId">Node Id</param>
public Connection(NetPeer manager, NetConnection con, INetEncryption encryption, String nodeId)
{
// This keep alive timer is used to overcome BAD connections that drop ping/pong messages a lot.
// It simply sends an empty message every five seconds. As long as some messages are retained
// and received on the connection, all will be well
_keepAliveTimer = new System.Timers.Timer(5000);
_keepAliveTimer.Elapsed += new ElapsedEventHandler((Object state, ElapsedEventArgs args) =>
this.SendMessage(this.NetManager.CreateMessage(0), NetDeliveryMethod.Unreliable));
this.Username = (con.Tag as Handshake).Username;
this.NetManager = manager;
this.NetConnection = con;
this.NetConnection.Tag = this;
this.NodeId = nodeId;
if (encryption != null)
{
_netEncryption = encryption;
}
else
{
// You could write code that makes it possible to transfer users between server
// where you don't have any encryption key YET. The place to start that would
// be here.
this.IsTransfering = true;
_netEncryption = new NetXtea(new Byte[16]);
}
// Not connected until everything is done.
System.Threading.Thread.MemoryBarrier();
_connected = true;
_keepAliveTimer.Start();
}
示例5: SendMessage
/// <summary>
/// Send a message to a specific connection
/// </summary>
/// <param name="msg">The message to send</param>
/// <param name="recipient">The recipient connection</param>
/// <param name="method">How to deliver the message</param>
/// <param name="sequenceChannel">Sequence channel within the delivery method</param>
public NetSendResult SendMessage(NetOutgoingMessage msg, NetConnection recipient, NetDeliveryMethod method, int sequenceChannel)
{
if (msg == null)
throw new ArgumentNullException("msg");
if (recipient == null)
throw new ArgumentNullException("recipient");
if (sequenceChannel >= NetConstants.NetChannelsPerDeliveryMethod)
throw new ArgumentOutOfRangeException("sequenceChannel");
NetException.Assert(
((method != NetDeliveryMethod.Unreliable && method != NetDeliveryMethod.ReliableUnordered) ||
((method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered) && sequenceChannel == 0)),
"Delivery method " + method + " cannot use sequence channels other than 0!"
);
NetException.Assert(method != NetDeliveryMethod.Unknown, "Bad delivery method!");
if (msg.m_isSent)
throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently");
msg.m_isSent = true;
int len = NetConstants.UnfragmentedMessageHeaderSize + msg.LengthBytes; // headers + length, faster than calling msg.GetEncodedSize
if (len <= recipient.m_currentMTU)
{
Interlocked.Increment(ref msg.m_recyclingCount);
return recipient.EnqueueMessage(msg, method, sequenceChannel);
}
else
{
// message must be fragmented!
SendFragmentedMessage(msg, new NetConnection[] { recipient }, method, sequenceChannel);
return NetSendResult.Queued; // could be different for each connection; Queued is "most true"
}
}
示例6: HandleMessage
private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
{
switch (type)
{
case NetMessageType.DebugMessage:
Console.WriteLine(buffer.ReadString());
break;
case NetMessageType.StatusChanged:
NetConnectionStatus status = source.Status;
if (status == NetConnectionStatus.Connected)
{
source.Tag = ImageClientStatus.JustConnected;
s_nextPixelToSend[source] = 0;
}
else if (status == NetConnectionStatus.Disconnected)
{
if (s_nextPixelToSend.ContainsKey(source))
s_nextPixelToSend.Remove(source);
}
break;
case NetMessageType.Receipt:
source.Tag = ImageClientStatus.Running;
break;
default:
// unhandled
break;
}
}
示例7: Character
public Character(string name, int x, int y, NetConnection conn)
{
Name = name;
X = x;
Y = y;
Connection = conn;
}
示例8: Process
public static void Process(NetServer server, NetBuffer buffer, NetConnection sender)
{
Config config = Config.Instance;
List<NetConnection> connections = server.Connections;
//Lets send that message onto any plugin clients
foreach (NetConnection connection in connections)
{
if (config.Server.client_connections.ContainsKey(connection.RemoteEndpoint.ToString()))
{
string client_type = (string)config.Server.client_connections[connection.RemoteEndpoint.ToString()];
if (client_type.ToLower() == "plugin")
{
string msg = buffer.ReadString();
Console.WriteLine("Slave: Data sent - " + msg);
NetBuffer slavebuf = server.CreateBuffer();
slavebuf.Write(msg);
server.SendMessage(slavebuf, connection, NetChannel.ReliableInOrder4);
}
}
}
}
示例9: HandleNetworkMessage
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
{
if (message.ComponentFamily == ComponentFamily.Equipment)
{
var type = (ComponentMessageType) message.MessageParameters[0];
var replies = new List<ComponentReplyMessage>();
switch (type) //Why does this send messages to itself THIS IS DUMB AND WILL BREAK THINGS. BZZZ
{
case ComponentMessageType.EquipItem:
EquipEntity(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]));
break;
case ComponentMessageType.EquipItemInHand:
EquipEntityInHand();
break;
case ComponentMessageType.EquipItemToPart:
EquipEntityToPart((EquipmentSlot) message.MessageParameters[1],
Owner.EntityManager.GetEntity((int) message.MessageParameters[2]));
break;
case ComponentMessageType.UnEquipItemToFloor:
UnEquipEntity(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]));
break;
case ComponentMessageType.UnEquipItemToHand:
if (!Owner.HasComponent(ComponentFamily.Hands))
return; //TODO REAL ERROR MESSAGE OR SOME FUCK SHIT
UnEquipEntityToHand(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]));
break;
case ComponentMessageType.UnEquipItemToSpecifiedHand:
if (!Owner.HasComponent(ComponentFamily.Hands))
return; //TODO REAL ERROR MESSAGE OR SOME FUCK SHIT
UnEquipEntityToHand(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]),
(Hand) message.MessageParameters[2]);
break;
}
}
}
示例10: OnDisconnected
internal override void OnDisconnected(NetConnection conn)
{
//vij dali e igral
if (!clients.Contains(conn))
return;
}
示例11: PlayerClient
public PlayerClient(NetConnection Connection)
: base()
{
Location = new Vector2((375 * 40) + 1, (375 * 40) + 1);
ClientConnection = Connection;
Sex = LastSex;
}
示例12: SetClientCameraFollow
private static void SetClientCameraFollow(long ID, NetConnection Connection)
{
NetOutgoingMessage Message = NetworkManager.Server.CreateMessage();
Message.Write((byte)MessageTypes.CameraFocusAt);
Message.Write(ID);
NetworkManager.Server.SendMessage(Message, Connection, NetDeliveryMethod.ReliableUnordered);
}
示例13: SendMessage
private static void SendMessage(NetServer server, MsgBase msg, NetConnection conn)
{
NetOutgoingMessage om = server.CreateMessage();
om.Write(msg.Id);
msg.W(om);
server.SendMessage(om, conn, NetDeliveryMethod.Unreliable, 0);
}
示例14: Connection
/// <summary>
/// Creates a new connection instance.
/// </summary>
/// <param name="messagingSettings">Qbes messaging configuration
/// node</param>
/// <param name="connection">NetConnection object</param>
/// <param name="callback">Callback for completed received multipart
/// messages</param>
public Connection(MessagingConfiguration messagingSettings, NetConnection connection, CompletedReceivedMultipartMessage callback)
{
_MaxMessageSize = messagingSettings.MaxMessageSize;
_Connection = connection;
_RemoteEndPoint = connection.RemoteEndPoint;
_CompletedReceivedMultipartCallback = callback;
}
示例15: AddConnection
public void AddConnection(NetConnection connection)
{
var lobbyPlayer = new LobbyPlayer();
lobbyPlayer.Id = idToGive;
connection.Tag = lobbyPlayer;
clients.Add(connection);
idToGive++;
var memory = new MemoryStream();
var writer = new BinaryWriter(memory);
writer.Write((byte) LobbyProtocol.SetID);
writer.Write(lobbyPlayer.Id);
myServer.SendLobbyData(memory.ToArray(), connection);
memory = new MemoryStream();
writer = new BinaryWriter(memory);
writer.Write((byte)LobbyProtocol.SendAllPlayers);
writer.Write(AllPlayersData());
myServer.SendLobbyData(memory.ToArray());
SendData(new byte[1]{MaxSlots}, LobbyProtocol.SendMaxSlots );
memory = new MemoryStream();
writer = new BinaryWriter(memory);
writer.Write(Name);
writer.Write(Description);
SendData(memory.ToArray(), LobbyProtocol.SendLobbyName);
}