Esempio n. 1
0
        public static void onExit()
        {
            ModuleManager ModuleDatabase = Sim.FindObject <ModuleManager>("ModuleDatabase");

            ModuleDatabase.UnloadExplicit("CoreModule");
            ModuleDatabase.UnloadGroup("Game");
        }
        //-----------------------------------------------------------------------------
        // Called when all datablocks have been transmitted.
        public void onEnterGame()
        {
            //TODO should this be pClient
            //GameConnection client = Sim.FindObject<GameConnection>(pClient);

            // Create a camera for the client.
            Camera theCamera = new Camera("TheCamera")
            {
                DataBlock = Sim.FindObjectByName <CameraData>("Observer")
            };

            theCamera.registerObject();
            theCamera.setTransform(new TransformF(new Point3F(0, 0, 2), new AngAxisF(1, 0, 0, 0)));

            // Cameras are not ghosted (sent across the network) by default; we need to
            // do it manually for the client that owns the camera or things will go south
            // quickly.
            theCamera.scopeToClient(this);
            // And let the client control the camera.
            setControlObject(theCamera);
            // Add the camera to the group of game objects so that it's cleaned up when
            // we close the game.
            SimGroup gameGroup = Sim.FindObject <SimGroup>("GameGroup");

            gameGroup.add(theCamera);
            // Activate HUD which allows us to see the game. This should technically be
            // a commandToClient, but since the client and server are on the same
            // machine...
            GuiCanvas canvas = Sim.FindObject <GuiCanvas>("Canvas");

            canvas.setContent(Sim.FindObject <GuiTSCtrl>("PlayGui"));
            Global.activateDirectInput();
        }
Esempio n. 3
0
        public PlayGui()
        {
            Name         = "PlayGui";
            IsContainer  = true;
            Profile      = Sim.FindObject <GuiControlProfile>("GuiDefaultProfile");
            HorizSizing  = GuiHorizontalSizing.ResizeRight;
            VertSizing   = GuiVerticalSizing.ResizeBottom;
            Position     = new Point2I(0, 0);
            Extent       = new Point2I(1024, 768);
            MinExtent    = new Point2I(8, 8);
            CanSave      = true;
            Visible      = true;
            Margin       = new RectSpacingI(0, 0, 0, 0);
            Padding      = new RectSpacingI(0, 0, 0, 0);
            AnchorTop    = true;
            AnchorBottom = false;
            AnchorLeft   = true;
            AnchorRight  = false;
            CameraZRot   = 0.0f;
            ForceFOV     = 0.0f;

            /* TODO: Are these necessary? If they are, set them with setField from SimObject
             *    enabled = "1";
             *    helpTag = "0";
             *    noCursor = "0";
             */
        }
Esempio n. 4
0
        /// <summary>
        /// A function used in order to easily parse the MissionGroup for classes . I'm pretty
        /// sure at this point the function can be easily modified to search the any group as well.
        /// </summary>
        /// <param name="className"></param>
        /// <param name="childGroup"></param>
        public static bool parseMissionGroup(string className, SimGroup childGroup = null)
        {
            if (childGroup == null)
            {
                childGroup = Sim.FindObject <SimGroup>("MissionGroup");
            }

            for (uint i = 0; i < childGroup.getCount(); i++)
            {
                if (childGroup.getObject(i).getClassName().Equals(className))
                {
                    return(true);
                }

                if (childGroup.getObject(i).getClassName().Equals("SimGroup"))
                {
                    if (parseMissionGroup(className, childGroup.getObject(i).As <SimGroup>()))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public static void disconnectedCleanup()
        {// End mission, if it's running.
            if (Globals.GetBool("Client::missionRunning"))
            {
                LevelLoad.clientEndMission();
            }

            // Disable mission lighting if it's going, this is here
            // in case we're disconnected while the mission is loading.

            Globals.SetBool("lightingMission", false);
            Globals.SetBool("sceneLighting::terminateLighting", true);

            // Back to the launch screen
            if (Global.isObject("MainMenuGui"))
            {
                Core.Canvas.GameCanvas.setContent(Sim.FindObject <GuiControl>("MainMenuGui"));
            }

            // Before we destroy the client physics world
            // make sure all ServerConnection objects are deleted.
            if (Global.isObject("ServerConnection"))
            {
                Sim.FindObject <GameConnectionToServer>("ServerConnection").deleteAllObjects();
            }

            // We can now delete the client physics simulation.
            Global.physicsDestroyWorld("client");
        }
Esempio n. 6
0
        //------------------------------------------------------------------------------
        // Loading info is text displayed on the client side while the mission
        // is being loaded.  This information is extracted from the mission file
        // and sent to each the client as it joins.
        //------------------------------------------------------------------------------


        /// <summary>
        /// Clears the mission info stored
        /// </summary>
        public static void clearLoadInfo()
        {
            if (Global.isObject("TheLevelInfo"))
            {
                Sim.FindObject <Torque3D.LevelInfo>("TheLevelInfo").delete();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Create a server of the given type, load the given level, and then
        /// create a local client connection to the server.
        /// </summary>
        /// <param name="serverType"></param>
        /// <param name="level"></param>
        /// <returns>true if succesful.</returns>
        public static bool createAndConnectToLocalServer(string serverType, string level)
        {
            if (!createServer(serverType, level))
            {
                return(false);
            }

            GameConnectionToServer ServerConnection = new GameConnectionToServer("ServerConnection", true);
            SimGroup RootGroup = Sim.FindObject <SimGroup>("RootGroup");

            RootGroup.add(ServerConnection);

            ServerConnection.setConnectArgs(Globals.GetString("pref::Player::Name"));
            ServerConnection.setJoinPassword(Globals.GetString("Client::Password"));

            string result = ServerConnection.connectLocal();

            if (!string.IsNullOrEmpty(result))
            {
                ServerConnection.delete();
                destroyServer();

                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        public static void onEnd()
        {
            // Delete the objects we created.
            SimGroup gameGroup = Sim.FindObject <SimGroup>("GameGroup");

            gameGroup.delete();
        }
Esempio n. 9
0
        public static void onExit()
        {
            // Stop file change events.
            Global.stopFileChangeNotifications();

            ModuleManager ModuleDatabase = Sim.FindObject <ModuleManager>("ModuleDatabase");

            ModuleDatabase.unloadExplicit("Game");
        }
Esempio n. 10
0
 public void OnClientLeaveGame(GameConnection client)
 {
     // Cleanup the camera
     if (Global.IsObject(GetFieldValue("camera")))
     {
         Camera camera = Sim.FindObject <Camera>(GetFieldValue("camera"));
         camera.Delete();
     }
 }
Esempio n. 11
0
        public static void unlockShadowViz()
        {
            if (!Global.isObject("AL_ShadowVizOverlayCtrl"))
            {
                return;
            }
            GuiControl AL_ShadowVizOverlayCtrl = Sim.FindObject <GuiControl>("AL_ShadowVizOverlayCtrl");

            AL_ShadowVizOverlayCtrl.setFieldValue("isLocked", "false");
        }
Esempio n. 12
0
        //----------------------------------------------------------------------------
        // Helper functions
        //----------------------------------------------------------------------------

        public static void connect(string server)
        {
            GameConnectionToServer conn = new GameConnectionToServer("ServerConnection", true);
            SimGroup RootGroup          = Sim.FindObject <SimGroup>("RootGroup");

            RootGroup.add(conn);
            conn.setConnectArgs(Globals.GetString("pref::Player::Name"));
            conn.setJoinPassword(Globals.GetString("Client::Password"));
            conn.connect(server);
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
        public static void ServerPlay3D(SFXProfile profile, TransformF transform)
        {
            SimSet ClientGroup = Sim.FindObject <SimSet>("ClientGroup");

            // Play the given sound profile at the given position on every client
            // The sound will be transmitted as an event, not attached to any object.
            for (uint i = 0; i < ClientGroup.getCount(); i++)
            {
                ClientGroup.getObject(i).As <GameConnectionToClient>().play3D(profile, transform);
            }
        }
        /// <summary>
        /// This function is called when a client drops for any reason
        /// </summary>
        /// <param name="reason"></param>
        public void onDrop(string reason)
        {
            Torque3D.LevelInfo theLevelInfo = Sim.FindObject <Torque3D.LevelInfo>("TheLevelInfo");
            if (Globals.GetBool("missionRunning"))
            {
                theLevelInfo.call("onClientLeaveGame");
            }

            Server.removeFromServerGuidList(Guid);

            Globals.Decrement("Server::PlayerCount");
        }
Esempio n. 16
0
        public static void onMissionDownloadProgress(float progress)
        {
            if (!Global.isObject("LoadingProgress"))
            {
                return;
            }

            GuiProgressBitmapCtrl LoadingProgress = Sim.FindObject <GuiProgressBitmapCtrl>("LoadingProgress");

            LoadingProgress.setValue(progress.ToString());
            Canvas.GameCanvas.repaint(33);
        }
Esempio n. 17
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);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Echo the mission information to the console
        /// </summary>
        /// <param name="mission"></param>
        public static void dumpLoadInfo()
        {
            Torque3D.LevelInfo theLevelInfo = Sim.FindObject <Torque3D.LevelInfo>("theLevelInfo");

            Global.echo("Level Name: " + theLevelInfo.Name);
            Global.echo("Level Description:");

            for (int i = 0; !string.IsNullOrEmpty(theLevelInfo.getFieldValue($"desc[{i}]")); i++)
            {
                Global.echo("   " + theLevelInfo.getFieldValue($"desc[{i}]"));
            }
        }
Esempio n. 19
0
        public void OnCollision(StaticShape coin, CoinCollector other, Point3F vec, float len)
        {
            ParticleEmitterNode emitterNode = new ParticleEmitterNode {
                DataBlock = Sim.FindObject <ParticleEmitterNodeData>("CoinNode"),
                Emitter   = Sim.FindObject <ParticleEmitterData>("CoinEmitter"),
                Position  = coin.GetPosition()
            };

            emitterNode.RegisterObject();
            emitterNode.Schedule("200", "delete");
            coin.Delete();

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

            other.Client.CoinsFound++;
            Core.Functions.MessageAll("MsgCoinPickedUp".Tag(), "-1", other.Client.PlayerName,
                                      other.Client, other.Client.CoinsFound.ToString(), other.Client.Kills.ToString(), other.Client.Deaths.ToString());
            if (Coins is null || Coins.GetCount() > 0)
            {
                return;
            }
            CoinCollectionGameConnection winnerClient =
                Core.Objects.ClientGroup.GetObject(0).As <CoinCollectionGameConnection>();

            List <CoinCollectionGameConnection> loserClients = new List <CoinCollectionGameConnection>();

            for (uint i = 1; i < Core.Objects.ClientGroup.GetCount(); i++)
            {
                var client = Core.Objects.ClientGroup.GetObject(i).As <CoinCollectionGameConnection>();
                if (client.CoinsFound > winnerClient.CoinsFound)
                {
                    loserClients.Add(winnerClient);
                    winnerClient = client;
                }
                else
                {
                    loserClients.Add(client);
                }
            }

            loserClients.ForEach(client =>
                                 Global.CommandToClient(
                                     client,
                                     "ShowDefeat".Tag(),
                                     client.CoinsFound.ToString()
                                     ));

            Global.CommandToClient(
                winnerClient,
                "ShowVictory".Tag(),
                winnerClient.CoinsFound.ToString());
        }
Esempio n. 20
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"), "");
        }
Esempio n. 21
0
        public static void onMissionDownloadPhase(string phase)
        {
            if (!Global.isObject("LoadingProgress"))
            {
                return;
            }

            GuiProgressBitmapCtrl LoadingProgress    = Sim.FindObject <GuiProgressBitmapCtrl>("LoadingProgress");
            GuiTextCtrl           LoadingProgressTxt = Sim.FindObject <GuiTextCtrl>("LoadingProgressTxt");

            LoadingProgress.setValue("0");
            LoadingProgressTxt.setValue(phase);
            Canvas.GameCanvas.repaint();
        }
Esempio n. 22
0
        public static void showShadovVizForLight(string light)
        {
            if (!Global.isObject("AL_ShadowVizOverlayCtrl"))
            {
                return;
            }
            GuiControl AL_ShadowVizOverlayCtrl = Sim.FindObject <GuiControl>("AL_ShadowVizOverlayCtrl");

            if (!AL_ShadowVizOverlayCtrl.isAwake())
            {
                Canvas.GameCanvas.pushDialog(AL_ShadowVizOverlayCtrl.Name, 100);
            }
            _setShadowVizLight(light, "true");
        }
Esempio n. 23
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);
                }
            }
        }
Esempio n. 24
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);
        }
        public void initialControlSet()
        {
            Global.echo("*** Initial Control Object");

            // The first control object has been set by the server
            // and we are now ready to go.

            // first check if the editor is active
            if (!Global.isToolBuild() || !Global.isMethod("Editor", "checkActiveLoadDone") || !GenericMarshal.StringToBool(Global.call("Editor::checkActiveLoadDone")))
            {
                GuiTSCtrl PlayGui = Sim.FindObject <GuiTSCtrl>("PlayGui");
                if (Core.Canvas.GameCanvas.getContent() != PlayGui.getId())
                {
                    Core.Canvas.GameCanvas.setContent(PlayGui);
                }
            }
        }
        //-----------------------------------------------------------------------------
        // Disconnect
        //-----------------------------------------------------------------------------

        public static void disconnect()
        {
            // We need to stop the client side simulation
            // else physics resources will not cleanup properly.
            Global.physicsStopSimulation("client");

            // Delete the connection if it's still there.
            if (Global.isObject("ServerConnection"))
            {
                Sim.FindObject <GameConnectionToServer>("ServerConnection").delete();
            }

            disconnectedCleanup();

            // Call destroyServer in case we're hosting
            Server.Server.destroyServer();
        }
Esempio n. 28
0
        /// <summary>
        /// A helper function which will return the ghosted client object
        /// from a server object when connected to a local server.
        /// </summary>
        /// <param name="serverObject"></param>
        public static int serverToClientObject(SimObject serverObject)
        {
            Debug.Assert(Global.isObject("LocalClientConnection"), "serverToClientObject() - No local client connection found!");
            Debug.Assert(Global.isObject("ServerConnection"), "serverToClientObject() - No server connection found!");

            GameConnection LocalClientConnection = Sim.FindObject <GameConnection>("LocalClientConnection");
            GameConnection ServerConnection      = Sim.FindObject <GameConnection>("ServerConnection");

            int ghostId = LocalClientConnection.getGhostID(serverObject.getId());

            if (ghostId == -1)
            {
                return(0);
            }

            return(ServerConnection.resolveGhostID(ghostId));
        }
Esempio n. 29
0
        private static object ConvertArgFromString(Type objType, string obj)
        {
            if (typeof(ISimObject).IsAssignableFrom(objType))
            {
                return(Sim.FindObject <UnknownSimObject>(obj).As(objType));
            }

            if (objType == typeof(int))
            {
                return(int.Parse(obj));
            }
            if (objType == typeof(uint))
            {
                return(uint.Parse(obj));
            }
            if (objType == typeof(float))
            {
                return(float.Parse(obj));
            }
            if (objType == typeof(double))
            {
                return(double.Parse(obj));
            }
            if (objType == typeof(bool))
            {
                return(GenericMarshal.StringToBool(obj));
            }
            if (objType.IsEnum)
            {
                if (string.IsNullOrEmpty(obj))
                {
                    return(Enum.Parse(objType, "0", true));
                }

                return(Enum.Parse(objType, obj, true));
            }

            ConstructorInfo cinfo = objType.GetConstructor(new[] { typeof(string) });

            if (cinfo != null)
            {
                return(cinfo.Invoke(new object[] { obj }));
            }

            return(obj);
        }
Esempio n. 30
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();
        }