// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // //------------------------------------------------------------------------------ // // This source code was auto-generated by an XSL transformation. // Do not change this file. Instead, change the XML data which contains // the packet definitions and re-run the transformation (publish/rebuild the // client library project). // //------------------------------------------------------------------------------ // ReSharper disable RedundantVerbatimPrefix // ReSharper disable AssignmentIsFullyDiscarded // ReSharper disable UnusedMember.Global // ReSharper disable UseObjectOrCollectionInitializer #nullable enable namespace MUnique.Client.Library; using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; using MUnique.OpenMU.Network; using MUnique.OpenMU.Network.Packets; using MUnique.OpenMU.Network.Packets.ChatServer; /// /// Extension methods to start writing messages of this namespace on a . /// public unsafe partial class ConnectionManager { /// /// Sends a to this connection. /// /// The handle of the connection. /// The room id. /// A token (integer number), formatted as string and "encrypted" with the 3-byte XOR key (FC CF AB). /// The length of . /// /// Is sent by the client when: This packet is sent by the client after it connected to the server, to authenticate itself. /// Causes reaction on server side: The server will check the token. If it's correct, the client gets added to the requested chat room. /// [UnmanagedCallersOnly(EntryPoint = "SendAuthenticate")] public static void SendAuthenticate(int handle, ushort @roomId, byte* @token, uint tokenByteLength) { if (!Connections.TryGetValue(handle, out var connection)) { return; } try { connection.CreateAndSend(pipeWriter => { var length = AuthenticateRef.Length; var packet = new AuthenticateRef(pipeWriter.GetSpan(length)[..length]); packet.RoomId = @roomId; new Span(@token, (int)tokenByteLength).CopyTo(packet.Token); return length; }); } catch (Exception ex) { Debug.WriteLine(ex); } } /// /// Sends a to this connection. /// /// The handle of the connection. /// The client index. /// The name. /// /// Is sent by the server when: This packet is sent by the server after another chat client joined the chat room. /// Causes reaction on client side: The client will add the client in its list (if over 2 clients are connected to the same room), or show its name in the title bar. /// [UnmanagedCallersOnly(EntryPoint = "SendChatRoomClientJoined")] public static void SendChatRoomClientJoined(int handle, byte @clientIndex, IntPtr @name) { if (!Connections.TryGetValue(handle, out var connection)) { return; } try { connection.CreateAndSend(pipeWriter => { var length = ChatRoomClientJoinedRef.Length; var packet = new ChatRoomClientJoinedRef(pipeWriter.GetSpan(length)[..length]); packet.ClientIndex = @clientIndex; packet.Name = NativeInterop.PtrToWideString(@name); return length; }); } catch (Exception ex) { Debug.WriteLine(ex); } } /// /// Sends a to this connection. /// /// The handle of the connection. /// /// Is sent by the client when: This packet is sent by the client when it leaves the chat room, before the connection closes. /// Causes reaction on server side: The server will remove the client from the chat room, notifying the remaining clients. /// [UnmanagedCallersOnly(EntryPoint = "SendLeaveChatRoom")] public static void SendLeaveChatRoom(int handle) { if (!Connections.TryGetValue(handle, out var connection)) { return; } try { connection.CreateAndSend(pipeWriter => { var length = LeaveChatRoomRef.Length; var packet = new LeaveChatRoomRef(pipeWriter.GetSpan(length)[..length]); return length; }); } catch (Exception ex) { Debug.WriteLine(ex); } } /// /// Sends a to this connection. /// /// The handle of the connection. /// The client index. /// The name. /// /// Is sent by the server when: This packet is sent by the server after a chat client left the chat room. /// Causes reaction on client side: The client will remove the client from its list, or mark its name in the title bar as offline. /// [UnmanagedCallersOnly(EntryPoint = "SendChatRoomClientLeft")] public static void SendChatRoomClientLeft(int handle, byte @clientIndex, IntPtr @name) { if (!Connections.TryGetValue(handle, out var connection)) { return; } try { connection.CreateAndSend(pipeWriter => { var length = ChatRoomClientLeftRef.Length; var packet = new ChatRoomClientLeftRef(pipeWriter.GetSpan(length)[..length]); packet.ClientIndex = @clientIndex; packet.Name = NativeInterop.PtrToWideString(@name); return length; }); } catch (Exception ex) { Debug.WriteLine(ex); } } /// /// Sends a to this connection. /// /// The handle of the connection. /// The sender index. /// The message length. /// The message. It's "encrypted" with the 3-byte XOR key (FC CF AB). /// The length of . /// /// Is sent by the server when: This packet is sent by the server after another chat client sent a message to the current chat room. /// Causes reaction on client side: The client will show the message. /// [UnmanagedCallersOnly(EntryPoint = "SendChatMessage")] public static void SendChatMessage(int handle, byte @senderIndex, byte @messageLength, byte* @message, uint messageByteLength) { if (!Connections.TryGetValue(handle, out var connection)) { return; } try { connection.CreateAndSend(pipeWriter => { var length = ChatMessageRef.GetRequiredSize((int)messageByteLength); var packet = new ChatMessageRef(pipeWriter.GetSpan(length)[..length]); packet.SenderIndex = @senderIndex; packet.MessageLength = @messageLength; new Span(@message, (int)messageByteLength).CopyTo(packet.Message); return length; }); } catch (Exception ex) { Debug.WriteLine(ex); } } /// /// Sends a to this connection. /// /// The handle of the connection. /// /// Is sent by the client when: This packet is sent by the client in a fixed interval. /// Causes reaction on server side: The server will keep the connection and chat room intact as long as the clients sends a message in a certain period of time. /// [UnmanagedCallersOnly(EntryPoint = "SendKeepAlive")] public static void SendKeepAlive(int handle) { if (!Connections.TryGetValue(handle, out var connection)) { return; } try { connection.CreateAndSend(pipeWriter => { var length = KeepAliveRef.Length; var packet = new KeepAliveRef(pipeWriter.GetSpan(length)[..length]); return length; }); } catch (Exception ex) { Debug.WriteLine(ex); } }}