Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  01
Language: C/C++
Code:
namespace QScalp.AppService
{
    using QScalp;
    using QScalp.Licensing;
    using System;
    using System.IO;
    using System.Net;
    using System.Runtime.InteropServices;
    using System.Text;

    public static class AppServiceRequest
    {
        private const string appServiceUrl = "http://www.qscap.ru/ice";
        private const string keyExpireFmt = "dd.MM.yyyy HH:mm:ss";
        private const int responseMaxLength = 0x400;
        private static readonly char[] sepatator = new char[] { '|' };
        private const string signature = "QScalp AppService Protocol";
        private static readonly DateTime unixEpoch = new DateTime(0x7b2, 1, 1).ToLocalTime();

        public static AppServiceReply Send(RequestType requestType, string text, string secInfo = null)
        {
            string str2;
            string str3;
            int appSvcLastId;
            int appSvcFlags;
            string str = sepatator[0].ToString();
            LicenseKey key = License.GetKey();
            if (key != null)
            {
                str2 = key.ToString();
                str3 = (key.ExpireDateTime == DateTime.MaxValue) ? "*" : key.ExpireDateTime.ToString("dd.MM.yyyy HH:mm:ss");
            }
            else
            {
                str2 = string.IsNullOrWhiteSpace(License.KeyText) ? "-" : "--";
                str3 = string.Empty;
            }
            if (Env.Workspace != null)
            {
                appSvcLastId = Env.Workspace.AppSvcLastId;
                appSvcFlags = Env.Workspace.AppSvcFlags;
            }
            else
            {
                appSvcLastId = -1;
                appSvcFlags = -1;
            }
            byte[] bytes = Encoding.UTF8.GetBytes(string.Concat(new object[] { 
                "QScalp AppService Protocol", str, ((Program.Version.Major << 0x18) | (Program.Version.Minor << 0x10)) | (Program.Version.Build & 0xffff), str, (int) requestType, str, Environment.OSVersion, str, Env.Id, str, Env.UserId, str, str2, str, str3, str,
                secInfo, str, Program.Token.ToString("X"), str, appSvcLastId, str, appSvcFlags, str, text
            }));
            AppServiceReply reply = new AppServiceReply();
            try
            {
                WebRequest request = WebRequest.Create("http://www.qslp.ru/appice");
                request.Method = "POST";
                request.ContentType = "text/plain; charset=utf-8";
                request.ContentLength = bytes.Length;
                request.GetRequestStream().Write(bytes, 0, bytes.Length);
                using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        bytes = new byte[0x400];
                        int count = stream.Read(bytes, 0, bytes.Length);
                        string[] strArray = Encoding.UTF8.GetString(bytes, 0, count).Split(sepatator);
                        if ((strArray.Length < 2) || (strArray[0] != "QScalp AppService Protocol"))
                        {
                            throw new Exception("Incorrect reply");
                        }
                        ReplyFlags flags = (ReplyFlags) int.Parse(strArray[1]);
                        int num4 = 2;
                        if ((flags & ReplyFlags.Message) != ReplyFlags.None)
                        {
                            reply.MessageId = int.Parse(strArray[num4++]);
                            reply.Message = strArray[num4++];
                        }
                        if ((flags & ReplyFlags.LicenseKey) != ReplyFlags.None)
                        {
                            reply.LicenseKey = strArray[num4++];
                        }
                        if ((flags & ReplyFlags.SrvState) != ReplyFlags.None)
                        {
                            reply.State1 = unixEpoch.AddSeconds((double) int.Parse(strArray[num4++]));
                            reply.State2 = unixEpoch.AddSeconds((double) int.Parse(strArray[num4++]));
                        }
                        if ((flags & ReplyFlags.KeyBack) != ReplyFlags.None)
                        {
                            reply.KeyBack = true;
                        }
                    }
                    return reply;
                }
            }
            catch (Exception exception)
            {
                reply.Error = exception.Message;
            }
            return reply;
        }

        [Flags]
        private enum ReplyFlags
        {
            KeyBack = 8,
            LicenseKey = 2,
            Message = 1,
            None = 0,
            SrvState = 4
        }
    }
}

     
Comments: