Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Development
Starlight [C#/.NET Core/Dapper]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Damien" data-source="post: 471637" data-attributes="member: 72299"><p>Small update, messenger is now working. Adding, removing, requests ext all work (aswell as when the target is offline) and I also took the time to update the message handler a little so it can parse in pre handled arguments. What this means is that the packet get gets processed before the event handles the data. Example bellow. This allows me to define variables for each event and reuse them without having to set them locally in the event handler, so the event handlers should look alot less cluttered now. I still have a few things left to do in the messenger like sending pms, room invites, stalking/in room status. But I'll finish that off when I've started the room engine.</p><p></p><p><strong>EventArgs:</strong></p><p>[code=csharp]</p><p>public class RemoveFriendArgs : IEventArgs</p><p>{</p><p> public IList<uint> TargetIds { get; private set; }</p><p></p><p> public RemoveFriendArgs()</p><p> {</p><p> TargetIds = new List<uint>();</p><p> }</p><p></p><p> public void Parse(IClientMessage message)</p><p> {</p><p> int count = message.ReadInt();</p><p> for (int i = 0; i < count; i++)</p><p> {</p><p> TargetIds.Add(message.ReadUint());</p><p> }</p><p> }</p><p>}</p><p>[/code]</p><p></p><p>RemoveFriendEvent handler<strong>:</strong></p><p>[code=csharp]</p><p>protected override async Task HandleAsync(ISession session, RemoveFriendArgs args)</p><p>{</p><p> foreach (uint targetId in args.TargetIds)</p><p> {</p><p> if (!_playerController.TryGetPlayer(targetId, out IPlayer targetPlayer))</p><p> {</p><p> IPlayerData targetPlayerData = await _playerController.GetPlayerDataByIdAsync(targetId);</p><p> if (targetPlayerData == null) continue;</p><p></p><p> targetPlayer = new Player(targetPlayerData, null);</p><p> }</p><p></p><p> if (!session.Player.MessengerComponent.FriendExists(targetPlayer.PlayerData.Id))</p><p> continue;</p><p></p><p> session.Player.MessengerComponent.RemoveFriend(targetPlayer.PlayerData.Id);</p><p> await session.WriteAndFlushAsync(new MessengerUpdateFriendComposer(targetPlayer.PlayerData.Id));</p><p></p><p> if (targetPlayer.Session != null && targetPlayer.MessengerComponent != null)</p><p> {</p><p> targetPlayer.MessengerComponent.RemoveFriend(session.Player.PlayerData.Id);</p><p> await targetPlayer.Session.WriteAndFlushAsync(new MessengerUpdateFriendComposer(session.Player.PlayerData.Id));</p><p> }</p><p></p><p> await _messengerController.RemovePlayerFriendAsync(session.Player.PlayerData.Id, targetPlayer.PlayerData.Id);</p><p> }</p><p>}</p><p>[/code]</p><p></p><p><strong>An image:</strong></p><p>[SPOILER]</p><p><img src="https://i.gyazo.com/7820b75b343dcc9be08341640213d0c1.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p><p>[/SPOILER]</p></blockquote><p></p>
[QUOTE="Damien, post: 471637, member: 72299"] Small update, messenger is now working. Adding, removing, requests ext all work (aswell as when the target is offline) and I also took the time to update the message handler a little so it can parse in pre handled arguments. What this means is that the packet get gets processed before the event handles the data. Example bellow. This allows me to define variables for each event and reuse them without having to set them locally in the event handler, so the event handlers should look alot less cluttered now. I still have a few things left to do in the messenger like sending pms, room invites, stalking/in room status. But I'll finish that off when I've started the room engine. [B]EventArgs:[/B] [code=csharp] public class RemoveFriendArgs : IEventArgs { public IList<uint> TargetIds { get; private set; } public RemoveFriendArgs() { TargetIds = new List<uint>(); } public void Parse(IClientMessage message) { int count = message.ReadInt(); for (int i = 0; i < count; i++) { TargetIds.Add(message.ReadUint()); } } } [/code] RemoveFriendEvent handler[B]:[/B] [code=csharp] protected override async Task HandleAsync(ISession session, RemoveFriendArgs args) { foreach (uint targetId in args.TargetIds) { if (!_playerController.TryGetPlayer(targetId, out IPlayer targetPlayer)) { IPlayerData targetPlayerData = await _playerController.GetPlayerDataByIdAsync(targetId); if (targetPlayerData == null) continue; targetPlayer = new Player(targetPlayerData, null); } if (!session.Player.MessengerComponent.FriendExists(targetPlayer.PlayerData.Id)) continue; session.Player.MessengerComponent.RemoveFriend(targetPlayer.PlayerData.Id); await session.WriteAndFlushAsync(new MessengerUpdateFriendComposer(targetPlayer.PlayerData.Id)); if (targetPlayer.Session != null && targetPlayer.MessengerComponent != null) { targetPlayer.MessengerComponent.RemoveFriend(session.Player.PlayerData.Id); await targetPlayer.Session.WriteAndFlushAsync(new MessengerUpdateFriendComposer(session.Player.PlayerData.Id)); } await _messengerController.RemovePlayerFriendAsync(session.Player.PlayerData.Id, targetPlayer.PlayerData.Id); } } [/code] [B]An image:[/B] [SPOILER] [IMG]https://i.gyazo.com/7820b75b343dcc9be08341640213d0c1.png[/IMG] [/SPOILER] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Development
Starlight [C#/.NET Core/Dapper]
Top