public override Task <DemoRpcMessageResponse> ProcessRequestOnMaster(INetworkMaster master, DemoRpcMessage request, string clientId) { Debug.Log($"Master got message: {request.message} from {clientId}"); return(Task.FromResult(new DemoRpcMessageResponse() { success = true, })); }
public override Task <DemoRpcSetClientStateResponse> ProcessRequestOnMaster(INetworkMaster master, DemoRpcSetClientState request, string clientId) { return(Task.FromResult(new DemoRpcSetClientStateResponse() { success = false, errorMessage = "Not supported" })); }
public async Task Connect(INetworkMaster master) { await Initialize(); var transactionManager = new RelayTransactionManager(); var options = await master.MasterOptions; var remote = await Remote; var eventHandler = new NetworkEventHandler(this, master); var masterService = new RelayMaster(eventHandler, transactionManager); var networkConnection = new NetworkConnection(this, masterService, eventHandler); // Try to connect transactionManager.SetEventLoop(true); master.NetworkConnection = networkConnection; await masterService.Connect(remote, options); // Save active connections _active.Add(new NetworkActiveService() { NetworkConnection = networkConnection, TransactionManager = transactionManager }); }
public override Task <DemoRpcSetUsernameResponse> ProcessRequestOnMaster(INetworkMaster master, DemoRpcSetUsername request, string clientId) { lock (Users) { if (Users.Contains(request.requestedPlayerName)) { return(Task.FromResult(new DemoRpcSetUsernameResponse() { success = false, errorMessage = "Invalid name, already in use", suggestedName = $"{request.requestedPlayerName}-{Guid.NewGuid()}" })); } else { Users.Add(request.requestedPlayerName); return(Task.FromResult(new DemoRpcSetUsernameResponse() { success = true })); } } }
private async Task VerifyPermission(NetworkConnection connection, NetworkCommand command, INetworkMaster master, string fromClientId) { if (!await connection.Permissions.IsPermittedOnMaster(command, master, fromClientId)) { throw new NetworkException(NetworkException.NetworkExceptionType.NotPermitted); } }
public async Task <NetworkCommand> ProcessIncomingMessage(NetworkConnection connection, NetworkCommand command, string raw, INetworkMaster master, string fromClientId) { // This is correct; we handle requests from clients on the master. var binding = FindBindingFor(command, _fromClient); if (binding == null) { throw new NetworkException(NetworkException.NetworkExceptionType.UnsupportedCommandType, command.commandInternalType); } try { var fullRequest = binding.DeserializeRequest(raw); await VerifyPermission(connection, fullRequest, master, fromClientId); return(await binding.HandleRequest(master, fullRequest, fromClientId)); } catch (Exception error) { throw new NetworkException(NetworkException.NetworkExceptionType.CommandFailed, error); } }
public NetworkEventHandler(NetworkConnectionManager manager, INetworkMaster master) { _manager = manager; _master = master; _commands = manager.Commands(); }
public Task <bool> IsPermittedOnMaster(NetworkCommand command, INetworkMaster clientId, string fromClientId) { return(Task.FromResult(true)); }
public abstract Task <TResponse> ProcessRequestOnMaster(INetworkMaster master, TRequest request, string clientId);