Ejemplo n.º 1
0
        ///<summary>
        /// Send _message to _targets on given _channel
        /// </summary>
        /// <param name="Send"></param>
        private void Send(string _message, int _channel, List <ServerClient> _targets)
        {
            //Anonymous function simply extracts the playerName from ServerClient for logging purposes
            ListTargets listTargets = (x) => {
                string info = "";
                foreach (var obj in x)
                {
                    info += obj.PlayerName + "/";
                }
                return(info);
            };

            Debug.Log(String.Format("Sending Data-> From: {0} To: {1} Data: {2}", this.name, listTargets(_targets), _message));
            byte[] msg = Encoding.Unicode.GetBytes(_message);
            foreach (var target in _targets)
            {
                NetworkTransport.Send(hostId, target.ConnectionId, _channel, msg, (sizeof(char) * _message.Length), out error);
            }
        }
Ejemplo n.º 2
0
        public async Task <ListTargets> GetTargets()
        {
            var credential = DependencyService.Get <ICredentialRetriever>().GetCredential();
            var list       = new ListTargets();

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("umbrella-api-username", UmbrellaApi.USERNAME);
                client.DefaultRequestHeaders.Add("umbrella-api-key", UmbrellaApi.PASSKEY);
                client.DefaultRequestHeaders.Add("umbrella-partner-id", UmbrellaApi.PARTNER_ID);
                var formContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("partner_id", credential.UserID.ToString())
                });
                var response = await client.PostAsync($"{UmbrellaApi.SCHEME}://{UmbrellaApi.API_HOST_URL}/targets/", formContent);

                var responseString = await response.Content.ReadAsStringAsync();

                list = JsonConvert.DeserializeObject <ListTargets>(responseString);
            }

            return(list);
        }