// Update is called once per frame void Update() { if (Input.GetButton("Fire1") && Time.time > nextFire) { MessageBuilder msg = new MessageBuilder(MessageType.SHOOTING_MASTER_SIMPLE); msg.Add(humanEntity.Position.x).Add(humanEntity.Position.y).Add(humanEntity.Position.z); msg.Add(humanEntity.Rotation.x).Add(humanEntity.Rotation.y).Add(humanEntity.Rotation.z).Add(humanEntity.Rotation.w); msg.Add("qwe"); Debug.Log("123123"); TCPHandler.getInstance().send(msg.Build()); nextFire = Time.time + fireRate; Vector3 position = transform.TransformPoint(0, 0, 0.2f); ProjectileFactory.CreateProjectile(humanEntity, "qwe"); /* Instantiate(blaster, position, Quaternion.Euler( cameraHeadTransform.eulerAngles.x + 90, transform.eulerAngles.y, 0 ));*/ } }
private static void LogIn(Command cmd) { string str = cmd.Parameters[0]; instance.token = str; MessageBuilder mb = new MessageBuilder(MessageType.LOGIN); mb.Add(str); TCPHandler.getInstance().send(mb.Build()); }
public void Build_Throws_When_Code_Not_Set() { var builder = new MessageBuilder(); var ex = Record.Exception(() => builder.Build()); Assert.NotNull(ex); Assert.IsType <InvalidOperationException>(ex); }
public void Parse_Returns_Expected_Data(string username) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.AddPrivilegedUser) .WriteString(username); var response = PrivilegedUserNotification.FromByteArray(builder.Build()); Assert.Equal(username, response); }
public void Parse_Returns_Expected_Data(string roomName) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.LeaveRoom) .WriteString(roomName); var response = RoomLeaveResponse.FromByteArray(builder.Build()); Assert.Equal(roomName, response.RoomName); }
private void GivenTheOtherwiseValidMessage(Action <MessageBuilder> overrides = null) { MessageBuilder messageBuilder = new MessageBuilder() .WithUserProperty(SpecificationId, _specificationId) .WithUserProperty(CorrelationId, _correlationId) .WithUserProperty(UserId, _userId); overrides?.Invoke(messageBuilder); _message = messageBuilder.Build(); }
public void Parse_Returns_Expected_Data(string username, bool isPrivileged) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.UserPrivileges) .WriteString(username) .WriteByte((byte)(isPrivileged ? 1 : 0)); var response = UserPrivilegeResponse.FromByteArray(builder.Build()); Assert.Equal(username, response.Username); Assert.Equal(isPrivileged, response.IsPrivileged); }
public void Parse_Returns_Expected_Data(int id, string username) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.NotifyPrivileges) .WriteInteger(id) .WriteString(username); var response = PrivilegeNotification.FromByteArray(builder.Build()); Assert.Equal(id, response.Id); Assert.Equal(username, response.Username); }
public void Parse_Returns_Expected_Data(string roomName, string username) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.UserLeftRoom) .WriteString(roomName) .WriteString(username); var response = UserLeftRoomNotification.FromByteArray(builder.Build()); Assert.Equal(roomName, response.RoomName); Assert.Equal(username, response.Username); }
public async Task Handle(string[] args, CallbackQuery query) { var user = await Db.Users .SingleOrDefaultAsync(x => x.Id == query.From.Id); var address = await Db.UserAddresses .SingleOrDefaultAsync(x => x.Id == args.GetInt(0)); if (address is null || address.UserId != query.From.Id) { // TODO: Throw an error return; } var isDelegate = _repo.IsDelegate(address.Address); var lang = user.Language; var title = _lang.Get(Res.AddressInfoTitle, lang, new { ua = address }); var message = new MessageBuilder() .AddLine(title) .AddEmptyLine() .WithHashTag("more_info") .WithHashTag("rating") .WithHashTag(address); var linkData = new { address = address.Address }; if (isDelegate) { message.AddLine(_lang.Get(Res.AddressLinkTezosNode, lang, linkData)); message.AddLine(_lang.Get(Res.AddressLinkTzKt, lang, linkData)); } else { message.AddLine(_lang.Get(Res.AddressLinkBackingBad, lang, linkData)); } var buttons = new InlineKeyboardMarkup( InlineKeyboardButton.WithCallbackData( _lang.Get(Res.AddressTransactionListLink, user.Language, new {}), $"address-transaction-list {address.Address} 1" ) ); await Bot.SendText( query.From.Id, message.Build(!user.HideHashTags), ParseMode.Html, disableWebPagePreview : true, replyMarkup : buttons ); }
private Message NewValidMessage(Action <MessageBuilder> overrides = null) { MessageBuilder messageBuilder = new MessageBuilder() .WithUserProperty(JobId, _jobId) .WithUserProperty(SpecificationId, _specificationId) .WithUserProperty(FundingStreamId, _fundingStreamId) .WithUserProperty(ProviderSnapshotId, _providerSnapshotId.ToString()) .WithUserProperty(DisableQueueCalculationJobKey, _disableQueueCalculationJobKey); overrides?.Invoke(messageBuilder); return(messageBuilder.Build()); }
private void doChat() { int requestCount = 0; byte[] bytesFrom; string dataFromClient = null; Byte[] sendBytes = null; string serverResponse = null; string rCount = null; requestCount = 0; while ((true)) { try { requestCount = requestCount + 1; NetworkStream networkStream = clientSocket.GetStream(); bytesFrom = new byte[(int)clientSocket.ReceiveBufferSize]; networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize); dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom); Console.WriteLine(dataFromClient.Substring(0,100)); /**Anfrage*/ dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$")); //Encrypt String MessageBuilder MB = new MessageBuilder(); String[] Request = MB.DeBuild(dataFromClient); RequestHandler RH = new RequestHandler(); String[] ResponseArray = RH.handleMe(Request); rCount = Convert.ToString(requestCount); /**Antwort*/ //Crypt String serverResponse = MB.Build(ResponseArray); sendBytes = Encoding.ASCII.GetBytes(serverResponse); networkStream.Write(sendBytes, 0, sendBytes.Length); networkStream.Flush(); Console.WriteLine(serverResponse); clientSocket.Close(); break; } catch (Exception ex) { Console.WriteLine(" >> " + ex.ToString()); } } }
/// <summary> /// Save the log configuration in the Crazyflie /// </summary> internal void Create() { if (!Identifier.HasValue) { throw new InvalidOperationException("LogConfig not yet correctly added (no identifier)."); } var messageBuilder = new MessageBuilder( (byte)CrtpPort.LOGGING, (byte)Logger.LogChannel.CHAN_SETTINGS); if (UseV2) { messageBuilder.Add((byte)Logger.LogConfigCommand.CMD_CREATE_BLOCK_V2); } else { messageBuilder.Add((byte)Logger.LogConfigCommand.CMD_CREATE_BLOCK); } messageBuilder.Add(Identifier.Value); foreach (var variable in _logVariables) { var storage = variable.GetStorageAndFetchByte(); if (!variable.IsTocVariable) // Memory location { _log.Debug($"Logging to raw memory {storage} 0x{variable.Address.ToString("X")}"); messageBuilder.Add(storage); messageBuilder.Add(variable.Address); } else { var tocId = _tocContainer.CurrentToc.GetElementId(variable.Name); _log.Debug($"Adding {variable.Name} with id={tocId} and type={storage}"); messageBuilder.Add(storage); if (UseV2) { messageBuilder.Add((byte)(tocId & 0x0ff)); messageBuilder.Add((byte)((tocId >> 8) & 0x0ff)); } else { messageBuilder.Add((byte)(tocId & 0x0ff)); } } } _log.Debug($"Adding log block id {Identifier}"); var msg = messageBuilder.Build(); _communicator.SendMessageExcpectAnswer(msg, msg.Data.Take(2).ToArray()); }
public static Message ApplyAndDisplay(ArcadeUser user, DailyResultFlag flag) { long reward = Reward; string header = $"{Reward:##,0}"; ImmutableColor color = ImmutableColor.GammaGreen; var icon = "+ 💸"; switch (flag) { case DailyResultFlag.Cooldown: TimeSpan sinceLast = StatHelper.SinceLast(user, CooldownVars.Daily); TimeSpan rem = Cooldown - sinceLast; DateTime time = DateTime.UtcNow.Add(rem); color = GammaPalette.Amber[Gamma.Max]; header = Format.Countdown(rem); icon = Icons.GetClock(time.Hour); break; case DailyResultFlag.Reset: color = GammaPalette.NeonRed[Gamma.Max]; user.SetVar(Stats.DailyStreak, 0); break; case DailyResultFlag.Bonus: color = GammaPalette.Glass[Gamma.Max]; header += $" + {Bonus:##,0}"; reward += Bonus; break; } if (flag != DailyResultFlag.Cooldown) { user.SetVar(CooldownVars.Daily, DateTime.UtcNow.Ticks); user.AddToVar(Stats.DailyStreak); user.AddToVar(Stats.TimesDaily); Var.SetIfGreater(user, Stats.LongestDailyStreak, Stats.DailyStreak); user.Give(reward); } var message = new MessageBuilder(); var embedder = Embedder.Default; embedder.Color = color; embedder.Header = $"**{icon} {header}**"; message.Content = $"*\"{Replies.GetReply(flag)}\"*"; message.Embedder = embedder; return(message.Build()); }
/// <summary> /// Constructs a <see cref="byte"/> array from this message. /// </summary> /// <returns>The constructed byte array.</returns> public byte[] ToByteArray() { var builder = new MessageBuilder() .WriteCode(MessageCode.Peer.BrowseResponse) .WriteInteger(DirectoryCount); foreach (var directory in Directories) { builder.WriteDirectory(directory); } builder.Compress(); return(builder.Build()); }
void FixedUpdate() { if(login) { MessageBuilder mb = new MessageBuilder(MessageType.MOVEMENT_SYNC); mb.Add(playerObj.transform.position.x); mb.Add(playerObj.transform.position.y); mb.Add(playerObj.transform.position.z); mb.Add(playerObj.transform.rotation.x); mb.Add(playerObj.transform.rotation.y); mb.Add(playerObj.transform.rotation.z); mb.Add(playerObj.transform.rotation.w); TCPHandler.getInstance().send(mb.Build()); } }
public void BuildReturnsMessageWithBannedProfileIndicatorTest() { var expected = new Profile { BannedAt = DateTimeOffset.Now }; var sut = new MessageBuilder(); var actual = sut.Build(expected, WebsiteUri, ApiUri); _output.WriteLine(actual); actual.Should().Contain("This profile was banned at " + expected.BannedAt.Value.ToString("D")); }
/// <summary> /// Constructs a <see cref="byte"/> array from this message. /// </summary> /// <returns>The constructed byte array.</returns> public byte[] ToByteArray() { var builder = new MessageBuilder(); builder .WriteCode(MessageCode.Server.CannotConnect) .WriteInteger(Token); if (!string.IsNullOrEmpty(Username)) { builder.WriteString(Username); } return(builder.Build()); }
private void GivenTheOtherwiseValidMessage(Action <MessageBuilder> overrides = null) { MessageBuilder messageBuilder = new MessageBuilder() .WithUserProperty(SpecificationId, _specificationId) .WithUserProperty(CorrelationId, _correlationId) .WithUserProperty(FundingStreamId, _fundingStreamId) .WithUserProperty(TemplateVersion, _templateVersion) .WithUserProperty(UserId, _userId) .WithUserProperty(UserName, _userName) .WithUserProperty(JobId, _jobId); overrides?.Invoke(messageBuilder); _message = messageBuilder.Build(); }
protected override void OnModelCreating(ModelBuilder builder) { MessageBuilder.Build(builder); UserBuilder.Build(builder); ConversationBuilder.Build(builder); FriendsRequestBuilder.Build(builder); MessageBuilder.Build(builder); UserContactBuilder.Build(builder); ContactBuilder.Build(builder); NotificationBuilder.Build(builder); NotificationTypeBuilder.Build(builder); ParticipantBuilder.Build(builder); FileStorageBuilder.Build(builder); ReadReceiptBuilder.Build(builder); MemberBuilder.Build(builder); }
public void Parse_Returns_Expected_Data_When_0_Users(string roomName) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.JoinRoom) .WriteString(roomName) .WriteInteger(0) // user count .WriteInteger(0) // status count .WriteInteger(0) // data count .WriteInteger(0) // slots free count .WriteInteger(0); // country count var response = RoomJoinResponse.FromByteArray(builder.Build()); Assert.Equal(roomName, response.Name); Assert.Equal(0, response.UserCount); }
public void BuildReturnsAboutCompiledFromMarkdownTest() { var aboutContent = Guid.NewGuid(); var expected = new Profile { About = "**" + aboutContent + "**" }; var sut = new MessageBuilder(); var actual = sut.Build(expected, WebsiteUri, ApiUri); _output.WriteLine(actual); actual.Should().Contain("<strong>" + aboutContent + "</strong>"); }
public void BuildReturnsMessageWithNullSkillsAndLanguagesTest() { var expected = new Profile { Skills = null, Languages = null }; var sut = new MessageBuilder(); var actual = sut.Build(expected, WebsiteUri, ApiUri); _output.WriteLine(actual); actual.Should().NotContain("Skills"); actual.Should().NotContain("Languages"); }
public async Task ScreenshareAsync() { SocketGuildUser user = Context.Guild.GetUser(Context.User.Id); if (user.VoiceChannel == null) { await Context.Channel.SendMessageAsync("> You aren't in a voice channel."); } else { MessageBuilder mb = new MessageBuilder(); string url = Format.GetVoiceChannelUrl(Context.Guild.Id, user.VoiceChannel.Id); mb.Embedder = Embedder.Default; mb.Content = $"> **{Discord.Format.Url(user.VoiceChannel.Name, url)}** ({user.VoiceChannel.Users.Count}/{user.VoiceChannel.UserLimit?.ToString() ?? "∞"})"; await Context.Channel.SendMessageAsync(mb.Build()); } }
public async Task PresetTestAsync(bool useEmbed = false, bool hideUrl = false) { var msg = new MessageBuilder(); msg.Content = "This is a message with content inside."; msg.Url = new MessageUrl("https://steamcdn-a.akamaihd.net/steam/apps/730/header.jpg") { IsHidden = hideUrl }; if (useEmbed) { msg.Embedder = Embedder.Default; } await Context.Channel.SendMessageAsync(msg.Build()); }
public void BuildReturnsMessageWithLinkToProfileTest() { var expected = new Profile { Id = Guid.NewGuid(), Status = ProfileStatus.Available, Email = Guid.NewGuid().ToString() }; var sut = new MessageBuilder(); var actual = sut.Build(expected, WebsiteUri, ApiUri); _output.WriteLine(actual); actual.Should().Contain(WebsiteUri + "profiles/" + expected.Id); }
public void WriteDirectory_Writes_Expected_Data(Directory directory) { var builder = new MessageBuilder(); builder.WriteCode(MessageCode.Peer.BrowseResponse); var ex = Record.Exception(() => builder.WriteDirectory(directory)); Assert.Null(ex); var msg = new MessageReader <MessageCode.Peer>(builder.Build()); msg.ReadCode(); Assert.Equal(directory.Name, msg.ReadString()); Assert.Equal(directory.FileCount, msg.ReadInteger()); }
public void Parse_Returns_Expected_Data(List <RoomInfo> rooms) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.RoomList); builder.WriteInteger(rooms.Count); rooms.ForEach(room => builder.WriteString(room.Name)); builder.WriteInteger(rooms.Count); rooms.ForEach(room => builder.WriteInteger(room.UserCount)); builder.WriteInteger(rooms.Count); rooms.ForEach(room => builder.WriteString(room.Name)); builder.WriteInteger(rooms.Count); rooms.ForEach(room => builder.WriteInteger(room.UserCount)); builder.WriteInteger(rooms.Count); rooms.ForEach(room => builder.WriteString(room.Name)); builder.WriteInteger(rooms.Count); rooms.ForEach(room => builder.WriteInteger(room.UserCount)); builder.WriteInteger(rooms.Count); rooms.ForEach(room => builder.WriteString(room.Name)); var response = RoomListResponse.FromByteArray(builder.Build()); foreach (var room in rooms) { Assert.Contains(response.Public, r => r.Name == room.Name && r.UserCount == room.UserCount); } foreach (var room in rooms) { Assert.Contains(response.Private, r => r.Name == room.Name && r.UserCount == room.UserCount); } foreach (var room in rooms) { Assert.Contains(response.Owned, r => r.Name == room.Name && r.UserCount == room.UserCount); } foreach (var room in rooms) { Assert.Contains(response.ModeratedRoomNames, r => r == room.Name); } }
/// <summary> /// Constructs a <see cref="byte"/> array from this message. /// </summary> /// <returns>The constructed byte array.</returns> public byte[] ToByteArray() { var builder = new MessageBuilder() .WriteCode(MessageCode.Peer.TransferResponse) .WriteInteger(Token) .WriteByte((byte)(Allowed ? 1 : 0)); if (Allowed) { builder.WriteLong(FileSize); } else { builder.WriteString(Message); } return(builder.Build()); }
public void Parse_Returns_Expected_Data(string roomName, List <string> users) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.PrivateRoomUsers); builder.WriteString(roomName); builder.WriteInteger(users.Count); users.ToList().ForEach(user => builder.WriteString(user)); var response = PrivateRoomUserListNotification.FromByteArray(builder.Build()); Assert.Equal(users.Count, response.UserCount); foreach (var user in users) { Assert.Contains(response.Users, u => u == user); } }
/// <summary> /// Constructs a <see cref="byte"/> array from this message. /// </summary> /// <returns>The constructed byte array.</returns> public byte[] ToByteArray() { var builder = new MessageBuilder() .WriteCode(MessageCode.Peer.FolderContentsResponse) .WriteInteger(Token) .WriteString(Directory.DirectoryName) .WriteInteger(1) // always one directory .WriteString(Directory.DirectoryName) .WriteInteger(Directory.FileCount); foreach (var file in Directory.Files) { builder.WriteFile(file); } builder.Compress(); return(builder.Build()); }
public void BuildReturnsMessageWithLinkToEmailTest() { var expected = new Profile { Id = Guid.NewGuid(), Status = ProfileStatus.Available, Email = Guid.NewGuid().ToString() }; var sut = new MessageBuilder(); var actual = sut.Build(expected, WebsiteUri, ApiUri); _output.WriteLine(actual); actual.Should().Contain(expected.Status.ToString()); actual.Should().Contain($"<a href=\"mailto:{expected.Email}\">{expected.Email}</a>"); }
public void BuildReturnsProfileImageTest() { var expected = new Profile { Id = Guid.NewGuid(), PhotoId = Guid.NewGuid(), PhotoHash = Guid.NewGuid().ToString() }; var sut = new MessageBuilder(); var actual = sut.Build(expected, WebsiteUri, ApiUri); _output.WriteLine(actual); actual.Should().Contain( "<img src=\"" + ApiUri + "profiles/" + expected.Id + "/photos/" + expected.PhotoId + "?hash=" + expected.PhotoHash + "\" />"); }
public void Parse_Returns_Expected_Data_When_Private_Channel(string roomName) { var builder = new MessageBuilder() .WriteCode(MessageCode.Server.JoinRoom) .WriteString(roomName) .WriteInteger(1) // user count .WriteString("1") .WriteInteger(1) // status count .WriteInteger((int)UserPresence.Online) .WriteInteger(1) // data count .WriteInteger(10) // average speed .WriteLong(11) // download count .WriteInteger(12) // file count .WriteInteger(13) // directory count .WriteInteger(1) // slots free count .WriteInteger(14) // slots free .WriteInteger(1) // country count .WriteString("US") .WriteString("owner") .WriteInteger(2) // operator count .WriteString("op1") .WriteString("op2"); var res = RoomJoinResponse.FromByteArray(builder.Build()); var users = res.Users.ToList(); Assert.Equal(roomName, res.Name); Assert.Equal(1, res.UserCount); Assert.Equal("1", users[0].Username); Assert.Equal(UserPresence.Online, users[0].Status); Assert.Equal(10, users[0].AverageSpeed); Assert.Equal(11, users[0].DownloadCount); Assert.Equal(12, users[0].FileCount); Assert.Equal(13, users[0].DirectoryCount); Assert.Equal(14, users[0].SlotsFree); Assert.Equal("US", users[0].CountryCode); Assert.True(res.IsPrivateRoom); Assert.Equal("owner", res.Owner); Assert.Equal(2, res.OperatorCount); Assert.Equal("op1", res.Operators.ToList()[0]); Assert.Equal("op2", res.Operators.ToList()[1]); }
public void message_should_be_Hello_World_exclamation() { var builder = new MessageBuilder(); builder.Build().Should().Be("Hello World!"); }