public async Task DisconnectAsync(IUserInfo user, DisconnectionReason reason) { if (user == null) { throw new ArgumentNullException("user"); } IConnection c = Manager.GetConnection(user); if (c == null) { return; } Manager.Disconnect(c); if (c.IsConnected) { await c.SendAsync(new DisconnectMessage (reason)).ConfigureAwait(false); await c.DisconnectAsync().ConfigureAwait(false); } List <Task> tasks = new List <Task>(); foreach (IConnection connection in Manager.GetConnections()) { tasks.Add(connection.SendAsync(new UserDisconnectedMessage(user.UserId))); } await Task.WhenAll(tasks).ConfigureAwait(false); }
private void DisconnectCore(DisconnectionReason reason, IClientConnection connection, bool reconnect, bool fireEvent) { lock (StateSync) { disconnectedInChannelId = CurrentUser.CurrentChannelId; this.connecting = false; this.running = false; this.formallyConnected = false; CurrentUser = new CurrentUser(this); this.Users.Reset(); this.Channels.Clear(); this.Sources.Reset(); this.Audio.Stop(); connection.DisconnectAsync(); if (fireEvent) { OnDisconnected(this, new DisconnectedEventArgs(reason)); } if (reconnect) { this.connecting = true; ThreadPool.QueueUserWorkItem(Reconnect); } } }
/// <summary> /// Disconnect the SSH transport protocol. /// </summary> /// <param name="disconnectReason">A descriptive reason for the disconnection.</param> /// <param name="reason">The SSH reason code.</param> public void Disconnect(String disconnectReason, DisconnectionReason reason) { try { this.disconnectReason = disconnectReason; SSHPacket packet = GetSSHPacket(true); packet.WriteByte(SSH_MSG_DISCONNECT); packet.WriteUINT32((int)reason); packet.WriteString(disconnectReason); packet.WriteString(""); #if DEBUG System.Diagnostics.Trace.WriteLine("Sending SSH_MSG_DISCONNECT"); System.Diagnostics.Trace.WriteLine(disconnectReason); #endif SendMessage(packet); } catch { } finally { InternalDisconnect(); } }
public void RemoveClient(UInt32 connectionID, DisconnectionReason reason, string debug) { if (connectedClients.Contains(connectionID)) { connectedClients.Remove(connectionID); server.CloseConnection(connectionID, (int)reason, debug, false); } }
/// <summary> /// Parsuje wiadomość. /// </summary> /// <param name="msg">Wiadomość.</param> public PlayerDisconnected(Message msg) { if (msg.Type != (MessageType)GameMessageType.PlayerDisconnected) { throw new InvalidCastException("Cannot convert this message to PlayerDisconnected"); } BinarySerializer s = new BinarySerializer(msg.Data); this.UserId = s.GetUInt32(); this.Reason = (DisconnectionReason)s.GetByte(); }
private void OnClientDisconnected(object sender, ClientDisconnectedEventArgs e) { DisconnectionReason reason = DisconnectionReason.Unknown; if (e.Reason == ConnectionResult.Custom) { switch (e.CustomReason) { case DisconnectReasonRequested: reason = DisconnectionReason.Requested; break; } } DisconnectCore(reason, this.client.Connection); }
internal void HandleDisconnection(DisconnectionReason reason) { if (isConnected) { var args = new DisconnectionEventArgs(reason); if (DisconnectionReason.DeviceRemoved != reason && OnDisconnecting != null) { OnDisconnecting(this, args); } if (OnDisconnected != null) { OnDisconnected(this, args); } isConnected = false; } }
private DisconnectHandling GetHandlingForReason(DisconnectionReason reason) { if (!ReconnectAutomatically) { return(DisconnectHandling.None); } switch (reason) { case DisconnectionReason.Unknown: return(DisconnectHandling.Reconnect); default: return(DisconnectHandling.None); } }
public void Disconnect(DisconnectionReason reason = DisconnectionReason.Normal, string reasonString = null) { if (string.IsNullOrEmpty(reasonString)) { peerSocket.Close((ushort)reason); } else { if (System.Text.Encoding.UTF8.GetBytes(reasonString).Length <= 123) { peerSocket.Close((ushort)reason, reasonString); } else { throw new ArgumentException("Reason string cannot take up more than 123 bytes"); } } }
public DisconnectionEventArgs(DisconnectionReason reason) { Reason = reason; }
public async Task DisconnectAsync (IUserInfo user, DisconnectionReason reason) { if (user == null) throw new ArgumentNullException ("user"); IConnection c = Manager.GetConnection (user); if (c == null) return; Manager.Disconnect (c); if (c.IsConnected) { await c.SendAsync (new DisconnectMessage (reason)).ConfigureAwait (false); await c.DisconnectAsync().ConfigureAwait (false); } List<Task> tasks = new List<Task>(); foreach (IConnection connection in Manager.GetConnections()) tasks.Add (connection.SendAsync (new UserDisconnectedMessage (user.UserId))); await Task.WhenAll (tasks).ConfigureAwait (false); }
/// <summary> /// Tworzy nową wiadomość. /// </summary> /// <param name="uid">Identyfikator gracza.</param> public PlayerDisconnected(uint uid, DisconnectionReason reason) { this.UserId = uid; this.Reason = reason; }
public DisconnectedFromServerEventArgs(DisconnectionReason reason, IServerData serverInfo) { Reason = reason; ServerInfo = serverInfo; }
public void Disconnect(DisconnectionReason reason = DisconnectionReason.Normal) { peerSocket.Close((ushort)reason); }
internal void HandleDisconnection(DisconnectionReason reason) { if (isConnected) { var args = new DisconnectionEventArgs(reason); if (DisconnectionReason.DeviceRemoved != reason && OnDisconnecting != null) OnDisconnecting(this, args); if (OnDisconnected != null) OnDisconnected(this, args); isConnected = false; } }
static void OnServerStatusUpdate(ref StatusInfo info) { // Debug.Log("Server Status: " + info.ToString()); switch (info.connectionInfo.state) { case Valve.Sockets.ConnectionState.None: break; case Valve.Sockets.ConnectionState.Connecting: if (Instance.acceptingClients && Instance.connectedClients.Count < Instance.maxConnections) { Result r = Instance.server.AcceptConnection(info.connection); Debug.Log("Server Accept connection result " + r.ToString()); //server.SetConnectionPollGroup(connectedPollGroup, info.connection); Instance.connectedClients.Add(info.connection); // Add to player manager Instance.sgr.pm.AddPlayer(info.connection); // TODO // Refactor all of these... // Send playerID to client { byte[] data; data = NetworkingMessageTranslator.GenerateClientIDNetworkingMessage(info.connection); // Reliable because we only send once. Instance.SendTo(info.connection, data, Valve.Sockets.SendFlags.Reliable); } // Send entity data { byte[] data; data = NetworkingMessageTranslator.GenerateEntityDataNetworkingMessage(Instance.sgr.em.GetData(), Instance.sgr.frame); // Reliable because we only send once. Instance.SendTo(info.connection, data, Valve.Sockets.SendFlags.Reliable); } // Send player data { byte[] data; data = NetworkingMessageTranslator.GeneratePlayerDataNetworkingMessage(Instance.sgr.pm.GetData(), Instance.sgr.frame); // Reliable because we only send once. Instance.SendTo(info.connection, data, Valve.Sockets.SendFlags.Reliable); } // End Refactor // Don't need to send gamestate since it will be updated in a second anyways... } else { Instance.server.CloseConnection(info.connection, (int)DisconnectionReason.SERVER_FULL, "Server full.", false); } break; case Valve.Sockets.ConnectionState.Connected: Debug.Log(String.Format("Client connected - ID: {0}, IP: {1}", info.connection, info.connectionInfo.address.GetIP())); break; case Valve.Sockets.ConnectionState.ClosedByPeer: case Valve.Sockets.ConnectionState.ProblemDetectedLocally: string closeDebug = ""; DisconnectionReason reason = 0; if (info.connectionInfo.state == Valve.Sockets.ConnectionState.ProblemDetectedLocally) { closeDebug = "Problem detected locally."; reason = DisconnectionReason.ERROR; } else { closeDebug = "Closed by peer."; reason = DisconnectionReason.NONE; } Instance.RemoveClient(info.connection, reason, closeDebug); Debug.Log(String.Format("Client disconnected from server - ID: {0}, IP: {1}", info.connection, info.connectionInfo.address.GetIP())); // Set active to false in player manager Instance.sgr.pm.GetPlayer(info.connection).active = false; break; } }
public DisconnectMessage(DisconnectionReason reason) : this() { Reason = reason; }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { Reason = (DisconnectionReason)reader.ReadByte (); }
private void DisconnectCore(DisconnectionReason reason, IClientConnection connection) { DisconnectCore(reason, connection, GetHandlingForReason(reason) == DisconnectHandling.Reconnect, true); }
public ClientDisconnectedEventArgs(IClientData client, DisconnectionReason reason) { Client = client; Reason = reason; }
public void InvokeDisconnectedEvent(IClientData client, DisconnectionReason reason) { ClientDisconnected?.Invoke(this, new ClientDisconnectedEventArgs(client, reason)); }
/// <summary> /// Initializes a new instance of the /// <see cref="Skahal.Infrastructure.Framework.Net.Messaging.DisconnectedEventArgs"/> class. /// </summary> /// <param name="reason">Reason.</param> public DisconnectedEventArgs (DisconnectionReason reason) { Reason = reason; }
internal static void OnDisconnected(RUDPSocket rudp, DisconnectionReason reason) { if (rudp._status == RUDPSocketStatus.Closed) return; //---- Reset rudp._outgoingPacketsLock.EnterWriteLock(); rudp._outgoingPackets.Clear(); rudp._outgoingPacketsLock.ExitWriteLock(); rudp.Reset(RUDPSocketStatus.Closed); //---- Notify if (reason != DisconnectionReason.ConnectionClosed) { RUDPSocketError error = RUDPSocketError.ConnectionReset; if (reason == DisconnectionReason.SocketError) error = RUDPSocketError.SocketError; if (reason == DisconnectionReason.TimeOut) error = RUDPSocketError.ConnectionReset; rudp._physical.OnDisconnected(rudp, error); } }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { Reason = (DisconnectionReason)reader.ReadByte(); }