OpenNos.GameObject.ClientSession.Destroy C# (CSharp) Method

Destroy() public method

public Destroy ( ) : void
return void
        public void Destroy()
        {
            // unregister from WCF events
            ServiceFactory.Instance.CommunicationCallback.CharacterConnectedEvent -= CommunicationCallback_CharacterConnectedEvent;
            ServiceFactory.Instance.CommunicationCallback.CharacterDisconnectedEvent -= CommunicationCallback_CharacterDisconnectedEvent;

            // do everything necessary before removing client, DB save, Whatever
            if (HasSelectedCharacter)
            {
                Character.Dispose();

                // TODO Check why ExchangeInfo.TargetCharacterId is null Character.CloseTrade();
                // disconnect client
                ServiceFactory.Instance.CommunicationService.DisconnectCharacter(Character.Name, Character.CharacterId);

                // unregister from map if registered
                if (CurrentMap != null)
                {
                    CurrentMap.UnregisterSession(this.Character.CharacterId);
                    CurrentMap = null;
                    ServerManager.Instance.UnregisterSession(this.Character.CharacterId);
                }
            }

            if (Account != null)
            {
                ServiceFactory.Instance.CommunicationService.DisconnectAccount(Account.Name);
            }

            ClearReceiveQueue();
        }