Beispiel #1
0
        public bool SendCommandToServer(string serverIp, BaseCommand command, ClientCommandType clientCommandType)
        {
            var commandHeader = new ClientCommandHeader
            {
                Type = clientCommandType
            };

            var client = new TcpClient();

            try
            {
                client.Connect(serverIp, Settings.ServerPort);

                // + составить байты из ClientHeader и сериализации команды (+prepend with length)
                byte[] messageBytes           = CommandUtils.ConcatByteArrays(commandHeader.ToBytes(), command.ToBytes());
                byte[] messageBytesWithLength = CommandUtils.PrependLengthBytes(messageBytes);

                // + отправить байты в NetworkStream
                NetworkStream networkStream = client.GetStream();
                networkStream.Write(messageBytesWithLength, 0, messageBytesWithLength.Length);

                // + Обработать ответ
                HandleServerResponse(client);
            }
            catch (SocketException)
            {
                Error("Cannot sent command to server");
                return(false);
            }

            return(true);
        }
 public ClientCommand(ClientCommandType _type, string _playerInfo = null, string _voteForLevelId = null)
 {
     version        = BSMultiplayerClient.version;
     commandType    = _type;
     playerInfo     = _playerInfo;
     voteForLevelId = _voteForLevelId;
 }
Beispiel #3
0
        /// <summary>
        /// Send message to HarmonyHub to request Configuration.
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetConfig()
        {
            _clientCommand = ClientCommandType.GetConfig;

            var iqToSend = new IQ { Type = IqType.get, Namespace = "", From = "1", To = "guest" };
            iqToSend.AddChild(HarmonyDocuments.ConfigDocument());
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);
        }
Beispiel #4
0
        /// <summary>
        /// Send message to HarmonyHub to request Configuration.
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetConfig()
        {
            _clientCommand = ClientCommandType.GetConfig;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.ConfigDocument());
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);
        }
Beispiel #5
0
        /// <summary>
        /// Send message to HarmonyHub to start a given activity
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="activityId"></param>
        public void StartActivity(string activityId)
        {
            _clientCommand = ClientCommandType.StartActivity;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.StartActivityDocument(activityId));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);
        }
Beispiel #6
0
        /// <summary>
        /// Send message to HarmonyHub to request to press a button
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="command"></param>
        public void PressButton(string deviceId, string command)
        {
            _clientCommand = ClientCommandType.PressButton;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.IrCommandDocument(deviceId, command));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 5);

            WaitForData(5);
        }
Beispiel #7
0
        /// <summary>
        /// Send message to HarmonyHub to request current activity
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetCurrentActivity()
        {
            EnsureConnection();

            _clientCommand = ClientCommandType.GetCurrentActivity;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.GetCurrentActivityDocument());
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);
        }
Beispiel #8
0
 private void Send(ClientCommandType type, object payload)
 {
     Send(Helpers.CreateClientCommand(type, payload));
 }
Beispiel #9
0
 public ClientCommand(ClientCommandType _type, string _playerInfo = null)
 {
     commandType = _type;
     playerInfo  = _playerInfo;
 }
Beispiel #10
0
        /// <summary>
        /// Send message to HarmonyHub to start a given activity
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="activityId"></param>
        public void StartActivity(string activityId)
        {
            _clientCommand = ClientCommandType.StartActivity;

            var iqToSend = new IQ { Type = IqType.get, Namespace = "", From = "1", To = "guest" };
            iqToSend.AddChild(HarmonyDocuments.StartActivityDocument(activityId));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);
        }
Beispiel #11
0
        /// <summary>
        /// Send message to HarmonyHub to request to press a button
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="command"></param>
        public void PressButton(string deviceId, string command)
        {
            _clientCommand = ClientCommandType.PressButton;

            var iqToSend = new IQ { Type = IqType.get, Namespace = "", From = "1", To = "guest" };
            iqToSend.AddChild(HarmonyDocuments.IRCommandDocument(deviceId, command));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            iqGrabber.SendIq(iqToSend, 5);

            WaitForData(5);
        }
Beispiel #12
0
 public static ClientCommand CreateClientCommand(ClientCommandType type, object payload) => new ClientCommand(type, JObject.FromObject(payload));
Beispiel #13
0
 public ClientCommand(ClientCommandType _type, string _playerInfo = null, string _voteForLevelId = null)
 {
     commandType    = _type;
     playerInfo     = _playerInfo;
     voteForLevelId = _voteForLevelId;
 }
 public ClientCommand(ClientCommandType _type, string _playerInfo = null)
 {
     version     = BSMultiplayerClient.version;
     commandType = _type;
     playerInfo  = _playerInfo;
 }
Beispiel #15
0
 public ClientCommand(ClientCommandType type, string indetifier)
 {
     Type             = type;
     ClientIdentifier = indetifier;
 }