How to make a mod only for server?

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

How to make a mod only for server?

by Laser0073 » Mon Aug 08, 2016 12:35

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 @3.2GHz, EVGA GTX 960 4GB ssc, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.15 dev, Ubuntu Studio 16.04LTS
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How to make a mod only for server?

by rubenwardy » Mon Aug 08, 2016 13:04

Mods only run on the server, no Lua is run on the client side (except for the main menu)
 

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

Re: How to make a mod only for server?

by Laser0073 » Mon Aug 08, 2016 13:29

Ok, thanks! So how would I make a lua script to detect if players are connected?
i5 6500 @3.2GHz, EVGA GTX 960 4GB ssc, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.15 dev, Ubuntu Studio 16.04LTS
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: How to make a mod only for server?

by Krock » Mon Aug 08, 2016 13:46

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:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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)
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

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

Re: How to make a mod only for server?

by Laser0073 » Mon Aug 08, 2016 14:25

THANK YOU!
i5 6500 @3.2GHz, EVGA GTX 960 4GB ssc, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.15 dev, Ubuntu Studio 16.04LTS
 

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

Re: How to make a mod only for server?

by Laser0073 » Mon Aug 08, 2016 14:45

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:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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 @3.2GHz, EVGA GTX 960 4GB ssc, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.15 dev, Ubuntu Studio 16.04LTS
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: How to make a mod only for server?

by Krock » Mon Aug 08, 2016 14:59

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.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
ExeterDad
Member
 
Posts: 1121
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad

Re: How to make a mod only for server?

by ExeterDad » Mon Aug 08, 2016 18:23

@krock
Nice command. Hope he doesn't copy paste and use it. Lol
٩(̾●̮̮̃̾•̃̾)۶

Kibbie and I have a beautiful public server now! HOMETOWN
 

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

Re: How to make a mod only for server?

by Laser0073 » Wed Aug 10, 2016 14:15

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.


Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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 @3.2GHz, EVGA GTX 960 4GB ssc, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.15 dev, Ubuntu Studio 16.04LTS
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: How to make a mod only for server?

by kaeza » Wed Aug 10, 2016 22:40

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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

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

Re: How to make a mod only for server?

by Laser0073 » Sat Aug 13, 2016 00:06

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 @3.2GHz, EVGA GTX 960 4GB ssc, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.15 dev, Ubuntu Studio 16.04LTS
 

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

Re: How to make a mod only for server?

by Laser0073 » Sun Oct 02, 2016 22:21

Ok, thanks kaeza! This helped a lot!
i5 6500 @3.2GHz, EVGA GTX 960 4GB ssc, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.15 dev, Ubuntu Studio 16.04LTS
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 46 guests

cron