/// <summary> /// Called when a a peer gets disconnected from us. /// </summary> private void OnPeerDisconnected(LiteNetLib.NetPeer peer, LiteNetLib.DisconnectInfo info) { if (peer == ArbiterPeer) { Console.Error.WriteLine(">>> Lost connection to arbiter! <<<"); } }
private void CloseConnection(bool force, DisconnectReason reason, int socketErrorCode) { lock (_connectionCloseLock) { //Nothing to do if (!IsRunning) return; //Send goodbye if (_peer != null && !force && _connected) { //Send disconnect data var disconnectPacket = NetPacket.CreateRawPacket(PacketProperty.Disconnect, 8); FastBitConverter.GetBytes(disconnectPacket, 1, _connectId); SendRaw(disconnectPacket, _peer.EndPoint); } //Clear data _peer = null; _connected = false; _connectTimer = 0; _connectAttempts = 0; SocketClearPeers(); //Send event to Listener var netEvent = CreateEvent(NetEventType.Disconnect); netEvent.DisconnectReason = reason; netEvent.AdditionalData = socketErrorCode; EnqueueEvent(netEvent); } }
public ReliableChannel(NetPeer peer, bool ordered, int windowSize) { _resendDelay = peer.Handler.ReliableResendTime; _windowSize = windowSize; _peer = peer; _ordered = ordered; _outgoingPackets = new Queue<NetPacket>(_windowSize); _outgoingAcks = new bool[_windowSize]; _pendingPackets = new PendingPacket[_windowSize]; for (int i = 0; i < _pendingPackets.Length; i++) { _pendingPackets[i] = new PendingPacket(); } if (_ordered) _receivedPackets = new NetPacket[_windowSize]; else _earlyReceived = new bool[_windowSize]; _localWindowStart = 0; _localSeqence = 0; _remoteSequence = 0; _remoteWindowStart = 0; }
private void RemovePeer(NetPeer peer) { lock (_peersToRemove) { _peersToRemove.Enqueue(peer.EndPoint); } }
public void OnPeerConnected(NetPeer peer) { Console.WriteLine("[Client] connected to: {0}:{1}", peer.EndPoint.Host, peer.EndPoint.Port); NetDataWriter dataWriter = new NetDataWriter(); for (int i = 0; i < 5; i++) { dataWriter.Reset(); dataWriter.Put(0); dataWriter.Put(i); peer.Send(dataWriter, SendOptions.ReliableUnordered); dataWriter.Reset(); dataWriter.Put(1); dataWriter.Put(i); peer.Send(dataWriter, SendOptions.ReliableOrdered); dataWriter.Reset(); dataWriter.Put(2); dataWriter.Put(i); peer.Send(dataWriter, SendOptions.Sequenced); dataWriter.Reset(); dataWriter.Put(3); dataWriter.Put(i); peer.Send(dataWriter, SendOptions.Unreliable); } //And test fragment byte[] testData = new byte[13218]; testData[0] = 192; testData[13217] = 31; peer.Send(testData, SendOptions.ReliableOrdered); }
public void CreatePlayer(LiteNetLib.NetPeer peer, string name, bool self) { LobbyPlayer p = Instantiate(playerPrefab, playersList, false); p.Init(); p.SetPlayer(peer, name, self, Players.Count); Players.Add(p); }
public void OnPeerConnected(NetPeer peer) { Console.WriteLine("[Server] Peer connected: " + peer.EndPoint); var peers = Server.GetPeers(); foreach (var netPeer in peers) { Console.WriteLine("ConnectedPeersList: id={0}, ep={1}", netPeer.Id, netPeer.EndPoint); } }
public void SetPlayer(LiteNetLib.NetPeer p, string name, bool b, int id) { peer = p; playerName = name; playerNameTxt.text = name; this.id = id; kickBtn.gameObject.SetActive(!b); }
/// <summary> /// Disconnect peer from server /// </summary> /// <param name="peer">peer to disconnect</param> public void DisconnectPeer(NetPeer peer) { if (peer != null && _peers.ContainsKey(peer.EndPoint)) { peer.CreateAndSend(PacketProperty.Disconnect); var netEvent = CreateEvent(NetEventType.Disconnect); netEvent.Peer = peer; netEvent.DisconnectReason = DisconnectReason.DisconnectPeerCalled; EnqueueEvent(netEvent); RemovePeer(peer); } }
public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { _newBallPosX = reader.GetFloat(); var pos = _clientBall.transform.position; _oldBallPosX = pos.x; pos.x = _newBallPosX; _clientBall.transform.position = pos; _lerpTime = 0f; }
public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { if (reader.AvailableBytes == 13218) { Console.WriteLine("[{0}] TestFrag: {1}, {2}", peer.Handler.LocalEndPoint.Port, reader.Data[0], reader.Data[13217]); } else { int type = reader.GetInt(); int num = reader.GetInt(); _messagesReceivedCount++; Console.WriteLine("[{0}] CNT: {1}, TYPE: {2}, NUM: {3}", peer.Handler.LocalEndPoint.Port, _messagesReceivedCount, type, num); } }
public LobbyPlayer GetPeer(LiteNetLib.NetPeer peer) { LobbyPlayer player = null; for (int i = 0; i < Players.Count; i++) { LobbyPlayer lp = Players[i]; if (lp.peer == peer) { player = lp; } } return(player); }
/// <summary> /// Get copy of current connected peers /// </summary> /// <returns>Array with connected peers</returns> public NetPeer[] GetPeers() { NetPeer[] peers; int num = 0; lock (_peers) { peers = new NetPeer[_peers.Count]; foreach (NetPeer netPeer in _peers.Values) { peers[num++] = netPeer; } } return peers; }
private void Listener_NetworkReceiveEvent(LiteNetLib.NetPeer peer, NetDataReader reader, DeliveryMethod deliveryMethod) { _packetProcessor.ReadAllPackets(reader, peer); // check if we even know this peer var key = peer.EndPoint.ToString(); if (_knownPlayers.ContainsKey(key)) { } else { Debug.Assert(false, "The Connected Peer was Unknown to us! (Did not exist in KnownPlayer list)"); // TODO: should assert or at least log this properly for future debugging Console.WriteLine($"Unknown Client connected as:{key}!"); } }
/// <summary> /// Called when a a peer connects to us; sends a `NodeOnline` message, but only to the arbiter. /// </summary> private void OnPeerConnected(LiteNetLib.NetPeer peer) { if (peer == ArbiterPeer) { // TODO: Connect to http://icanhazip.org or similar to get the external IP instead? var apiUri = new Uri(this.ApiUrl); var externalAddress = IPAddress.Parse(apiUri.Host); // WARNING: Ensure that ApiUrl is visible from outside - otherwise, all requests will fail to be forwarded to this node! var currentConfig = new SShared.Messages.NodeConfig() { BusAddress = externalAddress, BusPort = this.LocalBusPort, ApiUrl = this.ApiUrl, Path = QuadTreeNode.Path(), Bounds = QuadTreeNode.Bounds, }; this.Bus.SendMessage(currentConfig, peer); } }
public void OnPeerDisconnected(NetPeer peer, DisconnectReason reason, int socketErrorCode) { Debug.Log("[CLIENT] We disconnected because " + reason); }
void INetEventListener.OnNetworkReceive(NetPeer peer, NetDataReader reader) { if (NetworkReceiveEvent != null) NetworkReceiveEvent(peer, reader); }
/// <summary> /// Disconnect peer from server and send additional data (Size must be less or equal MTU - 8) /// </summary> /// <param name="peer">peer to disconnect</param> /// <param name="data">additional data</param> public void DisconnectPeer(NetPeer peer, byte[] data) { DisconnectPeer(peer, data, 0, data.Length); }
public void SendToClients(byte[] data, int start, int length, SendOptions options, NetPeer excludePeer) { lock (_peers) foreach (NetPeer netPeer in _peers.Values) { if (netPeer != excludePeer) { netPeer.Send(data, start, length, options); } } }
private void SendConnectAccept(NetPeer peer, ulong id) { //Reset connection timer peer.StartConnectionTimer(); //Make initial packet var connectPacket = NetPacket.CreateRawPacket(PacketProperty.ConnectAccept, 8); //Add data FastBitConverter.GetBytes(connectPacket, 1, id); //Send raw SendRaw(connectPacket, peer.EndPoint); }
/// <summary> /// Disconnect peer from server and send additional data (Size must be less or equal MTU - 8) /// </summary> /// <param name="peer">peer to disconnect</param> /// <param name="writer">additional data</param> public void DisconnectPeer(NetPeer peer, NetDataWriter writer) { DisconnectPeer(peer, writer.Data, 0, writer.Length); }
public void OnPeerDisconnected(NetPeer peer, DisconnectReason disconnectReason, int socketErrorCode) { Console.WriteLine("[Client] disconnected: " + disconnectReason); }
internal void ConnectionLatencyUpdated(NetPeer fromPeer, int latency) { var evt = CreateEvent(NetEventType.ConnectionLatencyUpdated); evt.Peer = fromPeer; evt.AdditionalData = latency; EnqueueEvent(evt); }
protected NetPeer CreatePeer(NetEndPoint remoteEndPoint) { var peer = new NetPeer(this, remoteEndPoint); peer.PingInterval = PingInterval; return peer; }
/// <summary> /// Send data to all connected peers /// </summary> /// <param name="data">Data</param> /// <param name="options">Send options (reliable, unreliable, etc.)</param> /// <param name="excludePeer">Excluded peer</param> public void SendToAll(byte[] data, DeliveryMethod options, NetPeer excludePeer) { SendToAll(data, 0, data.Length, options, excludePeer); }
void INetEventListener.OnNetworkLatencyUpdate(NetPeer peer, int latency) { if (NetworkLatencyUpdateEvent != null) NetworkLatencyUpdateEvent(peer, latency); }
/// <summary> /// Send data to all connected peers /// </summary> /// <param name="writer">DataWriter with data</param> /// <param name="options">Send options (reliable, unreliable, etc.)</param> /// <param name="excludePeer">Excluded peer</param> public void SendToAll(NetDataWriter writer, DeliveryMethod options, NetPeer excludePeer) { SendToAll(writer.Data, 0, writer.Length, options, excludePeer); }
public void Connect(NetEndPoint target) { if (!IsRunning) { throw new Exception("Client is not running"); } if (_peer != null) { //Already connected return; } //Create connect id for proper connection _connectId = (ulong)DateTime.UtcNow.Ticks; NetUtils.DebugWrite(ConsoleColor.Cyan, "[CC] ConnectId: {0}", _connectId); //Create reliable connection _peer = CreatePeer(target); _peer.DebugTextColor = ConsoleColor.Yellow; //Create connection packet and send SendConnectRequest(); _connectAttempts = 0; }
public void OnNetworkLatencyUpdate(NetPeer peer, int latency) { }
public SequencedChannel(NetPeer peer) { _outgoingPackets = new Queue<NetPacket>(); _peer = peer; }
public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { //echo peer.Send(reader.Data, SendOptions.ReliableUnordered); //fragment log if (reader.AvailableBytes == 13218) { Console.WriteLine("[Server] TestFrag: {0}, {1}", reader.Data[0], reader.Data[13217]); } }
public void SendToClients(NetDataWriter writer, SendOptions options, NetPeer excludePeer) { lock (_peers) foreach (NetPeer netPeer in _peers.Values) { if (netPeer != excludePeer) { netPeer.Send(writer, options); } } }
public void OnPeerConnected(NetPeer peer) { Debug.Log("[CLIENT] We connected to " + peer.EndPoint); }
void INetEventListener.OnPeerConnected(NetPeer peer) { if (PeerConnectedEvent != null) PeerConnectedEvent(peer); }
public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { }
/// <summary> /// Disconnect peer from server /// </summary> /// <param name="peer">peer to disconnect</param> public void DisconnectPeer(NetPeer peer) { DisconnectPeer(peer, null, 0, 0); }
void INetEventListener.OnPeerDisconnected(NetPeer peer, DisconnectReason disconnectReason, int socketErrorCode) { if (PeerDisconnectedEvent != null) PeerDisconnectedEvent(peer, disconnectReason, socketErrorCode); }
public void OnPeerConnected(NetPeer peer) { Console.WriteLine("[Client {0}] connected to: {1}:{2}", Client.LocalEndPoint.Port, peer.EndPoint.Host, peer.EndPoint.Port); }
/// <summary> /// Send data to all connected peers /// </summary> /// <param name="data">Data</param> /// <param name="start">Start of data</param> /// <param name="length">Length of data</param> /// <param name="options">Send options (reliable, unreliable, etc.)</param> /// <param name="excludePeer">Excluded peer</param> public void SendToAll(byte[] data, int start, int length, DeliveryMethod options, NetPeer excludePeer) { lock (_peers) { for (int i = 0; i < _peers.Count; i++) { var netPeer = _peers[i]; if (netPeer != excludePeer) { netPeer.Send(data, start, length, options); } } } }
public void OnPeerConnected(NetPeer peer) { Debug.Log("[SERVER] We have new peer " + peer.EndPoint); _ourPeer = peer; }
public void OnPeerDisconnected(NetPeer peer, DisconnectReason reason, int socketErrorCode) { Debug.Log("[SERVER] peer disconnected " + peer.EndPoint + ", info: " + reason); if (peer == _ourPeer) _ourPeer = null; }
public void OnPeerDisconnected(NetPeer peer, DisconnectReason disconnectReason, int socketErrorCode) { Console.WriteLine("[Server] Peer disconnected: " + peer.EndPoint + ", reason: " + disconnectReason); }
/// <summary> /// Immediately disconnect peer from server without additional data /// </summary> /// <param name="peer">peer to disconnect</param> public void DisconnectPeerForce(NetPeer peer) { DisconnectPeer(peer, DisconnectReason.DisconnectPeerCalled, 0, true, null, 0, 0); }