javascript – Is it a bad idea to store functions inside components in ECS?

Say I have three entities: Player, Spikes, and Zombie. All of them are just rectangles and they can collide with each other. All of them have the BoxCollision component.

So, the BoxCollison system would look something like this:

function detectCollisions () {
  // for each entity with box collision
    // check if they collide
      // then do something
}

The issue is, the sole purpose of the BoxCollision component is to detect collision, and that’s it. Where should I put the game rules, such as “if the Player collided with Spikes, diminish its health” or “if the Zombie collided with Spikes, instantly kill the Zombie”?

I came up with the idea that each Entity should have its onCollision function.

Programming languages such as Javascript and F# have high-order functions, so I can easily pass functions around. So when assembling my Player entity, I could do something like:

function onPlayerCollision (player) {
  return function (entity) {
    if (entity.tag === 'Zombie') {
      player.getComponent('Health').hp -= 1
    } else if (entity.tag === 'Spikes') {
      player.getComponent('Health').hp -= 5
    }
  }
}

const player = new Entity()
player.addComponent('Health', { hp: 100 })
player.addComponent('BoxCollision', { onCollision: onPlayerCollision(player) } 
// notice I store a reference to a function here, so now the BoxCollision component will execute this passing the entity the player has collided with
function detectCollisions () {
  // for each entity with box collision
    // check if they collide
      onCollision(entity)

onPlayerCollision is a curried/closure function that receives a player, and then returns a new function that wants another Entity.

Are there any flaws with this? Is it okay for components to store references to functions? What are other ways of avoiding game rules in components? Events?

Thanks!

reverse engineering – What is source of bad characters exist in buffer overflows

I’m new to exploit development and while watching a tutorial I came across the topic of “Bad character identification”. I’m referring to the process of sending all possible characters to the vulnerable process to see if there are characters which fail to pass to the receiver.

The existence and identification of those characters has been discussed many times before but I couldn’t find the root cause of their existence.

Why are there bad characters a target process mis-handles?

accessibility – HTML Aria function not being read by screen reader – Bad design?

I’m looking into how accessible some websites are using WebAIM’s WAVE tool. Many websites nowadays use the burger menu symbol to indicate the menu (YouTube and Gmail for example) and often I see the Aria attribute being used to say ‘open-menu’ or something of that sort. However, when I test it with NVDA and hover over them, the screen reader doesn’t return anything.

For example here: https://www.rijksmuseum.nl/en

On the left is the burger symbol, a magnifying glass (for search) and text-links. NVDA only reads out the latter text-links when hovered over, but not the former two non-text symbols. The two symbols (burger and magnifying glass) don’t change colour or give any indication that they’re clickable when hovered over besides the mouse pointer changing.

Is the Aria label supposed to be function (or not function) this way or is this just bad code/design? Or am I just completely misunderstanding how a screen reader is supposed to function?

dnd 5e – Food Scraps, what are they and do they go bad?

Only magically-created food has rules for spoilage

Interestingly, at this point in the development of 5e, there is no rules mechanism by which normal food spoils.

RAW, food may be obtained by characters through purchase, though foraging, or through magic.

Purchase (“Adventuring Gear”, PHB 153)

Rations. Rations consist of dry foods suitable for extended travel, including jerky, dried fruit, hardtack, and nuts.

Purchase (“Food, Drink, and Lodging”, PHB 158)

The Food, Drink, and Lodging table gives prices for individual food items and a single night’s lodging. These prices are included in your total lifestyle expenses.

Foraging (“Foraging”, DMG 111)

A foraging character finds nothing on a failed check. On a successful check, roll ld6 + the character’s Wisdom modifier to determine how much food (in pounds) the character finds, then repeat the roll for water (in gallons).

Magic (“Create Food and Water”, PHB 229)(emphasis mine)

You create 45 pounds of food and 30 gallons of water on the ground or in containers within range, enough to sustain up to fifteen humanoids or five steeds for 24 hours. The food is bland but nourishing, and spoils if uneaten after 24 hours. The water is clean and doesn’t go bad.

Notice that in all these sources of food, the only one that specifically mentions spoilage is the magically created food. The rations one can purchase for “extended travel” certainly seem like they are chosen to avoid spoilage, but notice that there is no mechanism by which fresh food foraged will go bad – no condition that raw meat you foraged in the tropical heat won’t be just as suitable to eat next week as it is now. Note that I am not saying that normal food doesn’t spoil – just that rules for this, the rules the OP asked about, do not exist.

This is a clear departure from previous editions, in which one could cheaply purchase “standard rations” (which would quickly spoil) or could pay much more for “iron rations” (which would last much longer). If you are interested in the subject, you might want to start with this and this.

To put a finer point on it, in 5e there is no mechanism by which spoiled food may be made wholesome again. The spell that previous editions used for that simply does not have that function.

“Purify Food and Drink”, PHB 270

All nonmagical food and drink within a 5-foot-radius sphere centered on a point of your choice within range is purified and rendered free of poison and disease.

Compare that is previous versions of the spell, such as in 3.5e:

This spell makes spoiled, rotten, poisonous, or otherwise contaminated food and water pure and suitable for eating and drinking. This spell does not prevent subsequent natural decay or spoilage.

The first answer to your question is that 5e simply has no mechanism for non-magical food spoilage; the scraps you have in your pocket, even uncooked meat scraps kept at room temperature, will not spoil as a consequence of anything written in to the game. If it is a truism that D&D is not a Physics Simulator, in this case neither is it a Biology Simulator. As other posts have indicated, if this is a level of detail you or your DM would like to incorporate you can do so. This could simply be by DM fiat, telling you that you scraps have spoiled, or you can create a more formal set of house rules. You might find previous editions useful in this regard. Working within the mechanics of 5e, the simplest thing to do might be to come up with a table for how long different kinds of foods may be kept before they are considered “poisoned”.

So what is the point of the personality trait?

As you say, you have so far just been collecting these scraps for role-playing your personality trait, it it is fine to have it remain there. The purpose of having specific, listed personality traits is exactly for this type of role play:

“Personality Traits”, PHB 123

Give your character two personality traits. Personality traits are small, simple ways to help you set your character apart from every other character. Your
personality traits should tell you something interesting and fun about your character. They should be self-descriptions that are specific about what makes your character stand out.

However, personality traits do not have to be limited to role play – they can have a mechanical effect, through Inspiration.

“Inspiration”, PHB 126:

Inspiration is a rule the Dungeon Master can use to reward you for playing your character in a way that’s true to his or her personality traits, ideal, bond, and flaw. By using inspiration, you can draw on your personality trait of compassion for the downtrodden to give you an edge in negotiating with the Beggar Prince…
Your DM can choose to give you inspiration for a variety of reasons. Typically, DM’s award it when you play out your personality traits, give in to the drawbacks
presented by a flaw or bond, and otherwise portray your character in a compelling way.

Since you have been role playing this all along, you may discuss with your DM whether they will be awarding Inspiration at some point based on your role play. They could use this to give you a bonus in a certain situation – as other posts have suggested, you might get Inspiration to use on an animal handling roll if you fish some table scraps out of your pocket before your interaction. Or if you are at a fancy dinner and insist on lowering your reputation with the host and other guests by saving food in your pockets, your DM might award you Inspiration for staying true to your personality.

None of this use of your personality trait needs to involve the food spoiling or the need to introduce new mechanics, since it is entirely up to DM fiat.

design – Is it bad practice to mutate your HttpClient objects?

Im in the process of creating a base class for typed HttpClient services (yes, I’m utilizing IHttpClientFactory). I wrote the process in such a way that for each CRUD method invoked from the service, the first thing said service does is check for and assign an access token to attach to the HttpClient header. Example:

public abstract class BaseNetworkService : IBaseNetworkService {
   protected HttpClient _httpClient { get; }

   public BaseNetworkService(HttpClient client, ...) {
      _httpClient = client;
   }
   
   public async Task<T> GetAsync<T>(string extendedUrl, ICacheContext cacheContext = null) {
      ... check Redis Cache, return result if there ...
      
      Http client = GetcurrentAccessToken(_httpClient);
      var response = await client.GetAsync(extendedUrl);
      ...
   }
}

I’ll admit upfront that I am not entirely sure why I have always made my HttpClients readonly and upon Googling for answers, it’s probably because every document and guide on HttpClient with dependency injection makes the client readonly. I didn’t find any material explaining the reason for that.

With that in mind, should your HttpClientremain readonly? Should any customization, such as attaching an access token, be done in the classes constructor?

frontend – Is it bad to use ObjectManager in list.phtml like in Code Below?? What’s the best Practice?

Is it bad practice to use ObjectManager in file app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/list.phtml

like this below.

        <?php 
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category');
        if($category->getDescription())
        {
            echo '<div style="padding: 13px;margin-top: 15px;">'.$category->getDescription().'</div>';
        }

Would there be a better way to write this???

Any help would be greatly appreciated. Thank you!

Is it bad to trust PHP’s $_SERVER information?

I want to know if is bad to trust the PHP’s global variable $_SERVER values.

I have a scenario that I change between developer and production site, and I have a config.php file. On this file, I check $_SERVER[‘SERVER_NAME’] value, to determine which group of constants I should use. If I’m on production environment I use a list A of constants, if I’m on developer environment I use another list of constants.

Does this make my PHP project vulnerable in any way?

Is it a bad idea to register domain names with hyphens now?

Advertising

y u no do it?

Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

Starts at just $1 per CPM or $0.10 per CPC.

docker – nginx proxy_pass return 502 Bad Gateway

I’m building nginx for reverse_proxy with Spring and Docker

Here is my configuration.

nginx.conf

user  proxy;
worker_processes  auto;
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    log_format  main  '$remote_addr - $remote_user ($time_local) "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include       mime.types;
    default_type  application/octet-stream;

    include /home/wertkey/nginx/conf/conf.d/*.conf;

    client_max_body_size 200M;
    client_header_buffer_size  48k;

    server {
        listen       7070 default_server;
        listen       (::):7070 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        location / {
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

conf.d/default.conf

server {
    listen 7070;
    server_name something.com;

    proxy_connect_timeout   900s;
    proxy_send_timeout      900s;
    proxy_read_timeout      900s;
    send_timeout            900s;

    location ^~ /editor/ {
        proxy_pass http://localhost:8081;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;

        rewrite ^/editor/(/.*)$ $1 break;
    }
}

docker

CONTAINER ID        IMAGE        COMMAND                  CREATED             STATUS              PORTS                    NAMES
a6a6a98a25a9        editor       "/bin/sh -c /usr/l..."   8 minutes ago       Up 8 minutes        0.0.0.0:8081->8080/tcp   editor

My spring server is running at 7070 port.
I want to be this way.

  1. request something.com:7070/api
  2. nginx proxy_pass to 8081
  3. and docker 8081 -> 8080

But response always return 502 Bad Gateway

What am i missing?

+
I am currently running two nginxs on the same server.
One is running at 8080 port and the other is running at 7070 port.
8080 nginx is for web servers and 7070 nginx is for proxy purposes.
The log does not appear in 7070 nginx and the log appears in 8080 nginx.
I don’t know why the request goes to 8080 nginx.
How can I send the request to 7070 nginx?

Why did my film captured pictures turn out bad?

I shot some photos with an old Canon AF35M film camera using Fujifilm 400 speed and had them developed by CVS. The result are terrible and I don’t know what the cause could be.

Anyone have insight into what can cause this darkness and coloration?

1