Example #1
0
        /// <summary>
        /// Connects to the login server.
        /// </summary>
        /// <param name="LoginArgs">Arguments used for login. Can be null.</param>
        public void Connect(LoginArgsContainer LoginArgs)
        {
            m_LoginArgs = LoginArgs;

            if (LoginArgs != null)
            {
                m_ClientEncryptor          = LoginArgs.Enc;
                m_ClientEncryptor.Username = LoginArgs.Username;
            }
            //Making sure that the client is not already connecting to the loginserver.
            if (!m_Sock.Connected)
            {
                IPAddress address = null;
                try
                {
                    IPHostEntry ipEntry = Dns.GetHostEntry(m_IP);
                    address = ipEntry.AddressList[0];
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error trying to get local address {0} ", ex.Message);
                }

                if (address == null)
                {
                    try { address = IPAddress.Parse(m_IP); } catch { return; }
                }
                m_Sock.BeginConnect(address, m_Port, new AsyncCallback(ConnectCallback), m_Sock);
            }
        }
        /// <summary>
        /// Sends a CharacterCreate packet to a CityServer.
        /// </summary>
        /// <param name="LoginArgs">Arguments used to log onto the CityServer.</param>
        /// <param name="Character">The character to create on the CityServer.</param>
        public static void SendCharacterCreateCity(LoginArgsContainer LoginArgs, TSOClient.VM.Sim Character)
        {
            PacketStream Packet = new PacketStream((byte)PacketType.CHARACTER_CREATE_CITY, 0);
            Packet.WriteHeader();

            byte[] EncryptionKey = LoginArgs.Enc.GetDecryptionArgsContainer().ARC4DecryptArgs.EncryptionKey;
            MemoryStream PacketData = new MemoryStream();
            BinaryWriter Writer = new BinaryWriter(PacketData);

            Writer.Write((byte)LoginArgs.Username.Length);
            Writer.Write(Encoding.ASCII.GetBytes(LoginArgs.Username), 0, Encoding.ASCII.GetBytes(LoginArgs.Username).Length);
            Writer.Write((byte)EncryptionKey.Length);
            Writer.Write(EncryptionKey);
            Writer.Write(PlayerAccount.CityToken);
            Writer.Write(Character.Timestamp);
            Writer.Write(Character.Name);
            Writer.Write(Character.Sex);
            Writer.Write(Character.Description);
            Writer.Write((ulong)Character.HeadOutfitID);
            Writer.Write((ulong)Character.BodyOutfitID);
            Writer.Write((byte)Character.AppearanceType);
            Writer.Write((string)Character.CityID.ToString());

            Packet.WriteUInt16((ushort)((ushort)PacketHeaders.UNENCRYPTED + PacketData.Length));
            Packet.WriteBytes(PacketData.ToArray());
            Writer.Close();

            LoginArgs.Client.Send(Packet.ToArray());
        }
Example #3
0
        /// <summary>
        /// Connects to the login server.
        /// </summary>
        /// <param name="LoginArgs">Arguments used for login. Can be null.</param>
        public void Connect(LoginArgsContainer LoginArgs)
        {
            m_LoginArgs = LoginArgs;

            if (LoginArgs != null)
            {
                m_ClientEncryptor          = LoginArgs.Enc;
                m_ClientEncryptor.Username = LoginArgs.Username;
            }
            //Making sure that the client is not already connecting to the loginserver.
            if (!m_Sock.Connected)
            {
                m_Sock.BeginConnect(IPAddress.Parse(m_IP), m_Port, new AsyncCallback(ConnectCallback), m_Sock);
            }
        }
Example #4
0
        /// <summary>
        /// Connects to the login server.
        /// </summary>
        /// <param name="LoginArgs">Arguments used for login. Can be null.</param>
        public void Connect(LoginArgsContainer LoginArgs)
        {
            m_LoginArgs = LoginArgs;

            if (LoginArgs != null)
            {
                m_ClientEncryptor = LoginArgs.Enc;
                m_ClientEncryptor.Username = LoginArgs.Username;
            }
            //Making sure that the client is not already connecting to the loginserver.
            if (!m_Sock.Connected)
            {
                IPAddress address = null;
                try
                {
                    IPHostEntry ipEntry = Dns.GetHostEntry(m_IP);
                    address = ipEntry.AddressList[0];
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error trying to get local address {0} ", ex.Message);
                }

                if (address == null )
                {
                    try { address = IPAddress.Parse(m_IP); } catch { return; }
                }
                m_Sock.BeginConnect(address, m_Port, new AsyncCallback(ConnectCallback), m_Sock);
            }
        }
        public static void SendLoginRequest(LoginArgsContainer Args)
        {
            //Variable length...
            PacketStream Packet = new PacketStream((byte)PacketType.LOGIN_REQUEST, 0);
            Packet.WriteByte(0x00);

            SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length);

            MemoryStream MemStream = new MemoryStream();

            DecryptionArgsContainer DecryptionArgs = Args.Enc.GetDecryptionArgsContainer();
            byte[] EncKey = DecryptionArgs.ARC4DecryptArgs.EncryptionKey;

            MemStream.WriteByte((byte)Args.Username.Length);
            MemStream.Write(Encoding.ASCII.GetBytes(Args.Username), 0, Encoding.ASCII.GetBytes(Args.Username).Length);

            byte[] HashBuf = Hash.ComputePasswordHash(Args.Username, Args.Password);
            PlayerAccount.Hash = HashBuf;

            MemStream.WriteByte((byte)HashBuf.Length);
            MemStream.Write(HashBuf, 0, HashBuf.Length);

            MemStream.WriteByte((byte)EncKey.Length);
            MemStream.Write(EncKey, 0, EncKey.Length);

            Packet.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + MemStream.ToArray().Length + 4));
            Packet.WriteBytes(MemStream.ToArray());

            string[] Version = GlobalSettings.Default.ClientVersion.Split('.');

            Packet.WriteByte((byte)int.Parse(Version[0])); //Version 1
            Packet.WriteByte((byte)int.Parse(Version[1])); //Version 2
            Packet.WriteByte((byte)int.Parse(Version[2])); //Version 3
            Packet.WriteByte((byte)int.Parse(Version[3])); //Version 4

            Args.Client.Send(Packet.ToArray());
        }
Example #6
0
        /// <summary>
        /// User clicked button to log in.
        /// </summary>
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            LoginArgsContainer Args = new LoginArgsContainer();

            if (TxtPassword.Text != "" && TxtUsername.Text != "")
            {
                NetworkFacade.Client = new NetworkClient(GlobalSettings.Default.LoginServerIP, 2106, 
                    GonzoNet.Encryption.EncryptionMode.AESCrypto);
                NetworkFacade.Client.OnConnected += new OnConnectedDelegate(NetworkController.Client_OnConnected);

                Args.Username = TxtUsername.Text.ToUpper();
                Args.Password = TxtPassword.Text.ToUpper();

                SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length);
                byte[] HashBuf = Hash.ComputePasswordHash(Args.Username.ToUpper(), Args.Password.ToUpper());
                Args.Enc = new AESEncryptor(Convert.ToBase64String(HashBuf));
                Args.Client = NetworkFacade.Client;

                PlayerAccount.Username = TxtUsername.Text;

                LblStatus.Invoke(new MethodInvoker(delegate{ LblStatus.Visible = true; }));
                LblStatus.Invoke(new MethodInvoker(delegate { LblStatus.Text = "Connecting..."; }));

                NetworkController.OnReceivedCharacters += new OnReceivedCharactersDelegate(NetworkController_OnReceivedCharacters);

                NetworkFacade.Client.Connect(Args);
            }
            else
                MessageBox.Show("Please enter a username and password!");
        }
        /// <summary>
        /// Creates a new CityTransitionScreen.
        /// </summary>
        /// <param name="SelectedCity">The city being transitioned to.</param>
        /// <param name="CharacterCreated">If transitioning from CreateASim, this should be true.
        /// A CharacterCreateCity packet will be sent to the CityServer. Otherwise, this should be false.
        /// A CityToken packet will be sent to the CityServer.</param>
        public CityTransitionScreen(CityInfo SelectedCity, bool CharacterCreated)
        {
            m_SelectedCity = SelectedCity;
            m_CharacterCreated = CharacterCreated;

            /**
             * Scale the whole screen to 1024
             */
            m_BackgroundCtnr = new UIContainer();
            m_BackgroundCtnr.ScaleX = m_BackgroundCtnr.ScaleY = ScreenWidth / 800.0f;

            /** Background image **/
            m_Background = new UIImage(GetTexture((ulong)FileIDs.UIFileIDs.setup));
            m_Background.ID = "Background";
            m_BackgroundCtnr.Add(m_Background);

            var lbl = new UILabel();
            lbl.Caption = "Version " + GlobalSettings.Default.ClientVersion;
            lbl.X = 20;
            lbl.Y = 558;
            m_BackgroundCtnr.Add(lbl);
            this.Add(m_BackgroundCtnr);

            m_LoginProgress = new UILoginProgress();
            m_LoginProgress.X = (ScreenWidth - (m_LoginProgress.Width + 20));
            m_LoginProgress.Y = (ScreenHeight - (m_LoginProgress.Height + 20));
            m_LoginProgress.Opacity = 0.9f;
            this.Add(m_LoginProgress);

            /*lock(NetworkFacade.Controller)
                NetworkFacade.Controller.OnNetworkError += new NetworkErrorDelegate(Controller_OnNetworkError);*/

            lock (NetworkFacade.Client)
            {
                lock (NetworkFacade.Client.ClientEncryptor)
                {
                    LoginArgsContainer LoginArgs = new LoginArgsContainer();
                    LoginArgs.Username = NetworkFacade.Client.ClientEncryptor.Username;
                    LoginArgs.Password = Convert.ToBase64String(PlayerAccount.Hash);
                    LoginArgs.Enc = NetworkFacade.Client.ClientEncryptor;

                    NetworkFacade.Client = new NetworkClient(SelectedCity.IP, SelectedCity.Port,
                        GonzoNet.Encryption.EncryptionMode.AESCrypto, true);
                    //This might not fix decryption of cityserver's packets, but it shouldn't make things worse...
                    NetworkFacade.Client.ClientEncryptor = LoginArgs.Enc;
                    //THIS IS IMPORTANT - THIS NEEDS TO BE COPIED AFTER IT HAS BEEN RECREATED FOR
                    //THE RECONNECTION TO WORK!
                    LoginArgs.Client = NetworkFacade.Client;
                    NetworkFacade.Client.OnConnected += new OnConnectedDelegate(Client_OnConnected);
                    NetworkFacade.Controller.Reconnect(ref NetworkFacade.Client, SelectedCity, LoginArgs);
                }
            }

            lock (NetworkFacade.Controller)
            {
                NetworkFacade.Controller.OnCharacterCreationStatus += new OnCharacterCreationStatusDelegate(Controller_OnCharacterCreationStatus);
                NetworkFacade.Controller.OnCityTransferProgress += new OnCityTransferProgressDelegate(Controller_OnCityTransfer);
                NetworkFacade.Controller.OnLoginNotifyCity += new OnLoginNotifyCityDelegate(Controller_OnLoginNotifyCity);
                NetworkFacade.Controller.OnLoginSuccessCity += new OnLoginSuccessCityDelegate(Controller_OnLoginSuccessCity);
                NetworkFacade.Controller.OnLoginFailureCity += new OnLoginFailureCityDelegate(Controller_OnLoginFailureCity);
                NetworkFacade.Controller.OnNetworkError += new NetworkErrorDelegate(Controller_OnNetworkError);
            }
        }
        private void Client_OnConnected(LoginArgsContainer LoginArgs)
        {
            ProgressEvent Progress =
                new ProgressEvent(EventCodes.PROGRESS_UPDATE);
            Progress.Done = 1;
            Progress.Total = 3;

            UIPacketSenders.SendLoginRequestCity(LoginArgs);
            OnTransitionProgress(Progress);
        }
 /// <summary>
 /// Reconnects to a CityServer.
 /// </summary>
 public void Reconnect(ref NetworkClient Client, CityInfo SelectedCity, LoginArgsContainer LoginArgs)
 {
     Client.Disconnect();
     Client.Connect(LoginArgs);
 }
        /// <summary>
        /// Authenticate with the service client to get a token,
        /// Then get info about avatars & cities
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public void InitialConnect(string username, string password)
        {
            var client = NetworkFacade.Client;
            LoginArgsContainer Args = new LoginArgsContainer();
            Args.Username = username;
            Args.Password = password;
            Args.Enc = new GonzoNet.Encryption.ARC4Encryptor(password);
            Args.Client = client;

            client.Connect(Args);
        }
        /// <summary>
        /// Connects to the login server.
        /// </summary>
        /// <param name="LoginArgs">Arguments used for login. Can be null.</param>
        public void Connect(LoginArgsContainer LoginArgs)
        {
            m_LoginArgs = LoginArgs;

            if (LoginArgs != null)
            {
                ClientEncryptor = LoginArgs.Enc;
                ClientEncryptor.Username = LoginArgs.Username;
            }

            m_Sock.BeginConnect(IPAddress.Parse(m_IP), m_Port, new AsyncCallback(ConnectCallback), m_Sock);
        }
        /// <summary>
        /// Reconnects to a CityServer.
        /// </summary>
        public void Reconnect(ref NetworkClient Client, CityInfo SelectedCity, LoginArgsContainer LoginArgs)
        {
            Client.Disconnect();

            if (LoginArgs.Enc == null)
            {
                Debug.WriteLine("LoginArgs.Enc was null!");
                LoginArgs.Enc = new GonzoNet.Encryption.AESEncryptor(Convert.ToBase64String(PlayerAccount.Hash));
            }
            else if (LoginArgs.Username == null || LoginArgs.Password == null)
            {
                Debug.WriteLine("LoginArgs.Username or LoginArgs.Password was null!");
                LoginArgs.Username = PlayerAccount.Username;
                LoginArgs.Password = Convert.ToBase64String(PlayerAccount.Hash);
            }

            Client.Connect(LoginArgs);
        }
        /// <summary>
        /// Authenticate with the service client to get a token,
        /// Then get info about avatars & cities
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public void InitialConnect(string username, string password)
        {
            lock (NetworkFacade.Client)
            {
                var client = NetworkFacade.Client;
                LoginArgsContainer Args = new LoginArgsContainer();
                Args.Username = username;
                Args.Password = password;

                //Doing the encryption this way eliminates the need to send key across the wire! :D
                SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length);
                byte[] HashBuf = Hash.ComputePasswordHash(Args.Username, Args.Password);

                Args.Enc = new GonzoNet.Encryption.AESEncryptor(Convert.ToBase64String(HashBuf));
                Args.Client = client;

                client.Connect(Args);
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            String isClient = "";
            try
            {
                isClient = args[0];
            }
            catch
            {
                isClient = "false";
            }

            #region GonzoNet Initialization (Server)
            if (isClient.Equals("false"))
            {
                GonzoNet.PacketHandlers.Register(0x01, false, 0, new OnPacketReceive(PacketHandlers.OnLoginRequest));
                GonzoNet.PacketHandlers.Register(0x02, false, 0, new OnPacketReceive(PacketHandlers.OnLoginSuccess));
                GonzoNet.PacketHandlers.Register(0x04, false, 0, new OnPacketReceive(PacketHandlers.OnChallengeRecieved));
                NetworkFacade.Listener.Initialize(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2223));
                ss = new ServerSettings();
                if (!File.Exists("blocked.txt") && ss.CensoringEnabled)
                {
                    Console.WriteLine("Downloading blocked words...");
                    WebClient wc = new WebClient();
                    // I'll make a proper list, which is compressed & encrypted, closer to release
                    wc.DownloadFileAsync(new Uri("http://www.bannedwordlist.com/lists/swearWords.txt"), "blocked.txt");
                }
            }
            #endregion
            #region Information
            Console.SetWindowSize(120, 45);
            string externalip = new WebClient().DownloadString("http://icanhazip.com");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("Welcome to the ");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("TS2 Online ");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("Server application!\n");                                      // Welcome text
            Console.WriteLine("IP Address: " + externalip);                 // IP Address
            Console.SetCursorPosition(0, Console.CursorTop - 1);
            Console.WriteLine("Version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            String command = "";
            Console.ForegroundColor = ConsoleColor.Yellow;
            PacketHandlers.OnChatMessageReceived();
            #endregion
            #region Commands

            while (!command.ToLower().Equals("shutdown"))
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("[ ");
                Console.ForegroundColor = ConsoleColor.White;
                command = Console.ReadLine();
                Console.CursorLeft = 0;
                Console.SetCursorPosition(0, Console.CursorTop - 1);
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.Write("[ " + command + " ]");
                Console.SetCursorPosition(0, Console.CursorTop + 1);
                Console.ForegroundColor = ConsoleColor.Yellow;
                // Now read the command.
                if (command.ToLower().Equals("help"))
                {
                    Console.WriteLine("Help: Commands:");
                    int i = 0;
                    try
                    {
                        while (_commands.commands[i] != null)
                        {
                            Console.WriteLine(_commands.commands[i]);
                            i++;
                        }
                    }
                    catch { }       // I'm not going to do anything here so there's no point wasting a couple of lines for some useless brackets.

                }

                else if (command.ToLower().Contains("forcekill"))
                {
                    string ipaddress = command.Replace("forcekill ", "");
                    try
                    {
                        // Shutdown the client here
                        Console.WriteLine("Client shutdown.");
                    }
                    catch
                    {
                        // Show an error message here - was the IP address connected?
                    }
                }

                else if (command.ToLower().Contains("logoff"))
                {
                    string ipaddress = command.Replace("logoff ", "");
                    try
                    {
                        // Disconnect the client here
                        Console.WriteLine("Client disconnected.");
                    }
                    catch
                    {
                        // Show an error message here - was the IP address connected?  Was it a GUID instead of an IP address?
                    }
                }

                else if (command.ToLower().Contains("getpacketids"))
                {
                    foreach (PacketIDs.PacketTypes packetName in Enum.GetValues(typeof(PacketIDs.PacketTypes)))
                    {
                        Console.WriteLine(packetName);
                        Console.WriteLine("\t" + PacketIDs.PacketDescriptors(packetName) + "\n");
                    }
                }
                else if (command.ToLower().Contains("sendtest"))
                {
                    //GonzoNet requires a log output stream to function correctly. This is built in behavior.
                    GonzoNet.Logger.OnMessageLogged += new MessageLoggedDelegate(Logger_OnMessageLogged);

                    NetworkFacade.Client = new NetworkClient("127.0.0.1", 2223, GonzoNet.Encryption.EncryptionMode.NoEncryption, false);
                    NetworkFacade.Client.OnConnected += new OnConnectedDelegate(m_Client_OnConnected);

                    LoginArgsContainer LoginArgs = new LoginArgsContainer();
                    LoginArgs.Enc = new AESEncryptor("test");
                    LoginArgs.Username = command.ToLower().Replace("sendtest ", "");
                    LoginArgs.Password = "******";
                    LoginArgs.Client = NetworkFacade.Client;

                    SaltedHash Hash = new SaltedHash(new SHA512Managed(), LoginArgs.Username.Length);
                    PacketHandlers.PasswordHash = Hash.ComputePasswordHash(LoginArgs.Username, LoginArgs.Password);

                    NetworkFacade.Client.Connect(LoginArgs);
                    NetworkFacade.Client.Disconnect();
                }

                else if (command.ToLower().Contains("reload"))
                {
                    Console.WriteLine("Reloading modules...");
                    Console.WriteLine("Reticulating Splines...");
                    Console.WriteLine("Getting all tons bacons...");
                    Console.WriteLine("Reload complete.  See reload.log for all logged module startup messages");
                    StreamWriter logWriter = new StreamWriter("reload.log", true);
                    logWriter.Write(Environment.NewLine + System.DateTime.Now.ToString() + " " + "modules currently not implemented");
                    logWriter.Close();
                }
                //Put all new commands above here.
                else if (command.ToLower().Contains("shutdown"))
                {
                    //This enables the command but because it doesn't do anything, it will shut it down because the while loop will stop.
                    //Enabling the command means we don't get an error message like the one below
                }
                else
                {
                    Console.WriteLine("Command " + command + @" not recognized; type ""help"" to get the current list of commands");
                    command = "";
                }
            #endregion
            }
        }
Example #15
0
 private static void m_Client_OnConnected(LoginArgsContainer LoginArgs)
 {
     PacketSenders.SendInitialConnectPacket(LoginArgs.Client, LoginArgs.Username);
     Console.WriteLine("Sent first packet!\r\n");
 }
Example #16
0
        public static void SendLoginRequest(LoginArgsContainer Args)
        {
            PacketStream InitialPacket = new PacketStream((byte)PacketType.LOGIN_REQUEST, 0);
            InitialPacket.WriteHeader();

            //ECDiffieHellmanCng PrivateKey = Args.Client.ClientEncryptor.GetDecryptionArgsContainer()
            //    .AESDecryptArgs.PrivateKey;
            //IMPORTANT: Public key must derive from the private key!
            //byte[] ClientPublicKey = PrivateKey.PublicKey.ToByteArray();

            byte[] NOnce = Args.Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.NOnce;

            //InitialPacket.WriteInt32(((byte)PacketHeaders.UNENCRYPTED +
            //    /*4 is for version*/ 4 + (ClientPublicKey.Length + 1) + (NOnce.Length + 1)));

            SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length);
            byte[] HashBuf = Hash.ComputePasswordHash(Args.Username, Args.Password);
            PlayerAccount.Hash = HashBuf;

            string[] Version = GlobalSettings.Default.ClientVersion.Split('.');

            InitialPacket.WriteByte((byte)int.Parse(Version[0])); //Version 1
            InitialPacket.WriteByte((byte)int.Parse(Version[1])); //Version 2
            InitialPacket.WriteByte((byte)int.Parse(Version[2])); //Version 3
            InitialPacket.WriteByte((byte)int.Parse(Version[3])); //Version 4

            //InitialPacket.WriteByte((byte)ClientPublicKey.Length);
            //InitialPacket.WriteBytes(ClientPublicKey);

            InitialPacket.WriteByte((byte)NOnce.Length);
            InitialPacket.WriteBytes(NOnce);

            Args.Client.Send(InitialPacket.ToArray());
        }
        /// <summary>
        /// Connects to the login server.
        /// </summary>
        /// <param name="LoginArgs">Arguments used for login. Can be null.</param>
        public void Connect(LoginArgsContainer LoginArgs)
        {
            m_LoginArgs = LoginArgs;

            if (LoginArgs != null)
            {
                m_ClientEncryptor = LoginArgs.Enc;
                m_ClientEncryptor.Username = LoginArgs.Username;
            }
            //Making sure that the client is not already connecting to the loginserver.
            if (!m_Sock.Connected)
            {
                m_Sock.BeginConnect(IPAddress.Parse(m_IP), m_Port, new AsyncCallback(ConnectCallback), m_Sock);
            }
        }
Example #18
0
        public static void SendLoginRequestCity(LoginArgsContainer Args)
        {
            PacketStream Packet = new PacketStream((byte)PacketType.LOGIN_REQUEST_CITY, 0);
            Packet.WriteHeader();

            //ECDiffieHellmanCng PrivateKey = Args.Client.ClientEncryptor.GetDecryptionArgsContainer()
            //    .AESDecryptArgs.PrivateKey;
            //IMPORTANT: Public key must derive from the private key!
            //byte[] ClientPublicKey = PrivateKey.PublicKey.ToByteArray();

            byte[] NOnce = Args.Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.NOnce;

            //Packet.WriteInt32(((byte)PacketHeaders.UNENCRYPTED +
            //    (ClientPublicKey.Length + 1) + (NOnce.Length + 1)));

            //Packet.WriteByte((byte)ClientPublicKey.Length);
            //Packet.WriteBytes(ClientPublicKey);

            Packet.WriteByte((byte)NOnce.Length);
            Packet.WriteBytes(NOnce);

            Args.Client.Send(Packet.ToArray());
        }
Example #19
0
        /// <summary>
        /// Authentication failed, so retry.
        /// </summary>
        private void Controller_OnLoginFailureCity()
        {
            if (EventSink.EventQueue[0].ECode == EventCodes.AUTHENTICATION_FAILURE)
            {
                ProgressEvent Progress =
                    new ProgressEvent(EventCodes.PROGRESS_UPDATE);
                Progress.Done = 1;
                Progress.Total = 3;

                LoginArgsContainer LoginArgs = new LoginArgsContainer();
                LoginArgs.Username = NetworkFacade.Client.ClientEncryptor.Username;
                LoginArgs.Password = Convert.ToBase64String(PlayerAccount.Hash);
                LoginArgs.Enc = NetworkFacade.Client.ClientEncryptor;

                NetworkFacade.Controller.Reconnect(ref NetworkFacade.Client, m_SelectedCity, LoginArgs);
                OnTransitionProgress(Progress);

                //Doing this instead of EventQueue.Clear() ensures we won't accidentally remove any
                //events that may have been added to the end.
                EventSink.EventQueue.Remove(EventSink.EventQueue[0]);
            }
        }
        /// <summary>
        /// Creates a new CityTransitionScreen.
        /// </summary>
        /// <param name="SelectedCity">The city being transitioned to.</param>
        /// <param name="CharacterCreated">If transitioning from CreateASim, this should be true.
        /// A CharacterCreateCity packet will be sent to the CityServer. Otherwise, this should be false.
        /// A CityToken packet will be sent to the CityServer.</param>
        public CityTransitionScreen(CityInfo SelectedCity, bool CharacterCreated)
        {
            m_SelectedCity = SelectedCity;
            m_CharacterCreated = CharacterCreated;

            /**
             * Scale the whole screen to 1024
             */
            m_BackgroundCtnr = new UIContainer();
            m_BackgroundCtnr.ScaleX = m_BackgroundCtnr.ScaleY = ScreenWidth / 800.0f;

            /** Background image **/
            m_Background = new UIImage(GetTexture((ulong)FileIDs.UIFileIDs.setup));
            m_Background.ID = "Background";
            m_BackgroundCtnr.Add(m_Background);

            var lbl = new UILabel();
            lbl.Caption = "Version 1.1097.1.0";
            lbl.X = 20;
            lbl.Y = 558;
            m_BackgroundCtnr.Add(lbl);
            this.Add(m_BackgroundCtnr);

            m_LoginProgress = new UILoginProgress();
            m_LoginProgress.X = (ScreenWidth - (m_LoginProgress.Width + 20));
            m_LoginProgress.Y = (ScreenHeight - (m_LoginProgress.Height + 20));
            m_LoginProgress.Opacity = 0.9f;
            this.Add(m_LoginProgress);

            NetworkFacade.Controller.OnNetworkError += new NetworkErrorDelegate(Controller_OnNetworkError);

            LoginArgsContainer LoginArgs = new LoginArgsContainer();
            LoginArgs.Username = NetworkFacade.Client.ClientEncryptor.Username;
            LoginArgs.Enc = NetworkFacade.Client.ClientEncryptor;

            NetworkFacade.Client = new NetworkClient(SelectedCity.IP, SelectedCity.Port);
            //THIS IS IMPORTANT - THIS NEEDS TO BE COPIED AFTER IT HAS BEEN RECREATED FOR
            //THE RECONNECTION TO WORK!
            LoginArgs.Client = NetworkFacade.Client;
            NetworkFacade.Client.OnConnected += new OnConnectedDelegate(Client_OnConnected);
            NetworkFacade.Controller.Reconnect(ref NetworkFacade.Client, SelectedCity, LoginArgs);

            NetworkFacade.Controller.OnCharacterCreationStatus += new OnCharacterCreationStatusDelegate(Controller_OnCharacterCreationStatus);
            NetworkFacade.Controller.OnCityTransfer += new OnCityTransferStatus(Controller_OnCityTransfer);
        }
Example #21
0
 private void m_LoginClient_OnConnected(LoginArgsContainer LoginArgs)
 {
     LoginPacketSenders.SendServerInfo(m_LoginClient);
 }
        private void Client_OnConnected(LoginArgsContainer LoginArgs)
        {
            TSOClient.Network.Events.ProgressEvent Progress =
                new TSOClient.Network.Events.ProgressEvent(TSOClient.Events.EventCodes.PROGRESS_UPDATE);
            Progress.Done = 1;
            Progress.Total = 2;

            if (m_CharacterCreated)
            {
                UIPacketSenders.SendCharacterCreateCity(LoginArgs, PlayerAccount.CurrentlyActiveSim);
                OnTransitionProgress(Progress);
            }
            else
            {
                UIPacketSenders.SendCityToken(NetworkFacade.Client);
                OnTransitionProgress(Progress);
            }
        }
Example #23
0
 private void Client_OnConnected(LoginArgsContainer LoginArgs)
 {
     if (OnStateChange != null) OnStateChange(1, 0f);
 }
        public static void SendLoginRequest(LoginArgsContainer Args)
        {
            //Variable length...
            PacketStream Packet = new PacketStream((byte)PacketType.LOGIN_REQUEST, 0);
            Packet.WriteByte(0x00);

            SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length);
            byte[] HashBuf = new byte[Encoding.ASCII.GetBytes(Args.Password).Length +
                Encoding.ASCII.GetBytes(Args.Username).Length];

            MemoryStream MemStream = new MemoryStream();

            DecryptionArgsContainer DecryptionArgs = Args.Enc.GetDecryptionArgsContainer();
            byte[] EncKey = DecryptionArgs.ARC4DecryptArgs.EncryptionKey;

            MemStream.WriteByte((byte)Args.Username.Length);
            MemStream.Write(Encoding.ASCII.GetBytes(Args.Username), 0, Encoding.ASCII.GetBytes(Args.Username).Length);

            HashBuf = Hash.ComputePasswordHash(Args.Username, Args.Password);
            PlayerAccount.Hash = HashBuf;

            MemStream.WriteByte((byte)HashBuf.Length);
            MemStream.Write(HashBuf, 0, HashBuf.Length);

            MemStream.WriteByte((byte)EncKey.Length);
            MemStream.Write(EncKey, 0, EncKey.Length);

            Packet.WriteUInt16((ushort)(2 + MemStream.ToArray().Length + 4));
            Packet.WriteBytes(MemStream.ToArray());
            //TODO: Change this to write a global client version.
            Packet.WriteByte(0x00); //Version 1
            Packet.WriteByte(0x00); //Version 2
            Packet.WriteByte(0x00); //Version 3
            Packet.WriteByte(0x01); //Version 4

            Args.Client.Send(Packet.ToArray());
        }