Exemplo n.º 1
0
        public static void HandleCharacterCreate(PacketStream P, CityClient Client)
        {
            byte PacketLength = (byte)P.ReadByte();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            byte UnencryptedLength = (byte)P.ReadByte();

            //Accountname isn't encrypted in this packet.
            string AccountName = P.ReadString();

            PacketStream FetchKeyPack = new PacketStream(0x01, 00);
            FetchKeyPack.WriteString(AccountName);
            Client.Send(FetchKeyPack.ToArray());

            //TODO: Wait until the key has been received...
            AResetEvent.WaitOne();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            PacketStream OutPacket = new PacketStream(0x01, 0x00);
            OutPacket.WriteByte((byte)0x01);
            OutPacket.WriteByte((byte)AccountName.Length);
            OutPacket.Write(Encoding.ASCII.GetBytes(AccountName), 0, AccountName.Length);

            Logger.LogDebug("Received CharacterCreate!");

            Guid ID = new Guid();

            Sim Character = new Sim(ID.ToString());
            Character.Timestamp = P.ReadString();
            Character.Name = P.ReadString();
            Character.Sex = P.ReadString();

            //TODO: This should check if the character exists in the DB...
            Database.CreateCharacter(Character);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a DBAsyncObject instance.
 /// </summary>
 /// <param name="AccountName">The name of the client's account.</param>
 /// <param name="Client">The client.</param>
 /// <param name="Command">The SQL command.</param>
 public DBAsyncObject(string AccountName, ref CityClient Client, SqlCommand Command, byte[] Hash)
 {
     m_Client      = Client;
     m_AccountName = AccountName;
     m_Command     = Command;
     m_Hash        = Hash;
 }
Exemplo n.º 3
0
 public DBAsyncObject(string AccountName, ref CityClient Client, DateTime Timestamp, SqlCommand Command)
 {
     m_Client             = Client;
     m_AccountName        = AccountName;
     m_CharacterTimestamp = Timestamp;
     m_Command            = Command;
 }
Exemplo n.º 4
0
        public static void HandleCreateSimulationObject(PacketStream P, ref CityClient C)
        {
            byte PacketLength = (byte)P.ReadByte();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            byte UnencryptedLength = (byte)P.ReadByte();

            BinaryFormatter BinFormatter = new BinaryFormatter();
            SimulationObject CreatedSimObject = (SimulationObject)BinFormatter.Deserialize(P);

            //TODO: Add the object to the client's lot's VM...
        }
        public static void HandleCreateSimulationObject(PacketStream P, ref CityClient C)
        {
            byte PacketLength = (byte)P.ReadByte();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            byte UnencryptedLength = (byte)P.ReadByte();

            BinaryFormatter  BinFormatter     = new BinaryFormatter();
            SimulationObject CreatedSimObject = (SimulationObject)BinFormatter.Deserialize(P);

            //TODO: Add the object to the client's lot's VM...
        }
Exemplo n.º 6
0
        public void OnAccept(IAsyncResult AR)
        {
            Socket AcceptedSocket = m_ListenerSock.EndAccept(AR);

            if (AcceptedSocket != null)
            {
                Console.WriteLine("\nNew client connected!");

                //Let sockets linger for 5 seconds after they're closed, in an attempt to make sure all
                //pending data is sent!
                AcceptedSocket.LingerState = new LingerOption(true, 5);
                CityClient NewClient = new CityClient(AcceptedSocket, this);
                m_LoginClients.Add(NewClient);
            }

            m_ListenerSock.BeginAccept(new AsyncCallback(OnAccept), m_ListenerSock);
        }
        public static void HandleCharacterCreate(PacketStream P, CityClient Client)
        {
            byte PacketLength = (byte)P.ReadByte();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            byte UnencryptedLength = (byte)P.ReadByte();

            //Accountname isn't encrypted in this packet.
            string AccountName = P.ReadString();

            PacketStream FetchKeyPack = new PacketStream(0x01, 00);

            FetchKeyPack.WriteString(AccountName);
            Client.Send(FetchKeyPack.ToArray());

            //TODO: Wait until the key has been received...
            AResetEvent.WaitOne();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            PacketStream OutPacket = new PacketStream(0x01, 0x00);

            OutPacket.WriteByte((byte)0x01);
            OutPacket.WriteByte((byte)AccountName.Length);
            OutPacket.Write(Encoding.ASCII.GetBytes(AccountName), 0, AccountName.Length);

            Logger.LogDebug("Received CharacterCreate!");

            Guid ID = new Guid();

            Sim Character = new Sim(ID.ToString());

            Character.Timestamp = P.ReadString();
            Character.Name      = P.ReadString();
            Character.Sex       = P.ReadString();

            //TODO: This should check if the character exists in the DB...
            Database.CreateCharacter(Character);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Constructs a DBAsyncObject instance.
 /// </summary>
 /// <param name="AccountName">The name of the client's account.</param>
 /// <param name="Client">The client.</param>
 /// <param name="Command">The SQL command.</param>
 public DBAsyncObject(string AccountName, ref CityClient Client, SqlCommand Command)
 {
     m_Client      = Client;
     m_AccountName = AccountName;
     m_Command     = Command;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Removes a client from the internal list of connected clients.
 /// Should really only be called internally by the LoginClient.Disconnect()
 /// method.
 /// </summary>
 /// <param name="Client">The client to remove.</param>
 public void RemoveClient(CityClient Client)
 {
     m_LoginClients.Remove(Client);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Constructs a DBAsyncObject instance.
 /// </summary>
 /// <param name="AccountName">The name of the client's account.</param>
 /// <param name="Client">The client.</param>
 /// <param name="Command">The SQL command.</param>
 public DBAsyncObject(string AccountName, ref CityClient Client, SqlCommand Command, byte[] Hash)
 {
     m_Client = Client;
     m_AccountName = AccountName;
     m_Command = Command;
     m_Hash = Hash;
 }
Exemplo n.º 11
0
 public DBAsyncObject(string AccountName, ref CityClient Client, DateTime Timestamp, SqlCommand Command)
 {
     m_Client = Client;
     m_AccountName = AccountName;
     m_CharacterTimestamp = Timestamp;
     m_Command = Command;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Constructs a DBAsyncObject instance.
 /// </summary>
 /// <param name="AccountName">The name of the client's account.</param>
 /// <param name="Client">The client.</param>
 /// <param name="Command">The SQL command.</param>
 public DBAsyncObject(string AccountName, ref CityClient Client, SqlCommand Command)
 {
     m_Client = Client;
     m_AccountName = AccountName;
     m_Command = Command;
 }
Exemplo n.º 13
0
 public LotSimulation(CityClient Owner)
 {
     m_Owner = Owner;
     m_VM.NewSimulationStateEvent += new OnNewSimulationState(m_VM_NewSimulationStateEvent);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Removes a client from the internal list of connected clients.
 /// Should really only be called internally by the LoginClient.Disconnect()
 /// method.
 /// </summary>
 /// <param name="Client">The client to remove.</param>
 public void RemoveClient(CityClient Client)
 {
     m_LoginClients.Remove(Client);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Called by LoginClient instances
 /// when they've received some new data
 /// (a new packet). Should not be called
 /// from anywhere else.
 /// </summary>
 /// <param name="P"></param>
 public void OnReceivedData(PacketStream P, CityClient Client)
 {
     OnReceiveEvent(P, Client);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Called by LoginClient instances
 /// when they've received some new data
 /// (a new packet). Should not be called
 /// from anywhere else.
 /// </summary>
 /// <param name="P"></param>
 public void OnReceivedData(PacketStream P, CityClient Client)
 {
     OnReceiveEvent(P, Client);
 }
Exemplo n.º 17
0
        public static void HandleClientKeyReceive(PacketStream P, ref CityClient C)
        {
            //TODO: Read packet and assign the key to the client.

            AResetEvent.Set();
        }
        public static void HandleClientKeyReceive(PacketStream P, ref CityClient C)
        {
            //TODO: Read packet and assign the key to the client.

            AResetEvent.Set();
        }
Exemplo n.º 19
0
        private void m_Listener_OnReceiveEvent(PacketStream P, CityClient Client)
        {
            byte ID = (byte)P.ReadByte();

            switch (ID)
            {
                case 0x00:
                    PacketHandlers.HandleCharacterCreate(P, Client);
                    break;
                case 0x01:
                    PacketHandlers.HandleClientKeyReceive(P, ref Client);
                    break;
            }
        }
Exemplo n.º 20
0
        public void OnAccept(IAsyncResult AR)
        {
            Socket AcceptedSocket = m_ListenerSock.EndAccept(AR);

            if (AcceptedSocket != null)
            {
                Console.WriteLine("\nNew client connected!");

                //Let sockets linger for 5 seconds after they're closed, in an attempt to make sure all
                //pending data is sent!
                AcceptedSocket.LingerState = new LingerOption(true, 5);
                CityClient NewClient = new CityClient(AcceptedSocket, this);
                m_LoginClients.Add(NewClient);
            }

            m_ListenerSock.BeginAccept(new AsyncCallback(OnAccept), m_ListenerSock);
        }