//
// 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.ConnectServer;
///
/// 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 server id.
///
/// Is sent by the client when: This packet is sent by the client after the user clicked on an entry of the server list.
/// Causes reaction on server side: The server will send a ConnectionInfo back to the client.
///
[UnmanagedCallersOnly(EntryPoint = "SendConnectionInfoRequest075")]
public static void SendConnectionInfoRequest075(int handle, byte @serverId)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = ConnectionInfoRequest075Ref.Length;
var packet = new ConnectionInfoRequest075Ref(pipeWriter.GetSpan(length)[..length]);
packet.ServerId = @serverId;
return length;
});
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
///
/// Sends a to this connection.
///
/// The handle of the connection.
/// The server id.
///
/// Is sent by the client when: This packet is sent by the client after the user clicked on an entry of the server list.
/// Causes reaction on server side: The server will send a ConnectionInfo back to the client.
///
[UnmanagedCallersOnly(EntryPoint = "SendConnectionInfoRequest")]
public static void SendConnectionInfoRequest(int handle, ushort @serverId)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = ConnectionInfoRequestRef.Length;
var packet = new ConnectionInfoRequestRef(pipeWriter.GetSpan(length)[..length]);
packet.ServerId = @serverId;
return length;
});
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
///
/// Sends a to this connection.
///
/// The handle of the connection.
/// The ip address.
/// The port.
///
/// Is sent by the server when: This packet is sent by the server after the client requested the connection information of a server. This happens after the user clicked on a server.
/// Causes reaction on client side: The client will try to connect to the server with the specified information.
///
[UnmanagedCallersOnly(EntryPoint = "SendConnectionInfo")]
public static void SendConnectionInfo(int handle, IntPtr @ipAddress, ushort @port)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = ConnectionInfoRef.Length;
var packet = new ConnectionInfoRef(pipeWriter.GetSpan(length)[..length]);
packet.IpAddress = NativeInterop.PtrToWideString(@ipAddress);
packet.Port = @port;
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 after it connected and received the 'Hello' message.
/// Causes reaction on server side: The server will send a ServerListResponse back to the client.
///
[UnmanagedCallersOnly(EntryPoint = "SendServerListRequest")]
public static void SendServerListRequest(int handle)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = ServerListRequestRef.Length;
var packet = new ServerListRequestRef(pipeWriter.GetSpan(length)[..length]);
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 (below season 1) after it connected and received the 'Hello' message.
/// Causes reaction on server side: The server will send a ServerListResponseOld back to the client.
///
[UnmanagedCallersOnly(EntryPoint = "SendServerListRequestOld")]
public static void SendServerListRequestOld(int handle)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = ServerListRequestOldRef.Length;
var packet = new ServerListRequestOldRef(pipeWriter.GetSpan(length)[..length]);
return length;
});
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
///
/// Sends a to this connection.
///
/// The handle of the connection.
///
/// Is sent by the server when: This packet is sent by the server after the client connected to the server.
/// Causes reaction on client side: A game client will request the server list. The launcher would request the patch state.
///
[UnmanagedCallersOnly(EntryPoint = "SendHello")]
public static void SendHello(int handle)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = HelloRef.Length;
var packet = new HelloRef(pipeWriter.GetSpan(length)[..length]);
return length;
});
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
///
/// Sends a to this connection.
///
/// The handle of the connection.
/// The major version.
/// The minor version.
/// The patch version.
///
/// Is sent by the client when: This packet is sent by the client (launcher) to check if the patch version is high enough to be able to connect to the server.
/// Causes reaction on server side: The connect server will check the version and sends a 'PatchVersionOkay' or a 'ClientNeedsPatch' message.
///
[UnmanagedCallersOnly(EntryPoint = "SendPatchCheckRequest")]
public static void SendPatchCheckRequest(int handle, byte @majorVersion, byte @minorVersion, byte @patchVersion)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = PatchCheckRequestRef.Length;
var packet = new PatchCheckRequestRef(pipeWriter.GetSpan(length)[..length]);
packet.MajorVersion = @majorVersion;
packet.MinorVersion = @minorVersion;
packet.PatchVersion = @patchVersion;
return length;
});
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
///
/// Sends a to this connection.
///
/// The handle of the connection.
///
/// Is sent by the server when: This packet is sent by the server after the client (launcher) requested the to check the patch version and it was high enough.
/// Causes reaction on client side: The launcher will activate its start button.
///
[UnmanagedCallersOnly(EntryPoint = "SendPatchVersionOkay")]
public static void SendPatchVersionOkay(int handle)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = PatchVersionOkayRef.Length;
var packet = new PatchVersionOkayRef(pipeWriter.GetSpan(length)[..length]);
return length;
});
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
///
/// Sends a to this connection.
///
/// The handle of the connection.
/// The patch version.
/// The patch address, usually to a ftp server. The address is usually "encrypted" with the 3-byte XOR key (FC CF AB).
///
/// Is sent by the server when: This packet is sent by the server after the client (launcher) requested to check the patch version and it requires an update.
/// Causes reaction on client side: The launcher will download the required patches and then activate the start button.
///
[UnmanagedCallersOnly(EntryPoint = "SendClientNeedsPatch")]
public static void SendClientNeedsPatch(int handle, byte @patchVersion, IntPtr @patchAddress)
{
if (!Connections.TryGetValue(handle, out var connection))
{
return;
}
try
{
connection.CreateAndSend(pipeWriter =>
{
var length = ClientNeedsPatchRef.Length;
var packet = new ClientNeedsPatchRef(pipeWriter.GetSpan(length)[..length]);
packet.PatchVersion = @patchVersion;
packet.PatchAddress = NativeInterop.PtrToWideString(@patchAddress);
return length;
});
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}}