示例#1
0
        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);
        }
示例#2
0
        // 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}");
        }
示例#3
0
        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}");
        }
示例#4
0
        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);
            }
        }
示例#5
0
 public static ExecutionCompleted Deserialize(IPCReader reader) => new ExecutionCompleted
 {
     Status        = (ExecutionStatus)reader.ReadByte(),
     ExitCode      = reader.ReadInt32(),
     Stdout        = reader.ReadString(),
     Stderr        = reader.ReadString(),
     ExecutionTime = reader.ReadInt64(),
 };
示例#6
0
 public static FetchResultRange Deserialize(IPCReader reader) => new FetchResultRange
 {
     FilePath     = reader.ReadLengthPrefixedStringArray(),
     BinaryOutput = reader.ReadBoolean(),
     ByteOffset   = reader.ReadInt32(),
     ByteCount    = reader.ReadInt32(),
     OutputOffset = reader.ReadInt32()
 };
示例#7
0
 public static Execute Deserialize(IPCReader reader) => new Execute
 {
     WorkingDirectory     = reader.ReadString(),
     Executable           = reader.ReadString(),
     Arguments            = reader.ReadString(),
     RunAsAdministrator   = reader.ReadBoolean(),
     ExecutionTimeoutSecs = reader.ReadInt32()
 };
示例#8
0
        void AddUser(IPCReceiver receiver, IPCReader data, SyncHandler sync)
        {
            var magic = data.ReadUInt64();
            var id    = data.ReadInt32();

            if (!sync.UserExists(magic))
            {
                sync.AddUser(magic, id);
            }
        }
示例#9
0
        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
            });
        }
示例#10
0
        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
            });
        }
示例#11
0
        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());
            }
        }
示例#12
0
        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);
        }
示例#13
0
 public static GetServerCapabilitiesResponse Deserialize(IPCReader reader) => new GetServerCapabilitiesResponse
 {
     Info = CapabilityInfo.Deserialize(reader)
 };
示例#14
0
 public static EnvironmentVariablesListed Deserialize(IPCReader reader) => new EnvironmentVariablesListed
 {
     Variables = reader.ReadLengthPrefixedStringDict()
 };
示例#15
0
 public static PutFileCommand Deserialize(IPCReader reader) => new PutFileCommand
 {
     Data    = reader.ReadLengthPrefixedBlob(),
     Path    = reader.ReadString(),
     WorkDir = reader.ReadString()
 };
示例#16
0
 public static GetFilesResponse Deserialize(IPCReader reader) => new GetFilesResponse
 {
     Status = (GetFilesStatus)reader.ReadByte(),
     Files  = reader.ReadLengthPrefixedFileArray()
 };
示例#17
0
 public static PutDirectoryCommand Deserialize(IPCReader reader) => new PutDirectoryCommand
 {
     Files = reader.ReadLengthPrefixedFileArray(),
     Path  = reader.ReadString(),
     PreserveTimestamps = reader.ReadBoolean()
 };
示例#18
0
 public static PutDirectoryResponse Deserialize(IPCReader reader) => new PutDirectoryResponse
 {
     Status = (PutDirectoryStatus)reader.ReadByte()
 };
示例#19
0
        void HeartBeat(IPCReceiver receiver, IPCReader data, SyncHandler sync)
        {
            var packet = new IPCWriter(IPC.HeartBeat);

            receiver.Send(packet);
        }
示例#20
0
 public static ResultRangeFetched Deserialize(IPCReader reader) => new ResultRangeFetched
 {
     Data      = reader.ReadLengthPrefixedBlob(),
     Timestamp = reader.ReadDateTime(),
     Status    = (FetchStatus)reader.ReadByte()
 };
示例#21
0
 public static MetadataFetched Deserialize(IPCReader reader) => new MetadataFetched
 {
     ByteCount = reader.ReadInt32(),
     Timestamp = reader.ReadDateTime(),
     Status    = (FetchStatus)reader.ReadByte()
 };
示例#22
0
 public static ListFilesCommand Deserialize(IPCReader reader) => new ListFilesCommand
 {
     Path = reader.ReadString(),
     IncludeSubdirectories = reader.ReadBoolean()
 };
示例#23
0
 public static GetFilesCommand Deserialize(IPCReader reader) => new GetFilesCommand
 {
     UseCompression = reader.ReadBoolean(),
     RootPath       = reader.ReadString(),
     Paths          = reader.ReadLengthPrefixedStringArray()
 };
示例#24
0
 public static ExecutionTimedOutActionCommand Deserialize(IPCReader reader) => new ExecutionTimedOutActionCommand
 {
     TerminateProcesses = reader.ReadBoolean()
 };
示例#25
0
 public static FetchMetadata Deserialize(IPCReader reader) => new FetchMetadata
 {
     FilePath     = reader.ReadLengthPrefixedStringArray(),
     BinaryOutput = reader.ReadBoolean()
 };
示例#26
0
 public static Deploy Deserialize(IPCReader reader) => new Deploy
 {
     Data        = reader.ReadLengthPrefixedBlob(),
     Destination = reader.ReadString()
 };
示例#27
0
 public static ExecutionTerminatedResponse Deserialize(IPCReader reader) => new ExecutionTerminatedResponse
 {
     TerminatedProcessTree = reader.ReadLengthPrefixedProcessArray()
 };
示例#28
0
 public static PutFileResponse Deserialize(IPCReader reader) => new PutFileResponse
 {
     Status = (PutFileStatus)reader.ReadByte()
 };
示例#29
0
 public static ListEnvironmentVariables Deserialize(IPCReader _) => new ListEnvironmentVariables();