protected virtual void HandleReceivedAccess(NetworkMessage netmsg) { var token = netmsg.ReadMessage <StringMessage>().value; Controller.ValidateAccess(token, (validatedAccess, error) => { if (validatedAccess == null) { Logger.Error("Failed to confirm access token:" + error); // Confirmation failed, disconnect the user netmsg.conn.Disconnect(); return; } Logger.Debug("Confirmed token access for peer: " + validatedAccess); // Get account info Msf.Server.Auth.GetPeerAccountInfo(validatedAccess.PeerId, (info, errorMsg) => { if (info == null) { Logger.Error("Failed to get account info of peer " + validatedAccess.PeerId + "" + ". Error: " + errorMsg); return; } Logger.Debug("Got peer account info: " + info); var player = new UnetMsfPlayer(netmsg.conn, info); OnPlayerJoined(player); }); }); }
public virtual void TeleportPlayerToAnotherZone(UnetMsfPlayer player, string zoneName, Vector3 newPos) { // Ignore if there's already a request pending if (_pendingTeleportationRequests.Contains(player.Username)) { return; } var packet = new TeleportRequestPacket() { Username = player.Username, ZoneName = zoneName, Position = newPos.x + "," + newPos.y + "," + newPos.z }; Controller.Connection.SendMessage(WorldDemoOpCodes.TeleportRequest, packet, (status, response) => { // Remove from the list of pending requests _pendingTeleportationRequests.Remove(packet.Username); if (status != ResponseStatus.Success) { Logs.Error(string.Format("Failed to teleport user '{0}' to zone '{1}': " + response.AsString(), player.Username, zoneName)); return; } // At this point, we are certain that player got access to another zone, // so we can force disconnect the player. After that, player will enter the loading screen, // from which he will connect to another zone player.Connection.Disconnect(); }); }
private void OnPlayerLeft(UnetMsfPlayer obj) { if (TerminateWhenLastPlayerQuits && Room.GetPlayers().Count == 0) { Application.Quit(); } }
private void OnPlayerJoined(UnetMsfPlayer player) { // Spawn the player object (https://docs.unity3d.com/Manual/UNetPlayers.html) // This is just a dummy example, you'll need to create your own object (or not) var playerGameObject = new GameObject(); NetworkServer.AddPlayerForConnection(player.Connection, playerGameObject, 0); }
protected virtual void OnPlayerJoined(UnetMsfPlayer player) { // Add to lookups PlayersByPeerId[player.PeerId] = player; PlayersByUsername[player.Username] = player; PlayersByConnectionId[player.Connection.connectionId] = player; if (PlayerJoined != null) { PlayerJoined.Invoke(player); } }
/// <summary> /// Invoked, when client provides a successful access token and enters the room /// </summary> /// <param name="player"></param> private void OnPlayerJoined(UnetMsfPlayer player) { Debug.LogError("Player trigerred OnPlayerJoined"); // Create an instance of the player prefab we made earlier var playerObj = Instantiate(playerPrefab); //add the connection to the game server to make sure the player can update on the client and the gameserver NetworkServer.AddPlayerForConnection(player.Connection, playerObj.gameObject, 0); return; }
protected virtual void OnPlayerLeft(UnetMsfPlayer player) { // Remove from lookups PlayersByPeerId.Remove(player.PeerId); PlayersByUsername.Remove(player.Username); PlayersByConnectionId.Remove(player.Connection.connectionId); if (PlayerLeft != null) { PlayerLeft.Invoke(player); } // Notify controller that the player has left Controller.PlayerLeft(player.PeerId); }
/// <summary> /// Invoked, when client provides a successful access token and enters the room /// </summary> /// <param name="player"></param> private void OnPlayerJoined(UnetMsfPlayer player) { // ----------------------------------- // IF all you want to do is spawn a player: // // MiniNetworkManager.SpawnPlayer(player.Connection, player.Username, "carrot"); // return; // ----------------------------------- // If you want to use player profile // Create an "empty" (default) player profile var defaultProfile = PlayerProfile.CreateProfileInServer(player.Username); // Get coins property from profile var coinsProperty = defaultProfile.GetProperty <ObservableInt>(PlayerProfile.CoinsKey); var completedChambers = defaultProfile.GetProperty <ObservableInt>(PlayerProfile.CompletedChambersKey); // Fill the profile with values from master server Msf.Server.Profiles.FillProfileValues(defaultProfile, (successful, error) => { if (!successful) { Logs.Error("Failed to retrieve profile values: " + error); } // We can still allow players to play with default profile ^_^ // Let's spawn the player character //var playerObject = SpawnPlayer(player.Connection, player.Username, "carrot"); var playerObject = Instantiate(this.playerPrefab, GetStartPosition()); // Set coins value from profile //playerObject.Coins = coinsProperty.Value; //playerObject.CoinsChanged += () => //{ // Every time player coins change, update the profile with new value // coinsProperty.Set(playerObject.Coins); //}; }); }
private void OnPlayerJoined(UnetMsfPlayer obj) { _hasFirstPlayerShowedUp = true; }
private void OnPlayerLeft(UnetMsfPlayer player) { }
// Called on server when client joins server private void OnPlayerLeft(UnetMsfPlayer player) { Debug.Log("Player joined"); return; }
private void OnPlayerLeft(UnetMsfPlayer player) { numberOfPlayers--; }