// ======================== MESSAGE HANDLERS - PLAYER ============================ // ------------------------------------------------------------------------------- // OnClientMessageRequestPlayerLogin // @Client -> @Server // ------------------------------------------------------------------------------- /// <summary> /// Event <c>OnClientMessageRequestPlayerLogin</c>. /// Triggered by the server receiving a player login request from the client. /// </summary> /// <param name="conn"></param> /// <param name="msg"></param> void OnClientMessageRequestPlayerLogin(NetworkConnection conn, ClientMessageRequestPlayerLogin msg) { ServerMessageResponsePlayerLogin message = new ServerMessageResponsePlayerLogin { success = true, text = "", causesDisconnect = false }; // -- check for GetIsUserLoggedIn because that covers all players on the account if (GetIsUserLoggedIn(msg.userName) && DatabaseManager.singleton.TryPlayerLogin(msg.playerName, msg.userName)) { LoginPlayer(conn, msg.userName, msg.playerName, 0); //dont check for token message.text = systemText.playerLoginSuccess; } else { message.text = systemText.playerLoginFailure; message.success = false; debug.LogFormat(this.name, nameof(OnClientMessageRequestPlayerLogin), conn.ID(), "DENIED"); //DEBUG } conn.Send(message); }
// ======================= PUBLIC METHODS - PLAYER ================================ // ------------------------------------------------------------------------------- // RequestPlayerLogin // @Client // ------------------------------------------------------------------------------- /// <summary> /// Protected override function <c>RequestPlayerLogin</c> that returns a boolean. /// Sends a player login request to the server. /// Checks whether the player login request is valid and can be sent to the server. /// Returns a boolean detailing whether the request was sent or not. /// </summary> /// <param name="conn"></param> /// <param name="playername"></param> /// <param name="username"></param> /// <returns> Returns a boolean detailing whether the request was sent to the server. </returns> protected override bool RequestPlayerLogin(NetworkConnection conn, string playername, string username) { if (!base.RequestPlayerLogin(conn, playername, username)) { return(false); } ClientMessageRequestPlayerLogin message = new ClientMessageRequestPlayerLogin { playername = playername, username = username }; // must be readied here, not in the response - otherwise it generates a warning ClientScene.Ready(conn); conn.Send(message); debug.LogFormat(this.name, nameof(RequestPlayerLogin), conn.Id(), username, playername); //DEBUG return(true); }