internal Task HandleBroadcastAsync(ControllerParameter parameter) { var packet = parameter.Packet; var data = packet.Data; var senderId = packet.SenderId; // if senderId == environment.ClientId then ... var address = parameter.Address; var tcpPort = data["tcpPort"].As <int>(); var udpPort = data["udpPort"].As <int>(); var name = data["name"].As <string>(); var text = data["text"].As <string>(); var imageHash = data["imageHash"].As <string>(); var instance = default(LinkProfile); var profile = Op.Lock(locker, () => profiles.GetOrAdd(senderId, key => (instance = new LinkProfile(key, LinkProfileType.Client)))); return(client.UpdateUIAsync(() => { profile.Name = name; profile.Text = text; profile.Address = address; profile.TcpPort = tcpPort; profile.UdpPort = udpPort; profile.LastOnlineDateTime = DateTime.Now; profile.ProfileStatus = LinkProfileStatus.Online; profile.RemoteImageHash = imageHash; if (instance != null) { client.ProfileCollection.Add(profile); } })); }
internal async Task HandleImageAsync(ControllerParameter parameter) { var data = parameter.Packet.Data; var imageHash = data["imageHash"].As <string>(); var message = new ImageMessage(data["messageId"].As <string>()) { ImageHash = imageHash, Status = MessageStatus.Pending }; try { if (await ResponseAsync(parameter, message) == false) { return; } if (!Cache.Exists(imageHash, out var fullpath)) { fullpath = await Cache.RequestAsync(imageHash, parameter.SenderProfile.GetTcpEndPoint(), cancellation.Token); } await UpdateUIAsync(() => { message.ImagePath = fullpath; message.Status = MessageStatus.Success; }); } catch (Exception) { await UpdateUIAsync(() => message.Status = MessageStatus.Aborted); throw; } }
private async Task <bool> ResponseAsync(ControllerParameter parameter, Message message) { void append() { var profile = parameter.SenderProfile; var messages = profile.MessageCollection; if (messages.Any(r => r.Id == message.Id)) { return; } messages.Add(message); var eventArgs = new MessageEventArgs(this, profile, message); NewMessage?.Invoke(this, eventArgs); if (eventArgs.Handled) { return; } profile.Hint++; } var success = parameter.SenderProfile != null; if (success) { await UpdateUIAsync(append); } var data = new { status = success ? "ok" : "refused" }; await parameter.ResponseAsync(data); return(success); }
internal async Task HandleTextAsync(ControllerParameter parameter) { var data = parameter.Packet.Data; var message = new TextMessage(data["messageId"].As <string>()) { Text = data["text"].As <string>(), Status = MessageStatus.Success }; await ResponseAsync(parameter, message); }
public void OnTriggerExit2D(Collider2D other) { var Parameters = other.gameObject.GetComponent <ControllerPhysicsVolume>(); if (Parameters == null) { return; } overrideParameters = null; }
internal async Task HandleCacheAsync(ControllerParameter parameter) { var data = parameter.Packet.Data; var hash = data["hash"].As <string>(); var path = GetFullPath(hash); var stream = parameter.Stream; using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { var length = filestream.Length; if (length > BufferLimits) { throw new InvalidOperationException(); } var header = BitConverter.GetBytes((int)length); await stream.WriteAsync(header, 0, header.Length, parameter.CancellationToken); await filestream.CopyToAsync(stream, BufferLength, parameter.CancellationToken); } }
internal async Task HandleDirectoryAsync(ControllerParameter parameter) { var profile = parameter.SenderProfile; var handler = NewDirectoryReceiver; if (profile == null || handler == null || parameter.ConnectionType != LinkConnectionType.Tcp) { return; } var data = parameter.Packet.Data; var name = data["name"].As <string>(); using (var receiver = new DirectoryReceiver(this, profile, parameter.Stream, name)) { await parameter.ResponseAsync(new { status = "wait" }); await UpdateUIAsync(() => handler.Invoke(receiver)); await receiver.LoopAsync(); } }