Esempio n. 1
0
        public ClientConnection(Socket pSocket)
            : base(pSocket)
        {
            uniqueid = Program.Random.Next(0, 10000);

            Pong = true;
            IsFake = false;
            Program.Clients.Add(this);
            Clear();
            _exporter = new MSBExporter();
            Logger_WriteLine("Client Connected!");

            byte[] sendkey = new byte[32], recvkey = new byte[32];
            Program.Random.NextBytes(sendkey);
            Program.Random.NextBytes(recvkey);

            using (MaplePacket pack = new MaplePacket(MaplePacket.CommunicationType.ServerPacket, 0xEEFF))
            {
                pack.WriteString(Logger.Version);

                // Add encryption keys
                pack.WriteBytes(recvkey);
                pack.WriteBytes(sendkey);

                for (byte i = 0; i < (byte)MaplePacket.CommunicationType.AMOUNT; i++)
                {
                    pack.WriteUShort((ushort)Program.ValidHeaders[i].Keys.Count);
                    foreach (var header in Program.ValidHeaders[i].Keys)
                        pack.WriteUShort(header);
                }

                pack.WriteByte((byte)Program.AcceptedIPs.Count);
                foreach (string ip in Program.AcceptedIPs)
                    pack.WriteString(ip);


#if LOCALE_GMS
                pack.WriteBool(true);
                pack.WriteBytes(GMSKeys.GetKeyForVersion());
#elif LOCALE_KMS
                pack.WriteBool(false);
#else
                pack.WriteBool(true);
                pack.WriteBytes(new byte[] { 0x13, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, 0x00,
            0x1B, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00 });
#endif


                pack.WriteByte(ServerMapleInfo.LOCALE);
                pack.WriteUShort(ServerMapleInfo.VERSION);

                SendPacket(pack);
            }

            SetKeys(sendkey, recvkey);

            SendInfoText("Welcome! Please open MapleStory.");
        }
Esempio n. 2
0
 private void Clear()
 {
     AccountID           = -1;
     UserID              = -1;
     CharacterInternalID = CharacterID = -1;
     _exporter           = null;
     CharData            = null;
     LastReportID        = -1;
     _CharactersInMap    = new List <string>();
 }
Esempio n. 3
0
        public void Save(bool pReset, bool pClean = true)
        {
            if (IsFake)
            {
                return;
            }

            Logger_WriteLine("Trying to save...");
            if (_exporter != null)
            {
                // Try to get logfile ID from DB

                if (!Directory.Exists("sessions"))
                {
                    Directory.CreateDirectory("sessions");
                }

                string filename = "sessions/Savefile_";
                int    packets  = _exporter.GetSize();
                try
                {
                    using (InsertQueryBuilder iqb = new InsertQueryBuilder("session_logfiles"))
                    {
                        iqb.AddColumns(false, "id", "information", "at");
                        iqb.AddRow(null, packets + " > " + LogFilename, new MySQL_Connection.NowType());
                        iqb.RunQuery();

                        filename += MySQL_Connection.Instance.GetLastInsertId();
                    }
                }
                catch
                {
                    filename += "NOMYSQL_" + MasterThread.CurrentDate.ToFileTime();
                }
                filename += ".msb";

                Logger_WriteLine("Saving packets to '{0}' ({1} packets logged)", filename, _exporter.GetSize());
                _exporter.Save(filename, ServerMapleInfo.VERSION, base.HostEndPoint, base.ClientEndPoint);
                if (pReset)
                {
                    _exporter = new MSBExporter();
                }
                else if (pClean)
                {
                    _exporter = null;
                }
            }
        }
Esempio n. 4
0
        public override void OnDisconnect()
        {
            if (MasterThread.Instance.IsInMainThread())
            {
                //Save(false);
                if (_exporter != null)
                {
                    _exporter.Clear(true);
                }
                _exporter = null;
                var info = SessionRestartCache.Instance.GetInfoForConnection(this);
                if (info != null)
                {
                    SessionRestartCache.Instance.RemoveInfo(info);
                }

                Logger_WriteLine("Client Disconnected.");
                Clear();
                Program.Clients.Remove(this);
            }
            else
            {
                MasterThread.Instance.AddCallback((a) =>
                {
                    if (_exporter != null)
                    {
                        _exporter.Clear(true);
                    }
                    _exporter = null;
                    //Save(false);

                    var info = SessionRestartCache.Instance.GetInfoForConnection(this);
                    if (info != null)
                    {
                        SessionRestartCache.Instance.RemoveInfo(info);
                    }

                    Logger_WriteLine("Client Disconnected.");
                    Clear();
                    Program.Clients.Remove(this);
                });
            }
        }
Esempio n. 5
0
        public ClientConnection(Socket pSocket)
            : base(pSocket)
        {
            uniqueid = Program.Random.Next(0, 10000);

            Pong   = true;
            IsFake = false;
            Program.Clients.Add(this);
            Clear();
            _exporter = new MSBExporter();
            Logger_WriteLine("Client Connected!");

            byte[] sendkey = new byte[32], recvkey = new byte[32];
            Program.Random.NextBytes(sendkey);
            Program.Random.NextBytes(recvkey);

            using (MaplePacket pack = new MaplePacket(MaplePacket.CommunicationType.ServerPacket, 0xEEFF))
            {
                pack.WriteString(Logger.Version);

                // Add encryption keys
                pack.WriteBytes(recvkey);
                pack.WriteBytes(sendkey);

                for (byte i = 0; i < (byte)MaplePacket.CommunicationType.AMOUNT; i++)
                {
                    pack.WriteUShort((ushort)Program.ValidHeaders[i].Keys.Count);
                    foreach (var header in Program.ValidHeaders[i].Keys)
                    {
                        pack.WriteUShort(header);
                    }
                }

                pack.WriteByte((byte)Program.AcceptedIPs.Count);
                foreach (string ip in Program.AcceptedIPs)
                {
                    pack.WriteString(ip);
                }


#if LOCALE_GMS
                pack.WriteBool(true);
                pack.WriteBytes(GMSKeys.GetKeyForVersion());
#elif LOCALE_KMS
                pack.WriteBool(false);
#else
                pack.WriteBool(true);
                pack.WriteBytes(new byte[] { 0x13, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, 0x00,
                                             0x1B, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00 });
#endif


                pack.WriteByte(ServerMapleInfo.LOCALE);
                pack.WriteUShort(ServerMapleInfo.VERSION);

                SendPacket(pack);
            }

            SetKeys(sendkey, recvkey);

            SendInfoText("Welcome! Please open MapleStory.");
        }
Esempio n. 6
0
        public override void OnDisconnect()
        {
            if (MasterThread.Instance.IsInMainThread())
            {
                //Save(false);
                if (_exporter != null) _exporter.Clear(true);
                _exporter = null;
                var info = SessionRestartCache.Instance.GetInfoForConnection(this);
                if (info != null)
                    SessionRestartCache.Instance.RemoveInfo(info);

                Logger_WriteLine("Client Disconnected.");
                Clear();
                Program.Clients.Remove(this);
            }
            else
            {
                MasterThread.Instance.AddCallback((a) =>
                {
                    if (_exporter != null) _exporter.Clear(true);
                    _exporter = null;
                    //Save(false);

                    var info = SessionRestartCache.Instance.GetInfoForConnection(this);
                    if (info != null)
                        SessionRestartCache.Instance.RemoveInfo(info);

                    Logger_WriteLine("Client Disconnected.");
                    Clear();
                    Program.Clients.Remove(this);
                });
            }
        }
Esempio n. 7
0
        public void Save(bool pReset, bool pClean = true)
        {
            if (IsFake) return;

            Logger_WriteLine("Trying to save...");
            if (_exporter != null)
            {
                // Try to get logfile ID from DB

                if (!Directory.Exists("sessions"))
                    Directory.CreateDirectory("sessions");

                string filename = "sessions/Savefile_";
                int packets = _exporter.GetSize();
                try
                {
                    using (InsertQueryBuilder iqb = new InsertQueryBuilder("session_logfiles"))
                    {
                        iqb.AddColumns(false, "id", "information", "at");
                        iqb.AddRow(null, packets + " > " + LogFilename, new MySQL_Connection.NowType());
                        iqb.RunQuery();

                        filename += MySQL_Connection.Instance.GetLastInsertId();
                    }
                }
                catch
                {
                    filename += "NOMYSQL_" + MasterThread.CurrentDate.ToFileTime();
                }
                filename += ".msb";

                Logger_WriteLine("Saving packets to '{0}' ({1} packets logged)", filename, _exporter.GetSize());
                _exporter.Save(filename, ServerMapleInfo.VERSION, base.HostEndPoint, base.ClientEndPoint);
                if (pReset)
                    _exporter = new MSBExporter();
                else if (pClean)
                    _exporter = null;
            }
        }
Esempio n. 8
0
 private void Clear()
 {
     AccountID = -1;
     UserID = -1;
     CharacterInternalID = CharacterID = -1;
     _exporter = null;
     CharData = null;
     LastReportID = -1;
     _CharactersInMap = new List<string>();
 }