Beispiel #1
0
 /// <summary>
 /// Simple use for access to util functions
 /// </summary>
 public CView(CSystem csystem)
 {
     Globals   = csystem.Globals;
     errors    = csystem.errors;
     debug     = csystem.debug;
     View_name = "";
 }
Beispiel #2
0
    //CServer m_ServerReference:

    // Use this for initialization
    void Start()
    {
        //Found this trick to get the initial IP Address, not sure if it works without connection.
        //http://stackoverflow.com/questions/6803073/get-local-ip-address
        using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
        {
            socket.Connect("8.8.8.8", 65530);
            IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
            m_szClientIP = endPoint.Address.ToString();
            Debug.Log(m_szClientIP + " is this client's IP address");
        }

        Debug.LogWarning(CGlobals.GetNistTime().ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
        //CGlobals.GetNISTTime();

        //Client uses as receive udp client
        m_udpClient = new UdpClient(10000);
        m_udpClient.EnableBroadcast   = true;
        m_udpClient.MulticastLoopback = true; //Necessary so it receives its own messages in the multicast.
        //Debug.Log("The updClients ExclusiveAddressUse value is: " + m_udpClient.ExclusiveAddressUse.ToString());// it must false;
        m_pServer = null;
        try
        {
            m_fTimeSinceLastResponse = 0.0f;
            Debug.Log("Beginning to receive: ");
            m_udpClient.BeginReceive(new AsyncCallback(recv), null);
            m_dtBeginDateTime = GetGlobalTime();
            SendUDPMessage('Y', "Begin_Con", m_dtBeginDateTime.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), IPAddress.Broadcast.ToString(), 10000);
        }
        catch (Exception e)
        {
            Debug.Log("caught exception : " + e.ToString());
        }
    }
Beispiel #3
0
    public string m_szMessageContent;              //Contenido del mensaje

    public Message(byte[] in_receivedBytes)
    {
        if (CGlobals.m_bIsEncrypted)           //If the Encryption flag is active, then Decrypt the message before constructing it.
        {
            in_receivedBytes = CGlobals.CesarCipherDecrypt(in_receivedBytes);
        }
        string tmpString = Encoding.UTF8.GetString(in_receivedBytes);

        //Debug.Log("Constructing a Message with: " + tmpString);
        string[] tmpValuesArray = tmpString.Split("\t".ToCharArray(), 6);  //Gives us 6 parts so we can use each one as one of the variables of this object.
        if (tmpValuesArray.Length != 6)
        {
            //Then, the received bytes did not have the correct format (which is, containing 4 tabs '\t' to adequately make the split).
            Debug.LogError("A message was constructed without the correct information. it was:  " + tmpString);
            m_cIsForServer         = '0';
            m_szSenderID           = null;
            m_szTargetAddress      = null;
            m_szMessageType        = null;
            m_szDestinationAddress = null;
            m_szMessageContent     = null;
            return; //return to exit the constructor.
        }

        //Else, everything is formated correctly, so we can create our message object easily.
        m_cIsForServer         = tmpValuesArray[0].ToCharArray()[0]; //By convention, this is where we will store this information.
        m_szSenderID           = tmpValuesArray[1];
        m_szTargetAddress      = tmpValuesArray[2];
        m_szMessageType        = tmpValuesArray[3];
        m_szDestinationAddress = tmpValuesArray[4];
        m_szMessageContent     = tmpValuesArray[5];

        //Debug.Log("A message was created, and it has the values: " + ToString());//Debug to see what does it say.
    }
Beispiel #4
0
    //Maybe also store Speed?? or something like that?
    public GameInstantState(Vector3 in_vPosition, Vector3 in_vEulerAngles, string in_szInputSate = "Still", bool in_bSetToZero = false)
    {
        m_vPosition            = in_vPosition;
        m_vRotationEulerAngles = in_vEulerAngles;

        m_dtTimeGenerated = CGlobals.GetGlobalTime(); //The time this message is generated
        m_szInput         = in_szInputSate;           //Or the name of the default value.
    }
Beispiel #5
0
 public CStructModifications(CSystem system, CGlobals app_globals)
 {
     sys        = system;
     Globals    = app_globals;
     cVistas    = Globals.AppDataSection(dPATH.VIEWS);
     cProgramas = Globals.AppDataSection(dPATH.PROGRAM);
     cProcesos  = Globals.AppDataSection(dPATH.PROCESSES);
 }
Beispiel #6
0
 /// <summary>
 /// Get controls in view from file
 /// </summary>
 /// <param name="Globals"></param>
 /// <param name="view"></param>
 /// <param name="control_guid"></param>
 public TBaseControls(CGlobals Globals, String view)
 {
     jErrors = new JArray();
     prcInfo = new JSonFile(Globals.AppDataSection(dCONTROLS.PATH), view, true);
     if (!prcInfo.hasErrors())
     {
         jErrors = prcInfo.jErrors;
     }
 }
Beispiel #7
0
 /// <summary>
 /// Get objects in view from file
 /// </summary>
 /// <param name="Globals"></param>
 /// <param name="view"></param>
 /// <param name="object_guid"></param>
 public TBaseObjects(CGlobals Globals, String view)
 {
     jErrors = new JArray();
     prcInfo = new JSonFile(Globals.debug, Globals.AppData_path(dCONTROLS.PATH), view, true);
     if (prcInfo.hasErrors())
     {
         jErrors = prcInfo.jErrors;
     }
 }
Beispiel #8
0
        /// <summary>
        /// Send code to editor
        /// </summary>
        /// <param name="arqode_path"></param>
        /// <param name="sys_app_path"></param>
        /// <param name="app_path"></param>
        /// <param name="app_name"></param>
        /// <param name="p_guid"></param>
        /// <param name="prc"></param>
        public static void SendCodeToEditor(String app_path, String app_name, String p_guid, TProcess prc)
        {
            CGlobals sys_globals  = new CGlobals();
            String   sys_app_path = sys_globals.App_path.FullName;
            String   arqode_path  = sys_globals.ARQODE_APP;

            // Save code in editor
            String editor_prc_guid = SaveCode(arqode_path, prc.Guid);

            if (prc.Guid != editor_prc_guid)
            {
                // get map vars code
                CMap cmap = new CMap(sys_app_path, app_path, arqode_path, app_name);

                // Map changes in views
                cmap.MapViews();

                // Map all vars
                String varsregion = cmap.MapVars(prc.BaseInputs as JArray, prc.BaseOutputs as JArray, prc.BaseConfiguration as JArray, prc.vars);

                // Get code file
                String codefile_path = Path.Combine(arqode_path, dEXPORTCODE.P_CODER_CS);
                String codefile      = File.ReadAllText(codefile_path);

                // get code from logic or from process json file
                String codigo_prc = get_Code_from_logic(arqode_path, p_guid);
                if ((codigo_prc == "") && (prc.Code != null) && (prc.Code.ToString() != ""))
                {
                    codigo_prc = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(prc.Code.ToString()));
                }

                if (codigo_prc != "")
                {
                    if (((dEXPORTCODE.P_Ini_code_process_mark + p_guid) == codigo_prc.Split('\n')[0].Replace("\r", "")) && (codefile.Contains(dEXPORTCODE.P_Begin_editor_code_mark)))
                    {
                        int write_code_index = write_code_index = codefile.IndexOf(dEXPORTCODE.P_Begin_editor_code_mark) + dEXPORTCODE.P_Begin_editor_code_mark.Length;

                        codefile = codefile.Insert(write_code_index, "\n\n" + codigo_prc);
                        File.WriteAllText(codefile_path, codefile);
                    }
                }
                else
                {
                    String prc_name = "//" + prc.Name.ToString();
                    codigo_prc = dEXPORTCODE.P_Ini_code_process_mark + p_guid + "\n" + prc_name + "\n\n" + varsregion + "\n\n" + dEXPORTCODE.P_End_code_process_mark + p_guid;
                    int write_code_index = write_code_index = codefile.IndexOf(dEXPORTCODE.P_Begin_editor_code_mark) + dEXPORTCODE.P_Begin_editor_code_mark.Length;
                    codefile = codefile.Insert(write_code_index, "\n\n" + codigo_prc);

                    File.WriteAllText(codefile_path, codefile);
                }
            }
        }
Beispiel #9
0
    //This one uses the defined Multicast Address and port to send, so it's less tedious to use.
    public void SendUDPMessageToGroup(char in_isForServer, string in_szTypeOfMessage, string in_szMessageContent)
    {
        Message NewMessage = new Message(in_isForServer, m_iID.ToString(), m_szClientIP, in_szTypeOfMessage, m_szMulticastIP, in_szMessageContent);

        byte[] msgBytes = Encoding.UTF8.GetBytes(NewMessage.ToString());
        if (CGlobals.m_bIsEncrypted == true)
        {
            msgBytes = CGlobals.CesarCipher(msgBytes);
        }
        //Debug.Log("Sending a message to Multicast group address: " + m_szMulticastIP.ToString() + " and port: " + m_iMulticastPort + " from IP: " + m_szClientIP);
        //Send a message to the server.
        IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse(m_szMulticastIP), m_iMulticastPort);

        m_udpClient.BeginSend(msgBytes, msgBytes.Length, RemoteIpEndPoint, sendCallback, null);//Do the multicast.
    }
Beispiel #10
0
 public TProcess(CSystem csystem, CGlobals Globals, JObject prc)
 {
     sys        = csystem;
     pActivePrc = new JSonFile(prc);
     if (!loadBaseProcess(Globals))
     {
         if (!loadBaseProcess(Globals))
         {
             csystem.ProgramErrors.invalidJSON =
                 String.Format("Error loading json: file not found {0}.{1}. ",
                               dPATH.PROCESSES,
                               Namespace);
         }
     }
 }
Beispiel #11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="base_errors"></param>
        /// <param name="base_debug"></param>
        /// <param name="MainView"></param>
        public CViewsManager(CSystem csystem)
        {
            cs      = csystem;
            globals = csystem.Globals;
            errors  = csystem.errors;
            debug   = csystem.debug;

            listViews = new List <CView>();

            String MainView_name = Globals.get(dGLOBALS.MAIN_VIEW).ToString();

            if (MainView_name != "")
            {
                AddView(MainView_name);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Primary constructor to call from view manager
        /// </summary>
        /// <param name="base_errors"></param>
        /// <param name="base_debug"></param>
        /// <param name="view_name"></param>
        public CView(CSystem csystem, String view_name)
        {
            Globals   = csystem.Globals;
            errors    = csystem.errors;
            debug     = csystem.debug;
            vars      = new Dictionary <string, object>();
            View_name = view_name;
            View_guid = Guid.NewGuid().ToString();
            ctrls     = new Dictionary <String, CtrlStruct>();
            objects   = new Dictionary <String, ObjStruct>();

            // Create main control and descendants
            CreateControl(view_name);

            // Create other objects
            CreateObjects(view_name);
        }
Beispiel #13
0
        public CProgram(CSystem csystem, CGlobals Globals, String program, object program_vars = null)
        {
            sys = csystem;
            // Remove program queued flag
            program_name = (program.StartsWith("&")) ? program.Substring(1) : program;
            // Read program
            progInfo = new JSonFile(Globals.AppDataSection(dPATH.PROGRAM), program_name, true);

            if (!progInfo.hasErrors())
            {
                // Init csystem.ProgramErrors and debug for program execution
                csystem.ProgramErrors = new TErrors(Globals, program);
                csystem.ProgramDebug  = new TDebug(Globals, program);
                debug = csystem.ProgramDebug;

                csystem.ProgramErrors.Name        = Name;
                csystem.ProgramErrors.Description = Description;
                debug.Name        = Name;
                debug.Description = Description;

                // Init vars
                if (program_vars == null)
                {
                    vars = new Dictionary <string, object>();
                }
                else
                {
                    vars = (Dictionary <string, object>)program_vars;
                }
                foreach (JValue var in Variables)
                {
                    if (!vars.ContainsKey(var.Value.ToString()))
                    {
                        vars.Add(var.Value.ToString(), null);
                    }
                }
            }
            else
            {
                csystem.ProgramErrors             = new TErrors(Globals, program);
                csystem.ProgramErrors.invalidJSON = progInfo.jErrors;
            }
        }
Beispiel #14
0
    //Unity predefined event called when the application is Quit.
    private void OnApplicationQuit()
    {
        //NOTE::: MAYBE IT COULD NOTIFY THE OTHERS BY ITSELF, WITH A SEND TO GROUP MESSAGE.
        //NOTE::: Remember that we use send so "Ensure" the transmision is made. That's why we don't call our standard SendUDP functions, as they use BeginSend.
        Debug.LogWarning("Quitting application, notifying the Server, so he notifies everyone else. Notifying the server: " + m_szServerIP);
        if (m_szServerIP != "0.0.0.0")
        {
            //SendUDPMessage('Y', "User_Quit", "Empty", m_szServerIP, 10000);
            if (m_pServer == null)
            {
                Message NewMessage = new Message('Y', m_iID.ToString(), m_szClientIP, "User_Quit", m_szServerIP, "Empty");
                byte[]  msgBytes   = Encoding.UTF8.GetBytes(NewMessage.ToString());
                if (CGlobals.m_bIsEncrypted == true)
                {
                    msgBytes = CGlobals.CesarCipher(msgBytes);
                }
                m_udpClient.Send(msgBytes, msgBytes.Length, m_szServerIP, 10000);
            }
            else
            {
                //Then, this node is the leader, so it has to cause an INSTANT RE-ELECTION of the leader. There's no need to do anything here, the check
                //is done at the reception of the User_Quit message.
                Debug.LogWarning("The Leader is Quitting Application, this will cause an Instant Re-Election.");
            }

            //Now to the multicast group synchronously.
            Message NewGroupMessage = new Message('N', m_iID.ToString(), m_szClientIP, "User_Quit", m_szMulticastIP, "Empty");
            byte[]  msgBytesGroup   = Encoding.UTF8.GetBytes(NewGroupMessage.ToString());
            if (CGlobals.m_bIsEncrypted == true)
            {
                msgBytesGroup = CGlobals.CesarCipher(msgBytesGroup);
            }
            m_udpClient.Send(msgBytesGroup, msgBytesGroup.Length, m_szMulticastIP, 10000);
            //SendUDPMessageToGroup('N', "User_Quit", "Empty");
        }
        else
        {
            Debug.LogWarning("This client knew no IPAddress for a server, so it will send nothing.");
        }

        m_udpClient.Close(); // this might need a super flag or something to avoid doing anything else when this is activated.
    }
Beispiel #15
0
        CView.CtrlStruct fireCtrl_str; // Controls struct who fire the event
        #endregion

        #region initialize

        /// <summary>
        /// Load all information from UI to work with
        /// </summary>
        /// <param name="viewManager"></param>
        /// <param name="eventDesc"></param>
        public CLogic(CSystem csystem, CViewsManager views_manager, CEventDesc eventDesc)
        {
            sys        = csystem;
            vm         = views_manager;
            Globals    = sys.Globals;
            errors     = sys.ProgramErrors;
            debug      = sys.ProgramDebug;
            event_desc = eventDesc;
            if (event_desc != null)
            {
                view = (event_desc.View_Guid != "") ? vm.getFirstView_byGuid(event_desc.View_Guid) : null;
                if (view != null)
                {
                    mainCtrl     = view.mainControl();
                    fireCtrl_str = view.getCtrlStruct(eventDesc.Control_Name);
                }
                fireCtrl = (Control)event_desc.fireCtrl;
                args     = event_desc.args;
            }
            MainView = ((view != null) && (Globals.get_str(dGLOBALS.MAIN_VIEW) == view.Name)) ? view : vm.getFirstView(Globals.get_str(dGLOBALS.MAIN_VIEW));
        }
Beispiel #16
0
        public CView(CGlobals globals, String view_name)
        {
            Globals   = globals;
            errors    = new CErrors(globals);
            debug     = new CDebug(globals);
            vars      = new Dictionary <string, object>();
            View_name = view_name;
            View_guid = Guid.NewGuid().ToString();
            ctrls     = new Dictionary <String, CtrlStruct>();
            objects   = new Dictionary <String, ObjStruct>();

            // Create main control and descendants
            view_desc = new TBaseControls(Globals, View_name);

            CreateControl(view_name, (view_desc.Namespace != null) ?
                          CreateTypedControl(view_name, view_desc.Namespace.ToString()) : null);

            // Create other objects
            CreateObjects(view_name);

            FLAG_VISTA_ACTIVA = 1;
        }
Beispiel #17
0
 public GameInstantState(string in_szMessageContent)
 {
     //3 of the first vec3, 3 of the second one, and 1 for Input and 1 for DateTime
     string [] tmpValue = in_szMessageContent.Split("\t".ToCharArray(), 3 + 3 + 2);     //4, as described in User_Update type of message.
     if (tmpValue.Length != (3 + 3 + 2))
     {
         Debug.LogError("ERROR, the format of the string to construct the GameInstantState was not correct, it was: " + in_szMessageContent);
         m_vPosition            = Vector3.zero;
         m_vRotationEulerAngles = Vector3.forward;
         m_dtTimeGenerated      = CGlobals.GetGlobalTime(); //The time this message is generated
         m_szInput = "Still";                               //Or the name of the default value.
     }
     else
     {
         m_vPosition.x            = float.Parse(tmpValue[0]);
         m_vPosition.y            = float.Parse(tmpValue[1]);
         m_vPosition.z            = float.Parse(tmpValue[2]);
         m_vRotationEulerAngles.x = float.Parse(tmpValue[3]);
         m_vRotationEulerAngles.y = float.Parse(tmpValue[4]);
         m_vRotationEulerAngles.z = float.Parse(tmpValue[5]);
         m_dtTimeGenerated        = DateTime.Parse(tmpValue[6]); //The time this message is generated
         m_szInput = tmpValue[7];                                //Or the name of the default value.
     }
 }
Beispiel #18
0
 private bool loadBaseProcess(CGlobals Globals)
 {
     pBasePrc = new JSonFile(Globals.AppDataSection(dPATH.PROCESSES), Namespace, false);
     if (pBasePrc.file_exists)
     {
         if (!pBasePrc.hasErrors())
         {
             pBasePrc.setActiveNode(String.Format("$.{0}[?(@.{1} == '{2}')]", dPROCESS.PROCESSES, dPROCESS.GUID.ToString(), Guid));
         }
         else
         {
             sys.ProgramErrors.invalidJSON =
                 String.Format("Error loading json file {0}.{1}. Details: {2}",
                               dPATH.PROCESSES,
                               Namespace,
                               pBasePrc.jErrors.ToString());
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #19
0
 public TDebug(CGlobals globals, String Program)
 {
     Globals   = globals;
     debugInfo = new JSonFile(Globals.AppPath(dPATH.DEBUG), Program);
     debugInfo.set(dDEBUG.PROCESSES, new JArray());
 }
Beispiel #20
0
 public TTracer(CGlobals globals)
 {
     Globals    = globals;
     tracerInfo = new JSonFile(Globals.AppDataSection(dPATH.TRACER), Globals.ActiveAppName, false);
     initializar_tracer();
 }
Beispiel #21
0
 public TDebug(CGlobals globals, String Program)
 {
     Globals               = globals;
     debugInfo             = new JSonFile(true, Globals.AppData_path(dPATH.DEBUG), Program);
     Show_debug_in_console = Globals.get(dGLOBALS.SHOW_DEBUG_IN_CONSOLE).ToObject <bool>();
 }
Beispiel #22
0
    public DateTime m_dtTimeSinceLastHeartBeat; //used to decide if that client must be considered DISCONNECTED.

    public ClientTimers(bool bTrue = true)
    {
        m_dtTimeSinceLastHeartBeat = m_dtTimeSinceLastMessage = CGlobals.GetGlobalTime();
    }
Beispiel #23
0
 public TErrors(CGlobals Globals, String Program)
 {
     errorInfo      = new JSonFile(true, Globals.AppData_path(dPATH.ERRORS), Program);
     Console_output = Globals.get(dGLOBALS.SHOW_ERRORS_IN_CONSOLE).ToObject <bool>();
     ErrorStatus    = errorStatus.OK;
 }
Beispiel #24
0
 public CMapObject(CGlobals App_globals, CGlobals Sys_globals)
 {
     app_globals = App_globals;
     sys_globals = Sys_globals;
 }
Beispiel #25
0
    //Returns the values in a string format, to be placed in a Message's Content field, in the following order:

    /*
     *      1. Vector3 of position of this gameObject.
     *      2. Vector3 of eulerAngles of this gameObject's rotation.
     *      3. DateTime of the UtcNow when the message is being sent.
     *      4. State of the input. In this case, it is the state of the player such as "Up_Down" or "Left_Right".
     */
    public string GetUpdateContent( )
    {
        string tmpResult = (CGlobals.Vec3ToString(transform.position) + '\t' + CGlobals.Vec3ToString(transform.localRotation.eulerAngles) + '\t' + GetGlobalTimeString() + '\t' + "Still");

        return(tmpResult);
    }
Beispiel #26
0
        public bool forceExitProgram = false; // Force program exit

        #endregion

        #region Constructor

        public TErrors(CGlobals Globals, String Program)
        {
            errorInfo = new JSonFile(Globals.AppPath(dPATH.ERRORS), Program);

            errorInfo.set(dERROR.STATUS, generalStatus.READY.ToString());
        }
Beispiel #27
0
 public TTracer(CGlobals globals)
 {
     Globals    = globals;
     tracerInfo = new JSonFile(Globals.AppPath(dPATH.TRACER), Globals.ActiveApp, false);
     initializar_tracer();
 }