The online racing simulator
Lua for insim? (idea)
1
(28 posts, started )
Lua for insim? (idea)
So I was thinking, while the system insim being cool. It isn't great for huge servers. Lots of traffic going back and forth.

Anyways... I was thinking of adding lua to LFS dedi (Building it right in so there is no connection needed). Would anyone be interested in this?

An example of how it would work.

function MSO(mso)
local msg = string.Sub(mso.Msg,mso.TextStart, (mso.Msg.Length - mso.TextStart))
if (msg == "hi") then
insim.Send_MST_Message("/msg hi")
end

end
hook.Add("MSO","MSOhook",MSO)

Just wondering if anyone is interested in this. If not then I wont bother.

Q: How will I connect to mysql?
A: I would add module support so that you can create your own dll to use with it. (mysql would be a default module of course)

Q: I don't want to use lua.
A: I am still figuring out what to use. I might allow C++ too. Or use C++ instead. Let me know what you want.

Please post comments/questions.
Quote from elmohellno :Anyways... I was thinking of adding lua to LFS dedi. Would anyone be interested in this?

There is an old proof of concept project that I was working on banging around somewhere here, called luaLFS, which was basically an InSim Client with the lua engine embedded, and it passed stuff backwards and fowards from lua scripts. It was very, very hacky but worked relatively well for single servers.

In concept it worked pretty much in the same way as you're proposing - hooks and events.

My goal was to make InSim a bit more accessible, but the big problem, in my belief, was actually making it easier to understand. If this is the same goal you're trying to hit then I'd be interested in seeing what can be brought up now

Edit: http://www.lfsforum.net/showthread.php?t=19832

I'm not saying it's a bad idea, but I'm just wondering what the goal is (not that there has to be one) and whether or not previous projects can help solve some of the possible issues you might come across with adoption
Quote from the_angry_angel :There is an old proof of concept project that I was working on banging around somewhere here, called luaLFS, which was basically an InSim Client with the lua engine embedded, and it passed stuff backwards and fowards from lua scripts. It was very, very hacky but worked relatively well for single servers.

In concept it worked pretty much in the same way as you're proposing - hooks and events.

My goal was to make InSim a bit more accessible, but the big problem, in my belief, was actually making it easier to understand. If this is the same goal you're trying to hit then I'd be interested in seeing what can be brought up now

Edit: http://www.lfsforum.net/showthread.php?t=19832

I'm not saying it's a bad idea, but I'm just wondering what the goal is (not that there has to be one) and whether or not previous projects can help solve some of the possible issues you might come across with adoption

What I want to do is make insim connectionless. So insim is handled inside the dedicated server itself instead of being dealt over a connection.
Ah, I see something like this has come up with the mods - I assume you're suggesting hooking into the dedi server? Sounds like an interesting idea
Quote from the_angry_angel :Ah, I see something like this has come up with the mods - I assume you're suggesting hooking into the dedi server? Sounds like an interesting idea

API Hooks into the dedicated server would be awesome! But I fear quite limited to C++, or if they feel like going the route of Plugins, PAWN (Aka SmallC).
Quote from Dygear :API Hooks into the dedicated server would be awesome!

If you modify the exe slightly and inject in a DLL of your own, there's no reason why you can't add a virtual machine to manage the scripting - be it lua, smallc, etc.

My guess would be this is exactly how elmohellno's patch works (http://www.lfsforum.net/showthread.php?t=50948), and what he's proposing here, if I'm reading things right?
Question (As I'm mis-informed).. what hack is elmohellno's patch fixing?
Wrong thread.
Not quite, seeing it does fit in with discussion (Karls post), so I'm asking him (maybe he knows?) what exploit the patch is fixing.
When you CarReset all the checks are client sided. So you can carreset on servers without this patch if you have a hack to remove the client side checks.
Quote from the_angry_angel :If you modify the exe slightly and inject in a DLL of your own, there's no reason why you can't add a virtual machine to manage the scripting - be it lua, smallc, etc.

I simply don't have the programming knowledge for that, to bad, as that would be awesome!
I could always throw in a few interfaces.

-Runtime Dll
-Lua
-pawn
-gamemonkeyscript
Quote from elmohellno :I could always throw in a few interfaces.

-Runtime Dll
-Lua
-pawn
-gamemonkeyscript

If you do, I might just die (from happiness). However, I would have to BEG that you put PAWN into the first release [No offense, but I not the biggest fan of Lua]. What is possible with the Hooks?

So, how far can we take this?

Things we can't do (From my understanding):
We can't make a car act any different, as the state has to be the same on both the client and the server, and as we only have access to the server, that makes things like giving a car extra boost or anything like that out of the question, at least, not without a client side implementation as well.

Things we can do (From my understanding):
We can do anything InSim can do . . .

It would be nice if the interfaces was also exposed to InSim pack information. Simple things like, client connect and client disconnect with information about their player state would be nice.
You are only limited to what the client can understand from the server.

Anyways I will probably start the project this weekend.
Lost power over the weekend. I am behind schedule by 3 days. Going to get the fast lookup done first. Then I am going to start this project.

Is anyone interested in helping? (Make like a frontend example that people can use?)
I am switching from unmanaged C++ to unmanaged/managed C++ to make some things go faster. So I think the first plugin interface will be a .net interface.

So it would be like the C# open source cruise server. A little...
As soon as you come up with the PAWN (SmallC) interface let me know!
Just started working on it.



runtime dlls will be supported first.


Still trying to figure out how I am going to do the call backs.

Most likely will look like this (unless anyone has suggestions).

Insim->AddCallback(MSO_MessageOut,&On_MSO_MessageOut);

int On_MSO_MessageOut(Packets::IS_MSO MSO)
{
Insim->Send_MST_Message("Someone just said something!");
return 1;
}

Very interesting trying to interface scripting languages with InSim. I have no experience with that so I may have to look at how you did things or even use your .dll myself with my upcoming C++ LYTe. A scripting language for some type of autox interface is a possibilty for it so, your work could help a LOT! Of course all of this won't be for a while as I'm still working on the basic editor. (C/C++ SDL+OpenGL)

For callbacks I used this tutorial: CodeGuru: C++ Callback Demo
I know how to do callbacks. Wondering how I should set it up so it is easier for the user.
I'll try to keep this thread up to date with what I am doing.

A lot of the stuff is inlined so I am writing out the stuff I need atm.

int GetPlayersCount();
int GetConnectionsCount();
int GetClientsCount();
int FindPlayerByID(char id);
int FindConnectionByIndex(char idx);
int FindClientByIndex(char connidx);

For Send_MST_Message all I had to do was.

void InsimInterface::MST_Message(std::string str)
{
MST_Message_Func(0, str.c_str(),0);
}

for MTC_MessageToConnection I have to do

void InsimInterface::MTC_MessageToConnection(std::string str, char UniqueID, char PlayerID)
{
if (str.empty())
return;
int idx;
if (PlayerID)
{
idx = FindPlayerByID(PlayerID);
}
else
{
idx = FindConnectionByID(UniqueID);
}
if (idx == -1)
return;
idx = FindClientByIndex(idx);
if (idx == -1)
return;
char packet[0x44];
memset(packet,0,0x44);
*(int*)packet = 0x2B;
strncpy(packet+0x4,str.c_str(),0x40);
SendMTCPacket(idx,packet,0x44);
}

For PAWN, just a small wish list. Most of these names are ripped out of SourceMod's API
[b]LFS[/b] (SourceMod)
forward OnPluginStart()
forward OnPluginEnd()
forward OnMapStart()
forward OnMapEnd()
forward OnAllPluginsLoaded()
native GetPluginFilename(Handle:plugin, String:buffer[], maxlength)
native bool:IsPluginDebugging(Handle:hndl)
native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength)
native RegPluginLibrary(const String:name[])
[b]Banning[/b]
forward Action:OnBanClient(client, time, flags, const String:reason[], const String:kick_message[], const String:command[], any:source)
forward Action:OnRemoveBan(const String:identity[], flags, const String:command[], any:source)
[b]Clients[/b]
forward bool:OnClientConnect(client)
forward OnClientDisconnect(client)
forward Action:OnClientCommand(client, args)
bool:OnClientSettingsChanged(client)
native GetMaxClients()
native GetClientCount(bool:inGameOnly=TRUE);
native bool:GetClientName(client, String:name[], maxlen)
native GetClientUserId(client)
native bool:IsClientInGame(client)
native bool:IsClientConnected(client)
native bool:IsClientInGame(client)
native bool:IsClientObserver(client)
native bool:GetClientInfo(client, const String:key[], String:value[], maxlen)
native GetClientCar(client, String:model[], maxlen) // GetClientModel
native GetClientAbsAngles(client, Float:ang[3])
native GetClientAbsOrigin(client, Float:vec[3])
native Float:GetClientTime(client)
native GetClientOfUserId(userid)
[b]Events[/b]
native HookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post)
native UnhookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post)
native FireEvent(Handle:event, bool:dontBroadcast=false)
[b]User Messages[/b]
native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength)
native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0)

Sorry for no updates for awhile, I haven't abandoned the project. I was looking for ways to do the callbacks while working on some of my other projects. The callbacks are almost sorted out. And once they are that means that it wont be long till this is done.
Been busy but did get 1 thing done this morning.



Callbacks are in place. Now I just need to do 3 more things(before alpha).

-Make callbacks threaded.
-Add system for accessing Connection/Player list
-Add the rest of sends/receives.
Sweet, can't wait!
1

Lua for insim? (idea)
(28 posts, started )
FGED GREDG RDFGDR GSFDG