public void Connect(string UserName, string Password, string Server, int Port)
        {
            this.UserName = UserName;
            this.Password = Password;
            this.Server   = Server;
            this.Port     = Port;
            string ResponseString;

            Connect(Server, Port);
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }

            WriteMessage("USER " + UserName + "\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }

            WriteMessage("PASS " + Password + "\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
        }
        /// <summary>
        /// Querys the serverinfos
        /// </summary>
        public override void GetServerInfo()
        {
            base.GetServerInfo();
            if (!IsOnline)
            {
                return;
            }
            Query(_QUERY_STATUS);

            if (ResponseString.IndexOf("disconnect") != -1)
            {
                _isOnline = false;
                return;
            }

            string[] lines = ResponseString.Substring(3).Split('\n');
            if (lines.Length < 2)
            {
                _isOnline = false;
                return;
            }
            AddParams(lines[1].Split('\\'));

            if (lines.Length > 2)
            {
                for (int i = 2; i < lines.Length; i++)
                {
                    if (lines[i].Length == 0)
                    {
                        continue;
                    }
                    _players.Add(ParsePlayer(lines[i]));
                }
            }
        }
示例#3
0
        private string ReadNextString()
        {
            int oldOffset = Offset;

            Offset += Response[Offset - 1];

            return(ResponseString.Substring(oldOffset, (Response[oldOffset - 1] - 1)));
        }
示例#4
0
        public override void GetServerInfo()
        {
            base.GetServerInfo();
            if (!IsOnline)
            {
                return;
            }
            Query(_QUERY_STATUS);

            Offset = 23;
            string key, val;
            int    playerOffset = ResponseString.IndexOf(System.Text.Encoding.Default.GetString(new byte[] {
                0, 0, 0, 0
            }));

            playerOffset += 3;

            while (Offset < playerOffset)
            {
                key = ReadNextParam();
                val = ReadNextParam();

                if (key.Length == 0)
                {
                    continue;
                }
                _params[key] = val;
            }

            Offset = playerOffset;

            int pNr;

            while (Offset < Response.Length)
            {
                // ok that's ugly, i fix this when someone playes doom3 online ;)
                try
                {
                    pNr = _players.Add(new Player());
                    _players[pNr].Parameters.Add("playernr", Response[Offset++].ToString());
                    _players[pNr].Ping  = BitConverter.ToInt16(Response, Offset);
                    Offset             += 2;
                    _players[pNr].Score = BitConverter.ToInt16(Response, Offset);
                    Offset             += 4;         // we skip two empty bytes
                    _players[pNr].Name  = ReadNextParam();

                    // is there a next playername?
                    if ((Offset + 7) > Response.Length)
                    {
                        break;
                    }
                }
                catch (ArgumentException)
                {
                    break;
                }
            }
        }
        public void Disconnect()
        {
            string ResponseString;

            WriteMessage("QUIT\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
        }
        public void Delete(Message MessageToDelete)
        {
            string ResponseString;

            WriteMessage("DELE " + MessageToDelete.MessageNumber + "\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
        }
示例#7
0
        // TOTO only tested on BFV
        private void ParseTeam()
        {
            if (!IsOnline)
            {
                return;
            }
            Offset = ResponseString.IndexOf(_SEPERATOR, 7) + 2;

            _teams.Add(ReadNextParam());
            ReadNextParam();
            _teams.Add(ReadNextParam());
        }
示例#8
0
        /// <summary>
        /// Querys the serverinfos
        /// </summary>
        public override void GetServerInfo()
        {
            if (!IsOnline)
            {
                return;
            }
            Query(_QUERY_INFO);
            AddParams(ResponseString.Split('\\'));

            Query(_QUERY_RULES);
            AddParams(ResponseString.Split('\\'));

            Query(_QUERY_PLAYERS);
            ParsePlayers();
        }
        public ICollection <Message> GetMessageList()
        {
            string ResponseString;

            List <Message> ReturnArray = new List <Message>();

            WriteMessage("LIST\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
            bool Done = false;

            while (!Done)
            {
                Regex TempRegex = new Regex(Regex.Escape("+") + "OK.*\r\n");
                if (!ResponseString.EndsWith("\r\n.\r\n", StringComparison.InvariantCulture))
                {
                    while (!ResponseString.EndsWith("\r\n.\r\n", StringComparison.InvariantCulture))
                    {
                        ResponseString += GetResponse();
                    }
                }
                ResponseString = TempRegex.Replace(ResponseString, "");
                string[] Seperator = { "\r\n" };
                string[] Values    = ResponseString.Split(Seperator, StringSplitOptions.RemoveEmptyEntries);
                foreach (string Value in Values)
                {
                    string[] NewSeperator = { " " };
                    string[] Pair         = Value.Split(NewSeperator, StringSplitOptions.RemoveEmptyEntries);
                    if (Pair.Length > 1)
                    {
                        Message TempMessage = new Message();
                        TempMessage.MessageNumber = Int32.Parse(Pair[0], CultureInfo.InvariantCulture);
                        TempMessage.MessageSize   = Int32.Parse(Pair[1], CultureInfo.InvariantCulture);
                        TempMessage.Retrieved     = false;
                        ReturnArray.Add(TempMessage);
                    }
                    else
                    {
                        Done = true;
                        break;
                    }
                }
            }
            return(ReturnArray);
        }
示例#10
0
    public void Main()
    {
        ResponseString responseString = new ResponseString {
            Success = true, StatusCode = 200, Data = "{ foo: \"bar\" }"
        };
        ResponseDecimal responseDecimal = new ResponseDecimal {
            Success = true, StatusCode = 200, Data = 19.99M
        };
        ResponseDateTime responseDateTime = new ResponseDateTime {
            Success = true, StatusCode = 200, Data = DateTime.Parse("4/13/2015 4:00PM")
        };

        GenericPrint("String Response", responseString.Data);
        GenericPrint("Decimal Response", responseDecimal.Data);
        GenericPrint("DateTime Response", responseDateTime.Data);
    }
示例#11
0
        public void ServiceAbout(string service)
        {
            ResponseString wrapper = new ResponseString();

            wrapper.message = "Success";
            wrapper.error   = 0;
            wrapper.action  = service;
            wrapper.info.Add("path", path);
            wrapper.info.Add("path_info", path_info);
            wrapper.info.Add("qstring", qstring);
            wrapper.info.Add("action", action);
            wrapper.info.Add("action_params", action_params);

            // get data
            wrapper.data = "Hi! I am gaming service, and I am reporting for service...";

            util.SerializeTypeJSONToResponse(_context, wrapper);
        }
示例#12
0
        //====== File methods ======

        //@Headers({ "Content-Type: application/json"})
        //@POST("api/v1/upload")
        //Call<ResponseCodes> upload(@Body RequestUpload requestUpload);
        public async Task <ResponseCodes> UploadAsync(RequestUpload requestUpload)
        {
            var uri = new Uri(baseUri + @"api/v1/upload");
            // Сформировать JSON данные
            string jsonContent = JsonConvert.SerializeObject(requestUpload);
            HttpResponseMessage httpResponse = await cmd.PostAsync(uri, jsonContent);

            ResponseString responseString = new ResponseString();

            if (httpResponse.IsSuccessStatusCode)
            {
                responseString = JsonConvert.DeserializeObject <ResponseString>(httpResponse.Content.ToString());
            }
            else
            {
                responseString.Error   = true;
                responseString.ErrCode = "";
                responseString.ErrMsg  = "Ошибка HttpClient.";
            }
            return(responseString);
        }
        // TODO make this generic would be much nicer...
        private void ParsePlayers()
        {
            if (!IsOnline)
            {
                return;
            }
            Offset = ResponseString.IndexOf(_SEPERATOR) + 2;

            int pNr;

            while (Offset < Response.Length)
            {
                pNr = _players.Add(new Player());
                _players[pNr].Name  = ReadNextParam();
                _players[pNr].Score = Int32.Parse(ReadNextParam());
                _players[pNr].Parameters.Add("deaths", ReadNextParam());
                _players[pNr].Ping = Int32.Parse(ReadNextParam());
                _players[pNr].Team = ReadNextParam();
                _players[pNr].Parameters.Add("kills", ReadNextParam());
            }
        }
        public Message GetMessage(Message MessageWanted)
        {
            string ResponseString;

            Message TempMessage = new Message();

            TempMessage.MessageSize   = MessageWanted.MessageSize;
            TempMessage.MessageNumber = MessageWanted.MessageNumber;

            WriteMessage("RETR " + MessageWanted.MessageNumber + "\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
            Regex TempRegex = new Regex(Regex.Escape("+") + "OK.*\r\n");

            ResponseString        = TempRegex.Replace(ResponseString, "");
            TempRegex             = new Regex("\r\n.\r\n$");
            TempMessage.Retrieved = true;
            string BodyText = "";

            while (true)
            {
                if (TempRegex.Match(ResponseString).Success || string.IsNullOrEmpty(ResponseString))
                {
                    BodyText += ResponseString;
                    BodyText  = TempRegex.Replace(BodyText, "");
                    break;
                }
                else
                {
                    BodyText += ResponseString;
                }
                ResponseString = GetResponse();
            }
            TempMessage.MessageBody = new Utilities.Web.Email.MIME.MIMEMessage(BodyText);

            return(TempMessage);
        }
示例#15
0
 public string Respond(string matchedData)
 {
     // evaluates the response to this rule with the given matched data
     return(ResponseString.Replace(VariableSymbol.ToString(), matchedData));
 }
示例#16
0
 protected override void DeserializeElement(XmlReader reader, bool s)
 {
     Key            = reader.GetAttribute(AttributeName);
     ResponseString = reader.ReadElementContentAs(typeof(string), null) as string;
     ResponseString = ResponseString.Trim();
 }
示例#17
0
    public void ResponseInfoReceieved(DataInfo dataInfo)
    {
        ResponseInfo responseInfo = (ResponseInfo)dataInfo;

        Debug.Log("Ответ: " + responseInfo.responseType);
        switch (responseInfo.responseType)
        {
        case ResponseInfo.ResponseType.VisitedOK:
            SyncContext.RunOnUnityThread(() => Links.ToastController.Show("Посещение засчитано!"));
            break;

        case ResponseInfo.ResponseType.ResponseString:
            ResponseString responseString = (ResponseString)responseInfo;
            SyncContext.RunOnUnityThread(() => Links.MainMenuController.QRlayout.ShowLayout(responseString.String));
            break;

        case ResponseInfo.ResponseType.AutorizationOk:
            SyncContext.RunOnUnityThread(Links.LoginLayoutController.OpenMainMenu);
            break;

        case ResponseInfo.ResponseType.ResponseUserInfo:
            ResponseUser tmp = (ResponseUser)responseInfo;

            if (tmp.responseUserType == ResponseUser.ResponseUserType.PurchaseOk)
            {
                Links.DeviceInformation.PlayerData = tmp.data;
                //TODO
                //Отрисовать купленный предмет
                return;
            }

            if (tmp.responseUserType == ResponseUser.ResponseUserType.DescriptionUpdate)
            {
                //Обновить описание!!!
                //TODO
                //Links.DeviceInformation.PlayerData.Description = ""
                Links.DeviceInformation.PlayerData = tmp.data;
                return;
            }

            Links.DeviceInformation.PlayerData = tmp.data;

            Links.LoginLayoutController.OpenMainMenu();
            break;

        case ResponseInfo.ResponseType.AutorizationFalied_WrongLogin:
            SyncContext.RunOnUnityThread(() =>
                                         Links.LoginLayoutController.OpenLoginLayoutWithError("Wrong login!"));
            break;

        case ResponseInfo.ResponseType.AutorizationFailed_WrongPassword:
            SyncContext.RunOnUnityThread(() =>
                                         Links.LoginLayoutController.OpenLoginLayoutWithError("Wrong password!"));
            break;

        case ResponseInfo.ResponseType.RegistartionFailed_ExistLogin:
            SyncContext.RunOnUnityThread(() =>
                                         Links.LoginLayoutController.OpenRegisterWithError("Login already exists!"));
            break;

        case ResponseInfo.ResponseType.ResponseEvents:
            //события на которые записан пользователь
            //TODO

            //actual: все события
            ResponseUserEvent responseUserEvent = (ResponseUserEvent)responseInfo;
            //responseUserEvent.data[0].visited  (не визит а записан)
            Links.DeviceInformation.PlayerEvents = responseUserEvent.data;
            SyncContext.RunOnUnityThread(() => Links.EventsLayout.UpdateList(responseUserEvent.data));
            break;

        case ResponseInfo.ResponseType.ResponseUsers:
            ResponseUsers response = (ResponseUsers)responseInfo;
            switch (response.usersType)
            {
            case ResponseUsers.UsersType.Name:
                SyncContext.RunOnUnityThread(() =>
                                             Links.FindUserLayout.UpdateList(response.players));
                break;

            case ResponseUsers.UsersType.Rating:
                SyncContext.RunOnUnityThread(() => Links.TopPlayersLayout.UpdateTop(response.players));
                break;
            }

            break;

        case ResponseInfo.ResponseType.ResponseUserEvents:
            //не Все предстоящие события (хз вообще что это)
            ResponseEvent responseEvent = (ResponseEvent)responseInfo;
            Links.DeviceInformation.FutureEvents = responseEvent.data;
            //SyncContext.RunOnUnityThread(() => Links.EventsLayout.UpdateList(responseEvent.data));
            break;

        case ResponseInfo.ResponseType.ResponseMainInfo:
            //Серверное время
            ResponseMainInfo mainInfo = (ResponseMainInfo)responseInfo;
            SyncContext.RunOnUnityThread(() => Links.CurrentPlayerGameManagerScript.ResponseMainInfo(mainInfo));
            break;

        case ResponseInfo.ResponseType.ResponseCastle:
            ResponseCastle responsedCastle = (ResponseCastle)responseInfo;
            SyncContext.RunOnUnityThread(() => Links.LastOpenedCastle.CastleResponse(responsedCastle));
            break;

        case ResponseInfo.ResponseType.ResponseReviews:
            ResponseReviews responsedReviews = (ResponseReviews)responseInfo;
            if (responsedReviews.responseReviewsType == ResponseReviews.ResponseReviewsType.CastleReviews)
            {
                SyncContext.RunOnUnityThread(() => Links.LastOpenedCastle.CastleHistoryResponse(responsedReviews));
            }

            if (responsedReviews.responseReviewsType == ResponseReviews.ResponseReviewsType.EventReviews)
            {
                Links.MainMenuController.CommentsLayout.GetComponent <CommentsLayout>()
                .ShowComments(responsedReviews.reviews);
            }

            break;

        case ResponseInfo.ResponseType.ResponseUpdate:
            ResponseUpdate responsedUpdate = (ResponseUpdate)responseInfo;

            switch (responsedUpdate.responseUpdateType)
            {
            case ResponseUpdate.ResponseUpdateType.UpdateEventReviews:
                //TODO
                //TODO
                ResponseReviews reviews = (ResponseReviews)responsedUpdate.updatingData;

                //обновить список комментов!
                //reviews.reviews
                break;

            case ResponseUpdate.ResponseUpdateType.UpdateCastleReviews:
                SyncContext.RunOnUnityThread(() =>
                                             Links.LastOpenedCastle.CastleUpdateResponse(responsedUpdate));
                break;
            }

            break;
        }
    }
示例#18
0
        private void ParsePlayers()
        {
            if (!IsOnline)
            {
                return;
            }

            if (_params.ContainsKey("numplayers"))
            {
                _players = new PlayerCollection();                // Int16.Parse( _params["numplayers"] ) );
            }

            string key, val;
            int    pNr;

            string[] parts = ResponseString.Split('\\');
            for (int i = 1; i < parts.Length; i++)
            {
                if (parts[i] == "queryid" || parts[i] == "final")
                {
                    i++;
                    continue;
                }

                key = parts[i].Substring(0, parts[i].IndexOf("_"));
                pNr = Int16.Parse(parts[i].Substring(parts[i].IndexOf("_") + 1));
                val = parts[++i];

                if (key == "teamname")
                {
                    _teams.Add(val);
                }

                try
                {
                    if (_players[pNr] == null)
                    {
                        _players.Insert(pNr, new Player());
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    _players.Insert(pNr, new Player());
                }

                switch (key)
                {
                case "playername":
                case "player":
                    _players[pNr].Name = val;
                    break;

                case "score":
                case "frags":
                    _players[pNr].Score = Int16.Parse(val);
                    break;

                case "ping":
                    _players[pNr].Ping = Int16.Parse(val);
                    break;

                case "team":
                    _players[pNr].Team = val;
                    break;

                default:
                    _players[pNr].Parameters.Add(key, val);
                    break;
                }
            }
        }