Disconnect() public method

public Disconnect ( ) : void
return void
Esempio n. 1
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MapClientManager.Instance.check.Abort();
            Exception ex = e.ExceptionObject as Exception;

            Logger.ShowError("Fatal: An unhandled exception is thrown, terminating...");
            Logger.ShowError("Error Message:" + ex.Message);
            Logger.ShowError("Call Stack:" + ex.StackTrace);
            Logger.ShowError("Trying to save all player's data");
            uint[] sessions;
            sessions = new uint[MapClientManager.Instance.Clients().Count];
            MapClientManager.Instance.Clients().Keys.CopyTo(sessions, 0);
            foreach (uint i in sessions)
            {
                try
                {
                    MapClient client = (MapClient)MapClientManager.Instance.Clients()[i];
                    if (client.Char == null)
                    {
                        continue;
                    }
                    client.Disconnect();
                }
                catch (Exception) { }
            }
        }
Esempio n. 2
0
 private static void ShutingDown(object sender, ConsoleCancelEventArgs args)
 {
     Logger.ShowInfo("Closing.....", null);
     uint[] sessions;
     sessions = new uint[MapClientManager.Instance.Clients().Count];
     MapClientManager.Instance.Clients().Keys.CopyTo(sessions, 0);
     foreach (uint i in sessions)
     {
         try
         {
             MapClient client = (MapClient)MapClientManager.Instance.Clients()[i];
             if (client.Char == null)
             {
                 continue;
             }
             client.Disconnect();
         }
         catch (Exception) { }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Receive the identity of the client.
        /// </summary>
        public void OnSendIdentity(SagaMap.Packets.Client.SendIdentity p)
        {
            MapClient client = new MapClient(p.GetSessionID());
            ActorPC   newChar;

            client.netIO = this.netIO;
            MapClientManager.Instance.Clients().Add(client.SessionID, client);
            if (client.state != SESSION_STATE.NOT_IDENTIFIED)
            {
                return;
            }

            uint charId = p.GetCharID();

            Logger.ShowInfo("Got identity (0x010C) from client: " + charId, null);
            try
            {
                newChar = MapServer.charDB.GetChar(charId);
                if (newChar == null)
                {
                    throw new Exception("cannot load char");
                }
            }
            catch (Exception e)
            {
                Logger.ShowError(e, null);
                client.Disconnect();
                return;
            }
            while ((MapClientManager.Instance.GetClient(newChar.Name) != null))
            {
                Logger.ShowInfo("Character:" + newChar.Name + " already online, kicking....");
                MapClientManager.Instance.GetClient(newChar.Name).Disconnect();
            }
            client.Char = newChar;
            if (client.Char.validationKey != p.GetValidationKey())
            {
                Logger.ShowError("Client " + this.netIO.sock.RemoteEndPoint.ToString() + " sent wrong validation key and got kicked.", null);
                this.Disconnect();
                return;
            }

#if Preview_Version
            if (MapClientManager.Instance.Players.Count > 10)
            {
                this.Disconnect();
                return;
            }
#endif
            if (client.Char.mapID == 0)
            {
                if (client.Char.save_map == 0)
                {
                    client.Char.save_map = 3;
                    client.Char.save_x   = -4811.951f;
                    client.Char.save_y   = 15936.05f;
                    client.Char.save_z   = 3894f;
                }
                client.Char.mapID = client.Char.save_map;
                client.Char.x     = client.Char.save_x;
                client.Char.y     = client.Char.save_y;
                client.Char.z     = client.Char.save_z;
            }

            if (!MapManager.Instance.GetMap(client.Char.mapID, out client.map))
            {
                Logger.ShowError("Could not obtain map for client " + this.netIO.sock.RemoteEndPoint.ToString() + ".", null);
                this.Disconnect();
                return;
            }
            client.CheckWeaponEXP();
            client.Char.e = new ActorEventHandlers.PC_EventHandler(client.Char, client);

            client.Char.Tasks    = new Dictionary <string, MultiRunTask>();
            client.state         = SESSION_STATE.IDENTIFIED;
            client.Char.invisble = true;
            client.map.RegisterActor(client.Char, p.GetSessionID());
            client.Char.Online = 1;
            //client.taskHeartbeat.Activate();  //heartbeat service deactivated
            client.Pc = new PC(client);
            Logger.ShowInfo("Player:" + client.Char.name + " logged in");
            Logger.ShowInfo("Total Player count:" + MapClientManager.Instance.Players.Count.ToString());
        }
Esempio n. 4
0
        /// <summary>
        /// Receive the identity of the client.
        /// </summary>
        public void OnSendIdentity(SagaMap.Packets.Client.SendIdentity p)
        {
            MapClient client = new MapClient(p.GetSessionID());
            ActorPC newChar;
            client.netIO = this.netIO;
            MapClientManager.Instance.Clients().Add(client.SessionID, client);
            if (client.state != SESSION_STATE.NOT_IDENTIFIED) return;

            uint charId = p.GetCharID();
            Logger.ShowInfo("Got identity (0x010C) from client: " + charId, null);
            try
            {
                newChar = MapServer.charDB.GetChar(charId);
                if (newChar == null) throw new Exception("cannot load char");
            }
            catch (Exception e)
            {
                Logger.ShowError(e, null);
                client.Disconnect();
                return;
            }
            while ((MapClientManager.Instance.GetClient(newChar.Name) != null))
            {
                Logger.ShowInfo("Character:" + newChar.Name + " already online, kicking....");
                MapClientManager.Instance.GetClient(newChar.Name).Disconnect();
            }
            client.Char = newChar;
            if (client.Char.validationKey != p.GetValidationKey())
            {
                Logger.ShowError("Client " + this.netIO.sock.RemoteEndPoint.ToString() + " sent wrong validation key and got kicked.", null);
                this.Disconnect();
                return;
            }

            #if Preview_Version
            if (MapClientManager.Instance.Players.Count > 10)
            {
                this.Disconnect();
                return;
            }
            #endif
            if (client.Char.mapID == 0)
            {
                if (client.Char.save_map == 0)
                {
                    client.Char.save_map = 3;
                    client.Char.save_x = -4811.951f;
                    client.Char.save_y = 15936.05f;
                    client.Char.save_z = 3894f;
                }
                client.Char.mapID = client.Char.save_map;
                client.Char.x = client.Char.save_x;
                client.Char.y = client.Char.save_y;
                client.Char.z = client.Char.save_z;
            }

            if (!MapManager.Instance.GetMap(client.Char.mapID, out client.map))
            {
                Logger.ShowError("Could not obtain map for client " + this.netIO.sock.RemoteEndPoint.ToString() + ".", null);
                this.Disconnect();
                return;
            }
            client.CheckWeaponEXP();
            client.Char.e = new ActorEventHandlers.PC_EventHandler(client.Char, client);

            client.Char.Tasks = new Dictionary<string, MultiRunTask>();
            client.state = SESSION_STATE.IDENTIFIED;
            client.Char.invisble = true;
            client.map.RegisterActor(client.Char, p.GetSessionID());
            client.Char.Online = 1;
            //client.taskHeartbeat.Activate();  //heartbeat service deactivated
            client.Pc = new PC(client);
            Logger.ShowInfo("Player:" + client.Char.name + " logged in");
            Logger.ShowInfo("Total Player count:" + MapClientManager.Instance.Players.Count.ToString());
        }