/// <summary> /// Validates that a given kick reason is acceptable for a remote kick. /// </summary> internal static NetCloseReason ValidateKickReason(NetCloseReason reason) { switch (reason) { case NetCloseReason.RejectNotHost: return(reason); case NetCloseReason.RejectFull: return(reason); case NetCloseReason.RejectVersion: return(reason); case NetCloseReason.KickTimeout: return(reason); case NetCloseReason.KickShutdown: return(reason); case NetCloseReason.KickError: return(reason); case NetCloseReason.KickUserReason: return(reason); } NetDebug.LogError("Bad kick reason: " + reason); return(NetCloseReason.INVALID); }
private void OnPeerClosed( NetPeer peer, NetCloseReason reason, byte userKickReason, SocketError error) { NetPeerWrapper wrapper = (NetPeerWrapper)peer.UserData; this.server.RemovePeer(wrapper); }
/// <summary> /// Closes a peer, sending out a best-effort notification and removing /// it from the dictionary of active peers. /// </summary> private void ClosePeer( NetPeer peer, NetCloseReason reason) { if (peer.IsOpen) { this.sender.SendKick(peer, reason); } this.ClosePeerSilent(peer); }
private NetEvent CreateClosedEvent( NetPeer target, NetCloseReason closeReason, byte userKickReason = 0, SocketError socketError = SocketError.SocketError) { NetEvent evnt = CreateEvent(NetEventType.PeerClosed, target); evnt.CloseReason = closeReason; evnt.UserKickReason = userKickReason; evnt.SocketError = socketError; return(evnt); }
/// <summary> /// Notifies a peer that we are disconnecting. May not arrive. /// </summary> internal SocketError SendKick(NetPeer peer, NetCloseReason reason, byte userReason = 0) { // Skip the packet if it's a bad reason (this will cause error output) if (NetUtil.ValidateKickReason(reason) == NetCloseReason.INVALID) { return(SocketError.Success); } lock (sendLock) { var length = NetEncoding.PackProtocol(sendBuffer, NetPacketType.Kick, (byte)reason, userReason); return(TrySend(peer.EndPoint, sendBuffer, length)); } }
private void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) { if (disconnectInfo.Reason == DisconnectReason.RemoteConnectionClose && disconnectInfo.AdditionalData.AvailableBytes > 0) { NetCloseReason reason = (NetCloseReason)disconnectInfo.AdditionalData.GetInt(); ExitMsg = reason.ToLocal("msg"); } else if (disconnectInfo.Reason == DisconnectReason.DisconnectPeerCalled) { //retain the existing exitmsg } else { ExitMsg = disconnectInfo.Reason.ToLocal("msg"); } client.Stop(); cleanup(); }
/// <summary> /// Sends a kick (reject) message to an unconnected peer. /// </summary> internal SocketError SendReject( IPEndPoint destination, NetCloseReason reason) { // Skip the packet if it's a bad reason (this will cause error output) if (NetUtil.ValidateKickReason(reason) == NetCloseReason.INVALID) { return(SocketError.Success); } lock (this.sendLock) { int length = NetEncoding.PackProtocol( this.sendBuffer, NetPacketType.Kick, (byte)reason, 0); return(this.TrySend(destination, this.sendBuffer, length)); } }
private void HandleKick( NetPeer peer, byte[] buffer, int length) { if (peer.IsClosed) { return; } byte rawReason; byte userReason; bool success = NetEncoding.ReadProtocol( buffer, length, out rawReason, out userReason); // Validate if (success == false) { NetDebug.LogError("Error reading kick"); return; } NetCloseReason closeReason = (NetCloseReason)rawReason; // Skip the packet if it's a bad reason (this will cause error output) if (NetUtil.ValidateKickReason(closeReason) == NetCloseReason.INVALID) { return; } peer.OnReceiveOther(this.Time); this.ClosePeerSilent(peer); this.eventOut.Enqueue( this.CreateClosedEvent(peer, closeReason, userReason)); }
/// <summary> /// Validates that a given kick reason is acceptable for a remote kick. /// </summary> internal static NetCloseReason ValidateKickReason(NetCloseReason reason) { switch (reason) { case NetCloseReason.RejectNotHost: return reason; case NetCloseReason.RejectFull: return reason; case NetCloseReason.RejectVersion: return reason; case NetCloseReason.KickTimeout: return reason; case NetCloseReason.KickShutdown: return reason; case NetCloseReason.KickError: return reason; case NetCloseReason.KickUserReason: return reason; } NetDebug.LogError("Bad kick reason: " + reason); return NetCloseReason.INVALID; }
internal void OnPeerClosed(NetCloseReason reason, byte userKickReason, SocketError error) { PeerClosed?.Invoke(this, reason, userKickReason, error); }
private void peerDisconnect(NetPeer peer, NetCloseReason reason) { ExitMsg = reason.ToLocal("msg"); peer.Disconnect(createDCMsg((int)reason)); }
private void Connection_PeerClosed(NetPeer peer, NetCloseReason reason, byte userKickReason, SocketError error) { Console.WriteLine("Peer closed due to reason: " + reason); }
/// <summary> /// Notifies a peer that we are disconnecting. May not arrive. /// </summary> internal SocketError SendKick( NetPeer peer, NetCloseReason reason, byte userReason = 0) { // Skip the packet if it's a bad reason (this will cause error output) if (NetUtil.ValidateKickReason(reason) == NetCloseReason.INVALID) return SocketError.Success; lock (this.sendLock) { int length = NetEncoding.PackProtocol( this.sendBuffer, NetPacketType.Kick, (byte)reason, userReason); return this.TrySend(peer.EndPoint, this.sendBuffer, length); } }
private void Network_PeerClosed(NetPeer peer, NetCloseReason reason, byte userKickReason, System.Net.Sockets.SocketError error) { Debug.Log("Disconnected: " + peer.EndPoint.ToString()); }
internal void OnPeerClosed(NetCloseReason reason, byte userKickReason, SocketError error) { this.PeerClosed?.Invoke(this, reason, userKickReason, error); }