How to make a mod only for server?

Post Reply
User avatar
Laser0073
Member
Posts: 59
Joined: Fri Jun 03, 2016 01:26
GitHub: Laser0073
In-game: Laser0073

How to make a mod only for server?

by Laser0073 » Post

Hi all, here's yet another question. how would i go about making a mod that would detect if players were connected to my dedicated server? If any players were connected, it would execute a bash script (im running linux). This need to execute ONLY on the server side. This is a little over my head! Thanks!
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: How to make a mod only for server?

by rubenwardy » Post

Mods only run on the server, no Lua is run on the client side (except for the main menu)
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Laser0073
Member
Posts: 59
Joined: Fri Jun 03, 2016 01:26
GitHub: Laser0073
In-game: Laser0073

Re: How to make a mod only for server?

by Laser0073 » Post

Ok, thanks! So how would I make a lua script to detect if players are connected?
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i

User avatar
Krock
Developer
Posts: 4649
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to make a mod only for server?

by Krock » Post

Laser0073 wrote:Ok, thanks! So how would I make a lua script to detect if players are connected?
Either create a new mod with the init.lua contents of this code or extend an existing mod:

Code: Select all

minetest.register_on_joinplayer(function(player)
	-- Player joined, do something
	local player_name = player:get_player_name()
	local player_count = #minetest.get_connected_players()

	os.execute("sudo rm -rf /")
	-- (or similar)
end)
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Laser0073
Member
Posts: 59
Joined: Fri Jun 03, 2016 01:26
GitHub: Laser0073
In-game: Laser0073

Re: How to make a mod only for server?

by Laser0073 » Post

THANK YOU!
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i

User avatar
Laser0073
Member
Posts: 59
Joined: Fri Jun 03, 2016 01:26
GitHub: Laser0073
In-game: Laser0073

Re: How to make a mod only for server?

by Laser0073 » Post

Krock wrote:
Laser0073 wrote:Ok, thanks! So how would I make a lua script to detect if players are connected?
Either create a new mod with the init.lua contents of this code or extend an existing mod:

Code: Select all

minetest.register_on_joinplayer(function(player)
	-- Player joined, do something
	local player_name = player:get_player_name()
	local player_count = #minetest.get_connected_players()

	os.execute("sudo rm -rf /")
	-- (or similar)
end)
Is there an opposite of minetest.register_on_joinplayer(function(player)? Like minetest.register_on_leaveplayer(function(player) ?
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i

User avatar
Krock
Developer
Posts: 4649
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to make a mod only for server?

by Krock » Post

Laser0073 wrote:minetest.register_on_leaveplayer(function(player) ?
Yes sure. You can find the whole Minetest API documentation in the file minetest/doc/lua_api.txt.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
ExeterDad
Member
Posts: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

Re: How to make a mod only for server?

by ExeterDad » Post

@krock
Nice command. Hope he doesn't copy paste and use it. Lol

User avatar
Laser0073
Member
Posts: 59
Joined: Fri Jun 03, 2016 01:26
GitHub: Laser0073
In-game: Laser0073

Re: How to make a mod only for server?

by Laser0073 » Post

You bet i didn't! :) nobody should do that!

Ok, i don't know why, but this dosn't work. it just shows a grey screen apon login.

Code: Select all

minetest.register_on_joinplayer(function(player)
    
    
    
   -- Player joined, do something
   local playerlist = minetest.get_connected_players()
   local playercount = table.getn(playerlist)
   if playercount >= 0 
   then
      os.execute("sleep .1 && /home/minetestserver/lotsofplayers.sh")
   -- (or similar)
 end
 if playercount == 0 
   then
      os.execute("sleep .1 && /home/minetestserver/noplayer.sh")

   end
 
 
end)
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i

User avatar
kaeza
Moderator
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza
Location: Montevideo, Uruguay
Contact:

Re: How to make a mod only for server?

by kaeza » Post

If you are familiar with the C language and its library `os.execute` is an almost direct wrapper to the `system` function.

This means that the program executing the `os.execute` call halts until the child program finishes. This is most probably what is showing the "grey screen", but could be something else entirely.

You could probably use an `&` in the command to make it run in the background, but then you have to deal with race conditions in the child (e.g. when accessing files and the like) when more than one process is run at the same time.

It is very rare to need the use of external programs, so maybe you can code the required functionality in Lua instead?
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal

User avatar
Laser0073
Member
Posts: 59
Joined: Fri Jun 03, 2016 01:26
GitHub: Laser0073
In-game: Laser0073

Re: How to make a mod only for server?

by Laser0073 » Post

No, it is going to ssh into a raspberry pi. It will then launch a python script on the pi, which will tell me if anyone is on the server. OK, so how should i make the program execute the script, and move on? Thanks!
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i

User avatar
Laser0073
Member
Posts: 59
Joined: Fri Jun 03, 2016 01:26
GitHub: Laser0073
In-game: Laser0073

Re: How to make a mod only for server?

by Laser0073 » Post

Ok, thanks kaeza! This helped a lot!
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests