Giter VIP home page Giter VIP logo

raffle-server's Introduction

Raffle server ๐ŸŽŸ

A cute little web socket server that can start a raffle, add some players, and pick a winner. Players join through a join code set by the host and are notified if they've won when a winner is picked.

Connections should communicate through json encoded messages as specified under Usage.

Requirements

  • composer
  • PHP ^8.1

Usage

composer install
php ./bin/start.php

The server is now running on localhost:8080.

Start a raffle

  1. Connect to the server using a web socket client. To try it out, open a browser tab, and in the console type:

    ws = new WebSocket('ws://localhost:8080')

    You can now start sending messages to the server with ws.send()

  2. Register as a host by sending a registerHost message. This will start the raffle pool. The join code provided is the code that joining players will have to send.

    {"message":  "registerHost", "joinCode":  "1234"}
  3. Players can join the pool by connecting to the server (see: step 1), and sending a registerPlayer message:

    {"message":  "registerPlayer", "username": "Veg McCabbage", "joinCode":  "1234"}
  4. Pick a winner by sending a pickWinner message:

    {"message":  "pickWinner"}

    Players will then be notified about their win (You won!) or loss (Better luck next time...). The host will also be notified of the winner.

  5. The pool will remain open to pick more winners, as long as the host is connected and the pool isn't timed out.

Further usage notes

  • Messages sent from the raffle server to clients will always be json encoded and will have either a message or an error property.
  • One pool may be active at any given time (may change in future versions). To start a new pool, the current host must first disconnect.
  • The pool will be closed automatically when the host disconnects or when it times out (defaults to 1 hour). Players will automatically be disconnected as well.
  • Usernames must be unique per pool so the host may be notified.
  • In future versions of this raffle server, you'll be able to override defaults (e.g. port, win/loss message, timeout, max pool size, etc.).

raffle-server's People

Contributors

paulinevos avatar rdohms avatar dependabot[bot] avatar

Watchers

James Cloos 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.