LFS Mods
Wednesday, 2024.12.25,   21:50   Welcome, Guest | RSS
[ Updated threads · New messages · Members · Forum rules · Search · RSS ]

InSim - Forum

  • Page 1 of 1
  • 1
InSim
@ Admin Male Date: Wednesday, 2023.01.18, 14:45 | Message # 1
Admin
LFS Mods Team
Group: Administrators
Posts: 91
Awards: 0
Reputation: 58
Status: Offline
This is the simplest InSim program you can write (that does something). We initialize InSim and send the message 'Hello, InSim!' to the games chat.

Code
InSim insim = new InSim();

// Initialize InSim
insim.Initialize(new InSimSettings {
    Host = "127.0.0.1",
    Port = 29999,
    Admin = String.Empty,
});

// Send message to LFS
insim.Send("/msg Hello, InSim!");


To receive a packet bind a handler using the InSim.Bind() method. In this example we bind a handler for the IS_MSO (MeSsage Out) packet event.

Code
void RunInSim() {
    InSim insim = new InSim();

    // Bind MSO packet event.
    insim.Bind<IS_MSO>(MessageOut);

    // Initialize InSim
    insim.Initialize(new InSimSettings {
        Host = "127.0.0.1",
        Port = 29999,
        Admin = String.Empty,
    });
}

// Method called when MSO packet is recieved
void MessageOut(InSim insim, IS_MSO packet) {
    // Print contents of MSO message to the console.
    Console.WriteLine(packet.Msg);
}


To send a packet use the InSim.Send(ISendable) method.

Code
insim.Send(new IS_TINY {
    SubT = TinyType.TINY_NCN
});


To save bandwidth send multiple packets in a single call using the InSim.Send(params ISendable[]) method.

Code
insim.Send(
    new IS_TINY {
        SubT = TinyType.TINY_NCN
    },
    new IS_SMALL {
        SubT = SmallType.SMALL_SSP,
    }
);

To keep a program open while InSim is still connected.

while (insim.IsConnected) {
    Thread.Sleep(200);
}


Here is it all together.

Code
void RunInSim() {
    InSim insim = new InSim();

    // Bind packet events.
    insim.Bind<IS_NCN>(NewConnection);
    insim.Bind<IS_NPL>(NewPlayer);

    // Initialize InSim
    insim.Initialize(new InSimSettings {
        Host = "127.0.0.1",
        Port = 29999,
        Admin = String.Empty,
    });
    
    // Request all connections and players to be sent.
    insim.Send(new [] {
        new IS_TINY { SubT = TinyType.TINY_NCN },
        new IS_TINY { SubT = TinyType.TINY_NPL },
    });
    
    // Stop console app from exiting while connection is active.
    while (insim.IsConnected) {
        Thread.Sleep(200);
    }
}

// Method called when NCN packet is recieved
void NewConnection(InSim insim, IS_NCN packet) {
    // Handle new connection.
}

// Method called when NPL packet is recieved
void NewPlayer(InSim insim, IS_NPL packet) {
    // Handle new player.
}
(¯·._.·(¯°·._.·°º*[ LFS MODS ]*º°·._.·°¯)·._.·¯)
 
  • Page 1 of 1
  • 1
Search: