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; }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
private void Send(ClientCommandType type, object payload) { Send(Helpers.CreateClientCommand(type, payload)); }
public ClientCommand(ClientCommandType _type, string _playerInfo = null) { commandType = _type; playerInfo = _playerInfo; }
/// <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); }
/// <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); }
public static ClientCommand CreateClientCommand(ClientCommandType type, object payload) => new ClientCommand(type, JObject.FromObject(payload));
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; }
public ClientCommand(ClientCommandType type, string indetifier) { Type = type; ClientIdentifier = indetifier; }