From 8926fce4b945a3a634057141c3968e8820870022 Mon Sep 17 00:00:00 2001 From: Tait Hoyem Date: Thu, 25 Jun 2020 18:40:41 +0000 Subject: [PATCH] Update _site static files --- _site/2020/06/25/tmux-minecraft.html | 178 +++++++++++++++++++++++++ _site/blog/index.html | 13 ++ _site/feed.xml | 186 +++++++++++++++++++-------- _site/sitemap.xml | 4 + 4 files changed, 330 insertions(+), 51 deletions(-) create mode 100644 _site/2020/06/25/tmux-minecraft.html diff --git a/_site/2020/06/25/tmux-minecraft.html b/_site/2020/06/25/tmux-minecraft.html new file mode 100644 index 0000000..5348323 --- /dev/null +++ b/_site/2020/06/25/tmux-minecraft.html @@ -0,0 +1,178 @@ + + + + + How to use tmux to send and receive things from your Minecraft server | tait.tech + + + + +
+ + +

How to use tmux to send and receive things from your Minecraft server

+ + +
+

So recently I had problem. +I run a Minecraft server on a big Linux computer I have running in my room. +Now, as a system administrator it is very helpful to be able to run some simple commands without needing to login with my key, password, TFA, etc. +It is, frankly, a lot of work. +Especially when I really just want to be playing games, but something seems to be wrong.

+ +

So for simple things like finding out of the network, CPU, memory or disk usage is my bottleneck, I wrote this really nifty script to connect the world of Minecraft and the Linux shell.

+ +

My completed solution for what I needed can be found at https://github.com/TTWNO/termcraft.

+ +

If you want some of the implementation details, stick around.

+ +

Solution

+ +

So to solve this interesting problem, I decided to use tmux. +tmux is a tterminal multiplexer. +This allows you to run a terminal session, the leave it while it still runs in the background.

+ +

This is very valuable when running command line applications that need to have an active console connection, like a Minecraft server.

+ +

So first I looked at the tmux command send-keys.

+ +

send-keys

+ +

send-keys allows you to send text, and key presses to a tmux session. +Now assuming this tmux session is attached to a Minecraft server, +there is no reason you could not run a command like this:

+ +
+$ tmux send-keys "tell @a This is a Test" Enter
+
+ +

This will send the text “tell @a This is a Test” to the Minecraft server. +Then, it will hit the newline character, this will execute the command.

+ +

So now we can send information to the server and have it tell the users something.

+ +

But how do we get information about who is typing what in the Minecraft chat?

+ +

tmux’s capture-pane is painful

+ +

So in the manual page for tmux I can see a section recorded below for options I can give to the capture-pane subcommand.

+ +
+  -S and -E specify the starting and ending line numbers,
+  zero is the first line of the visible pane and negative
+  numbers are lines in the history.  ‘-’ to -S is the start
+  of the history and to -E the end of the visible pane.  The
+  default is to capture only the visible contents of the pane.
+
+ +

What it seems to be saying is I can start at line -S n and end at line -E n. +Negative numbers start from the bottom, so in theory I can do the following: tmux capture-pane -S -1 should capture only the last line, because I’m starting from the last line. Right?

+ +

No. It just doesn’t work. Negative numbers do not work with the tmux capture-pane subcommand.

+ +

So I did some simple UNIX piping, like so, to get just the last thing in the chat. +-p prints the result to the terminal/stdout. +steve is the name of the tmux session I’m trying to pull form.

+ +
+$ tmux capture-pane -p -t steve | tail -n1
+[SERVER] [ExtraDebuggingInfoHere]: <TaterTheTot> MY_MESSAGE
+
+ +

So that’s done! Beauty!

+ +

So now I have a line which will look something like this:

+ +

[SERVER] [ExtraDebugInfoHere]: <TaterTheTot> MY_MESSAGE

+ +

TaterTheTot is my Minecraft username :)

+ +

So, how can we get only the message I wrote, and my username?

+ +

grep

+ +

grep is a command to find patterns of text. +grep has an option to only show a matching pattern of text. +This option is -o.

+ +

Let’s see how we can use this in conjunction with our latest line of server output to get our results.

+ +
+$ echo "[DEBUG] [SERVER] blah blah: <TaterTheTot> MY_MESAGE" | grep -o "<.*>"
+<TaterTheTot>
+
+ +

Now, that’s my name with the < and > attached. Not bad! +We can use the sed command to clean it up a bit.

+ +

The syntax is like so: select/somepattern/replacewith/global

+ +

So the following command is: s/[<>]//g

+ +

Select any characters that are either < or >. +Replace with nothing. +Do so globally (as in, don’t stop after you replace only one character).

+ +

Take two!

+ +
+$ echo "[DEBUG] [SERVER] blah blah: <TaterTheTot> MY_MESAGE" | grep -o "<.*>" | sed 's/[<>]//g'
+TaterTheTot
+
+ +

Beautiful!

+ +

Now what about that pesky message?

+ +

more grep; more sed

+ +

Simple: capture everything after the >. Leaving the user’s message entirely in tact.

+ +
+$ echo "[DEBUG] [SERVER] blah blah: <TaterTheTot> MY_MESAGE" | grep -o ">.*$" | sed 's/> //'
+MY_MESSAGE
+
+ +

So now we have a way to get the username of someone typing in the Minecraft server chat. +We have a way to find out what they said. +And, we have a way to respond.

+ +

You can imagine how these might go together for your own use case.

+ +

Conclusion

+ +

This shows some pretty fun stuff you can do with a few simple Linux commands and a Minecraft server.

+ +

I hope you learned something and found my explanations not horrific haha!

+ +

Remember to checkout the git repository to see what I did with it: https://github.com/TTWNO/termcraft.

+ +

Happy hacking!

+ +
+ + + +
+ + diff --git a/_site/blog/index.html b/_site/blog/index.html index e46701d..04e5f00 100644 --- a/_site/blog/index.html +++ b/_site/blog/index.html @@ -30,6 +30,19 @@ + + + +
+

How to use tmux to send and receive things from your Minecraft server

+ +

So recently I had problem. +I run a Minecraft server on a big Linux computer I have running in my room. +Now, as a system administrator it is very helpful to be able to run some simple commands without needing to login with my key, password, TFA, etc. +It is, frankly, a lot of work. +Especially when I really just want to be playing games, but something seems to be wrong.

+
+

Site Update

diff --git a/_site/feed.xml b/_site/feed.xml index 758ab63..7203816 100644 --- a/_site/feed.xml +++ b/_site/feed.xml @@ -1,4 +1,137 @@ -Jekyll2020-06-25T17:56:35+00:00http://localhost:4000/feed.xmlSite Update2020-06-04T00:00:00+00:002020-06-04T00:00:00+00:00http://localhost:4000/2020/06/04/site-update<p>I updated the site with some easier to identify information about me and my projects :)</p> +Jekyll2020-06-25T18:40:18+00:00http://localhost:4000/feed.xmlHow to use tmux to send and receive things from your Minecraft server2020-06-25T00:00:00+00:002020-06-25T00:00:00+00:00http://localhost:4000/2020/06/25/tmux-minecraft<p>So recently I had problem. +I run a Minecraft server on a big Linux computer I have running in my room. +Now, as a system administrator it is very helpful to be able to run some simple commands without needing to login with my key, password, TFA, etc. +It is, frankly, a lot of work. +Especially when I really just want to be playing games, but something seems to be wrong.</p> + +<p>So for simple things like finding out of the network, CPU, memory or disk usage is my bottleneck, I wrote this really nifty script to connect the world of Minecraft and the Linux shell.</p> + +<p>My completed solution for what I needed can be found at <a href="https://github.com/TTWNO/termcraft/">https://github.com/TTWNO/termcraft</a>.</p> + +<p>If you want some of the implementation details, stick around.</p> + +<h2 id="solution">Solution</h2> + +<p>So to solve this interesting problem, I decided to use <code class="highlighter-rouge">tmux</code>. +<code class="highlighter-rouge">tmux</code> is a <strong>t</strong>terminal <strong>mu</strong>ltiple<strong>x</strong>er. +This allows you to run a terminal session, the leave it while it still runs in the background.</p> + +<p>This is very valuable when running command line applications that need to have an active console connection, like a Minecraft server.</p> + +<p>So first I looked at the <code class="highlighter-rouge">tmux</code> command <code class="highlighter-rouge">send-keys</code>.</p> + +<h4 id="send-keys"><code class="highlighter-rouge">send-keys</code></h4> + +<p><code class="highlighter-rouge">send-keys</code> allows you to send text, and key presses to a <code class="highlighter-rouge">tmux</code> session. +Now assuming this <code class="highlighter-rouge">tmux</code> session is attached to a Minecraft server, +there is no reason you could not run a command like this:</p> + +<pre class="terminal"> +$ tmux send-keys "tell @a This is a Test" Enter +</pre> + +<p>This will send the text “tell @a This is a Test” to the Minecraft server. +Then, it will hit the newline character, this will execute the command.</p> + +<p>So now we can send information to the server and have it tell the users something.</p> + +<p>But how do we get information about who is typing what in the Minecraft chat?</p> + +<h3 id="tmuxs-capture-pane-is-painful"><code class="highlighter-rouge">tmux</code>’s <code class="highlighter-rouge">capture-pane</code> is painful</h3> + +<p>So in the manual page for <code class="highlighter-rouge">tmux</code> I can see a section recorded below for options I can give to the <code class="highlighter-rouge">capture-pane</code> subcommand.</p> + +<pre class="terminal"> + -S and -E specify the starting and ending line numbers, + zero is the first line of the visible pane and negative + numbers are lines in the history. ‘-’ to -S is the start + of the history and to -E the end of the visible pane. The + default is to capture only the visible contents of the pane. +</pre> + +<p>What it seems to be saying is I can start at line <code class="highlighter-rouge">-S n</code> and end at line <code class="highlighter-rouge">-E n</code>. +Negative numbers start from the bottom, so <em>in theory</em> I can do the following: <code class="highlighter-rouge">tmux capture-pane -S -1</code> should capture only the last line, because I’m starting from the last line. Right?</p> + +<p>No. It just doesn’t work. Negative numbers do <em>not</em> work with the <code class="highlighter-rouge">tmux capture-pane</code> subcommand.</p> + +<p>So I did some simple UNIX piping, like so, to get just the last thing in the chat. +<code class="highlighter-rouge">-p</code> prints the result to the terminal/stdout. +<code class="highlighter-rouge">steve</code> is the name of the tmux session I’m trying to pull form.</p> + +<pre class="terminal"> +$ tmux capture-pane -p -t steve | tail -n1 +[SERVER] [ExtraDebuggingInfoHere]: &lt;TaterTheTot&gt; MY_MESSAGE +</pre> + +<p>So that’s done! Beauty!</p> + +<p>So now I have a line which will look something like this:</p> + +<p><code class="highlighter-rouge">[SERVER] [ExtraDebugInfoHere]: &lt;TaterTheTot&gt; MY_MESSAGE</code></p> + +<p>TaterTheTot is my Minecraft username :)</p> + +<p>So, how can we get only the message I wrote, and my username?</p> + +<h3 id="grep"><code class="highlighter-rouge">grep</code></h3> + +<p><code class="highlighter-rouge">grep</code> is a command to find patterns of text. +<code class="highlighter-rouge">grep</code> has an option to only show a matching pattern of text. +This option is <code class="highlighter-rouge">-o</code>.</p> + +<p>Let’s see how we can use this in conjunction with our latest line of server output to get our results.</p> + +<pre class="terminal"> +$ echo "[DEBUG] [SERVER] blah blah: &lt;TaterTheTot&gt; MY_MESAGE" | grep -o "&lt;.&ast;&gt;" +&lt;TaterTheTot&gt; +</pre> + +<p>Now, that’s my name with the &lt; and &gt; attached. Not bad! +We can use the <code class="highlighter-rouge">sed</code> command to clean it up a bit.</p> + +<p>The syntax is like so: <code class="highlighter-rouge">select/somepattern/replacewith/global</code></p> + +<p>So the following command is: <code class="highlighter-rouge">s/[&lt;&gt;]//g</code></p> + +<p>Select any characters that are either &lt; or &gt;. +Replace with nothing. +Do so globally (as in, don’t stop after you replace only one character).</p> + +<p>Take two!</p> + +<pre class="terminal"> +$ echo "[DEBUG] [SERVER] blah blah: &lt;TaterTheTot&gt; MY_MESAGE" | grep -o "&lt;.&ast;&gt;" | sed 's/[&lt;&gt;]//g' +TaterTheTot +</pre> + +<p>Beautiful!</p> + +<p>Now what about that pesky message?</p> + +<h3 id="more-grep-more-sed">more <code class="highlighter-rouge">grep</code>; more <code class="highlighter-rouge">sed</code></h3> + +<p>Simple: capture everything after the &gt;. Leaving the user’s message entirely in tact.</p> + +<pre class="terminal"> +$ echo "[DEBUG] [SERVER] blah blah: &lt;TaterTheTot&gt; MY_MESAGE" | grep -o "&gt;.&ast;$" | sed 's/&gt; //' +MY_MESSAGE +</pre> + +<p>So now we have a way to get the username of someone typing in the Minecraft server chat. +We have a way to find out what they said. +And, we have a way to respond.</p> + +<p>You can imagine how these might go together for your own use case.</p> + +<h3 id="conclusion">Conclusion</h3> + +<p>This shows some pretty fun stuff you can do with a few simple Linux commands and a Minecraft server.</p> + +<p>I hope you learned something and found my explanations not horrific haha!</p> + +<p>Remember to checkout the git repository to see what I did with it: <a href="https://github.com/TTWNO/termcraft">https://github.com/TTWNO/termcraft</a>.</p> + +<p>Happy hacking!</p>So recently I had problem. I run a Minecraft server on a big Linux computer I have running in my room. Now, as a system administrator it is very helpful to be able to run some simple commands without needing to login with my key, password, TFA, etc. It is, frankly, a lot of work. Especially when I really just want to be playing games, but something seems to be wrong.Site Update2020-06-04T00:00:00+00:002020-06-04T00:00:00+00:00http://localhost:4000/2020/06/04/site-update<p>I updated the site with some easier to identify information about me and my projects :)</p> <p>Also, Clue has been delayed due to my partner in crime on the project wokring too many hours.</p> @@ -853,53 +986,4 @@ I will discuss this more in another article, but for the technically inclined:&l <ol> <li><a href="https://en.wikipedia.org/wiki/RSA_(cryptosystem)">RSA</a>/<a href="https://en.wikipedia.org/wiki/Elliptic-curve_cryptography">EC</a> provides <em>very</em> large cryptographic keys. It would be impossible for a human to encrypt or decrypt a message manually.</li> <li><a href="https://www.youtube.com/watch?v=GSIDS_lvRv4">Asymetric cryptography</a> provides four keys, instead of just one; stopping evesdroppers from listening in on your secret conversations—even if you do not have the chance to exchange keys in advance.</li> -</ol>taitThere are many kinds of encryption used in our everyday communication. Online and offline, over the internet and in person. In this article, I will explain the basics of how encryption should work in theory. I explain in this article why encryption is important, and why you should care about it.Is Encryption Worth It?2020-01-26T00:00:00+00:002020-01-26T00:00:00+00:00http://localhost:4000/2020/01/26/rsa1<p>What is the most embarassing thing you have typed into Google search? What is the most personal secret you told a friend in confidence? What is your bank password? What is your business’s secret to stay ahead of the competition?</p> - -<p>Now at first these questions may seem not completely related. There is a point though: You likely sent all of this information over the internet.</p> - -<p>When you send that messege to your friend or business partner, why is it that any person can’t just listen to the signals coming from your phone or laptop and know what you sent to your friend or colleague? The answer: encryption.</p> - -<p>First, some background about internet privacy. You can’t have a conversation about internet encryption and privacy without discussing the man himself:</p> - -<h3 id="snowden">Snowden</h3> - -<p><a href="https://en.wikipedia.org/wiki/Edward_Snowden" target="_blank">Edward Joseph Snowden</a> is an ex-NSA, ex-CIA employee who felt the <a href="https://en.wikipedia.org/wiki/Fourth_Amendment_to_the_United_States_Constitution" target="_blank">United State’s 4th Ammendment</a> was being violated by their programs of msas survailence. -Snowden was raised a staunch establishmentarian conservative; his girlfriend Lisndey however, slowly started changing his mind. Snowden became very influenced by the ideology of <a href="https://en.wikipedia.org/wiki/Populism" target="_blank">populism</a>. -His populist thinking is shown very clearly when he explains his reasoning for his disclosure of humongous troves of NSA documents.</p> - -<blockquote> - <p>“My sole motive is to inform the public as to that which is done in their name and that which is done against them.” -—<a href="https://www.theguardian.com/world/video/2013/jun/09/nsa-whistleblower-edward-snowden-interview-video" target="_blank">Edward Snowden</a></p> -</blockquote> - -<p>Snowden’s first set of leaks went public in <a href="https://www.theguardian.com/world/2013/sep/05/nsa-gchq-encryption-codes-security" target="_blank">The Gaurdian</a>, <a href="https://www.nytimes.com/2013/06/10/us/former-cia-worker-says-he-leaked-surveillance-data.html" target="_blank">The New York Times</a>, and <a href="https://www.propublica.org/article/the-nsas-secret-campaign-to-crack-undermine-internet-encryption" target="_blank">ProPublica</a> in late 2013; -people started to realize that their governments and internet service providers (ISPs) <strong>are</strong> listening. People understood there might be more sinister motives than “national security” at play.</p> - -<p>Personally, I have seen a lot of non-tech-savy individuals using security-conscious software when I am helping them fix a problem. -In fact, there was one time I saw a collage student from rural Alberta who had a VPN running on her phone. This impressed me!</p> - -<h3 id="encryption-on-the-web">Encryption on The Web</h3> - -<p>The type of encryption used on the web is called: HyperText Transfer Protocol–Secure (HTTPS). -This kind of encryption stops two things from happening: A) it stops the information you are sending and recieving online from being seen by easvesdroppers and criminals, and B) stops those same third-parties from tampering with the data.</p> - -<p>Without HTTPS it is possible for sombody to listen in and change the data being sent between you and a server.</p> - -<p>Only in recent years has HTTPS become near-universal across the web. It is used even on the simplest sites these days: this one included. After 2013, people became weary of government, criminal, and ISP interference with their web traffic. -This can be backed up by statistics: -The level of encrypted web traffic around the time of the Snowden leaks was around 30 percent. It was mostly used by banks, email providers, government, and journalists. -At the turn of the 2020s however, this has risen to nearly 90 percent among U.S. users of Firefox. -Japan lags slightly behind with 80 percent encrypted traffic.</p> - -<figure> - <img src="/assets/img/encrypted-web-traffic.png" alt="Use of encrypted web traffic incresing over time." /> - <figcaption> - More at: <a href="https://letsencrypt.org/stats/" target="_blank">Let's Encrypt</a> - </figcaption> -</figure> - -<p>This is just the data we know of. You can disable the <a href="https://en.wikipedia.org/wiki/Telemetry#Software" target="_blank">telemetry</a> settings in Firefox, and it is very likely that hardcore privacy advocates would disable this data collection, so perhaps the amount of encrypted web traffic is slightly higher.</p> - -<h3 id="what-about-rsa">What about RSA?</h3> - -<p>RSA is an encryption method named after the initials of the inventors’ sir names: Ron <strong>R</strong>ivest, Adi <strong>S</strong>hamir, and Leonard <strong>A</strong>dleman. It uses the mathematical “factoring problem” to secure communication. The details of this specific type of encryption will be discussed in an article soon to come.</p>taitWhat is the most embarassing thing you have typed into Google search? What is the most personal secret you told a friend in confidence? What is your bank password? What is your business’s secret to stay ahead of the competition? \ No newline at end of file +</ol>taitThere are many kinds of encryption used in our everyday communication. Online and offline, over the internet and in person. In this article, I will explain the basics of how encryption should work in theory. I explain in this article why encryption is important, and why you should care about it. \ No newline at end of file diff --git a/_site/sitemap.xml b/_site/sitemap.xml index 6e1b3cf..781faf4 100644 --- a/_site/sitemap.xml +++ b/_site/sitemap.xml @@ -45,6 +45,10 @@ 2020-06-04T00:00:00+00:00 +http://localhost:4000/2020/06/25/tmux-minecraft.html +2020-06-25T00:00:00+00:00 + + http://localhost:4000/2020-04-27-quiz-your-friends-xss.html