Page 1 of 1

REQUEST: register_on_player_join & register_on_player_quit

PostPosted: Tue Mar 20, 2012 20:07
by randomproof
These would be call backs to LUA for when a player joins and quits a server. It could be used to serve MOTD kind of stuff, server logging, etc.

I have no problem doing the coding, but I don't want to waste by time if it won't be merged. So if someone with some authority to merge code says yes, I will make a pull request.

PostPosted: Wed Mar 21, 2012 20:36
by LolManKuba
I might not be a LUA coder or a modder ect. but I +2 this idea/

PostPosted: Wed Mar 21, 2012 21:27
by RabbiBob
+1

Could this be leveraged at the point of all of the 'joins\joined' messaging that takes place in server.cpp?

Line 2156 in celeron55-minetest-c053092../src/server.cpp

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

    if(command == TOSERVER_INIT2)
    {
        verbosestream<<"Server: Got TOSERVER_INIT2 from "
                <<peer_id<<std::endl;


        getClient(peer_id)->serialization_version
                = getClient(peer_id)->pending_serialization_version;

        /*
            Send some initialization data
        */

        infostream<<"Server: Sending content to "
                <<getPlayerName(peer_id)<<std::endl;

        // Send item definitions
        SendItemDef(m_con, peer_id, m_itemdef);
       
        // Send node definitions
        SendNodeDef(m_con, peer_id, m_nodedef);
       
        // Send texture announcement
        SendTextureAnnouncement(peer_id);
       
        // Send player info to all players
        //SendPlayerInfos();

.....etc/etc

PostPosted: Wed Mar 21, 2012 21:37
by randomproof
RabbiBob wrote:+1

Could this be leveraged at the point of all of the 'joins\joined' messaging that takes place in server.cpp?


Yes. I would want to make sure that the new player is all loaded and in the system. That is that his/her player is registered in minetest.object_refs so that a reference to the player can be sent to the LUA callback.

PostPosted: Thu Mar 22, 2012 02:46
by kahrl
+1, would be useful for my Away mod too.

It might be a bit tricky to make this work in 100% of all cases ("work" meaning that the object reference passed to the callback is not nil, and the game doesn't crash) because of the way ServerRemotePlayer is derived from Player. (The system also has existing bugs for the same reason, in particular the !m_is_in_environment server crash when somebody reconnects too fast.)

I have written a PlayerSAO class some time ago. Itreplaces ServerRemotePlayer but is not a subclass of Player, that way there can be multiple PlayerSAOs in the environment for any player and those bugs are fixed.

I'll probably add those callbacks to the playersao branch.

PostPosted: Thu Mar 22, 2012 19:21
by sfan5
+1

PostPosted: Thu Mar 22, 2012 19:32
by LorenzoVulcan
Isn't there "register_new_player" ?

PostPosted: Thu Mar 22, 2012 19:34
by sfan5
LorenzoVulcan wrote:Isn't there "register_new_player" ?

Yep, but thats called if a new player joins
new = never on the server before

PostPosted: Thu Mar 22, 2012 19:36
by LorenzoVulcan
sfan5 wrote:
LorenzoVulcan wrote:Isn't there "register_new_player" ?

Yep, but thats called if a new player joins
new = never on the server before

Uh,Ok.
So there isn't any function like it?

PostPosted: Thu Mar 22, 2012 19:36
by sfan5
Yep!

PostPosted: Thu Mar 22, 2012 19:38
by LorenzoVulcan
sfan5 wrote:Yep!

Uh,Ok thanks.
So why the "Give Initial Stuff" doesn't give everytime a player re-log on the server those stuff?

PostPosted: Thu Mar 22, 2012 20:25
by sfan5
LorenzoVulcan wrote:
sfan5 wrote:Yep!

Uh,Ok thanks.
So why the "Give Initial Stuff" doesn't give everytime a player re-log on the server those stuff?

Because the Server knows, that you already have been on the Server (Inventory File, auth.txt Entry)