예제 #1
0
        public static void initServer()
        {
            Global.echo("\n--------- Initializing " + Globals.GetString("appName") + ": Server Scripts ---------");

            // Load prefs
            string prefPath = Core.HelperFunctions.getPrefpath();

            if (Global.isFile(prefPath + "/serverPrefs.cs"))
            {
                Global.exec(prefPath + "/serverPrefs.cs");
            }
            else
            {
                //todo exec server/defaults.cs
                Global.exec("data/clientServer/scripts/server/defaults.cs");
            }

            Audio.Init();
            Commands.Init();
            Message.Init();
            LevelDownload.Init();
            LevelLoad.Init();
            LevelInfo.Init();
            GameConnectionToClient.Init();

            // Server::Status is returned in the Game Info Query and represents the
            // current status of the server. This string sould be very short.
            Globals.SetString("Server::Status", "Unknown");

            // Turn on testing/debug script functions
            Globals.SetBool("Server::TestCheats", false);

            // Specify where the mission files are.
            Globals.SetString("Server::MissionFileSpec", "data/levels/*.mis");
        }
예제 #2
0
        //-----------------------------------------------------------------------------
        public static void messageClient(GameConnectionToClient client, string msgType, string msgString, params string[] args)
        {
            List <string> argList = new List <string>(args);

            argList.Insert(0, msgType);
            argList.Insert(1, msgString);
            Global.commandToClient(client, "ServerMessage".Tag(), argList.ToArray());
        }
예제 #3
0
        public static void messageAll(string msgType, string msgString, params string[] args)
        {
            SimSet ClientGroup = Sim.FindObject <SimSet>("ClientGroup");

            for (uint i = 0; i < ClientGroup.getCount(); i++)
            {
                GameConnectionToClient client = ClientGroup.getObject(i).As <GameConnectionToClient>();
                messageClient(client, msgType, msgString, args);
            }
        }
예제 #4
0
        //-----------------------------------------------------------------------------
        // Misc. server commands avialable to clients
        //-----------------------------------------------------------------------------

        //----------------------------------------------------------------------------
        // Debug commands
        //----------------------------------------------------------------------------
        public static void serverCmdNetSimulateLag(string client, string msDelay, string packetLossPercent)
        {
            GameConnectionToClient clientConnection = Sim.FindObject <GameConnectionToClient>(client);

            if (clientConnection.IsAdmin)
            {
                float pctLossPrct = float.Parse(packetLossPercent);
                int   delay       = int.Parse(msDelay);

                clientConnection.setSimulatedNetParams(pctLossPrct, delay);
            }
        }
예제 #5
0
        /// <summary>
        /// Sends mission description to the client
        /// </summary>
        /// <param name="client"></param>
        public static void sendLoadInfoToClient(GameConnectionToClient client)
        {
            Torque3D.LevelInfo theLevelInfo = Sim.FindObject <Torque3D.LevelInfo>("theLevelInfo");
            Message.messageClient(client, Global.addTaggedString("MsgLoadInfo"), "", theLevelInfo.getFieldValue("levelName"));

            for (int i = 0; !string.IsNullOrEmpty(theLevelInfo.getFieldValue($"desc[{i}]")); i++)
            {
                Message.messageClient(client, Global.addTaggedString("MsgLoadDescription"), "", theLevelInfo.getFieldValue(
                                          $"desc[{i}]"));
            }

            Message.messageClient(client, Global.addTaggedString("MsgLoadInfoDone"), "");
        }
예제 #6
0
        public static void messageAllExcept(GameConnectionToClient client, string msgType, string msgString, params string[] args)
        {
            //can exclude a client, a team or both. A -1 value in either field will ignore that exclusion, so
            //messageAllExcept(-1, -1, $Mesblah, 'Blah!'); will message everyone (since there shouldn't be a client -1 or client on team -1).
            SimSet ClientGroup = Sim.FindObject <SimSet>("ClientGroup");

            for (uint i = 0; i < ClientGroup.getCount(); i++)
            {
                GameConnectionToClient recipient = ClientGroup.getObject(i).As <GameConnectionToClient>();
                if (recipient.getId() != client.getId())
                {
                    messageClient(recipient, msgType, msgString, args);
                }
            }
        }
예제 #7
0
        //-----------------------------------------------------------------------------
        //This is the first call made by the server to kick the loading process off
        public static void loadMission(string missionName, bool isFirstMission)
        {
            endMission();
            Global.echo("*** LOADING MISSION: " + missionName);
            Global.echo("*** Stage 1 load");

            // increment the mission sequence (used for ghost sequencing)
            Globals.Increment("missionSequence");
            Globals.SetBool("missionRunning", false);
            Globals.SetString("Server::MissionFile", missionName);
            Globals.SetString("Server::LoadFailMsg", "");

            // Extract mission info from the mission file,
            // including the display name and stuff to send
            // to the client.
            LevelInfo.buildLoadInfo(missionName);

            SimGroup ClientGroup = Sim.FindObject <SimGroup>("ClientGroup");

            // Download mission info to the clients
            int count = ClientGroup.getCount();

            for (uint cl = 0; cl < count; cl++)
            {
                GameConnectionToClient client = ClientGroup.getObject(cl).As <GameConnectionToClient>();

                if (!client.isAIControlled())
                {
                    LevelInfo.sendLoadInfoToClient(client);
                }
            }

            // Now that we've sent the LevelInfo to the clients
            // clear it so that it won't conflict with the actual
            // LevelInfo loaded in the level
            LevelInfo.clearLoadInfo();

            // if this isn't the first mission, allow some time for the server
            // to transmit information to the clients:
            if (isFirstMission || Globals.GetString("Server::ServerType").Equals("SinglePlayer"))
            {
                loadMissionStage2();
            }
            else
            {
                Global.schedule(Globals.GetString("MissionLoadPause"), "ServerGroup", "loadMissionStage2");
            };
        }
        private bool isNameUnique(string name)
        {
            SimGroup ClientGroup = Sim.FindObject <SimGroup>("ClientGroup");

            for (uint i = 0; i < ClientGroup.getCount(); i++)
            {
                GameConnectionToClient test = ClientGroup.getObject(i).As <GameConnectionToClient>();
                string rawName = Global.stripChars(Global.detag(test.PlayerName.Tag()),
                                                   "\\cp\\co\\c6\\c7\\c8\\c9".ColorEscape());
                if (name.Equals(rawName))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #9
0
        public static void serverCmdMissionStartPhase2Ack(string client, string seq)
        {
            GameConnectionToClient clientConnection = Sim.FindObject <GameConnectionToClient>(client);

            // Make sure to ignore calls from a previous mission load
            if (!seq.Equals(Globals.GetString("missionSequence")) || !Globals.GetBool("MissionRunning") || clientConnection.CurrentPhase != "1.5")
            {
                return;
            }

            clientConnection.CurrentPhase = "2";

            // Update mod paths, this needs to get there before the objects.
            clientConnection.transmitPaths();

            // Start ghosting objects to the client
            clientConnection.activateGhosting();
        }
예제 #10
0
        public static void serverCmdMissionStartPhase1Ack(string client, string seq)
        {
            GameConnectionToClient clientConnection = Sim.FindObject <GameConnectionToClient>(client);

            // Make sure to ignore calls from a previous mission load
            if (!seq.Equals(Globals.GetString("missionSequence")) || !Globals.GetBool("MissionRunning") || clientConnection.CurrentPhase != "0")
            {
                return;
            }

            clientConnection.CurrentPhase = "1";

            // Start with the CRC
            clientConnection.setMissionCRC(Globals.GetInt("missionCRC"));

            // Send over the datablocks...
            // OnDataBlocksDone will get called when have confirmation
            // that they've all been received.
            clientConnection.transmitDataBlocks(Globals.GetInt("missionSequence"));
        }
예제 #11
0
        public static void serverCmdMissionStartPhase3Ack(string client, string seq)
        {
            GameConnectionToClient clientConnection = Sim.FindObject <GameConnectionToClient>(client);

            // Make sure to ignore calls from a previous mission load
            if (!seq.Equals(Globals.GetString("missionSequence")) || !Globals.GetBool("MissionRunning") || clientConnection.CurrentPhase != "2")
            {
                return;
            }

            clientConnection.CurrentPhase = "3";

            // Server is ready to drop into the game

            Torque3D.LevelInfo TheLevelInfo = Sim.FindObject <Torque3D.LevelInfo>("TheLevelInfo");

            //Have any special game-play handling here
            TheLevelInfo.call("onClientEnterGame", client);

            clientConnection.startMission();
        }
예제 #12
0
        public static void onServerDestroyed()
        {
            Global.physicsStopSimulation("server");

            if (!Global.isObject("MissionGroup"))
            {
                return;
            }

            Global.echo("*** ENDING MISSION");

            // Inform the game code we're done.
            Torque3D.LevelInfo TheLevelInfo = Sim.FindObject <Torque3D.LevelInfo>("TheLevelInfo");
            //todo onMissionEnded
            TheLevelInfo.call("onMissionEnded");

            SimGroup ClientGroup = Sim.FindObject <SimGroup>("ClientGroup");

            // Inform the clients
            for (uint clientIndex = 0; clientIndex < ClientGroup.getCount(); clientIndex++)
            {
                // clear ghosts and paths from all clients
                GameConnectionToClient cl = ClientGroup.getObject(clientIndex).As <GameConnectionToClient>();
                cl.endMission();
                cl.resetGhosting();
                cl.clearPaths();
            }

            SimGroup MissionGroup   = Sim.FindObject <SimGroup>("MissionGroup");
            SimGroup MissionCleanup = Sim.FindObject <SimGroup>("MissionCleanup");

            // Delete everything
            MissionGroup.delete();
            MissionCleanup.delete();

            Global.clearServerPaths();
        }