void GetChannels(IPCReceiver receiver, IPCReader data, SyncHandler sync) { var channels = sync.GetAllChannels(); var packet = new IPCWriter(IPC.ChannelList); packet.Write(channels.Count); // server count foreach (var server in channels) { packet.Write((int)server.Key); // server id packet.Write(server.Value.Count); // channel count foreach (var channel in server.Value) { packet.Write(channel.Value.id); packet.Write(channel.Value.type); packet.Write((int)channel.Value.ip); packet.Write(channel.Value.port); packet.Write(channel.Value.maxPlayers); packet.Write(channel.Value.curPlayers); } } receiver.Send(packet); }
// TODO: Rename commands and responses to follow a predictable pattern of XCommand -> XResponse // (e.g. ExecuteCommand and ExecuteResponse instead of Execute and ExecutionFinished) public static ICommand ReadCommand(this IPCReader reader) { var type = reader.ReadByte(); switch ((CommandType)type) { case CommandType.Execute: return(Execute.Deserialize(reader)); case CommandType.FetchMetadata: return(FetchMetadata.Deserialize(reader)); case CommandType.FetchResultRange: return(FetchResultRange.Deserialize(reader)); case CommandType.Deploy: return(Deploy.Deserialize(reader)); case CommandType.ListEnvironmentVariables: return(ListEnvironmentVariables.Deserialize(reader)); case CommandType.PutFile: return(PutFileCommand.Deserialize(reader)); case CommandType.PutDirectory: return(PutDirectoryCommand.Deserialize(reader)); case CommandType.ListFiles: return(ListFilesCommand.Deserialize(reader)); case CommandType.GetFiles: return(GetFilesCommand.Deserialize(reader)); case CommandType.GetServerCapabilities: return(GetServerCapabilitiesCommand.Deserialize(reader)); case CommandType.ExecutionTimedOutAction: return(ExecutionTimedOutActionCommand.Deserialize(reader)); case CommandType.CompressedCommand: return(CompressedCommand.Deserialize(reader)); } throw new InvalidDataException($"Unexpected command type byte: {type}"); }
public static IResponse ReadResponse(this IPCReader reader) { var type = reader.ReadByte(); switch ((ResponseType)type) { case ResponseType.ExecutionCompleted: return(ExecutionCompleted.Deserialize(reader)); case ResponseType.MetadataFetched: return(MetadataFetched.Deserialize(reader)); case ResponseType.ResultRangeFetched: return(ResultRangeFetched.Deserialize(reader)); case ResponseType.EnvironmentVariablesListed: return(EnvironmentVariablesListed.Deserialize(reader)); case ResponseType.PutFile: return(PutFileResponse.Deserialize(reader)); case ResponseType.PutDirectory: return(PutDirectoryResponse.Deserialize(reader)); case ResponseType.ListFiles: return(ListFilesResponse.Deserialize(reader)); case ResponseType.GetFiles: return(GetFilesResponse.Deserialize(reader)); case ResponseType.GetServerCapabilities: return(GetServerCapabilitiesResponse.Deserialize(reader)); case ResponseType.ExecutionTimedOut: return(ExecutionTimedOutResponse.Deserialize(reader)); case ResponseType.ExecutionTerminated: return(ExecutionTerminatedResponse.Deserialize(reader)); case ResponseType.CompressedResponse: return(CompressedResponse.Deserialize(reader)); } throw new InvalidDataException($"Unexpected response type byte: {type}"); }
void AddChannel(IPCReceiver receiver, IPCReader data, SyncHandler sync) { var serverId = data.ReadByte(); var channelId = data.ReadByte(); var type = data.ReadInt32(); var ip = data.ReadUInt32(); var port = data.ReadInt16(); var maxPlayers = data.ReadInt16(); if (!sync.ServerExists(serverId)) { sync.AddServer(serverId); } if (sync.ServerHasChannel(serverId, channelId)) { return; } sync.AddServerChannel(serverId, channelId, new ChannelData(channelId, type, ip, port, maxPlayers, 0)); receiver.SetServerInfo(serverId, channelId); if (!Configuration.serverDBs.ContainsKey(serverId)) { Configuration.LoadMasterServer(serverId); Log.Message("Connecting to Database for Server " + serverId.ToString() + "...", Log.DefaultFG); var db = new DatabaseHandler(Configuration.serverDBTypes[serverId], Configuration.serverDBIPs[serverId], Configuration.serverDBs[serverId], Configuration.serverDBUsers[serverId], Configuration.serverDBPasses[serverId]); sync.AddServerDB(serverId, db); } }
public static ExecutionCompleted Deserialize(IPCReader reader) => new ExecutionCompleted { Status = (ExecutionStatus)reader.ReadByte(), ExitCode = reader.ReadInt32(), Stdout = reader.ReadString(), Stderr = reader.ReadString(), ExecutionTime = reader.ReadInt64(), };
public static FetchResultRange Deserialize(IPCReader reader) => new FetchResultRange { FilePath = reader.ReadLengthPrefixedStringArray(), BinaryOutput = reader.ReadBoolean(), ByteOffset = reader.ReadInt32(), ByteCount = reader.ReadInt32(), OutputOffset = reader.ReadInt32() };
public static Execute Deserialize(IPCReader reader) => new Execute { WorkingDirectory = reader.ReadString(), Executable = reader.ReadString(), Arguments = reader.ReadString(), RunAsAdministrator = reader.ReadBoolean(), ExecutionTimeoutSecs = reader.ReadInt32() };
void AddUser(IPCReceiver receiver, IPCReader data, SyncHandler sync) { var magic = data.ReadUInt64(); var id = data.ReadInt32(); if (!sync.UserExists(magic)) { sync.AddUser(magic, id); } }
public static GetServerCapabilitiesCommand Deserialize(IPCReader reader) { var capabilityCount = reader.Read7BitEncodedInt(); var capabilities = new HashSet <ExtensionCapability>(); for (int i = 0; i < capabilityCount; ++i) { capabilities.Add((ExtensionCapability)reader.ReadByte()); } return(new GetServerCapabilitiesCommand { ExtensionCapabilities = capabilities }); }
public static ListFilesResponse Deserialize(IPCReader reader) { var length = reader.Read7BitEncodedInt(); var files = new FileMetadata[length]; for (int i = 0; i < length; ++i) { files[i] = new FileMetadata(reader.ReadString(), reader.ReadInt64(), reader.ReadDateTime()); } return(new ListFilesResponse { Files = files }); }
public static IResponse Deserialize(IPCReader reader) { var commandData = reader.ReadLengthPrefixedBlob(); using (var uncompresedStream = new MemoryStream()) { using (var inputStream = new MemoryStream(commandData)) using (var dstream = new DeflateStream(inputStream, CompressionMode.Decompress)) dstream.CopyTo(uncompresedStream); uncompresedStream.Seek(0, SeekOrigin.Begin); using (var uncompressedReader = new IPCReader(uncompresedStream)) return(uncompressedReader.ReadResponse()); } }
void GetUser(IPCReceiver receiver, IPCReader data, SyncHandler sync) { var magic = data.ReadUInt64(); var packet = new IPCWriter(IPC.GetUser); if (!sync.UserExists(magic)) { packet.Write(-1); receiver.Send(packet); return; } var id = sync.GetUser(magic); packet.Write(id); receiver.Send(packet); }
public static GetServerCapabilitiesResponse Deserialize(IPCReader reader) => new GetServerCapabilitiesResponse { Info = CapabilityInfo.Deserialize(reader) };
public static EnvironmentVariablesListed Deserialize(IPCReader reader) => new EnvironmentVariablesListed { Variables = reader.ReadLengthPrefixedStringDict() };
public static PutFileCommand Deserialize(IPCReader reader) => new PutFileCommand { Data = reader.ReadLengthPrefixedBlob(), Path = reader.ReadString(), WorkDir = reader.ReadString() };
public static GetFilesResponse Deserialize(IPCReader reader) => new GetFilesResponse { Status = (GetFilesStatus)reader.ReadByte(), Files = reader.ReadLengthPrefixedFileArray() };
public static PutDirectoryCommand Deserialize(IPCReader reader) => new PutDirectoryCommand { Files = reader.ReadLengthPrefixedFileArray(), Path = reader.ReadString(), PreserveTimestamps = reader.ReadBoolean() };
public static PutDirectoryResponse Deserialize(IPCReader reader) => new PutDirectoryResponse { Status = (PutDirectoryStatus)reader.ReadByte() };
void HeartBeat(IPCReceiver receiver, IPCReader data, SyncHandler sync) { var packet = new IPCWriter(IPC.HeartBeat); receiver.Send(packet); }
public static ResultRangeFetched Deserialize(IPCReader reader) => new ResultRangeFetched { Data = reader.ReadLengthPrefixedBlob(), Timestamp = reader.ReadDateTime(), Status = (FetchStatus)reader.ReadByte() };
public static MetadataFetched Deserialize(IPCReader reader) => new MetadataFetched { ByteCount = reader.ReadInt32(), Timestamp = reader.ReadDateTime(), Status = (FetchStatus)reader.ReadByte() };
public static ListFilesCommand Deserialize(IPCReader reader) => new ListFilesCommand { Path = reader.ReadString(), IncludeSubdirectories = reader.ReadBoolean() };
public static GetFilesCommand Deserialize(IPCReader reader) => new GetFilesCommand { UseCompression = reader.ReadBoolean(), RootPath = reader.ReadString(), Paths = reader.ReadLengthPrefixedStringArray() };
public static ExecutionTimedOutActionCommand Deserialize(IPCReader reader) => new ExecutionTimedOutActionCommand { TerminateProcesses = reader.ReadBoolean() };
public static FetchMetadata Deserialize(IPCReader reader) => new FetchMetadata { FilePath = reader.ReadLengthPrefixedStringArray(), BinaryOutput = reader.ReadBoolean() };
public static Deploy Deserialize(IPCReader reader) => new Deploy { Data = reader.ReadLengthPrefixedBlob(), Destination = reader.ReadString() };
public static ExecutionTerminatedResponse Deserialize(IPCReader reader) => new ExecutionTerminatedResponse { TerminatedProcessTree = reader.ReadLengthPrefixedProcessArray() };
public static PutFileResponse Deserialize(IPCReader reader) => new PutFileResponse { Status = (PutFileStatus)reader.ReadByte() };
public static ListEnvironmentVariables Deserialize(IPCReader _) => new ListEnvironmentVariables();