<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MrSoUndso</title>
    <description>The latest articles on DEV Community by MrSoUndso (@mrsoundso).</description>
    <link>https://dev.to/mrsoundso</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F260741%2F453b1419-4764-4e4b-bc31-9cec6aeee711.png</url>
      <title>DEV Community: MrSoUndso</title>
      <link>https://dev.to/mrsoundso</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mrsoundso"/>
    <language>en</language>
    <item>
      <title>Setting up a OpenTTD Server</title>
      <dc:creator>MrSoUndso</dc:creator>
      <pubDate>Thu, 09 Jul 2020 15:04:33 +0000</pubDate>
      <link>https://dev.to/mrsoundso/setting-up-a-openttd-server-2ie9</link>
      <guid>https://dev.to/mrsoundso/setting-up-a-openttd-server-2ie9</guid>
      <description>&lt;h6&gt;
  
  
  Tl;Dr; at the end
&lt;/h6&gt;

&lt;blockquote&gt;
&lt;p&gt;OpenTTD is a business simulation game in which players try to earn money via transporting passengers and freight by road, rail, water and air. It is an open-source[3] remake and expansion of the 1994 Chris Sawyer video game Transport Tycoon Deluxe. (from: &lt;a href="https://en.wikipedia.org/wiki/OpenTTD"&gt;Wikipedia&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Setting up a server to play with your friends is a easy thing to do, but finding a guide has been really hard.&lt;br&gt;
So I decided to write my own:&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You have a Linux server with Ubuntu&lt;/li&gt;
&lt;li&gt;You have cli and sudo access to that server&lt;/li&gt;
&lt;li&gt;You have your favorite editor installed (this guide uses nano)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Getting OpenTTD
&lt;/h2&gt;

&lt;p&gt;Getting OpenTTD is easy. Simply run &lt;br&gt;
&lt;code&gt;sudo apt install openttd openttd-opengfx&lt;/code&gt; &lt;br&gt;
and you're set!&lt;/p&gt;
&lt;h2&gt;
  
  
  Making OpenTTD run
&lt;/h2&gt;

&lt;p&gt;To make sure OpenTTD keeps running even after you close your terminal window, it has to be a systemd service. &lt;br&gt;
To create a service navigate to /etc/systemd/system (using &lt;code&gt;cd /etc/systemd/system&lt;/code&gt;) and create a new file called openttd.service (&lt;code&gt;sudo nano openttd.service&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;In this file, we add the following lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Unit]
Description=OpenTTD Server
Documentation=""

[Service]
Type=simple
ExecStart=/usr/games/openttd -D
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Let's see whats going on here line by line:
&lt;/h3&gt;

&lt;p&gt;The file is separated into three main parts, &lt;code&gt;[Unit]&lt;/code&gt;,&lt;code&gt;[Service]&lt;/code&gt; and &lt;code&gt;[Install]&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[Unit]&lt;/code&gt; is for metadata like the title of the service and its relationship to other services&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[Service]&lt;/code&gt; is the place for instructions on what the service should do&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[Install]&lt;/code&gt; tells systemd how to enable and disable the service (this part stays the same most of the time)
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  A closer look at &lt;code&gt;[Service]&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;First we define the service type with &lt;code&gt;Type=simple&lt;/code&gt;. This is the default type and tells systemd that this service is going to be a long running one.&lt;br&gt;
The next line is &lt;code&gt;ExecStart=/usr/games/openttd -D&lt;/code&gt;. This tells systemd to start &lt;code&gt;/usr/games/openttd&lt;/code&gt; with the &lt;code&gt;-D&lt;/code&gt; command line flag (&lt;code&gt;-D&lt;/code&gt; tells OpenTTD to start in server mode)&lt;br&gt;
The next to lines &lt;code&gt;Restart=on-failure&lt;/code&gt; and &lt;code&gt;RestartSec=10s&lt;/code&gt; tell systemd to restart the service if if fails, but not before it has waited ten seconds.&lt;/p&gt;

&lt;p&gt;(If you want more information on services, &lt;a href="https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files#anatomy-of-a-unit-file"&gt;this&lt;/a&gt; is a good guide)&lt;/p&gt;
&lt;h3&gt;
  
  
  Starting the service
&lt;/h3&gt;

&lt;p&gt;To start the service, you first have to enable it. Enable it with:&lt;br&gt;
 &lt;code&gt;sudo systemctl enable openttd.service&lt;/code&gt;.&lt;br&gt;
Afterwards, you can start it with&lt;br&gt;
 &lt;code&gt;sudo systemctl start openttd.service&lt;/code&gt; &lt;br&gt;
and view its status with&lt;br&gt;
 &lt;code&gt;sudo systemctl status openttd.service&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuring the firewall
&lt;/h2&gt;

&lt;p&gt;To access the server from anywhere in the world, you'll have to configure the firewall of your server. Thankfully, Ubuntu makes this easy!&lt;/p&gt;

&lt;p&gt;Install the "&lt;strong&gt;U&lt;/strong&gt;ncomplicated &lt;strong&gt;F&lt;/strong&gt;ire &lt;strong&gt;W&lt;/strong&gt;all":&lt;br&gt;
&lt;code&gt;sudo apt install ufw&lt;/code&gt;&lt;br&gt;
and allow connections on the ssh and the OpenTTD ports:&lt;br&gt;
&lt;code&gt;sudo ufw allow ssh&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo ufw allow 3979&lt;/code&gt;&lt;br&gt;
This makes your server available to the world, but it will not be visible on the public server list. If you want to add your server to the list, run&lt;br&gt;
&lt;code&gt;sudo ufw allow 3979/udp&lt;/code&gt;&lt;br&gt;
Now you need to enable the firewall. You can do this by running: &lt;br&gt;
&lt;code&gt;sudo ufw enable&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And that's it! Your OpenTTD server should be working fully now!&lt;/p&gt;

&lt;p&gt;If your are searching for the openttd.cfg, it is located at &lt;code&gt;/root/.openttd/openttd.cfg&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  TL;DR:
&lt;/h2&gt;

&lt;p&gt;These are the commands you need to setup a server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install openttd openttd-opengfx ufw
sudo nano /etc/systemd/system/openttd.service
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Paste this inside the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Unit]
Description=OpenTTD Server
Documentation=""

[Service]
Type=simple
ExecStart=/usr/games/openttd -D
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl enable openttd.service
sudo systemctl start openttd.service
sudo systemctl status openttd.service

sudo ufw allow ssh
sudo ufw allow 3979
sudo ufw enable
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>linux</category>
      <category>games</category>
      <category>systemd</category>
    </item>
    <item>
      <title>A strange Square</title>
      <dc:creator>MrSoUndso</dc:creator>
      <pubDate>Tue, 29 Oct 2019 20:46:21 +0000</pubDate>
      <link>https://dev.to/mrsoundso/a-strange-square-f98</link>
      <guid>https://dev.to/mrsoundso/a-strange-square-f98</guid>
      <description>&lt;p&gt;Hi everybody!&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/mrsoundso/my-first-adventure-4hh0"&gt;last post&lt;/a&gt; I showed you the the way I approached the "Print a rectangle test".&lt;br&gt;
The next test I'll have to tackle is: &lt;/p&gt;

&lt;h4&gt;
  
  
  Print a crossed square to the console
&lt;/h4&gt;

&lt;p&gt;So I started with the nearly the same code I used in my last project, but I quickly realized that the three for loops I used made everything way harder than it should be.&lt;/p&gt;

&lt;p&gt;So I switched over to two nested for loops:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 0; i &amp;lt; x; i++) {
    for(int b = 0; b &amp;lt; x; b++) {
      printf(%c,c);
    }
    printf("\n");
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This resulted in a completely filled rectangle, just as I intended.&lt;br&gt;
So I once again added a if check to make sure only the parts I wanted to be char where chars.&lt;/p&gt;

&lt;p&gt;I started with the walls: the top line should be filled if &lt;code&gt;i == 0&lt;/code&gt;, and the bottom if &lt;code&gt;i = x - 1&lt;/code&gt;. The walls worked after a similar principle, just replace the &lt;code&gt;i&lt;/code&gt; with a &lt;code&gt;b&lt;/code&gt;. It's also important to add a &lt;code&gt;else&lt;/code&gt; statement to print a space if none of the conditions on top are met.&lt;/p&gt;

&lt;p&gt;The cross part was harder than I initially thought. While the line going from the top left corner to the bottom right one was simple as it simply follows the &lt;code&gt;i == b&lt;/code&gt; condition, the one going the other way made me scratch my head a lot more.&lt;br&gt;
The thing I came up with was this formula: &lt;code&gt;(i + b) == x - 1&lt;/code&gt;&lt;br&gt;
This condition is meet for every point on the line between the bottom left corner and the top right one.&lt;/p&gt;

&lt;p&gt;In the end my complete code looked like this: &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 0; i &amp;lt; x; i++) {
  for(int b = 0; b &amp;lt; x; b++) {
    if(i == 0 || i == x -1 || b == 0 || b == x - 1 || i == b || i + b == x - 1) {
       printf("%c",c );
    } else {
      printf(" ");
    }
  }
printf("\n");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;If you would try the same thing with 3 individual loops instead of 2 nested ones, you would run into really really unfunny issues with these simple if checks. For example, I had issues with the lines not meeting in the middle or having spaces everywhere but not where I wanted to have them. &lt;/p&gt;

&lt;p&gt;Have a nice day!&lt;/p&gt;

&lt;p&gt;P.S: I'm sorry for the strange formating. If you know how to fix it please leave me a comment!&lt;/p&gt;

&lt;p&gt;P.P.S: Thanks to &lt;/p&gt;
&lt;div class="ltag__user ltag__user__id__246551"&gt;
  
    .ltag__user__id__246551 .follow-action-button {
      background-color: #ee719e !important;
      color: #7f007f !important;
      border-color: #ee719e !important;
    }
  
    &lt;a href="/katnel20" class="ltag__user__link profile-image-link"&gt;
      &lt;div class="ltag__user__pic"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HrNukbSy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--80kHQLqQ--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/246551/2e2d871e-f586-46ae-838a-23873852941a.jpeg" alt="katnel20 image"&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;div class="ltag__user__content"&gt;
    &lt;h2&gt;
&lt;a class="ltag__user__link" href="/katnel20"&gt;Katie Nelson&lt;/a&gt;
&lt;/h2&gt;
    &lt;div class="ltag__user__summary"&gt;
      &lt;a class="ltag__user__link" href="/katnel20"&gt;Welcome tag moderator AKA Unofficial DEV cheerleader. While most of my friends are found on SnapChat or Tic-Toc, you can find me here. And I OOP, but I’m not a VSCO girl.&lt;/a&gt;
    &lt;/div&gt;
    &lt;p class="ltag__user__social"&gt;
        &lt;a href="https://twitter.com/KatieGirlCoder" rel="noopener"&gt;
          &lt;img class="icon-img" alt="twitter logo" src="https://res.cloudinary.com/practicaldev/image/fetch/s--oEHrSmvE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-logo.svg"&gt;KatieGirlCoder
        &lt;/a&gt;
        &lt;a href="https://github.com/KatNel20" rel="noopener"&gt;
          &lt;img class="icon-img" alt="github logo" src="https://res.cloudinary.com/practicaldev/image/fetch/s--C74Jn3f1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo.svg"&gt;KatNel20
        &lt;/a&gt;
    &lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;for telling me how to fix my issues!&lt;/p&gt;

</description>
      <category>c</category>
    </item>
    <item>
      <title>My first C Adventure</title>
      <dc:creator>MrSoUndso</dc:creator>
      <pubDate>Tue, 29 Oct 2019 20:12:13 +0000</pubDate>
      <link>https://dev.to/mrsoundso/my-first-adventure-4hh0</link>
      <guid>https://dev.to/mrsoundso/my-first-adventure-4hh0</guid>
      <description>&lt;p&gt;Hi everybody!&lt;/p&gt;

&lt;p&gt;This is the first post of my new series: "Adventures in learning C".&lt;br&gt;
First of all, please let my introduce myself: I'm Mr SoUndso and I currently study "Technische Informatik" (probably best translated as "technical computer science") in Germany.  One of my lectures teaches me how to program in C. To pass the class, I'll have to complete different exercises. This series will be a write up on the different challenges I faced, and the ways I used to overcome them.&lt;/p&gt;

&lt;p&gt;So lets start with the first test: &lt;/p&gt;

&lt;h4&gt;
  
  
  Write a program that prints a rectangle to the console
&lt;/h4&gt;

&lt;p&gt;This sounds like a simple task, and it is. But i made a mistake along the way, that made my attempt at the next test way harder.&lt;/p&gt;

&lt;p&gt;I started out with three different for loops, one for the top row, one for the side walls and one for the bottom.&lt;/p&gt;

&lt;p&gt;&lt;code&gt; &lt;br&gt;
  for (int i = 0; i &amp;lt; y; i++) {&lt;br&gt;
    //print first row&lt;br&gt;
  }&lt;br&gt;
   printf("/n");&lt;br&gt;
  for (int i = 1; i &amp;lt; x; i++) {&lt;br&gt;
    //print the sides&lt;br&gt;
  }&lt;br&gt;
  for (int i = 0; i &amp;lt; y; i++) {&lt;br&gt;
    //print last row&lt;br&gt;
  }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The top and bottom rows were simple: I just added a &lt;code&gt; printf(%c,c); &lt;/code&gt; into the loop and was set.&lt;/p&gt;

&lt;p&gt;The sides were harder nuts to crack. I could not simply add a &lt;code&gt;    printf("%c   %c \n",c, c);&lt;/code&gt; to the loop, as a requirement of the test was to make a the hight and width configurable. &lt;br&gt;
So I added a second for loop into the mix.&lt;br&gt;
My second loop now looked like this: &lt;br&gt;
&lt;code&gt;&lt;br&gt;
for (int i = 1; i &amp;lt; x; i++) {&lt;br&gt;
    for (int b = 0; b &amp;lt; y; b++) {&lt;br&gt;
      printf("%c", c);&lt;br&gt;
    }&lt;br&gt;
    printf("\n");&lt;br&gt;
  }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This would give me a completely filled rectangle. I realized I wasn't far from my goal, I only needed to fill the center with spaces instead of chars. &lt;/p&gt;

&lt;p&gt;To do this, I added a if to check if the second iterator (b) is equal to 0 or y. &lt;br&gt;
This resulted in a strange output:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
xxxxx&lt;br&gt;
x&lt;br&gt;
x&lt;br&gt;
x&lt;br&gt;
x&lt;br&gt;
x&lt;br&gt;
xxxxx &lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I realized that b could never be equal to y, as the for loop would stop if&lt;br&gt;
 &lt;code&gt; b == y &lt;/code&gt;. &lt;br&gt;
So I changed the check from &lt;code&gt; b == y &lt;/code&gt; to &lt;code&gt;b == y - 1&lt;/code&gt; and voilà: My code worked!&lt;/p&gt;

&lt;p&gt;But wait: I told you earlier that I made a mistake making my next attempt way harder. Using 3 for loops instead of 2 nested ones made me scratch my head a lot when working on the next test. But this is a story for another post.&lt;/p&gt;

&lt;p&gt;Have a nice day.&lt;/p&gt;

</description>
      <category>c</category>
    </item>
  </channel>
</rss>
