Ejemplo n.º 1
0
        public static void DisconnectClient(ClientStructure client, string reason = "")
        {
            if (!string.IsNullOrEmpty(reason))
            {
                LunaLog.Debug($"{client.PlayerName} sent Connection end message, reason: {reason}");
            }

            VesselUpdateRelaySystem.RemovePlayer(client);

            //Remove Clients from list
            if (ServerContext.Clients.ContainsKey(client.Endpoint))
            {
                ServerContext.Clients.TryRemove(client.Endpoint, out client);
                LunaLog.Debug($"Online Players: {ServerContext.PlayerCount}, connected: {ServerContext.Clients.Count}");
            }

            if (client.ConnectionStatus != ConnectionStatus.Disconnected)
            {
                client.ConnectionStatus = ConnectionStatus.Disconnected;
                LmpPluginHandler.FireOnClientDisconnect(client);
                if (client.Authenticated)
                {
                    ChatSystem.RemovePlayer(client.PlayerName);
                    MessageQueuer.RelayMessage <PlayerConnectionSrvMsg>(client, new PlayerConnectionLeaveMsgData {
                        PlayerName = client.PlayerName
                    });
                    LockSystem.ReleasePlayerLocks(client.PlayerName);

                    if (!ServerContext.Clients.Any(c => c.Value.Subspace == client.Subspace))
                    {
                        WarpSystem.RemoveSubspace(client.Subspace);
                        VesselRelaySystem.RemoveSubspace(client.Subspace);
                    }
                }

                try
                {
                    client.Connection?.Disconnect(reason);
                }
                catch (Exception e)
                {
                    LunaLog.Debug($"Error closing client Connection: {e.Message}");
                }
                ServerContext.LastPlayerActivity = ServerContext.ServerClock.ElapsedMilliseconds;
            }
        }
Ejemplo n.º 2
0
 public static void HandleDisconnectException(string location, ClientStructure client, Exception e)
 {
     if (!client.DisconnectClient && (client.ConnectionStatus != ConnectionStatus.DISCONNECTED))
     {
         if (e.InnerException != null)
         {
             LunaLog.Normal(
                 $"Client {client.PlayerName} disconnected in {location}, Endpoint {client.Endpoint}, " +
                 $"error: {e.Message} ({e.InnerException.Message})");
         }
         else
         {
             LunaLog.Normal(
                 $"Client {client.PlayerName} disconnected in {location}, Endpoint {client.Endpoint}, " +
                 $"error: {e.Message}");
         }
     }
     ClientConnectionHandler.DisconnectClient(client);
 }
Ejemplo n.º 3
0
        public static void ConnectClient(NetConnection newClientConnection)
        {
            var newClientObject = new ClientStructure(newClientConnection.RemoteEndPoint)
            {
                Subspace         = int.MinValue,
                PlayerStatus     = new PlayerStatus(),
                ConnectionStatus = ConnectionStatus.Connected,
                Connection       = newClientConnection,
                LastSendTime     = 0,
                LastReceiveTime  = ServerContext.ServerClock.ElapsedMilliseconds
            };

            Task.Run(() => MessageSender.StartSendingOutgoingMessages(newClientObject));

            LmpPluginHandler.FireOnClientConnect(newClientObject);

            ServerContext.Clients.TryAdd(newClientObject.Endpoint, newClientObject);
            VesselUpdateRelaySystem.AddPlayer(newClientObject);
            LunaLog.Debug($"Online Players: {ServerContext.PlayerCount}, connected: {ServerContext.Clients.Count}");
        }
Ejemplo n.º 4
0
 public static bool ClientConnected(ClientStructure client)
 {
     return(ServerContext.Clients.ContainsKey(client.Endpoint));
 }