Beispiel #1
0
        void acceptor_OnClientConnected(Session session)
        {
            Logger.Write(Logger.LogTypes.연결, "클라이언트 {0} 연결됨", session.Socket.RemoteEndPoint.ToString());

            Random rand = new Random();
            int riv = rand.Next();
            int siv = rand.Next();

            session.RIV = new MapleCrypto(BitConverter.GetBytes(riv), Config.MajorVersion);
            session.SIV = new MapleCrypto(BitConverter.GetBytes(siv), Config.MajorVersion);

            PacketWriter packet = new PacketWriter();
            packet.WriteShort(0);
            packet.WriteShort(Config.MajorVersion);
            packet.WriteShort(1);
            packet.WriteByte(0x31);
            packet.WriteInt(riv);
            packet.WriteInt(siv);
            packet.WriteByte(0x08);
            packet.SetShort(0, packet.Length - 2);
            session.SendRawPacket(packet.ToArray());

            Client c = new Client(session);
            mGameServer.Clients.Add(c);
        }
Beispiel #2
0
		/// <summary>
		/// Client connected handler
		/// </summary>
		/// <param name="iarl">The IAsyncResult</param>
		private void OnClientConnect(IAsyncResult iar)
		{
			try
			{
				Socket socket = _listener.EndAccept(iar);
				Session session = new Session(socket, SessionType.SERVER_TO_CLIENT);

				if (OnClientConnected != null)
					OnClientConnected(session);

				session.WaitForData();

				_listener.BeginAccept(new AsyncCallback(OnClientConnect), null);
			}
			catch (ObjectDisposedException)
			{
                Helpers.ErrorLogger.Log(Helpers.ErrorLevel.Critical, "[Error] OnClientConnect: Socket closed.");
				//Helpers.ErrorLogger.Log(Helpers.ErrorLevel.Critical, "[Error] OnClientConnect: Socket closed.");
			}
			catch (Exception se)
			{
                Helpers.ErrorLogger.Log(Helpers.ErrorLevel.Critical, "[Error] OnClientConnect: " + se);
				//Helpers.ErrorLogger.Log(Helpers.ErrorLevel.Critical, "[Error] OnClientConnect: " + se);
			}
		}
        void _Acceptor_OnClientConnected(Session session)
        {
            Logger.Write(Logger.LogTypes.연결, "opened connection with {0}", session.Socket.RemoteEndPoint.ToString());

            session.RIV = new MapleCrypto(new byte[4], Common.Config.MajorVersion);
            session.SIV = new MapleCrypto(new byte[4], Common.Config.MajorVersion);

            PacketWriter packet = new PacketWriter();
            packet.WriteShort(0);
            packet.WriteShort(Common.Config.MajorVersion);
            packet.WriteShort(1);
            packet.WriteByte(0x31);
            packet.WriteInt(0);
            packet.WriteInt(0);
            packet.WriteByte(0x08);
            packet.SetShort(0, packet.Length - 2);
            session.SendRawPacket(packet.ToArray());

            GameServerConnection con = new GameServerConnection(session);
            _ConnectedClients.Add(con);
        }
        void mConnector_OnClientConnected(Session session)
        {
            mSession = session;
            mSession.OnPacketReceived += mSession_OnPacketReceived;
            mSession.OnClientDisconnected += mSession_OnClientDisconnected;
            mSession.OnInitPacketReceived += mSession_OnInitPacketReceived;
            mSession.RIV = new MapleCrypto(new byte[4], Common.Config.MajorVersion);
            mSession.SIV = new MapleCrypto(new byte[4], Common.Config.MajorVersion);

            new Thread(() =>
            {
                Thread.Sleep(1000);
                mSession.SendPacket(CenterServerPacketDefinitions.Identify(Common.Config.CenterServerKey));
                    while (session.Socket.Connected)
                    {
                        mSession.SendPacket(CenterServerPacketDefinitions.ConnectedClients((byte)Program.mServer.ServerId, Program.mServer.Clients.Count));
                        mSession.SendPacket(CenterServerPacketDefinitions.PollConnectedClients());
                        Thread.Sleep(5000);
                    }
                }).Start();
        }
Beispiel #5
0
 public Client(Session pSession)
 {
     mSession = pSession;
     mSession.OnPacketReceived += mSession_OnPacketReceived;
     mSession.OnClientDisconnected += mSession_OnClientDisconnected;
     LastKeepAlive = DateTime.Now.ToFileTime();
     new System.Threading.Thread(() =>
         {
             while (mSession.Socket.Connected)
             {
                 //if (DateTime.Now.ToFileTime() - LastKeepAlive > DateTime.FromFileTime(0).AddSeconds(30).ToFileTime())
                 //{
                 //    mSession.Socket.Close();
                 //    Logger.Write(Logger.LogTypes.연결, "KeepAlive timeout {0}, {1}, {2}", DateTime.Now.ToFileTime(), LastKeepAlive, DateTime.FromFileTime(0).AddSeconds(15).ToFileTime());
                 //    return;
                 //}
                 SendPacket(CClientSocket.KeepAlive());
                 System.Threading.Thread.Sleep(1000);
             }
         }).Start();
 }
 void mSession_OnClientDisconnected(Session session)
 {
     Logger.Write(Logger.LogTypes.경고, "CenterServer {0} disconnected", mCenterServer.Name);
 }
Beispiel #7
0
 void mSession_OnClientDisconnected(Session session)
 {
     if (!Migrate)
         Database.ExecuteQuery("UPDATE account SET Connected = 0 WHERE AccountName = '{0}';", Username);
     Logger.Write(Logger.LogTypes.연결, "클라이언트 {0} 끊겨짐", session.Socket.RemoteEndPoint.ToString());
     Program.mServer.Clients.Remove(this);
 }
Beispiel #8
0
        /// <summary>
        /// Creates the session after connecting
        /// </summary>
        /// <returns>Session created with listener</returns>
        private Session CreateSession()
        {
            Session session = new Session(_socket, SessionType.CLIENT_TO_SERVER);

            if (OnClientConnected != null)
                OnClientConnected(session);

            session.WaitForDataNoEncryption();

            return session;
        }
 void _Session_OnClientDisconnected(Session session)
 {
     mGameServer.Connection = null;
     Program.mServer._Acceptor._ConnectedClients.Remove(this);
 }
 public GameServerConnection(Session pSession)
 {
     mSession = pSession;
     mSession.OnClientDisconnected += _Session_OnClientDisconnected;
     mSession.OnPacketReceived += _Session_OnPacketReceived;
 }
Beispiel #11
0
 void mSession_OnClientDisconnected(Session session)
 {
     if (!mAccount.Migrate)
         Database.ExecuteQuery("UPDATE account SET Connected = 0 WHERE AccountName = '{0}';", mAccount.Username);
     Logger.Write(Logger.LogTypes.연결, "클라이언트 {0} 끊겨짐", session.Socket.RemoteEndPoint.ToString());
     Program.mServer.Fields[mCharacter.mField][mCharacter.mFieldInstance].SendPacket(mCharacter.GenerateDespawnPacket().ToArray());
     Program.mServer.Clients.Remove(this);
 }