Пример #1
0
        private static void InitProjectSpecific()
        {
            commands.Add(new Command("restart|reset", "restart/reset: Close and restart the server.", (string[] args) =>
            {
                NewMessage("*****************", Color.Lime);
                NewMessage("RESTARTING SERVER", Color.Lime);
                NewMessage("*****************", Color.Lime);
                GameMain.Instance.CloseServer();
                GameMain.Instance.StartServer();
            }));

            commands.Add(new Command("exit|quit|close", "exit/quit/close: Exit the application.", (string[] args) =>
            {
                GameMain.ShouldRun = false;
            }));

            commands.Add(new Command("say", "say [message]: Send a chat message that displays \"HOST\" as the sender.", (string[] args) =>
            {
                string text = string.Join(" ", args);
                text        = "HOST: " + text;
                GameMain.Server.SendChatMessage(text, ChatMessageType.Server);
            }));

            commands.Add(new Command("msg", "msg [message]: Send a chat message with no sender specified.", (string[] args) =>
            {
                string text = string.Join(" ", args);
                GameMain.Server.SendChatMessage(text, ChatMessageType.Server);
            }));

            commands.Add(new Command("servername", "servername [name]: Change the name of the server.", (string[] args) =>
            {
                GameMain.Server.Name = string.Join(" ", args);
                GameMain.NetLobbyScreen.ChangeServerName(string.Join(" ", args));
            }));

            commands.Add(new Command("servermsg", "servermsg [message]: Change the message displayed in the server lobby.", (string[] args) =>
            {
                GameMain.NetLobbyScreen.ChangeServerMessage(string.Join(" ", args));
            }));

            commands.Add(new Command("seed|levelseed", "seed/levelseed: Changes the level seed for the next round.", (string[] args) =>
            {
                GameMain.NetLobbyScreen.LevelSeed = string.Join(" ", args);
            }));

            commands.Add(new Command("randomizeseed", "randomizeseed: Toggles level seed randomization on/off.", (string[] args) =>
            {
                GameMain.Server.RandomizeSeed = !GameMain.Server.RandomizeSeed;
                NewMessage((GameMain.Server.RandomizeSeed ? "Enabled" : "Disabled") + " level seed randomization.", Color.Cyan);
            }));

            commands.Add(new Command("gamemode", "gamemode [name]/[index]: Select the game mode for the next round. The parameter can either be the name or the index number of the game mode (0 = sandbox, 1 = mission, etc).", (string[] args) =>
            {
                int index = -1;
                if (int.TryParse(string.Join(" ", args), out index))
                {
                    if (index > 0 && index < GameMain.NetLobbyScreen.GameModes.Length &&
                        GameMain.NetLobbyScreen.GameModes[index].Name == "Campaign")
                    {
                        MultiPlayerCampaign.StartCampaignSetup();
                    }
                    else
                    {
                        GameMain.NetLobbyScreen.SelectedModeIndex = index;
                    }
                }
                else
                {
                    string modeName = string.Join(" ", args);
                    if (modeName.ToLowerInvariant() == "campaign")
                    {
                        MultiPlayerCampaign.StartCampaignSetup();
                    }
                    else
                    {
                        GameMain.NetLobbyScreen.SelectedModeName = modeName;
                    }
                }
                NewMessage("Set gamemode to " + GameMain.NetLobbyScreen.SelectedModeName, Color.Cyan);
            },
                                     () =>
            {
                return(new string[][]
                {
                    GameModePreset.list.Select(gm => gm.Name).ToArray()
                });
            }));

            commands.Add(new Command("mission", "mission [name]/[index]: Select the mission type for the next round. The parameter can either be the name or the index number of the mission type (0 = first mission type, 1 = second mission type, etc).", (string[] args) =>
            {
                int index = -1;
                if (int.TryParse(string.Join(" ", args), out index))
                {
                    GameMain.NetLobbyScreen.MissionTypeIndex = index;
                }
                else
                {
                    GameMain.NetLobbyScreen.MissionTypeName = string.Join(" ", args);
                }
                NewMessage("Set mission to " + GameMain.NetLobbyScreen.MissionTypeName, Color.Cyan);
            },
                                     () =>
            {
                return(new string[][]
                {
                    MissionPrefab.MissionTypes.ToArray()
                });
            }));

            commands.Add(new Command("sub|submarine", "submarine [name]: Select the submarine for the next round.", (string[] args) =>
            {
                Submarine sub = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", args).ToLower());

                if (sub != null)
                {
                    GameMain.NetLobbyScreen.SelectedSub = sub;
                }
                sub = GameMain.NetLobbyScreen.SelectedSub;
                NewMessage("Selected sub: " + sub.Name + (sub.HasTag(SubmarineTag.Shuttle) ? " (shuttle)" : ""), Color.Cyan);
            },
                                     () =>
            {
                return(new string[][]
                {
                    Submarine.Loaded.Select(s => s.Name).ToArray()
                });
            }));

            commands.Add(new Command("shuttle", "shuttle [name]: Select the specified submarine as the respawn shuttle for the next round.", (string[] args) =>
            {
                Submarine shuttle = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", args).ToLower());

                if (shuttle != null)
                {
                    GameMain.NetLobbyScreen.SelectedShuttle = shuttle;
                }
                shuttle = GameMain.NetLobbyScreen.SelectedShuttle;
                NewMessage("Selected shuttle: " + shuttle.Name + (shuttle.HasTag(SubmarineTag.Shuttle) ? "" : " (not shuttle)"), Color.Cyan);
            },
                                     () =>
            {
                return(new string[][]
                {
                    Submarine.Loaded.Select(s => s.Name).ToArray()
                });
            }));

            commands.Add(new Command("startgame|startround|start", "start/startgame/startround: Start a new round.", (string[] args) =>
            {
                if (Screen.Selected == GameMain.GameScreen)
                {
                    return;
                }
                if (!GameMain.Server.StartGame())
                {
                    NewMessage("Failed to start a new round", Color.Yellow);
                }
            }));

            commands.Add(new Command("endgame|endround|end", "end/endgame/endround: End the current round.", (string[] args) =>
            {
                if (Screen.Selected == GameMain.NetLobbyScreen)
                {
                    return;
                }
                GameMain.Server.EndGame();
            }));

            commands.Add(new Command("entitydata", "", (string[] args) =>
            {
                if (args.Length == 0)
                {
                    return;
                }
                Entity ent = Entity.FindEntityByID(Convert.ToUInt16(args[0]));
                if (ent != null)
                {
                    NewMessage(ent.ToString(), Color.Lime);
                }
            }));

            //"dummy commands" that only exist so that the server can give clients permissions to use them
            commands.Add(new Command("control|controlcharacter", "control [character name]: Start controlling the specified character (client-only).", null));
            commands.Add(new Command("los", "Toggle the line of sight effect on/off (client-only).", null));
            commands.Add(new Command("lighting|lights", "Toggle lighting on/off (client-only).", null));
            commands.Add(new Command("debugdraw", "Toggle the debug drawing mode on/off (client-only).", null));
            commands.Add(new Command("togglehud|hud", "Toggle the character HUD (inventories, icons, buttons, etc) on/off (client-only).", null));
            commands.Add(new Command("followsub", "Toggle whether the camera should follow the nearest submarine (client-only).", null));
            commands.Add(new Command("toggleaitargets|aitargets", "Toggle the visibility of AI targets (= targets that enemies can detect and attack/escape from) (client-only).", null));

#if DEBUG
            commands.Add(new Command("eventdata", "", (string[] args) =>
            {
                if (args.Length == 0)
                {
                    return;
                }
                ServerEntityEvent ev = GameMain.Server.EntityEventManager.Events[Convert.ToUInt16(args[0])];
                if (ev != null)
                {
                    NewMessage(ev.StackTrace, Color.Lime);
                }
            }));

            commands.Add(new Command("spamchatmessages", "", (string[] args) =>
            {
                int msgCount = 1000;
                if (args.Length > 0)
                {
                    int.TryParse(args[0], out msgCount);
                }
                int msgLength = 50;
                if (args.Length > 1)
                {
                    int.TryParse(args[1], out msgLength);
                }

                for (int i = 0; i < msgCount; i++)
                {
                    GameMain.Server.SendChatMessage(ToolBox.RandomSeed(msgLength), ChatMessageType.Default);
                }
            }));
#endif
        }
Пример #2
0
        public void DefaultServerStartup()
        {
            Boolean startcampaign = false;

            //Default Mission Parameters
            if (GameMain.NilMod.DefaultGamemode.ToLowerInvariant() == "mission")
            {
                GameMain.NetLobbyScreen.SelectedModeIndex = 1;
                //GameMain.NilMod.DefaultMissionType = "Cargo";
                //Only select this default if we actually default to mission mode
                switch (GameMain.NilMod.DefaultMissionType.ToLowerInvariant())
                {
                case "random":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 0;
                    break;

                case "salvage":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 1;
                    break;

                case "monster":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 2;
                    break;

                case "cargo":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 3;
                    break;

                case "combat":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 4;
                    break;

                //Random if no valid mission type
                default:
                    GameMain.NetLobbyScreen.MissionTypeIndex = 0;
                    break;
                }
            }
            else if (GameMain.NilMod.DefaultGamemode.ToLowerInvariant() == "campaign")
            {
                startcampaign = true;
                GameMain.NetLobbyScreen.SelectedModeIndex = 1;
            }
            else
            {
                GameMain.NetLobbyScreen.SelectedModeIndex = 0;
            }

            if (GameMain.NilMod.DefaultLevelSeed != "")
            {
                GameMain.NetLobbyScreen.LevelSeed = GameMain.NilMod.DefaultLevelSeed;
            }

            if (GameMain.NilMod.DefaultSubmarine != "")
            {
                Submarine sub = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == GameMain.NilMod.DefaultSubmarine.ToLower());

                if (sub != null)
                {
                    GameMain.NetLobbyScreen.SelectedSub = sub;
                }
                else
                {
                    sub = GameMain.NetLobbyScreen.SelectedSub;
                    DebugConsole.NewMessage("Default submarine: " + GameMain.NilMod.DefaultSubmarine + " not found, using " + sub.Name + " instead", Color.Red);
                }
            }

            if (GameMain.NilMod.DefaultRespawnShuttle != "")
            {
                Submarine shuttle = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == GameMain.NilMod.DefaultRespawnShuttle.ToLower());

                if (shuttle != null)
                {
                    GameMain.NetLobbyScreen.SelectedShuttle = shuttle;
                }
                else
                {
                    shuttle = GameMain.NetLobbyScreen.SelectedShuttle;
                    DebugConsole.NewMessage("Default shuttle: " + GameMain.NilMod.DefaultRespawnShuttle + " not found, using " + shuttle.Name + " instead", Color.Red);
                }
            }

            DebugConsole.NewMessage(
                "Save Server Logs: " + (GameMain.Server.SaveServerLogs ? "YES" : "NO") +
                ", Allow File Transfers: " + (GameMain.Server.AllowFileTransfers ? "YES" : "NO"), Color.Cyan);

            DebugConsole.NewMessage(
                "Allow Spectating: " + (GameMain.Server.AllowSpectating ? "YES" : "NO"), Color.Cyan);

            //LevelSeed = ToolBox.RandomSeed(8);



            DebugConsole.NewMessage(" ", Color.Cyan);

            DebugConsole.NewMessage(
                "Auto Restart: " + (GameMain.Server.AutoRestart ? "YES" : "NO") +
                ", Auto Restart Interval: " + ToolBox.SecondsToReadableTime(GameMain.Server.AutoRestartInterval), Color.Cyan);

            DebugConsole.NewMessage(
                "End Round At Level End: " + (GameMain.Server.EndRoundAtLevelEnd ? "YES" : "NO") +
                ", End Vote Required Ratio: " + (GameMain.Server.EndVoteRequiredRatio * 100) + "%", Color.Cyan);

            DebugConsole.NewMessage(
                "Allow Vote Kick: " + (GameMain.Server.AllowVoteKick ? "YES" : "NO") +
                ", Kick Vote Required Ratio: " + (GameMain.Server.KickVoteRequiredRatio * 100) + "%", Color.Cyan);

            DebugConsole.NewMessage(" ", Color.Cyan);

            DebugConsole.NewMessage(
                "Allow Respawns: " + (GameMain.Server.AllowRespawn ? "YES" : "NO") +
                ", Min Respawn Ratio:" + GameMain.Server.MinRespawnRatio, Color.Cyan);

            DebugConsole.NewMessage(
                "Respawn Interval: " + ToolBox.SecondsToReadableTime(GameMain.Server.RespawnInterval) +
                ", Max Transport Time:" + ToolBox.SecondsToReadableTime(GameMain.Server.MaxTransportTime), Color.Cyan);

            DebugConsole.NewMessage(" ", Color.Cyan);

            DebugConsole.NewMessage(
                "Gamemode Selection: " + GameMain.Server.ModeSelectionMode.ToString() +
                ", Submarine Selection: " + GameMain.Server.SubSelectionMode.ToString(), Color.Cyan);

            DebugConsole.NewMessage(
                "Default Gamemode: " + GameMain.NetLobbyScreen.SelectedModeName +
                ", Default Mission Type: " + GameMain.NetLobbyScreen.MissionTypeName, Color.Cyan);

            DebugConsole.NewMessage("TraitorsEnabled: " + GameMain.Server.TraitorsEnabled.ToString(), Color.Cyan);

            DebugConsole.NewMessage(" ", Color.Cyan);

            if (!startcampaign)
            {
                DebugConsole.NewMessage("Starting with Level Seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
                DebugConsole.NewMessage("On submarine: " + GameMain.NetLobbyScreen.SelectedSub.Name, Color.Cyan);
                DebugConsole.NewMessage("Using respawn shuttle: " + GameMain.NetLobbyScreen.SelectedShuttle.Name, Color.Cyan);
            }
            else
            {
                if (GameMain.NilMod.CampaignDefaultSaveName != "")
                {
                    MultiPlayerCampaign.StartCampaignSetup(true);
                }
                else
                {
                    DebugConsole.NewMessage("Nilmod default campaign savefile not specified. Please setup the campaign or specify a filename in nilmodsettings.xml", Color.Cyan);
                    MultiPlayerCampaign.StartCampaignSetup(false);
                }
                DebugConsole.NewMessage(" ", Color.Cyan);
            }
        }