SendMessage() public method

Send a message to this remote connection
public SendMessage ( NetOutgoingMessage msg, NetDeliveryMethod method, int sequenceChannel ) : NetSendResult
msg NetOutgoingMessage The message to send
method NetDeliveryMethod How to deliver the message
sequenceChannel int Sequence channel within the delivery method
return NetSendResult
 /// <summary>
 /// Sends a message using the specified channel; takes ownership of the NetBuffer, don't reuse it after this call
 /// </summary>
 public void SendMessage(NetBuffer data, NetChannel channel)
 {
     if (m_serverConnection == null || m_serverConnection.Status != NetConnectionStatus.Connected)
     {
         throw new NetException("You must be connected first!");
     }
     m_serverConnection.SendMessage(data, channel);
 }
Example #2
0
        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);
        }
 /// <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);
 }
Example #4
0
		/// <summary>
		/// Sends message to server
		/// </summary>
		public NetSendResult SendMessage(NetOutgoingMessage msg, NetDeliveryMethod method)
		{
			NetConnection serverConnection = ServerConnection;
			if (serverConnection == null)
			{
				LogWarning("Cannot send message, no server connection!");
				return NetSendResult.FailedNotConnected;
			}

			return serverConnection.SendMessage(msg, method, 0);
		}
Example #5
0
        /// <summary>
        /// Sends message to server
        /// </summary>
        public NetSendResult SendMessage(NetOutgoingMessage msg, NetDeliveryMethod method, int sequenceChannel)
        {
            NetConnection serverConnection = ServerConnection;

            if (serverConnection == null)
            {
                LogWarning("Cannot send message, no server connection!");
                return(NetSendResult.Failed);
            }

            return(serverConnection.SendMessage(msg, method, sequenceChannel));
        }
Example #6
0
        /// <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
        }
Example #7
0
 /// <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);
 }
 public void SendPacket(Packet P, NetConnection Connection)
 {
     Connection.SendMessage(P.ToOutgoing(_client), NetDeliveryMethod.ReliableOrdered, 0);
 }
Example #9
0
        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);
        }
Example #10
0
 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);
 }
Example #11
0
 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);
 }
        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)
                ));
        }