示例#1
0
 public void Reconnect()
 {
     Console.WriteLine("Reconnecting...");
     new Thread(new ThreadStart(delegate
     {
         client.Close();
         Thread.Sleep(500);
         Connect();
     })).Start();
 }
示例#2
0
 public void Reconnect()
 {
     Log.Info("Reconnecting...");
     new Thread(new ThreadStart(delegate
     {
         client.Close();
         Thread.Sleep(500);
         Connect();
     })).Start();
 }
示例#3
0
 void ProcessMessage(ClientConnection client, Logout message)
 {
     if (client.Avatar != null)
     {
         // remove from world.
         _world.Remove(client.Avatar);
     }
     _log.Info("Logged out '" + client.AuthenticatedUsername + "'.");
     client.Close();
 }
示例#4
0
        private static async Task PipeAsync(ClientConnection client, IConnection conn)
        {
            var readBytes  = ConnectionExtensions.GetBytes(out var readDisposable);
            var writeBytes = ConnectionExtensions.GetBytes(out var writeDisposable);
            var readTask   = Task.Run(async() =>
            {
                try
                {
                    for (; ;)
                    {
                        var result = await client.ReceiveAsync(readBytes);
                        if (result == 0)
                        {
                            return;//FIN
                        }
                        await conn.SendAsync(readBytes.Slice(0, result));
                    }
                }
                finally
                {
                    conn.Close();
                }
            });
            var writeTask = Task.Run(async() =>
            {
                try
                {
                    for (; ;)
                    {
                        var result = await conn.ReceiveAsync(writeBytes);
                        if (result == 0)
                        {
                            return;//FIN
                        }
                        await client.SendAsync(writeBytes.Slice(0, result));
                    }
                }
                finally
                {
                    client.Close();
                }
            });

            try
            {
                await Task.WhenAll(readTask, writeTask);
            }
            finally
            {
                readDisposable.Dispose();
                writeDisposable.Dispose();
            }
        }
示例#5
0
        void ProcessMessage(ClientConnection client, Login loginMessage)
        {
            if (_world.UserLookup(loginMessage.Username, loginMessage.Password, ref client.PlayerId))
            {
                // login succeeded, check there is not an existing connection for this player
                foreach (ClientConnection c in _listener.Clients
                         .Where(c => c != client && c.AuthenticatedUsername == loginMessage.Username))
                {
                    c.Close();
                }

                _log.Info("User " + loginMessage.Username + " logged in");
                client.AuthenticatedUsername = loginMessage.Username;
            }
            else
            {
                _log.Info("Login failed for username '" + loginMessage.Username + "'");
                client.Close();
            }
        }
        void IConnectionsService.Remove(ClientConnection connection)
        {
            connections.Remove(connection);
            connection.UserObject.Status = Status.Offline;
            try
            {
                using (var context = new DataBaseContext())
                {
                    var user = context.Users.FirstOrDefault(u => u.AccessToken == connection.UserObject.AccessToken);
                    user.Status = Status.Offline;
                    context.SaveChanges();
                }
            }
            catch (Exception exception)
            {
                logger.Write(exception);
            }

            connection.Close();
        }
示例#7
0
        public void DisconnectFromServer()
        {
            if (!Connection.Connected)
            {
                return;
            }

            _updateTimer.Stop();
            SoundEngine.StopAllChannels();
            Connection.Close();

            Interface       = null;
            SoundEngine     = null;
            ResourceManager = null;
            StateManager    = null;

            Map             = null;
            ATOMs           = null;
            ScreenObjects   = null;
            IconAppearances = null;

            MainWindow.Show();
        }
示例#8
0
 public void Close()
 {
     // Something called close twice, so let's just wait for the other thread to finish.
     if (exited)
     {
         exitEvent.WaitOne();
     }
     // Initialize close sequence
     else
     {
         exited = true;
         //if (ReadThread != null && WriteThread != null)
         //{
         //    if (ReadThread.IsAlive || WriteThread.IsAlive)
         //    {
         //        ReadThread.Join();
         //        WriteThread.Join();
         //    }
         //}
         // Kill the socket.
         if (ClientConnection != null)
         {
             try
             {
                 ClientConnection.Close();
             }
             catch (Exception ex)
             {
                 //DebugWriteLine($"Error closing socket to {IPAddress}: {ex.Message}");
             }
         }
         // Remove everything.
         OnDisconnect(this.ServerID);
         // Notify other callers you can terminate.
         exitEvent.Set();
     }
 }
示例#9
0
 public void WhenICloseTheClientConnection()
 {
     ClientConnection.Close();
 }
 public void CloseTCPConnection()
 {
     clientConnection.Close();
 }
 private void Close()
 {
     ConnectionStream.Dispose();
     ClientConnection.Close();
     Server.Stop();
 }
示例#12
0
 public void Close()
 {
     ClientConnection.Close();
     ConnectionStream.Dispose();
 }