Haven & Hearth-Extension

Forum for alternative clients, mods & discussions on the same.

Moderator: Phades

Haven & Hearth-Extension

Postby -DMZ- » Sun Jul 10, 2011 10:04 pm

I have been using this handy app a bunch lattly, it works good and is for Google chrome. Its has helped out when sever crashes so you would be the first to know when it comes back up because it checks server statues every 60 seconds.

.............................................................................................................................................................................................
A simple extension that periodically checks the server status of the indie MMO Haven & Hearth (http://www.havenandhearth.com).

The H&H game icon is displayed with a green overlay showing the current logged-in user count when the server is up; when the server is down, a black-and-white version of the icon is shown with a red overlay.

Desktop notifications are also displayed whenever the server changes state from up or down; these are enabled by default, but can be disabled on the extension's options page.

Status check intervals vary; by default, it checks every 5 minutes when the server is up and every 60 seconds when it's down. Version 0.2.0 introduces the ability to modify these intervals.

v0.2.1:
- fixed timer/update bug

v0.2.0:
- added popup; displays:
- in-game day, year and time
- last server heartbeat time
- links to H&H homepage, forum, wiki, and srv-state
- expanded options (right-click on icon, select "Options...") to include settings for up and down status check intervals (bounded at a minimum of 60 seconds each)

https://chrome.google.com/webstore/deta ... apmmkciimd
-DMZ-
 
Posts: 16
Joined: Tue Jun 28, 2011 10:12 pm

Re: Haven & Hearth-Extension

Postby Projeear » Sun Jul 10, 2011 10:05 pm

Alternative: Auto-refresher + Dual Monitor :D
Grand Walker of World 1 (w1).
Ex-Lawspeaker of New London, Deadwood and New Deadwood (w3).
Witness of the World 4 Great Explosion (w4).
Ex-Lawspeaker of Gregminster (w5).
Ex-Lawspeaker of Laketown (w6).
Squatter and Rebuilder of Templus Pacis (w6).
Hermit thereafter.
Lawspeaker of Tachbrookshire (Hafen 2)
User avatar
Projeear
 
Posts: 950
Joined: Tue Jan 11, 2011 2:02 am
Location: Jolly ol' England

Re: Haven & Hearth-Extension

Postby Radenk » Sun Jul 10, 2011 10:22 pm

Why Chrome? Why, why, why
User avatar
Radenk
 
Posts: 252
Joined: Mon Feb 07, 2011 11:38 am

Re: Haven & Hearth-Extension

Postby Projeear » Sun Jul 10, 2011 10:44 pm

Radenk wrote:Why Chrome? Why, why, why


I've been a fanatic Firefox.. fr..fo..Friend, for quite a while now. But lately, it's been laggy as shit starting up.

Meanwhile, Google Chrome is like, "Bro, you clicked me. All ready to go, bro, let's go."

"but I only just let go of the second cli-"

"LET'S GO. MOVE IT. NO TIME TO WASTE."
Grand Walker of World 1 (w1).
Ex-Lawspeaker of New London, Deadwood and New Deadwood (w3).
Witness of the World 4 Great Explosion (w4).
Ex-Lawspeaker of Gregminster (w5).
Ex-Lawspeaker of Laketown (w6).
Squatter and Rebuilder of Templus Pacis (w6).
Hermit thereafter.
Lawspeaker of Tachbrookshire (Hafen 2)
User avatar
Projeear
 
Posts: 950
Joined: Tue Jan 11, 2011 2:02 am
Location: Jolly ol' England

Re: Haven & Hearth-Extension

Postby Robertzon » Sun Jul 10, 2011 10:49 pm

RockMelt is better than everything.
User avatar
Robertzon
 
Posts: 1464
Joined: Mon Jan 03, 2011 11:51 pm

Re: Haven & Hearth-Extension

Postby burgingham » Mon Jul 11, 2011 6:46 am

Moved.
User avatar
burgingham
 
Posts: 8486
Joined: Fri Aug 14, 2009 10:58 pm

Re: Haven & Hearth-Extension

Postby Butko » Mon Jul 11, 2011 7:48 am

Projeear wrote:
Radenk wrote:Why Chrome? Why, why, why


I've been a fanatic Firefox.. fr..fo..Friend, for quite a while now. But lately, it's been laggy as shit starting up.

Meanwhile, Google Chrome is like, "Bro, you clicked me. All ready to go, bro, let's go."

"but I only just let go of the second cli-"

"LET'S GO. MOVE IT. NO TIME TO WASTE."

+1
Butko
 
Posts: 542
Joined: Tue Sep 07, 2010 10:05 am

Re: Haven & Hearth-Extension

Postby Radenk » Tue Jul 12, 2011 3:01 am

Projeear wrote:
Radenk wrote:Why Chrome? Why, why, why


I've been a fanatic Firefox.. fr..fo..Friend, for quite a while now. But lately, it's been laggy as shit starting up.

Meanwhile, Google Chrome is like, "Bro, you clicked me. All ready to go, bro, let's go."

"but I only just let go of the second cli-"

"LET'S GO. MOVE IT. NO TIME TO WASTE."

That's just because you haven't tried out Nightly.
User avatar
Radenk
 
Posts: 252
Joined: Mon Feb 07, 2011 11:38 am

Re: Haven & Hearth-Extension

Postby gt4329b » Wed Jul 20, 2011 3:21 pm

-DMZ- wrote:I have been using this handy app a bunch lattly, it works good and is for Google chrome. Its has helped out when sever crashes so you would be the first to know when it comes back up because it checks server statues every 60 seconds.


Glad you've found it useful. I'd like to add a moon phase indicator to it, but AFAIK there's no way to determine current moon phase from the globtime reported in srv-state :/

As to why Chrome: speed, memory footprint, ease of use.
"Also, the game was never user friendly." - jorb
User avatar
gt4329b
 
Posts: 64
Joined: Sun May 30, 2010 4:28 am
Location: 40.053482, -105.291904

Re: Haven & Hearth-Extension

Postby sabinati » Wed Jul 20, 2011 4:13 pm

kaka made this a long time ago, should be able to look at it and determine how to get moon phase

Code: Select all
#!/usr/bin/python
#encoding: utf8

# This application is released under the GNU General Public License
# v3 (or, at your option, any later version). You can find the full
# text of the license under http://www.gnu.org/licenses/gpl.txt.
# By using, editing and/or distributing this software you agree to
# the terms and conditions of this license.
# Thank you for using free software!

# HavenScreenlet (c) Kaka 2009 <kaka@dolda2000.com>

import screenlets
from screenlets.options import BoolOption, IntOption
import pango
import gobject
import math

class HavenScreenlet(screenlets.Screenlet):
    """A Haven &amp; Hearth screenlet"""

    __name__   = "HavenScreenlet"
    __version__   = "1.1"
    __author__   = "Kaka"
    __desc__   = __doc__

    server = None
    active = True
    gubbe = ""
    clock_timer = None

    # General settings
    update_interval = 1 # minutes
    notify_state    = True
    mini_view       = False

    def __init__(self, **keyword_args):
        screenlets.Screenlet.__init__(self, width = 200, height = 100, uses_theme = True, **keyword_args)
        self.theme_name = "default"

        self.server = self.get_server()
        self.info_timer = gobject.timeout_add(self.update_interval * 60000, self.update_info)

        self.add_menuitem("mini_view", "Toggle mini-view")
        self.add_options_group("General", "General settings for this shit")
        self.add_option(IntOption("General", "update_interval", self.update_interval, "Update interval (minutes)", "Time between updates of the servers state", min=1, max=20))
        self.add_option(BoolOption("General", "notify_state", self.notify_state, "Notify state changes", "Show a notification popup when the servers state changes"))
        self.add_option(BoolOption("General", "mini_view", self.mini_view, "Show mini-view", "Shows a miniature view of the screenlet"))

    def on_after_set_atribute(self, name, value):
        if name == "update_interval":
            gobject.source_remove(self.info_timer)
            self.info_timer = gobject.timeout_add(self.update_interval * 60000, self.update_info)
        if name == "mini_view":
            self.set_size()
            self.redraw_canvas()

    def on_hide(self):
        self.active = False
        gobject.source_remove(self.info_timer)

    def on_init(self):
        self.add_default_menuitems()
        self.draw_buttons = False

    def on_load_theme(self):
        if self.clock_timer is not None:
            gobject.source_remove(self.clock_timer)
        if self.theme_name == "default":
            import os, random
            self.gubbe = random.sample(os.listdir(self.theme.path + "/gubbs"), 1)[0]
        elif self.theme_name == "berdel black":
            self.clock_timer = gobject.timeout_add(20000, self.update_clock)
        elif self.theme_name == "winter white":
            self.clock_timer = gobject.timeout_add(20000, self.update_clock)
        self.set_size()

    def on_menuitem_select(self, id):
        if id == "mini_view":
            self.mini_view = not self.mini_view
            self.set_size()
            self.redraw_canvas()

    def on_mouse_enter(self, event):
        if self.theme_name == "default":
            if self.server and self.server.state == "up":
                if self.mini_view: self.show_tooltip("%s - %s hearthlings online" % (self.server.stime(), self.server.chars), self.x + self.mousex, self.y + self.mousey)
                else:              self.show_tooltip(self.server.stime(), self.x + self.mousex, self.y + self.mousey)
            else:
                self.show_tooltip("The server appears to have %s since %s ago" % (self.server.state, self.server.inactivetime()), self.x + self.mousex, self.y + self.mousey)
        elif self.theme_name == "berdel black":
            if self.mini_view:
                self.show_tooltip("%s - %s hearthlings online" % (self.server.stime(), self.server.chars), self.x + self.mousex, self.y + self.mousey)
        elif self.theme_name == "winter white":
            if self.mini_view:
                self.show_tooltip("%s - %s hearthlings online" % (self.server.stime(), self.server.chars), self.x + self.mousex, self.y + self.mousey)

    def on_mouse_leave(self, event):
        self.hide_tooltip()

    def on_quit(self):
        return True

    def on_show(self):
        self.active = True
        self.server = self.get_server()
        gobject.source_remove(self.info_timer)
        self.info_timer = gobject.timeout_add(60000, self.update_info)

    def on_draw(self, ctx):
        if self.theme:
            ctx.scale(self.scale, self.scale)

            ### DEFAULT THEME ###
            if self.theme_name == "default":
                def draw_calendar(x, y, draw_setting = False):
                    if 6 <= self.server.time[2] < 18: daystate = "day"
                    else:                             daystate = "night"
                    timeofday = self.server.globtime % (60*60*24)
                    a = 2 * math.pi * timeofday / float(60*60*24)
                    moonc = -math.sin(a) * 23 + x + 61, -math.cos(a) * 23 + y + 29
                    sunc =   math.sin(a) * 23 + x + 59,  math.cos(a) * 23 + y + 27
                    path = self.theme.path + "/calendar/"
                    if draw_setting:
                        self.draw_image(ctx, x, y, path + "setting.png")
                    self.draw_image(ctx, x, y, path + "%ssky.png" % daystate)
                    self.draw_image(ctx, moonc[0], moonc[1], path + "m0%s.png" % self.server.moonphase)
                    self.draw_image(ctx, sunc[0],  sunc[1],  path + "sun.png")
                    self.draw_image(ctx, x, y, path + "%sscape.png" % daystate)

                if not self.mini_view:
                    if self.server and self.server.state == "up":
                        draw_calendar(-32, 1)
                        img = "/gubbs/" + self.gubbe
                    else:
                        self.draw_image(ctx, 0, 0, self.theme.path + "/crashcircle.png")
                        img = "/crashx.png"
                    self.theme.render(ctx, "frame")
                    self.draw_image(ctx, 0, 0, self.theme.path + img)
                    if self.server and self.server.state == "up":
                        self.draw_image(ctx, 0, 0, self.theme.path + "/times.png")
                        offset = (3 - len(str(self.server.chars))) * 17
                        for n, c in enumerate(str(self.server.chars)):
                            self.draw_image(ctx, 46 + offset + n*17, 4, self.theme.path + "/digits/" + c + ".png")
                else:
                    if self.server and self.server.state == "up":
                        draw_calendar(0, 0, True)
                    else:
                        self.draw_image(ctx, 0, 0, self.theme.path + "/calendar/setting.png")
                        self.draw_image(ctx, 32, -1, self.theme.path + "/crashcircle.png")

            ### BLACK THEME ###
            elif self.theme_name == "berdel black":
                if not self.mini_view:
                    self.theme.render(ctx, "bg")
                    self.draw_str(ctx, "Haven &amp; Hearth", 10, 5, "Monospace", 16)
                    ctx.set_source_rgba(1, 1, 1, 0.5)
                    self.draw_line(ctx, 10, 35.5, self.width - 20, 0, 1)
                    ctx.set_source_rgba(0, 0, 0, 0.5)
                    self.draw_line(ctx, 10, 35, self.width - 20, 0, 1)

                    if self.server:
                        font = "Monospace"
                        fsize = 12
    #                    self.server.state = "crashed"
                        if self.server.state == "up":
                            self.draw_str(ctx, self.server.stime(), 15, 45, font, fsize)
                            self.draw_str(ctx, "%s online" % self.server.chars, 15, 65, font, fsize)
                            if 6 <= self.server.time[2] < 18:
                                self.draw_scaled_image(ctx, 130, 40, self.theme.path + "/sun.png", 50, 50)
                                self.draw_scaled_image(ctx, 137.5, 47.5, self.theme.path + "/moon/%s.png" % self.server.moonphase, 35, 35)
                            else:
                                self.draw_scaled_image(ctx, 130, 40, self.theme.path + "/moon/%s.png" % self.server.moonphase, 50, 50)

                        elif self.server.state == "no connection":
                            self.draw_str(ctx, "Failed to connect to server :(", 15, 45, font, fsize)

                        else:
                            import time
                            elapsedtime = int(time.time()) - self.server.lastbeat
                            m, h = elapsedtime % 3600 / 60, elapsedtime % 86400 / 3600
                            self.draw_str(ctx, "Server " + self.server.state, 15, 45, font, fsize)
                            self.draw_str(ctx, self.server.inactivetime(), 15, 65, font, fsize)
                            self.draw_image(ctx, 138, 63, self.theme.path + "/cow.png")
                else:
                    self.theme.render(ctx, "bg_mini")
                    if self.server:
                        if self.server.state == "up":
                            if 6 <= self.server.time[2] < 18:
                                self.draw_scaled_image(ctx, 3, 3, self.theme.path + "/sun.png", 50, 50)
                                self.draw_scaled_image(ctx, 10.5, 10.5, self.theme.path + "/moon/%s.png" % self.server.moonphase, 35, 35)
                            else:
                                self.draw_scaled_image(ctx, 3, 3, self.theme.path + "/moon/%s.png" % self.server.moonphase, 50, 50)
                        else:
                            self.draw_image(ctx, 2, 15, self.theme.path + "/cow.png")

            ### WINTER WHITE THEME ###
            elif self.theme_name == "winter white":
                def draw_calendar(x, y):
                    if   9 <= self.server.time[2] < 15: daystate = "day0"
                    elif 8 <= self.server.time[2] < 16: daystate = "day1"
                    elif 7 <= self.server.time[2] < 17: daystate = "day2"
                    elif 6 <= self.server.time[2] < 18: daystate = "day3"
                    else:                               daystate = "night"
                    timeofday = self.server.globtime % (60*60*24)
                    a = 2 * math.pi * timeofday / float(60*60*24)
                    moonc = -math.sin(a) * 18 + x + 25, -math.cos(a) * 15 + y + 25
                    sunc =   math.sin(a) * 18 + x + 21,  math.cos(a) * 15 + y + 21
                    self.draw_image(ctx, x, y, self.theme.path + "/%s/sky.png" % daystate)
                    if 16 <= self.server.time[2] <= 24 or 0 <= self.server.time[2] <= 6:
                        self.draw_image(ctx, moonc[0], moonc[1], self.theme.path + "/moon/%s.png" % self.server.moonphase)
                    if 4 <= self.server.time[2] <= 18:
                        self.draw_image(ctx, sunc[0],  sunc[1],  self.theme.path + "/sun.png")
                    self.draw_image(ctx, x, y, self.theme.path + "/%s/ground.png" % daystate)

                if not self.mini_view:
                    self.theme.render(ctx, "bg")
                    self.draw_str(ctx, "Haven &amp; Hearth", 10, 5, "Monospace", 12)
                    ctx.set_source_rgba(1, 1, 1, 0.25)
                    self.draw_line(ctx, 10, 26.5, self.width - 20, 0, 1)
                    ctx.set_source_rgba(0, 0, 0, 0.25)
                    self.draw_line(ctx, 10, 26, self.width - 20, 0, 1)

                    if self.server:
                        font = "Monospace"
                        fsize = 10
    #                    self.server.state = "crashed"
                        if self.server.state == "up":
                            self.draw_str(ctx, self.server.stime(), 12, 35, font, fsize)
                            self.draw_str(ctx, "%s online" % self.server.chars, 12, 50, font, fsize)
                            draw_calendar(90, 30)

                        elif self.server.state == "no connection":
                            self.draw_str(ctx, "Failed to connect to server :(", 12, 35, font, fsize)

                        else:
                            self.draw_str(ctx, "Server " + self.server.state, 12, 30, font, fsize)
                            self.draw_str(ctx, self.server.inactivetime(), 12, 50, font, fsize)
                            self.draw_image(ctx, 105, 45, self.theme.path + "/cow.png")
                else:
                    if self.server:
                        if self.server.state == "up":
                            draw_calendar(0, 0)
                        else:
                            self.draw_image(ctx, 5, 10, self.theme.path + "/cow.png")

    def on_draw_shape(self, ctx):
        self.on_draw(ctx)

    ### Cake functions ###

    def notify(self, text):
        if self.notify_state:
            self.show_notification(text)
            gobject.timeout_add(3000, self.hide_notification)

    def on_server_crash(self):
        self.notify("Oh noes! :O\nThe Haven server has crashed!")

    def on_server_restart(self):
        self.notify("Yay! \\o/\nThe Haven server has restarted!")

    def draw_str(self, ctx, text, x, y, font, fontsize, width = None):
        width = width or (self.width - x)
        ctx.set_source_rgba(1, 1, 1, 0.55)
        self.draw_text(ctx, text, x + 1, y + 1, font, fontsize, width, pango.ALIGN_LEFT)
        ctx.set_source_rgba(0, 0, 0, 0.55)
        self.draw_text(ctx, text, x,     y,     font, fontsize, width, pango.ALIGN_LEFT)

    def pluralize(count, singular, plural = None):
        if count == 1: return singular
        else:          return (plural is None and singular + "s") or plural

    def set_size(self):
        if self.theme_name == "default":
            if self.mini_view: self.width, self.height = 134, 71
            else:              self.width, self.height = 139, 70
        elif self.theme_name == "berdel black":
            if self.mini_view: self.width, self.height = 55, 55
            else:              self.width, self.height = 200, 100
        elif self.theme_name == "winter white":
            if self.mini_view: self.width, self.height = 63, 46
            else:              self.width, self.height = 160, 80

    def update_info(self):
        if self.active:
            if self.server: old_state = self.server.state
            else:           old_state = None
            self.server = self.get_server()
            self.redraw_canvas()
            if old_state == "up" and self.server.state not in ["up", "no connection"]: self.on_server_crash()
            if old_state not in [None, "up", "no connection"] and self.server.state == "up": self.on_server_restart()
            gobject.source_remove(self.clock_timer)
            self.clock_timer = gobject.timeout_add(20000, self.update_clock)
        return True

    def update_clock(self):
        if self.server:
            self.server.globtime += 60
            self.server.calctime()
            self.redraw_canvas()
        return True

    def get_server(self):
        def get(dict, attr, defret):
            if attr in dict: return (isinstance(defret, int) and int(dict[attr]) or dict[attr])
            else:            return defret

        class server(object):
            def __init__(self, srv):
                import time
                self.state = get(srv, "state", "no connection")
                #self.users = get(srv, "users", 0)
                self.chars = get(srv, "chars", 0)
                self.lastbeat = get(srv, "lastbeat", 0)
                self.lasttime = time.ctime(self.lastbeat)
                self.globtime = get(srv, "globtime", 0)
                self.moonphase = 0
                self.calctime()

            def calctime(self):
                self.time = [
                    self.globtime % 60,                               # Second
                    self.globtime % (60*60) / 60,                     # Minute
                    self.globtime % (60*60*24) / (60*60),             # Hour
                    self.globtime % (60*60*24*30) / (60*60*24),       # Day
                    self.globtime % (60*60*24*30*12) / (60*60*24*30), # Month
                    self.globtime / (60*60*24*30*12)                  # Year
                    ]
                self.moonphase = int(8 * (self.time[3] / 30.0))

            def moonphase(self):
                return (15 - abs(15 - self.time[3])) / 0.15

            def stime(self):
                return "%02d:%02d" % (self.time[2], self.time[1])

            def inactivetime(self):
                import time
                elapsedtime = int(time.time()) - self.lastbeat
                return "%02d:%02d" % (elapsedtime % 86400 / 3600, elapsedtime % 3600 / 60)


        params = {}
        try:
            import urllib
            file = urllib.urlopen("http://www.havenandhearth.com/portal/srv-state")
            for line in file.readlines():
                k, v = line.split()
                params[k] = v
        except: pass
        return server(params)

if __name__ == "__main__":
    import screenlets.session
    screenlets.session.create_session(HavenScreenlet)
User avatar
sabinati
 
Posts: 15513
Joined: Mon Jul 13, 2009 4:25 am
Location: View active topics

Next

Return to The Wizards' Tower

Who is online

Users browsing this forum: Ahrefs [Bot], Claude [Bot] and 1 guest