using System;
using InSimDotNet;
using InSimDotNet.Packets;
using InSimDotNet.Helpers;
class Program
{
static void Main(string[] args)
{
InSim insim = new InSim();
// Bind the MSO packet handler
insim.Bind<IS_MSO>(MessageMSO);
insim.Bind<IR_HOS>(HostList);
// Initialize InSim relay
insim.Initialize(new InSimSettings {
IsRelayHost = true,
});
// Send host select packet
insim.Send(new IR_HLR { ReqI = 1 });
insim.Send(new IR_SEL {
HName = "Hostname", // Host to select
Admin = "Passwprd", // Optional admin pass
Spec = String.Empty // Optional spectator pass
});
insim.Send(new IS_TINY { ReqI = 1, SubT = TinyType.TINY_NCN,});
insim.Send(new IS_MTC {UCID= 255, ReqI = 3, Msg = "This is Testing"});
Console.WriteLine("Connected to relay. Press any key to exit.");
Console.ReadKey();
}
static void HostList(InSim insim, IR_HOS hos) {
// Loop through each host connected to the server and print out some details
foreach (HInfo info in hos.Info) {
Console.WriteLine(
"{0} ({1} / {2})",
StringHelper.StripColors(info.HName),
info.Track,
info.NumConns);
}
}
// MSO message handler
static void MessageMSO(InSim insim, IS_MSO packet)
{
Console.WriteLine($"[{packet.UCID}] {packet.Msg}");
}
}
using System;
using InSimDotNet;
using InSimDotNet.Packets;
class Program
{
static void Main(string[] args)
{
InSim insim = new InSim();
// Bind the MSO packet handler
insim.Bind<IS_MSO>(MessageMSO);
// Initialize InSim relay
insim.Initialize(new InSimSettings {
IsRelayHost = true,
Admin = "",
Host = "isrelay.lfs.net",
Port = 47474
});
// Send host select packet
insim.Send(new IR_HLR { ReqI = 1 });
insim.Send(new IR_SEL { HName = "Hostname" });
insim.Send(new IS_MTC{UCID = 255, Msg = "This is Testing"});
Console.WriteLine("Connected to relay. Press any key to exit.");
Console.ReadKey();
}
// MSO message handler
static void MessageMSO(InSim insim, IS_MSO packet)
{
Console.WriteLine($"[{packet.UCID}] {packet.Msg}");
}
}
using System;
using InSimDotNet;
using InSimDotNet.Packets;
using InSimDotNet.Helpers;
class Program {
static void Main() {
InSim insim = new InSim();
// Bind handler for HOS (host list) packet.
insim.Bind<IR_HOS>(HostList);
// Initialize connection to InSim Relay
insim.Initialize(new InSimSettings {
Host = "isrelay.lfs.net", // Relay host
Port = 47474, // Default relay port
IsRelayHost = true,
Admin = "", // Not needed for relay
IName = "HostLister" // Name of this client
});
// Request host list.
insim.Send(new IR_HLR { ReqI = 1 });
Console.WriteLine("Requesting host list from InSim Relay...");
Console.ReadLine();
}
static void HostList(InSim insim, IR_HOS hos) {
if (hos.NumHosts == 0) {
Console.WriteLine("No hosts found.");
return;
}
Console.WriteLine("Found {0} host(s):", hos.NumHosts);
foreach (HInfo info in hos.Info) {
Console.WriteLine(
"{0} ({1} / {2} connections)",
StringHelper.StripColors(info.HName),
info.Track,
info.NumConns);
}
}
}
using System;
using System.IO;
using InSimDotNet;
using InSimDotNet.Packets;
using InSimDotNet.Helpers;
namespace LFSInSimRelay
{
class Program
{
// File to log messages to
private static readonly string LogFile = "mso_log.txt";
static void Main(string[] args)
{
Console.WriteLine("Starting LFS InSim Relay...");
InSim insim = new InSim();
// Bind event handlers
insim.Bind<IS_NCN>(NewConnection);
insim.Bind<IS_MSO>(MessageOut); // Add MSO event handler
// Initialize InSim relay
insim.Initialize(new InSimSettings {
IsRelayHost = true
});
Console.WriteLine("InSim relay initialized.");
Console.WriteLine("Selecting host:");
// Select a host
insim.Send(new IR_SEL {
HName = "", // Host to select
Admin = "", // Optional admin pass
Spec = String.Empty // Optional spectator pass
});
Console.WriteLine("Requesting current connection list...");
// Request connection list
insim.Send(new IS_TINY {
ReqI = 1,
SubT = TinyType.TINY_NCN,
});
Console.WriteLine("Monitoring for new connections and MSO messages.");
Console.WriteLine("Press Enter to exit.");
Console.ReadLine();
// Clean up
insim.Disconnect();
}
static void NewConnection(InSim insim, IS_NCN ncn)
{
// Output name of each player connected to the host
Console.WriteLine("Player connected: {0}", StringHelper.StripColors(ncn.PName));
}
static void MessageOut(InSim insim, IS_MSO mso)
{
// Strip color codes from message
string cleanMessage = StringHelper.StripColors(mso.Msg);
// Format the message with user info when available
string logMessage;
if (mso.UCID > 0)
{
// Message from a user
logMessage = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [USER:{mso.UCID}] {cleanMessage}";
}
else
{
// System message
logMessage = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [SYSTEM] {cleanMessage}";
}
// Output to console
Console.WriteLine(logMessage);
// Log to file
try
{
File.AppendAllText(LogFile, logMessage + Environment.NewLine);
}
catch (Exception ex)
{
Console.WriteLine($"Error writing to log file: {ex.Message}");
}
}
}
}