Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use No IP Dynamic DNS #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ Steps to get up-and-running on Heroku:
# to set the MCL_EC2_REGION variable
$ heroku config:set MCL_EC2_REGION=<EC2 region name>

# Optional Dynamic DNS Settings
# If you don't want to have a constantly-changing IP address, you can add your
# login credentials for https://www.noip.com (which is free!)
#
# This service gives you a URL that Minecloud will automatically point
# to your server IP and keep up to date.
$ heroku config:set NO_IP_HOSTNAME=my-great-hostname.servegame.com
$ heroku config:set [email protected]
$ heroku config:set NO_IP_PASSWORD=secretpassword

# Review all your settings
$ heroku config

Expand Down
16 changes: 16 additions & 0 deletions minecloud/launcher/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from .models import Instance
from .sseview import send_event

import urllib
import urllib2
import base64
import string

@task
def launch(instance_id):
# Retrive instance obj from DB.
Expand Down Expand Up @@ -64,6 +69,17 @@ def launch(instance_id):
instance.save()
send_event('instance_state', instance.state)

# Update dynamic IP
dynamic_ip_hostname = os.getenv('NO_IP_HOSTNAME', None)
dynamic_ip_username = os.getenv('NO_IP_USERNAME', None)
dynamic_ip_password = os.getenv('NO_IP_PASSWORD', None)
if dynamic_ip_hostname and dynamic_ip_username and dynamic_ip_password:
opener = urllib2.build_opener()
auth = base64.encodestring('%s:%s' % (dynamic_ip_username, dynamic_ip_password)).replace('\n', '')
opener.addheaders = [('User-agent', 'Minecloud-No-IP/1.0 http://github.com/toffer/minecloud'), ("Authorization", "Basic %s" % auth)]
url = "http://dynupdate.no-ip.com/nic/update?hostname=" + urllib.quote_plus(dynamic_ip_hostname) + "&myip=" + urllib.quote_plus(server.ip_address)
opener.open(url)

# Send task to check if instance is running
check_state.delay(instance_id, 'running')

Expand Down
8 changes: 5 additions & 3 deletions minecloud/launcher/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@
from .models import Instance, Session
from .sseview import SseView, send_event

import os

@login_required
def index(request):
instance = None
current_sessions = None
err_msg = None
running_instances = Instance.objects.exclude(state__exact='terminated')
if len(running_instances) == 1:
if len(running_instances) == 1:
instance = running_instances[0]
current_sessions = (Session.objects
.filter(instance_id__exact=instance.id)
.filter(logout__isnull=True)
)
elif len(running_instances) > 1:
err_msg = "Error: Multiple instances are running at once."
return render(request,
return render(request,
'launcher/index.html',
{'instance': instance,
'sessions': current_sessions,
'no_ip_hostname': os.getenv('NO_IP_HOSTNAME', None),
'err_msg': err_msg})

@login_required
@require_POST
def launch(request):
Expand Down
40 changes: 37 additions & 3 deletions templates/launcher/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ <h3>Server Info</h3>
</div>
{% elif instance and instance.state == 'pending' %}
<div id="msm-up">
<h2>Server is <span class="text-info">waking up</span> at <span class="text-info">{{ instance.ip_address }}</span>.</h2>
<h2>Server is <span class="text-info">waking up</span> at
<span class="text-info">
{% if no_ip_hostname %}
{{ no_ip_hostname }}
{% else %}
{{ instance.ip_address }}
{% endif %}
</span>
</h2>
<div class="row">
<div class="span9">
<div class="alert alert-info alert-block"><p>Now, it's restoring saved game data. Almost ready...</p></div>
Expand All @@ -41,6 +49,12 @@ <h3>Server Info</h3>
<td class="server-info-field">IP Address</td>
<td>{{ instance.ip_address }}</td>
</tr>
{% if no_ip_hostname %}
<tr>
<td class="server-info-field">DDNS Hostname</td>
<td>{{ no_ip_hostname }}</td>
</tr>
{% endif %}
<tr>
<td class="server-info-field">Start Time</td>
<td>{{ instance.start }}</td>
Expand All @@ -56,14 +70,28 @@ <h3>Server Info</h3>
</div>
{% elif instance and instance.state == 'running' %}
<div id="msm-up">
<h2>Server is <span class="text-success">running</span> at <span class="text-success">{{ instance.ip_address }}</span>.</h2>
<h2>Server is <span class="text-success">running</span> at
<span class="text-success">
{% if no_ip_hostname %}
{{ no_ip_hostname }}
{% else %}
{{ instance.ip_address }}
{% endif %}
</span>
</h2>
<div class="row">
<div class="span9">
<div class="alert alert-success alert-block">
<h4><p>Join the server!</p></h4>
<ul>
{% if no_ip_hostname %}
<li>Open Minecraft, click Multiplayer, and add a new server.</li>
<li>Copy above hostname into the Server Address field.</li>
{% else %}
<li>Open Minecraft, click Multiplayer, and edit the Server Info.</li>
<li>Copy the IP address into the Server Address field.</li>
<li>This IP address will change each time the server is restarted.</li>
{% endif %}
</ul>
</div>

Expand All @@ -74,6 +102,12 @@ <h3>Server Info</h3>
<td class="server-info-field">IP Address</td>
<td>{{ instance.ip_address }}</td>
</tr>
{% if no_ip_hostname %}
<tr>
<td class="server-info-field">DDNS Hostname</td>
<td>{{ no_ip_hostname }}</td>
</tr>
{% endif %}
<tr>
<td class="server-info-field">Start Time</td>
<td>{{ instance.start }}</td>
Expand Down Expand Up @@ -177,6 +211,6 @@ <h2>Server is <span class="text-error">sleeping</span>.</h2>
location.reload(true)
}, false);

});
});
</script>
{% endblock content %}