コード例 #1
0
 public static void GreetNewPlayer(NetworkUser joiningUser)
 {
     if (DropInConfig.WelcomeMessage) //If the host man has enabled this config option.
     {
         var message = DropInConfig.CustomWelcomeMessage;
         if (message.Length > 1000)
         {
             return;
         }
         message = message.ReplaceOnce("{username}", joiningUser.userName);
         message = message.ReplaceOnce("{survivorlist}", string.Join(", ", BodyHelper.GetSurvivorDisplayNames()));
         AddChatMessage(message, 1f);
     }
 }
コード例 #2
0
ファイル: Main.cs プロジェクト: niwith/DropInMultiplayer
        private void JoinAs(NetworkUser user, string characterName, string username)
        {
            if (!DropInConfig.JoinAsEnabled)
            {
                Logger.LogWarning("Join_As disabled. Returning...");
                return;
            }

            if (DropInConfig.HostOnlySpawnAs)
            {
                if (NetworkUser.readOnlyInstancesList[0].netId != user.netId)
                {
                    Logger.LogWarning("HostOnlySpawnAs is enabled and the person using join_as isn't host. Returning!");
                    return;
                }
            }

            if (JoinAsBlocked)
            {
                SendJoinAsBlockedMessage();
                return;
            }

            //Finding the NetworkUser from the person who is using the command.
            NetworkUser player;

            // No user name provided, default to self
            if (string.IsNullOrWhiteSpace(username))
            {
                player = user;
            }
            else
            {
                player = GetNetUserFromString(username);
                if (player == null)
                {
                    ChatHelper.AddChatMessage($"Could not find player with identifier: {username}");
                    return;
                }
            }

            //Finding the body the player wants to spawn as.
            GameObject bodyPrefab = BodyHelper.FindBodyPrefab(characterName);

            // The character the player is trying to spawn as doesn't exist.
            if (!bodyPrefab)
            {
                ChatHelper.AddChatMessage($"{characterName} not found. Availible survivors are: {string.Join(", ", BodyHelper.GetSurvivorDisplayNames())} (or use Random)");
                Logger.LogWarning("Sent message to player informing them that what they requested to join as does not exist. Also bodyPrefab does not exist, returning!");
                return;
            }

            if (player.master == null) // If the player is joining for the first time
            {
                Logger.LogInfo($"Spawning {player.userName} as newly joined player");

                // Make sure the person can actually join. This allows SetupUserCharacterMaster (which is called in OnUserAdded) to work.
                Run.instance.SetFieldValue("allowNewParticipants", true);

                //Now that we've made sure the person can join, let's give them a CharacterMaster.
                Run.instance.OnUserAdded(player);

                ChangeOrSetCharacter(player, bodyPrefab, true);

                // Turn this back off again so a new player isn't immediatly dropped in without getting to pick their character
                Run.instance.SetFieldValue("allowNewParticipants", false);
            }
            else // The player has already joined
            {
                Logger.LogInfo($"{player.userName} has already joined, checking other join conditions");

                if (!DropInConfig.AllowReJoinAs)
                {
                    Logger.LogInfo($"{player.userName} could not use join_as after selecting ");
                    ChatHelper.AddChatMessage($"Sorry {player.userName}! The host has made it so you can't use join_as after selecting character.");
                }
                else if (player.master.lostBodyToDeath)
                {
                    Logger.LogInfo($"{player.userName} is dead and can't change character");
                    ChatHelper.AddChatMessage($"Sorry {player.userName}! You can't use join_as while dead.");
                }
                else
                {
                    Logger.LogInfo($"Changing existing character for {player.userName}");
                    ChangeOrSetCharacter(player, bodyPrefab, false);
                }
            }
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: swuff-star/DropInMultiplayer
 private void GreetNewPlayer(On.RoR2.NetworkUser.orig_Start orig, NetworkUser self)
 {
     orig(self);
     if (NetworkServer.active && Stage.instance != null && //Make sure we're host.
         _config.WelcomeMessage)                           //If the host man has enabled this config option.
     {
         AddChatMessage("Hello " + self.userName + $"! Join the game by typing 'join [character name]' or 'join_as [character name]' in chat (without the apostrophes of course) into the chat. Available survivors are: { string.Join(", ", BodyHelper.GetSurvivorDisplayNames())}", 1f);
     }
 }