Beispiel #1
0
        public void Sim200ms(float dt)
        {
            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("sent_joules", x, y);

            if (outstanding && message != null)
            {
                // We got a response from the server, deal with it
                int spare = (int)message["spare"];
                if ((outstanding_joules - spare) > 0)
                {
                    this.battery.ConsumeEnergy(outstanding_joules - spare);
                }
                outstanding        = false;
                outstanding_joules = 0;
            }
            // Only send messages to the server if we are actually enabled
            if (!outstanding && ztransporter.is_enabled_and_linked())
            {
                // We are not currently waiting for a message
                // so make a message, and then wait for response
                int int_joules_to_send = (int)this.battery.JoulesAvailable;
                if (int_joules_to_send > 0)
                {
                    outstanding_joules = int_joules_to_send;
                    message            = Network.make_message("send_joules", x, y);
                    message["joules"]  = int_joules_to_send;
                    Z.net.send_message(message);
                    outstanding = true;
                }
            }
        }
Beispiel #2
0
        public void Sim1000ms(float dt)
        {
            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            // Buffer five objects to send, that way you dont only get
            // 20g (or whatever) per second
            if (autoSend && (objects.Count <= 5))
            {
                add_to_object_list();
            }

            JObject message = Z.net.get_message_for("sent_object", x, y);

            if (outstanding && message != null)
            {
                // We got a response from the server, deal with it
                if ((bool)message["accepted"])
                {
                    objects.RemoveAt(0);
                }
                outstanding = false;
            }
            // Only send message when enabled, you know the rest
            if (!outstanding && objects.Count != 0 && ztransporter.is_enabled_and_linked())
            {
                // We are not currently waiting for a message
                // so make a message, and then wait for response
                message = Network.make_message("send_object", x, y);
                String object_to_send = objects[0];
                message["object"] = object_to_send;
                // We need to (re)send the current message to the server
                Z.net.send_message(message);
                outstanding = true;
            }
        }
Beispiel #3
0
        public void Dispense(float dt)
        {
            // Because of how complex materials, we are NOT going to only
            // use the internal buffer of the tank/whatever.
            // As soon as we get a suitable element to send, we are going to
            // cache it in a special buffer, and that buffer has these rules:
            //  1. There can only EVER be one thing buffered at a time
            //  2. Any thing that enters the buffer MUST exit
            //     by being sent to the server, it cannot use any other way
            // using these two simple rules, that should prevent a lot of
            // possible exploits from happening, like asking the server to
            // take 500g of 21 degree temperture, and then having it rise by
            // 5 degrees while waiting for a response, and this having
            // the 5 degrees destroyed
            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("sent_packet", x, y);

            if (outstanding && message != null)
            {
                // We got a response from the server, deal with it
                if ((bool)message["accepted"])
                {
                    buffered = null; // Message sent and received, KILL IT
                }
                outstanding = false;
            }
            // Only make and send a message if we are enabled
            if (!outstanding && ztransporter.is_enabled_and_linked())
            {
                // We are not currently waiting for a message
                // so make a message (if necessary), and then wait for response

                if (buffered == null)
                {
                    // We need to remove some of the primary element, make a
                    // message out of it and then send that to the sever

                    PrimaryElement suitableElement
                        = this.FindSuitableElement();
                    // If the suitableElement returned is null, then we
                    // don't have any suitable elements in our storage,
                    // so skip this whole section
                    if (suitableElement != null)
                    {
                        suitableElement.KeepZeroMassObject = false;
                        message          = Network.make_message("send_packet", x, y);
                        message["phase"] = (this.isGas ? "Gas" : "Liquid");
                        message["packet"]
                            = convert_from_primary(suitableElement);

                        buffered = message;
                    }
                }
                if (buffered != null)
                {
                    // We need to (re)send the current message to the server
                    Z.net.send_message(buffered);
                    outstanding = true;
                }
            }
        }