Example #1
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);
            }
        }
Example #2
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}");
        }
Example #3
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}");
        }
Example #4
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(),
 };
Example #5
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
            });
        }
Example #6
0
 public static GetFilesResponse Deserialize(IPCReader reader) => new GetFilesResponse
 {
     Status = (GetFilesStatus)reader.ReadByte(),
     Files  = reader.ReadLengthPrefixedFileArray()
 };
Example #7
0
 public static PutDirectoryResponse Deserialize(IPCReader reader) => new PutDirectoryResponse
 {
     Status = (PutDirectoryStatus)reader.ReadByte()
 };
Example #8
0
 public static PutFileResponse Deserialize(IPCReader reader) => new PutFileResponse
 {
     Status = (PutFileStatus)reader.ReadByte()
 };
Example #9
0
 public static ResultRangeFetched Deserialize(IPCReader reader) => new ResultRangeFetched
 {
     Data      = reader.ReadLengthPrefixedBlob(),
     Timestamp = reader.ReadDateTime(),
     Status    = (FetchStatus)reader.ReadByte()
 };
Example #10
0
 public static MetadataFetched Deserialize(IPCReader reader) => new MetadataFetched
 {
     ByteCount = reader.ReadInt32(),
     Timestamp = reader.ReadDateTime(),
     Status    = (FetchStatus)reader.ReadByte()
 };