本文整理汇总了C#中Lidgren.Network.NetConnection.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# NetConnection.SendMessage方法的具体用法?C# NetConnection.SendMessage怎么用?C# NetConnection.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetConnection
的用法示例。
在下文中一共展示了NetConnection.SendMessage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WorldDataSync
public WorldDataSync(NetConnection Connection)
{
Connect = Connection;
NetOutgoingMessage Message = NetworkManager.Server.CreateMessage();
Message.Write((byte)MessageTypes.ConnectionOkay);
Connection.SendMessage(Message, NetDeliveryMethod.ReliableUnordered, 0);
NetOutgoingMessage NameRequest = NetworkManager.Server.CreateMessage();
NameRequest.Write((byte)MessageTypes.RequestPlayerName);
Connection.SendMessage(NameRequest, NetDeliveryMethod.ReliableUnordered, 0);
}
示例2: Authenticate
/// <summary>
/// Authenticates the connection
/// </summary>
/// <param name="connection">Connection to authenticate</param>
/// <param name="username">Username</param>
/// <param name="password">Password</param>
/// <param name="data">Additional data to send</param>
public static void Authenticate(NetConnection connection, String username, String password, Byte[] data = null)
{
var handshake = new Handshake(true, KeySize);
var request = handshake.GenerateSRPRequest(username, password, data ?? new Byte[0]);
var result = Create(connection, Handshake.Contents.Username, request.ByteSize);
handshake.WriteSRPRequest(result);
connection.SendMessage(result, NetDeliveryMethod.ReliableUnordered, 0);
connection.Tag = handshake;
#if DEBUG
Console.WriteLine(">> Autenticating with user:{0} and pass:{1} <<", username, password);
#endif
}
示例3: SendMessage
/// <summary>
/// Sends a message to a specific connection
/// </summary>
public void SendMessage(NetBuffer data, NetConnection recipient, NetChannel channel)
{
if (recipient == null)
throw new ArgumentNullException("recipient");
recipient.SendMessage(data, channel);
}
示例4: SendPacket
public void SendPacket(Packet P, NetConnection Connection)
{
Connection.SendMessage(P.ToOutgoing(_client), NetDeliveryMethod.ReliableOrdered, 0);
}
示例5: AddPlayer
static void AddPlayer(NetConnection connection)
{
var playerId = connections.Add(connection);
var tag = connection.Tag as Player;
tag.Id = (ushort)playerId;
var idMessage = peer.CreateMessage(3);
idMessage.Write(RPCUtils.SetPlayerId);
idMessage.Write(tag.Id);
connection.SendMessage(idMessage, NetDeliveryMethod.ReliableOrdered, Channels.STATIC_UTILS);
Debug.Log("sent id to player {0}", tag.Id);
OnPlayerConnected(tag);
}
示例6: HostSendMessage
public static void HostSendMessage(NetConnection client,KSPPacket packet)
{
NetOutgoingMessage om = netServer.CreateMessage();
om.Write((byte)packet.MessageType);
packet.Encode(om);
client.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 0);
}
示例7: SendFile
private static void SendFile(string FileName, NetConnection sendto)
{
byte[] item = System.IO.File.ReadAllBytes(FileName);
NetOutgoingMessage msg = server.CreateMessage();
msg.Write("###FILE###");
msg.Write("");
msg.Write(item.Length + 2);
msg.Write(item);
sendto.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
}
示例8: onClientFullyConnected
private void onClientFullyConnected(NetConnection connection)
{
var newPlayerId = this.connections[connection];
var newPlayer = this.players.First(p => p.ID == newPlayerId);
var otherClientConnections = this.connections
.Where(c => c != connection)
.Where(c => c.Status == NetConnectionStatus.Connected)
.ToList();
// tell other clients about this player
if (otherClientConnections.Count > 0)
{
var newPlayerMessage = this.server.CreateMessage();
newPlayerMessage.Write((byte)LobbyMessageType.NewPlayer);
newPlayerMessage.Write(newPlayer.ID.Simple);
newPlayerMessage.Write(newPlayer.Name);
this.server.SendMessage(newPlayerMessage, otherClientConnections, NetDeliveryMethod.ReliableOrdered, 0);
}
var allOthersMessage = this.server.CreateMessage();
allOthersMessage.Write((byte)LobbyMessageType.NewPlayers);
allOthersMessage.Write((byte)(otherClientConnections.Count + 1));
foreach (var p in this.players.Where(p => p.ID != newPlayerId)
.Where(p =>
{
var c = this.connections[p.ID];
return c == null || c.Status == NetConnectionStatus.Connected;
}))
{
// collect all players
allOthersMessage.Write(p.ID.Simple);
allOthersMessage.Write(p.Name);
}
// tell this client about other players
connection.SendMessage(allOthersMessage, NetDeliveryMethod.ReliableOrdered, 0);
// add client to visible player list
this.form.Invoke(new Action(() =>
this.form.AddPlayer(newPlayer.ID, newPlayer.Name)
));
}