# evennia.server.portal.grapevine

Grapevine network connection

This is an implementation of the Grapevine Websocket protocol v 1.0.0 as outlined here: https://grapevine.haus/docs

This will allow the linked game to transfer status as well as connects the grapevine client to in-game channels.

class `evennia.server.portal.grapevine.``RestartingWebsocketServerFactory`(sessionhandler, *args, **kwargs)

  Bases: `autobahn.twisted.websocket.WebSocketClientFactory`, `twisted.internet.protocol.ReconnectingClientFactory`

  A variant of the websocket-factory that auto-reconnects.

  `initialDelay` = 1
  `factor` = 1.5
  `maxDelay` = 60
  `__init__`(sessionhandler, *args, **kwargs)

    In addition to all arguments to the constructor of :func:autobahn.websocket.interfaces.IWebSocketClientChannelFactory, you can supply a **reactor** keyword argument to specify the Twisted reactor to be used.

  `buildProtocol`(addr)

    Build new instance of protocol

    Parameters

      addr (str) – Not used, using factory/settings data

  `startedConnecting`(connector)

    Tracks reconnections for debugging.

    Parameters

      connector (Connector) – Represents the connection.

  `clientConnectionFailed`(connector, reason)

    Called when Client failed to connect.

    Parameters

      - connector (Connection) – Represents the connection.

      - reason (str) – The reason for the failure.

  `clientConnectionLost`(connector, reason)

    Called when Client loses connection.

    Parameters

      - connector (Connection) – Represents the connection.

      - reason (str) – The reason for the failure.

  `reconnect`()

    Force a reconnection of the bot protocol. This requires de-registering the session and then reattaching a new one, otherwise you end up with an ever growing number of bot sessions.

  `start`()

    Connect protocol to remote server

class `evennia.server.portal.grapevine.``GrapevineClient`

  Bases: `autobahn.twisted.websocket.WebSocketClientProtocol`, `evennia.server.session.Session`

  Implements the grapevine client

  `__init__`()

    Initialize self. See help(type(self)) for accurate signature.

  `at_login`()
  `onOpen`()

    Called when connection is established.

  `onMessage`(payload, isBinary)

    Callback fired when a complete WebSocket message was received.

    Parameters

      - payload (bytes) – The WebSocket message received.

      - isBinary (bool) – Flag indicating whether payload is binary or UTF-8 encoded text.

  `onClose`(wasClean, code=None, reason=None)

    This is executed when the connection is lost for whatever reason. it can also be called directly, from the disconnect method.

    Parameters

      - wasClean (bool) – **True** if the WebSocket was closed cleanly.

      - code (int or None) – Close status as sent by the WebSocket peer.

      - reason (str or None) – Close reason as sent by the WebSocket peer.

  `disconnect`(reason=None)

    Generic hook for the engine to call in order to disconnect this protocol.

    Parameters

      reason (str or None) – Motivation for the disconnection.

  `send_authenticate`(*args, **kwargs)

    Send grapevine authentication. This should be send immediately upon connection.

  `send_heartbeat`(*args, **kwargs)

    Send heartbeat to remote grapevine server.

  `send_subscribe`(channelname, *args, **kwargs)

    Subscribe to new grapevine channel

    Use with session.msg(subscribe=”channelname”)

  `send_unsubscribe`(channelname, *args, **kwargs)

    Un-subscribe to a grapevine channel

    Use with session.msg(unsubscribe=”channelname”)

  `send_channel`(text, channel, sender, *args, **kwargs)

    Send text type Evennia -> grapevine

    This is the channels/send message type

    Use with session.msg(channel=(message, channel, sender))

  `send_default`(*args, **kwargs)

    Ignore other outputfuncs

  `data_in`(data, **kwargs)

    Send data grapevine -> Evennia

    Keyword Arguments

      data (dict) – Converted json data.