Example #1
0
        public void RecreateClient()
        {
            if (RefClient != null)
            {
                RefClient.Dispose();
                RefClient = null;
            }

            RefClient = new WebClient();
            RefClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0");
            RefClient.Headers.Add(HttpRequestHeader.AcceptLanguage, "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4");
            RefClient.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
        }
Example #2
0
        protected string SendRequest(string action)
        {
            Account.LastActionTime = DateTime.Now;
            if ((DateTime.Now - LastSendRequestTimeStamp).TotalSeconds < Account.Settings.MinSendRequestInterval)
            {
                ThreadSleep(Account.Settings.MinSendRequestInterval, Account.Settings.MinSendRequestInterval);
                ExtendedLog(this, new MessageEventsArgs("Send Action Sleep"));
            }

            string s   = "";
            int    foo = 0;

            if (CheckServerConnection())
            {
                DoReLogin(ref s, ref foo);
                if (ExtendedLog != null)
                {
                    ExtendedLog(this, new MessageEventsArgs("Relogin"));
                }
            }

            if (action == ActionTypes.LoginToSF)
            {
                if (Account.Settings.HasLogin)
                {
                    throw new Exception("Fehler im SendRequest");
                }
                else                     //einziger Sonderfall ist das Login in SF
                {
                    streamData   = RefClient.OpenRead(String.Concat("http://", Account.Settings.Server, ".sfgame.de/request.php?req=00000000000000000000000000000000002", Account.Settings.Username, ";", Account.Settings.PasswordHash, ";", "v1.70&random=%2&rnd=", RandomValue, (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds));
                    streamReader = new StreamReader(streamData);
                    string sData = streamReader.ReadToEnd();
                    return(sData);
                }
            }

            int count = 3;

            do
            {
                if (count < 0)
                {
                    throw new Exception("Can't login anymore");
                }

                if (s == "E065" || s == "+E065")
                {
                    DoReLogin(ref s, ref count);
                    ExtendedLog(this, new MessageEventsArgs("Relogin wegen Fehler E065"));
                }

                streamData   = RefClient.OpenRead(String.Concat("http://", Account.Settings.Server, ".sfgame.de/request.php?req=", Account.Settings.SessionID, action, "&random=%2&rnd=", RandomValue, (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds));
                streamReader = new StreamReader(streamData);
                s            = streamReader.ReadToEnd();

                if (ExtendedLog != null && !action.StartsWith("517"))
                {
                    ExtendedLog(this, new MessageEventsArgs(action + Environment.NewLine + s));
                }
            } while (s == "E065" || s == "+E065");

            LastSendRequestTimeStamp = DateTime.Now;
            return(s);
        }