Example #1
0
        private void Register()
        {
            // this function will send the client the server GUID BEFORE the client sends theirs
            Packet p = new Packet(Packet.PacketType.Registration, Server.guid);

            p.packetString = HeartCore.commandKey;

            Data_OUT(p);
            HeartCore.GetCore().Write("Sent registration packet to " + clientSocket.AddressFamily.ToString());
        }
Example #2
0
 public void Data_OUT(Packet p)
 {
     try
     {
         clientSocket.Send(p.ToBytes());
     }
     catch (Exception e)
     {
         HeartCore.GetCore().Write("Unable to send data to the Shard at IP " + clientSocket.AddressFamily.ToString() + ". Closing connection. Restart the Shard.");
         Close();
     }
 }
Example #3
0
        public HeartCore()
        {
            core = this;

            baseDir = System.Environment.GetEnvironmentVariable("HOME") + baseDir;

            // allows the log file to be created in the home directory
            logBaseDir = System.Environment.GetEnvironmentVariable("HOME") + logBaseDir;

            // allows the config file to be created in the home directory. ie: /home/austin/
            configDir = System.Environment.GetEnvironmentVariable("HOME") + configDir;

            Init();
        }
Example #4
0
        public ClientData(Socket clientSocket)
        {
            this.clientSocket = clientSocket;

            HeartCore.GetCore().Write("Incoming connection from Shard. IP: " + clientSocket.AddressFamily.ToString());

            if (HeartCore.cfg_set)
            {
                HeartCore.GetCore().Write("Registering with client " + clientSocket.AddressFamily.ToString());
                Register();

                // after we accept a connection, we start a new thread for listening to the client
                clientThread = new Thread(Data_IN);
                clientThread.Start(clientSocket);
            }
            else
            {
                HeartCore.GetCore().Write("Refusing connection with client " + clientSocket.AddressFamily.ToString() + ". Please set up the config file.");
                HeartCore.GetCore().Write("After config is set up, try again.");
                SendClientError("Heart configuration is not set up. All connections will be refused until it is.");
                Close();
            }
        }
Example #5
0
        private void Run()
        {
            process                        = new ProcessStartInfo();
            process.Arguments              = args;
            process.FileName               = cmd;
            process.UseShellExecute        = false;
            process.RedirectStandardOutput = true;

            try
            {
                p = Process.Start(process);
            }
            catch (Exception e)
            {
                HeartCore.GetCore().Write("Unable to start Python process. Details: " + e.Message);
                HeartCore.GetCore().Close();
            }

            while (script_thread.IsAlive)
            {
                string foo = p.StandardOutput.ReadLine();
                Write(foo);
            }
        }
Example #6
0
        // this will handle everything about the packet
        public void DataManager(Packet p)
        {
            // if the client is not verified, we will not accept any other type of packet
            // this if statement checks if the connected client has been set up before
            if (!verified)
            {
                // if the client is sending something other than a registration packet, bounce the request
                // (only the registration packet is allowed when the connection isn't verified)
                if (p.packetType != Packet.PacketType.Registration)
                {
                    return;
                }

                // assign the local GUID var to the packet's sender ID
                id = p.senderID;

                // search shard cfg files that have been created previously for the client's id. if there's a match, continue
                if (RetrieveShard(id))
                {
                    verified = true;

                    // shard information is loaded into the local var's from the RetrieveShard() function

                    // confirm successful connection
                    HeartCore.GetCore().Write("Shard " + shardName + " registered and connected successfully. Sending handshake.");
                    Data_OUT(new Packet(Packet.PacketType.Handshake, Server.guid));
                    return;
                }
                // if there isnt a match, inform the client that it needs to be initialized. Maintain connection though, don't close it.
                else
                {
                    HeartCore.GetCore().Write("Shard using GUID " + id + " and IP " + clientSocket.AddressFamily.ToString() + " tried to connect, verification failed. Please set up the Shard.");
                    SendClientError("Shard is not set up. Please set up the shard through your internet browser.");
                    return;
                }
            }

            switch (p.packetType)
            {
            case Packet.PacketType.CloseConnection:
                HeartCore.GetCore().Write("Shard " + shardName + " has disconnected.");
                Close();
                break;

            case Packet.PacketType.Command:
                string[] splitCommandArray = p.packetString.ToLower().Split();
                string   commandWord       = splitCommandArray[0]; // I want a better way to do this part

                // analyze command and respond appropriately
                switch (commandWord)
                {
                case "":
                    break;

                default:
                    break;
                }
                break;

            default:
                HeartCore.GetCore().Write(shardName + " sent an unrecognized packet type. Command ignored.");
                SendClientError("Unrecognized packet type was sent. Please restart the Shard and try again.");
                break;
            }
        }