Announcement

Collapse
No announcement yet.

Basic Server Multiplayer Functions (Kick/Ban/Etc)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Basic Server Multiplayer Functions (Kick/Ban/Etc)

    Hi all, in first i would say that i'm not using Sessions.

    So, what i already know is that some of the server code can be implemented in the GameMode class. But when i need to kick or ban player from server, how i can do that?

    Thanks

    #2
    https://docs.unrealengine.com/latest...ion/index.html

    There are already Methods for Banning/Kicking Players
    Engine(r)s - Deutsche Engine Community | https://enginers.de/

    Comment


      #3
      Originally posted by ExCluSiv3 View Post
      https://docs.unrealengine.com/latest...ion/index.html

      There are already Methods for Banning/Kicking Players
      Old thread, but this still ranks high on google searches. That page is great and all, looks like some fine functions. But there is little in the way of instruction on how to get your game session and cast to it so that you can use those functions.

      Comment


        #4
        The GameSession is available from the GameMode.

        Comment


          #5
          Originally posted by TheJamsh View Post
          The GameSession is available from the GameMode.
          I'm sorry, but that's a really simplistic and not terribly helpful answer. Game session isn't gotten and casted to the same way many of the other core parts like game state, game mode, etc are. There isn't much information on this, but I managed to work it out last night. This can only be accessed in a meaningful manner via C++. While you can "get game session class" in blueprints you can't do anything with it.

          You need to do this to cast to the game session properly so that you can use it.

          Code:
          CurrentGameSessionRef = GetGameSessionClass();
          CurrentGameSession = Cast<AGameSession>(CurrentGameSessionRef->GetDefaultObject());
          if you want to kick, especially via blueprints create a header like this:
          Code:
          UFUNCTION(BlueprintCallable, meta = (DisplayName = "KickPlayer"))
          bool BP_Kickplayer(APlayerController * KickedPlayer, const FText & KickReason);
          with the following code in CPP:
          Code:
           if (CurrentGameSession)
          {
          return CurrentGameSession->KickPlayer(KickedPlayer, KickReason);
          }
          else
          {
          return false;
          }
          Be aware that using ban player currently is pointless since all ban player does is call kick directly. Despite the description on the unreal documents ban player does not in any way ban the player from the server permanently. You need you to create a way to reliably identify the player and check if they're banned during pre-login on the game mode to prevent them from rejoining the server.

          Comment


            #6
            ...however the GameSession is available from the GameMode like suggested.

            Code:
            GetWorld()->GetAuthGameMode()->GameSession

            Comment


              #7
              Originally posted by GarnerP57 View Post
              ...however the GameSession is available from the GameMode like suggested.

              Code:
              GetWorld()->GetAuthGameMode()->GameSession
              And my question was:

              But there is little in the way of instruction on how to get your game session and cast to it so that you can use those functions.
              Not about where it was but how to get it and cast to it, which is different from every other core piece like the game mode, game instance, game state, etc. Simply stating "You can get it from the game mode" is not a helpful answer to that question.

              Comment


                #8
                This is how you get it and you don't have to Cast it to call KickPlayer since it is already a GameSession Type.

                Comment


                  #9
                  Originally posted by GarnerP57 View Post
                  This is how you get it and you don't have to Cast it to call KickPlayer since it is already a GameSession Type.
                  That's why I was asking for specifics, that answer doesn't come up on google searches for "get game session" and the only results I was getting were threads like this with vague references and no specifics. Thank you for that, that is a lot easier than my solution.

                  Comment


                    #10
                    You won't find a lot of decent multiplayer tutorials on the web at large unfortunately, a few of us have even complained in the past that Epic's official MP tutorials don't cover the best practices. It's a complicated topic and the best documentation is the source code itself, along with Epic's ShooterGame example project - which is extremely comprehensive.

                    The GameSession is just an actor spawned by the Server - I figured my comment would be enough for you to go looking and find what you need. As has been said you can get the spawned GameSession from there. You will most likely need to subclass it however and add your own code, because the default engine implementation is pretty barebones at best. Again, ShooterGame is the place to look for info.

                    IIRC there is no "Ban" functionality implemented by default, it just routes straight to kick. That's something you have to add yourself since the concept of banning is usually unique and bespoke for every game.

                    Comment

                    Working...
                    X