Coder Social home page Coder Social logo

edg-l / teeobserver Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 84 KB

This tool continuously fetches the DDNet master server and observes the changes, broadcasting the events and providing a API.

Home Page: https://observer.ddstats.org

License: GNU Affero General Public License v3.0

Rust 93.04% HTML 6.96%

teeobserver's Introduction

teeobserver

This tool continuously fetches the DDNet master server and observes the changes, broadcasting the events to connected websockets.

By default it listens to 127.0.0.1:3000 and the websocket connection is at ws://localhost:3000/ws

Port can be changed with the PORT environment variable.

> RUST_LOG="teeobserver=debug"
> teeobserver
2023-10-02T14:18:54.933535Z DEBUG teeobserver::util: making request to master
2023-10-02T14:18:55.419999Z DEBUG teeobserver::util: got 1139 servers
2023-10-02T14:18:55.421385Z  INFO teeobserver: listening on http://127.0.0.1:3000
2023-10-02T14:18:55.422382Z DEBUG teeobserver::util: making request to master
2023-10-02T14:18:55.525406Z DEBUG teeobserver::util: got 1139 servers
2023-10-02T14:18:55.530730Z  INFO teeobserver: sent 0 events to 0 receivers
2023-10-02T14:18:57.627921Z  INFO teeobserver::routes: `websocket: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0` at 127.0.0.1:44564 connected.
2023-10-02T14:19:05.422137Z DEBUG teeobserver::util: making request to master
2023-10-02T14:19:05.554810Z DEBUG teeobserver::util: got 1139 servers
2023-10-02T14:19:05.559945Z  INFO teeobserver: sent 68 events to 1 receivers
2023-10-02T14:19:15.421549Z DEBUG teeobserver::util: making request to master
2023-10-02T14:19:15.540133Z DEBUG teeobserver::util: got 1139 servers
2023-10-02T14:19:15.545310Z  INFO teeobserver: sent 75 events to 1 receivers

To connect with a simple webpage:

<html>
<body>
</body>
<script>
// Create WebSocket connection.
const socket = new WebSocket("ws://localhost:3000/ws");

// Listen for messages
socket.addEventListener("message", (event) => {
  console.log("Message from server ", event.data);
});

</script>
</html>

Useful typescript interfaces:

// Event structure send to the websocket

export interface MasterEvent {
    observers: number
    event: Event
    time: string
}

export interface Event {
    ClientJoined?: ClientJoined
    ClientLeft?: ClientLeft
    ServerWentOffline?: ServerWentOffline
    ServerWentOnline?: ServerWentOnline
}

export interface ClientLeft {
    client: Client
    server: Server
}

export interface ClientJoined {
    client: Client
    server: Server
}

export interface ServerWentOffline {
    addresses: string[]
    info: Info
    location: string
}

export interface ServerWentOnline {
    addresses: string[]
    info: Info
    location: string
}

export interface Client {
    afk?: boolean
    clan: string
    country: number
    is_player: boolean
    name: string
    score: number
    skin: Skin
    team?: number
}

export interface Skin {
    color_body?: number
    color_feet?: number
    name: string
}

export interface Server {
    addresses: string[]
    info: Info
    location: string
}

export interface Info {
    client_score_kind?: string
    clients: Client[]
    game_type: string
    map: Map
    max_clients: number
    max_players: number
    name: string
    passworded: boolean
    version: string
}

export interface Map {
    name: string
    sha256?: string
    size: number
}

teeobserver's People

Contributors

edg-l avatar

Stargazers

Chiller Dragon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.