public bool Bind(IDFStream outStream, RemoteFunctionBase function, string name, string proto) { if (!_active || Socket == null) { return(false); } _bindCall.Reset(); { var input = _bindCall.Input; input.method = name; if (proto.Length != 0) { input.plugin = proto; } input.input_msg = function.PInTemplate.GetType().ToString(); input.output_msg = function.POutTemplate.GetType().ToString(); } if (_bindCall.TryExecute(outStream) != CommandResult.CrOk) { return(false); } function.Id = (Int16)_bindCall.Output.assigned_id; return(true); }
public bool bind(IDFStream outStream, RemoteFunctionBase function, string name, string proto) { if (!active || socket == null) { return(false); } bind_call.reset(); { var input = bind_call.input; input.method = name; if (proto.Length != 0) { input.plugin = proto; } input.input_msg = function.p_in_template.GetType().ToString(); input.output_msg = function.p_out_template.GetType().ToString(); } if (bind_call.TryExecute(outStream) != command_result.CR_OK) { return(false); } function.id = (Int16)bind_call.output.assigned_id; return(true); }
public command_result TryExecute(IDFStream stream) { Output tempOut; command_result result = base.TryExecute <Input, Output>(stream, input, out tempOut); output = tempOut; return(result); }
protected TOutput Execute <TInput, TOutput>(IDFStream stream, TInput input) where TInput : class, IExtensible, new() where TOutput : class, IExtensible, new() { TOutput value; var result = TryExecute(stream, input, out value); if (result == CommandResult.CrOk) { return(value); } else { throw new InvalidOperationException("Remotefunction encountered error: " + value); } }
public RemoteClient(IDFStream defaultOutput = null) { _pDefaultOutput = defaultOutput; _active = false; Socket = null; _suspendReady = false; if (_pDefaultOutput == null) { _deleteOutput = true; _pDefaultOutput = new ConsoleDFStream(); } else { _deleteOutput = false; } }
public RemoteClient(IDFStream default_output = null) { p_default_output = default_output; active = false; socket = null; suspend_ready = false; if (p_default_output == null) { delete_output = true; p_default_output = new color_ostream(); } else { delete_output = false; } }
public CommandResult RunCommand(IDFStream output, string cmd, List <string> args) { if (!_active || Socket == null) { output.PrintErr("In RunCommand: client connection not valid.\n"); return(CommandResult.CrFailure); } _runcmdCall.Reset(); _runcmdCall.Input.command = cmd; foreach (var t in args) { _runcmdCall.Input.arguments.Add(t); } return(_runcmdCall.TryExecute(output)); }
public command_result run_command(IDFStream output, string cmd, List <string> args) { if (!active || socket == null) { output.printerr("In RunCommand: client connection not valid.\n"); return(command_result.CR_FAILURE); } runcmd_call.reset(); runcmd_call.input.command = cmd; for (int i = 0; i < args.Count; i++) { runcmd_call.input.arguments.Add(args[i]); } return(runcmd_call.TryExecute(output)); }
public bool Bind(IDFStream output, RemoteClient client, string name, string proto = "") { if (IsValid()) { if (PClient == client && Name == name && Proto == proto) { return(true); } output.PrintErr("Function already bound to %s::%s\n", Proto, Name); return(false); } Name = name; Proto = proto; PClient = client; return(client.Bind(output, this, name, proto)); }
public bool bind(IDFStream output, RemoteClient client, string name, string proto = "") { if (isValid()) { if (p_client == client && this.name == name && this.proto == proto) { return(true); } output.printerr("Function already bound to %s::%s\n", this.proto, this.name); return(false); } this.name = name; this.proto = proto; this.p_client = client; return(client.bind(output, this, name, proto)); }
//virtual void flush_proxy(); public ColorOstreamProxy(IDFStream targetIn) { target = targetIn; }
public CommandResult TryExecute(IDFStream stream, TInput input) { EmptyMessage empty; return(base.TryExecute(stream, input, out empty)); }
protected CommandResult TryExecute <TInput, TOutput>(IDFStream outString, TInput input, out TOutput output) where TInput : class, IExtensible, new() where TOutput : class, IExtensible, new() { if (!IsValid()) { outString.PrintErr("Calling an unbound RPC function %s::%s.\n", Proto, Name); output = default(TOutput); return(CommandResult.CrNotImplemented); } if (PClient.Socket == null) { outString.PrintErr("In call to %s::%s: invalid socket.\n", Proto, Name); output = default(TOutput); return(CommandResult.CrLinkFailure); } MemoryStream sendStream = new MemoryStream(); Serializer.Serialize(sendStream, input); long sendSize = sendStream.Length; if (sendSize > RpcMessageHeader.MaxMessageSize) { outString.PrintErr("In call to %s::%s: message too large: %d.\n", Proto, Name, sendSize); output = default(TOutput); return(CommandResult.CrLinkFailure); } if (!SendRemoteMessage(PClient.Socket, Id, sendStream)) { outString.PrintErr("In call to %s::%s: I/O error in send.\n", Proto, Name); output = default(TOutput); return(CommandResult.CrLinkFailure); } ColorOstreamProxy textDecoder = new ColorOstreamProxy(outString); //output = new Output(); //return command_result.CR_OK; while (true) { RpcMessageHeader header = new RpcMessageHeader(); byte[] buffer = new byte[8]; if (!RemoteClient.ReadFullBuffer(PClient.Socket, buffer, 8)) { outString.PrintErr("In call to %s::%s: I/O error in receive header.\n", Proto, Name); output = default(TOutput); return(CommandResult.CrLinkFailure); } header.Id = BitConverter.ToInt16(buffer, 0); header.Size = BitConverter.ToInt32(buffer, 4); //because something, somewhere, is f*****g retarded //outString.print("Received %d:%d.\n", header.id, header.size); if ((DfHackReplyCode)header.Id == DfHackReplyCode.RpcReplyFail) { output = default(TOutput); if (header.Size == (int)CommandResult.CrOk) { return(CommandResult.CrFailure); } else { return((CommandResult)header.Size); } } if (header.Size < 0 || header.Size > RpcMessageHeader.MaxMessageSize) { outString.PrintErr("In call to %s::%s: invalid received size %d.\n", Proto, Name, header.Size); output = default(TOutput); return(CommandResult.CrLinkFailure); } byte[] buf = new byte[header.Size]; if (!RemoteClient.ReadFullBuffer(PClient.Socket, buf, header.Size)) { outString.PrintErr("In call to %s::%s: I/O error in receive %d bytes of data.\n", Proto, Name, header.Size); output = default(TOutput); return(CommandResult.CrLinkFailure); } switch ((DfHackReplyCode)header.Id) { case DfHackReplyCode.RpcReplyResult: output = Serializer.Deserialize <TOutput>(new MemoryStream(buf)); if (output != null) { return(CommandResult.CrOk); } outString.PrintErr("In call to %s::%s: error parsing received result.\n", Proto, Name); return(CommandResult.CrLinkFailure); case DfHackReplyCode.RpcReplyText: var textData = Serializer.Deserialize <CoreTextNotification>(new MemoryStream(buf)); if (textData != null) { textDecoder.Decode(textData); } else { outString.PrintErr("In call to %s::%s: received invalid text data.\n", Proto, Name); } break; } } }
public command_result TryExecute(IDFStream stream, Input input, out Output output) { return(base.TryExecute <Input, Output>(stream, input, out output)); }
protected command_result TryExecute <Input, Output>(IDFStream outString, Input input, out Output output) where Input : class, message_type, new() where Output : class, message_type, new() { if (!isValid()) { outString.printerr("Calling an unbound RPC function %s::%s.\n", this.proto, this.name); output = default(Output); return(command_result.CR_NOT_IMPLEMENTED); } if (p_client.socket == null) { outString.printerr("In call to %s::%s: invalid socket.\n", this.proto, this.name); output = default(Output); return(command_result.CR_LINK_FAILURE); } GameMap.BeginSample(name); MemoryStream sendStream = new MemoryStream(); ProtoBuf.Serializer.Serialize <Input>(sendStream, input); long send_size = sendStream.Length; if (send_size > RPCMessageHeader.MAX_MESSAGE_SIZE) { outString.printerr("In call to %s::%s: message too large: %d.\n", this.proto, this.name, send_size); output = default(Output); GameMap.EndSample(); return(command_result.CR_LINK_FAILURE); } if (!sendRemoteMessage(p_client.socket, id, sendStream)) { outString.printerr("In call to %s::%s: I/O error in send.\n", this.proto, this.name); output = default(Output); GameMap.EndSample(); return(command_result.CR_LINK_FAILURE); } color_ostream_proxy text_decoder = new color_ostream_proxy(outString); CoreTextNotification text_data; //output = new Output(); //return command_result.CR_OK; while (true) { RPCMessageHeader header = new RPCMessageHeader(); byte[] buffer = new byte[8]; if (!RemoteClient.readFullBuffer(p_client.socket, buffer, 8)) { outString.printerr("In call to %s::%s: I/O error in receive header.\n", this.proto, this.name); output = default(Output); GameMap.EndSample(); return(command_result.CR_LINK_FAILURE); } header.id = BitConverter.ToInt16(buffer, 0); header.size = BitConverter.ToInt32(buffer, 4); //because something, somewhere, is f*****g retarded //outString.print("Received %d:%d.\n", header.id, header.size); if ((DFHackReplyCode)header.id == DFHackReplyCode.RPC_REPLY_FAIL) { output = default(Output); GameMap.EndSample(); if (header.size == (int)command_result.CR_OK) { return(command_result.CR_FAILURE); } else { return((command_result)header.size); } } if (header.size < 0 || header.size > RPCMessageHeader.MAX_MESSAGE_SIZE) { outString.printerr("In call to %s::%s: invalid received size %d.\n", this.proto, this.name, header.size); output = default(Output); GameMap.EndSample(); return(command_result.CR_LINK_FAILURE); } byte[] buf = new byte[header.size]; if (!RemoteClient.readFullBuffer(p_client.socket, buf, header.size)) { outString.printerr("In call to %s::%s: I/O error in receive %d bytes of data.\n", this.proto, this.name, header.size); output = default(Output); GameMap.EndSample(); return(command_result.CR_LINK_FAILURE); } switch ((DFHackReplyCode)header.id) { case DFHackReplyCode.RPC_REPLY_RESULT: //if (buf.Length >= 50) //{ // String tempString = ""; // for (int i = header.size - 50; i < header.size; i++) // { // //if (Char.IsControl((char)buf[i])) // tempString += (byte)buf[i]; // //else // // tempString += (char)buf[i]; // tempString += ","; // } // UnityEngine.Debug.Log("Got buf[" + buf.Length + "] = " + tempString); //} output = ProtoBuf.Serializer.Deserialize <Output>(new MemoryStream(buf)); if (output == null) { outString.printerr("In call to %s::%s: error parsing received result.\n", this.proto, this.name); GameMap.EndSample(); return(command_result.CR_LINK_FAILURE); } GameMap.EndSample(); return(command_result.CR_OK); case DFHackReplyCode.RPC_REPLY_TEXT: text_data = ProtoBuf.Serializer.Deserialize <CoreTextNotification>(new MemoryStream(buf)); if (text_data != null) { text_decoder.decode(text_data); } else { outString.printerr("In call to %s::%s: received invalid text data.\n", this.proto, this.name); } break; default: break; } } }
//virtual void flush_proxy(); public color_ostream_proxy(IDFStream targetIn) { target = targetIn; }