public override bool onHandshake()
        {
            base.SendMessage(new MsgClientSettings(base.Client.Properties.AllowChannels, base.Client.Properties.AllowPeers));

            SyncObject syncObject = null;

            if (!(syncObject = base.ReceiveMessage((IMessage message) =>
            {
                MsgClientInfo mci = message as MsgClientInfo;

                if (mci != null)
                {
                    Client.Connection.ClientId = mci.ClientId;
                    Client.Token = mci.Token;
                    Client.VirtualIP = mci.VirtualIP;

                    if (Client.UseUDP)
                    {
                        Client.UdpHandshakeCode = mci.UdpHandshakeCode;
                    }
                    return(true);
                }
                return(false);
            })).Wait <bool>(false, 30000))
            {
                Client.Disconnect(DisconnectReason.TimeOut);
                Client.onException(new Exception("Handshake went wrong, CHS_ClientInfo"), ErrorType.Core);
                if (syncObject.TimedOut)
                {
                    throw new TimeoutException(OutOfSyncMessage);
                }
                throw new Exception("Failed to retrieve the Client Id");
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void ProcessPacket(PatchServer server, byte[] buffer)
        {
            if (InvokeRequired)
            {
                Invoke(new Action <PatchServer, byte[]>(ProcessPacket), server, buffer);
                return;
            }

            if (buffer.Length < 4)
            {
                return;
            }

            PacketType type = (PacketType)BitConverter.ToUInt32(buffer, 2);

            switch (type)
            {
            case PacketType.MsgClientInfo:
                MsgClientInfo msg  = new MsgClientInfo(buffer);
                List <string> list = msg.GetStrings();
                if (list.Count <= 0)
                {
                    Kernel.HasAgreedPrivacy = true;
                    RequestPatches(AutoUpdateRequestType.CheckForLauncherUpdates, server);
                    return;
                }

                string strPrivacyDate = m_ifConfig.GetEntryValue("Config", "TermsOfPrivacy").ToString();
                if (!DateTime.TryParse(strPrivacyDate, out DateTime date) ||
                    !DateTime.TryParse(list[0], out DateTime serverTime) ||
                    serverTime > date)
                {
                    if (new FrmTermsOfPrivacy(m_szPrivacyTerms).ShowDialog(this) != DialogResult.OK)
                    {
                        NoDownload(UpdateReturnMessage.PrivacyNotAccepted, false);
                        return;
                    }

                    m_ifConfig.SetValue("Config", "TermsOfPrivacy", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                Kernel.HasAgreedPrivacy = true;
                Kernel.Stage            = AutoPatchStage.WaitingForUpdaterPatchs;
                RequestPatches(AutoUpdateRequestType.CheckForLauncherUpdates, server);
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     This method is invoked when the client has been approved of connecting to the server. The client should
        ///     be constructed in this method, and cipher algorithms should be initialized. If any packets need to be
        ///     sent in the connection state, they should be sent here.
        /// </summary>
        /// <param name="pState">Represents the status of an asynchronous operation.</param>
        public void Connect(AsynchronousState pState)
        {
            var pServer = new PatchServer(this, pState.Socket);

            pState.Client = pServer;

            Program.FrmMain.Edit(Program.FrmMain.lblCenterStatus, LabelAsyncOperation.Text, LanguageManager.GetString("StrCheckingPrivacyTerms"));

            MsgClientInfo msg = new MsgClientInfo();

            msg.MacAddress = Program.FrmMain.GetMacAddress();
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.OPERATING_SYSTEM, MsgClientInfo.OperatingSystem).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.BASE_BOARD, MsgClientInfo.BaseBoard).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.PROCESSOR, MsgClientInfo.Processor).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.PHYSICAL_MEMORY, MsgClientInfo.PhysicalMemory).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.VIDEO_CONTROLLER, MsgClientInfo.VideoController).Values.ToArray());
            pServer.Send(msg);
        }
        public void ProcessClientInfo(User user, byte[] buffer)
        {
            /**
             * Todo store user data securely
             * Todo develop something to encrypt data
             */
            MsgClientInfo msg = new MsgClientInfo(buffer);

            Program.WriteLog($"IPAddress [{user.IpAddress}] has connected [MacAddress:{msg.MacAddress}]");

            /**
             * Todo Send user info and Mac Address to the login server to allow connections.
             */

            user.MacAddress = msg.MacAddress;

            if (Kernel.AllowedUsers.ContainsKey(user.MacAddress) || !Kernel.AllowedUsers.TryAdd(user.MacAddress, user))
            {
                user.Send(new MsgRequestInfo
                {
                    CurrentVersion = 0,
                    Mode           = AutoUpdateRequestType.CheckForGameUpdates
                });
                return;
            }

            /**
             * Sends the latest update! Since it's web host we wont have problems with this. The client
             * will just display the page! :D
             */
            MsgClientInfo back = new MsgClientInfo();

            back.MacAddress = msg.MacAddress;
            back.Append(Kernel.PrivacyTermsUpdate.ToString("yyyy-MM-dd HH:mm:ss"));
            user.Send(back);
        }